akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef pair<pl, ll> ppl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e3;
const char newl = '\n';

ll n;
vl a(MAX);

ll calculate(ll num) {
  ll cost=0;
  rep(i, n) cost += (a[i]-num)*(a[i]-num);
  return cost;
}

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

  cin >> n;
  ll sum=0;
  rep(i, n) {cin >> a[i]; sum += a[i];}
  
  ll e=sum/n, ans=INF;
  chmin(ans, calculate(e-1));
  chmin(ans, calculate(e));
  chmin(ans, calculate(e+1));
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
 
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;
}
ll max(ll a, ll b){
    if(a > b) return a;
    else return b;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}

int main(void){
    int H,W; cin >> H >> W;
    vector<vector<char>> S(H+2, vector<char>(W+2, '.'));
    for(int i = 1; i < H+1; i++){
        for(int j = 1; j < W+1; j++){
            cin >> S[i][j];
        }
    }
    
    for(int i = 1; i < H+1; i++){
        for(int j = 1; j < W+1; j++){
            if(S[i][j]  == '.'){
                int count = 0;
                for(int k = -1; k <= 1; k++){
                    for(int l = -1; l <= 1; l++){
                        if(S[i+k][j+l] == '#') count++;
                    }
                }
            cout << count;
            }else{
                cout << "#";
            }
        }
        cout << endl;
    }
    
}

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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

vector<vector<ll>> F;
vector<vector<ll>> P;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	F.resize(N);

	REP(i, N)
	{
		REP(j, 10)
		{
			ll a; cin >> a;
			F[i].push_back(a);
		}
	}

	P.resize(N);

	REP(i, N)
	{
		REP(j, 11)
		{
			ll a; cin >> a;
			P[i].push_back(a);
		}
	}

	ll res{-INF};
	for (ll bits = 0; bits < (1 << 10); ++bits)
	{
		bool ok{false};
		ll tmp{0};
		REP(n, N)
		{
			ll cnt{0};
			REP(i, 10)
			{
				if ((bits & (1 << i)) && F[n][i])
				{
					++cnt;
				}
			}

			if (cnt > 0) ok = true;
			tmp += P[n][cnt];
		}
		if (ok)
			res = max(res, tmp);
	}

	std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n;
    cin >> n;
    int ans = 1, cnt = 0;
    rep(i, n)
    {
        int a;
        cin >> a;
        int pos = 2 * cnt + 1;
        if (pos <= a)
        {
            cnt++;
            continue;
        }
        (ans *= cnt + 1) %= mod;
    }
    for (int i = 1; i <= cnt; i++)
        (ans *= i) %= mod;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.math.*;
import java.util.*;
import java.io.*;

class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	class SegTree {
		int n = 1;
		int[] v;

		public SegTree(int n) {
			while (this.n < n)
				this.n *= 2;
			v = new int[2 * this.n - 1];
		}

		void set(int k) {
			v[k] = 1;
			while (k > 0) {
				k = (k - 1) / 2;
				v[k] = v[2 * k + 1] + v[2 * k + 2];
			}
		}

		int query(int a, int b) {
			return query(0, n, a, b, 0);
		}

		int query(int l, int r, int a, int b, int k) {
			if (r <= a || b <= l)
				return 0;
			else if (a <= l && r <= b)
				return v[k];
			else {
				int vl = query(l, (l + r) / 2, a, b, 2 * k + 1);
				int vr = query((l + r) / 2, r, a, b, 2 * k + 2);
				return vl + vr;
			}

		}
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		//a...b
		//b...a
		long ans=0;
		long[][] cnt=new long[10][10];
		for(int i=1;i<=N;++i) {
			int i_=i;
			while(i_>=10)i_/=10;
			cnt[i%10][i_]++;
		}
		for(int i=0;i<10;++i)for(int j=0;j<10;++j) {
			ans+=cnt[i][j]*cnt[j][i];
		}
		System.out.println(ans);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int tempList[] = new int[3];
        for (int i = 0; i < 3; i++) {
            tempList[i] = sc.nextInt();
        }
        Arrays.sort(tempList);

        int[] anserList = {5, 5, 7};

        if (Arrays.equals(tempList, anserList)) {
            System.out.println("YES");
        }else {
            System.out.println("NO");
        }

    }
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//bool f[100001];//1000000以下の素数を調べよう！
//rrep(i,2,100001){
  //      f[i]=false;
    //}
//rrep(i,2,100001){
  //      if(!f[i]){
    //        for(int j=i+i;j<=100000;j+=i){
      //          f[j]=true;
        //    }
        //}
    //}
    //for(int i=3;i<=100000;i+=2){
      //  if(!f[i]){
        //    c[i]++;
      //  }
   // }

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

//-------------------------↓↓↓↓↓↓----------------------------

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

       cin >> s;
       rep(i,Size(s)){
           if(i%2==0){
               cout << s[i];
           }
       }
       cout << endl;
       
return 0;
}


Measured memory_bytes: 592
module Main where

import Data.Bool
import Data.Functor
import Data.List
import Data.Maybe

getInts :: IO [Int]
getInts = map read . words <$> getLine

getDice :: IO Dice
getDice = toDice <$> getInts

toDice :: [Int] -> Dice
toDice [u,v,w,x,y,z] = (u,v,w,x,y,z)

main :: IO ()
main = do
  { [n] <- getInts
  ; ds <- loop n
  ; putStrLn $ bool "No" "Yes" (n == (length $ group $ sort $ map (sort . trans) ds))
  }

loop :: Int -> IO [Dice]
loop 0 = return []
loop n = do
  { d  <- getDice
  ; ds <- loop (n-1)
  ; return (d:ds)
  }

type Dice = (Int,Int,Int,Int,Int,Int)

updowns :: Dice -> [Dice]
updowns d@(t,s,e,w,n,b) = [d,(b,s,w,e,n,t)]

spins d@(t,s,e,w,n,b) = [d,(s,w,b,t,e,n),(w,t,n,s,b,e)]

rots :: Dice -> [Dice]
rots d@(t,s,e,w,n,b) = [d,(t,e,n,s,w,b),(t,n,w,e,s,b),(t,w,s,n,e,b)]

trans :: Dice -> [Dice]
trans = concatMap spins . concatMap rots . updowns

Measured memory_bytes: 4344
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
int cnt = 0;
vector< vector<ll> > ans;
vector<vector<ll>> vac;
ll vacation(int N,int i){
  if(N==0){
      return vac[N][i];
  }
  if(ans[N][i]!=-1)
  	return ans[N][i];
  for(int j=0;j<3;j++){
    if(i!=j){
      cnt++;
      ans[N-1][j] = vacation(N-1,j);
    }
  }
  for(int j=0;j<3;j++){
    if(i!=j){
      ans[N][i] = max(vac[N][i]+ans[N-1][j],ans[N][i]);
    }
  }
  return ans[N][i];
}
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  #ifdef SANS
        freopen("ongoingin.txt","r",stdin);
        freopen("ongoingout.txt","w",stdout);
    #endif
  ll N;
  cin>>N;
  ans.resize(N);
  vac.resize(N);

  for(int i=0;i<N;i++){
    ans[i].resize(3);
    vac[i].resize(3);
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      ans[i][j] = -1;
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      cin>>vac[i][j];
      //cout<<vacation[i][j]<<" ";
    }
  }
  
  ll final_ans = vacation(N-1,0);

  final_ans = max(final_ans,vacation(N-1,1));
  final_ans = max(final_ans,vacation(N-1,2));

  cout<<final_ans<<endl;
  // cout<<cnt<<endl;
  // cout<<"\nTime Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC <<"sec\n";
  
  return 0;
  /*
  for(int i=0;i<1e5;i++){
    cout<<i+1<<endl;
  }*/

}

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

int main()
{
  string S;
  string T;
  string U;
  int A,B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if(S==U)
  {
    A--;
  }
  else
  {
    B--;
  }
  cout << A <<" "<< B <<endl;
}

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

int dp[3005][3005];

int main(){
	IOS;
	memset(dp,0,sizeof(dp));
	string s,t;
	cin >> s >> t;
	s = "$" + s;
	t = "#" + t;
	int n = s.size();
	int m = t.size();

	for(int i=1;i<=n ; ++i){
		for(int j=1;j<=m ; ++j){
			if(s[i]==t[j]){
				dp[i][j] = 1 + dp[i-1][j-1];
			}
			else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}
	string ans = "";
	int i = n;
	int j = m;
	while(i>0 && j > 0){
		if(s[i]==t[j]){
			//cout << s[i] << endl;
			ans += s[i];
			i--;
			j--;
		}
		else{
			if(dp[i-1][j]>=dp[i][j-1]){
				i--;
			}
			else j--;
		}
	}
	reverse(ans.begin(),ans.end());
	cout << ans.substr(0,ans.size()-1) << endl;
}


Measured memory_bytes: 35584
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n,m,x,y,l;
	char d;
	int i, j;
	while (cin >> n) {
		if (n == 0)break;
		int a[21][21];
		for (i = 0; i < 21; i++) {
			for (j = 0; j <21; j++) {
				a[i][j] = 0;
			}
		}
		for (i = 0; i < n; i++) {
			cin >> x >> y; a[x][y] = 1;
		}
		cin >> m;
		int nowx = 10; int nowy = 10;
		for (i = 0; i < m; i++) {
			cin >> d >> l;
			if (d == 'S') {
				for (j = 1; j <= l; j++) {
					a[nowx][nowy - j] = 0;
				}
				nowy -= l;
			}
			else if (d == 'N') {
				for (j = 1; j <= l; j++) {
					a[nowx][nowy + j] = 0;
				}
				nowy += l;
			}
			else if (d == 'E') {
				for (j = 1; j <= l; j++) {
					a[nowx+j][nowy] = 0;
				}
				nowx += l;
			}
			else if (d == 'W') {
				for (j = 1; j <= l; j++) {
					a[nowx-j][nowy] = 0;
				}
				nowx -= l;
			}
		}
		bool f = true;
		for (i = 0; i < 21; i++) {
			for (j = 0; j < 21; j++) {
				if (a[i][j] == 1)f = false;
			}
		}
		if (f)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}


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

int main(){
    int h, a;
    cin >> h >> a;
    int ans = 0;
    /*while(h>0){
        h-=a;
        ans++;
    }
    
    */
    ans = (h+a-1)/a;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] a){
		Scanner scan = new Scanner(System.in);
		int[] train = new int[10];
		int point = 0;
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n > 0){
				train[point] = n;
				point++;
			}
			else{
				System.out.println(train[point - 1]);
				point--;
			}
		}
	}
}

Measured memory_bytes: 17208
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [u64; n],
    }

    let mut ans: u64 = 0;
    let mut tmp: u64;
    let mut sum_for_mult: u64 = 0;

    for j in 1..n {
        tmp = sum_for_mult + a[j];
        sum_for_mult = tmp % (10_i32.pow(9) + 7) as u64;
    }

    for i in 0..(n - 1) {
        tmp = (sum_for_mult * a[i]) % (10_i32.pow(9) + 7) as u64;
        ans = (tmp + ans) % (10_i32.pow(9) + 7) as u64;

        //println!("{}", sum_for_mult);
        if sum_for_mult < a[i + 1] {
            tmp = a[i + 1] - sum_for_mult;
            sum_for_mult = (10_i32.pow(9) + 7) as u64 - tmp;

        } else {
            sum_for_mult -= a[i + 1];
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 5588
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    string s, t;
    cin >> s >> t;
    ll s_size = s.size(), t_size = t.size();
    vvi dp(s_size+1, vi(t_size+1, 0));

    for(ll i=1; i<=s_size; i++){
        for(ll j=1; j<=t_size; j++){
            if(s[i-1] == t[j-1]) chmax(dp[i][j], dp[i-1][j-1]+1);
            chmax(dp[i][j], max(dp[i-1][j], dp[i][j-1]));
        }
    }
    string ans = "";
    ll i = s_size, j = t_size;
    while(i>0 && j>0){
        if(dp[i][j] == dp[i-1][j]) i--;
        else if(dp[i][j] == dp[i][j-1]) j--;
        else{
            ans = s[i-1] + ans;
            i--; j--;
        }
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int main(void)
{
  ll n, s=0;
  cin >> n;
  VI a(n), b(n);
  REP(i, n) {
    cin >> a[i];
    s += a[i];
  }
  if(s%(n*(n+1)/2)) {
    cout << "NO" << endl;
    return 0;
  }
  int aa=s/(n*(n+1)/2);
  REP(i, n) b[i] = a[(i+1)%n]-a[i];
  REP(i, n) {
    if((b[i]-aa)%n || b[i] > aa) {
      cout << "NO" << endl;
       return 0;
    }
  }

  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;

using namespace std;

const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	string s;
	string t;
	int res = 0;
	cin >> s >> t;

	fi(3) {
		if (s[i] == t[i]) {
			res++;
		}
	}
	ce(res);

}

int main()
{

	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
dish_list = [int(input()) for _ in range(5)]
last_num_list = [int(str(dish_i)[-1]) for dish_i in dish_list]

if sum(last_num_list) % 10 == 0:
  print(sum(dish_list))
else:  
  target_index = min(list(filter(lambda x: x>0, last_num_list)))

  last_num_min_index = last_num_list.index(target_index)
  ceiling_dish_list = [-10* (-i//10) for i in dish_list]

  print(sum(ceiling_dish_list) - ceiling_dish_list[last_num_min_index] + dish_list[last_num_min_index])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n; cin >> n;
	ll a; vector<ll> l(n,0);
	REP(i, n) {
		cin >> a;
		if (i != 0)
			l[i] = l[i - 1] + a;
		else
			l[i] = a;
	}
	ll ans = 100000000000000000;
	REP(i, n) {
		ans = min(ans,abs(l[n - 1]-l[i] * 2));
	}
	cout << ans;
}

Measured memory_bytes: 1792
R, C, K = map(int, input().split())

V = [[0]*(C+1) for _ in range(R+1)]
for _ in range(K):
    r, c, v = map(int, input().split())
    V[r][c] = v

max_p = [0]*(C+1)
for i in range(R+1):
    now0, now1, now2, now3 = [[0]*(C+1) for _ in range(4)]
    for j in range(C+1):
        v = V[i][j]
        la = lb = 0
        if j > 0:
            la = now0[j-1]
            lb = now1[j-1]
            now2[j] = max(now2[j], now2[j-1], lb + v)
            now3[j] = max(now3[j], now3[j-1], now2[j-1] + v)
        if i > 0:
            now0[j] = max(now0[j], max_p[j], la)
            now1[j] = max(now1[j], max_p[j] + v, la + v, lb)
        max_p[j] = max(now0[j], now1[j], now2[j], now3[j])

print(max(now0[C], now1[C], now2[C], now3[C]))


Measured memory_bytes: 151052
#include <iostream>
#include<fstream>
#include<algorithm>
#include<vector>
#include<deque>
using namespace std;
const int dx[4] = { -1,1,0,0 };
const int dy[4] = { 0,0,1,-1 };

int a[1000][1000];
deque<pair<int, int>>dq;

int h, w;
bool is_in(const int x, const int y) {
	return 0 <= x && x < h&&y < w && 0 <= y;
}
int main() {
	cin >> h >> w;
	char c;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> c;
			if (c == '#') {
				a[i][j] = 0;
		//		cout << i << " " << j << endl;
				dq.push_back(make_pair(i,j));
			}
			else {
				a[i][j] = -1;
			}
		}
	}
	int ans = 0;
	while (!dq.empty()) {
		const int x = dq.front().first;
		const int y = dq.front().second;
		//cout << x << " " << y << endl;
		dq.pop_front();
		for (int i = 0; i < 4; i++) {
			const int nx = x + dx[i];
			const int ny = y + dy[i];
			if (is_in(nx, ny)) {
				if (a[nx][ny] == -1|| a[nx][ny] > a[x][y] + 1) {
					a[nx][ny] = a[x][y] + 1;
					if (ans < a[nx][ny]) {
						ans = a[nx][ny];
					}
					dq.push_back(make_pair(nx, ny));
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 12304
# -*- coding: utf-8 -*-
#import pdb;    pdb.set_trace()
import sys

def solv(v):
    w = set(v)
    if len(w)==1 or len(w)==3:
        d={1:3, 2:3, 3:3}
    elif 1 in w and 2 in w:
        d={1:1, 2:2}
    elif 2 in w and 3 in w:
        d={2:1, 3:2}
    else:
        d={3:1, 1:2}
    return(list(map(lambda x:d[x], v) ))
def main():
    if True:
        fh = sys.stdin
    else:
        fh = open('vol2_0205.txt', 'r')
    try:
        while True:
            te = []
            for _ in range(5):
                x=int(fh.readline().strip())
                if x==0:
                    raise Exception
                te.append(x)
            b=(solv(te))
            for i in b:
                print(i)
    except Exception:
        1
    fh.close()
    
if __name__ == '__main__':
    main()



Measured memory_bytes: 5652
INF = pow(10, 9)


def main():
    n, m, x = map(int, input().split())
    i = 0
    c = []
    a = []

    for i in range(n):
        tmp = list(map(int, input().split()))
        c.append(tmp[0])
        a.append(tmp[1:])

    ans = INF
    for i in range(2**n):
        tmp = [0 for i in range(m)]
        cost = 0
        flag = True
        for j in range(n):
            if ((i >> j) & 1) == 1:
                tmp = [x+y for x, y in zip(tmp, a[j])]
                cost += c[j]
        # print(tmp)
        for j in range(m):
            if tmp[j] < x:
                flag = False
                break
        # print(cost)
        if flag == True:
            if cost < ans:
                ans = cost
    print(ans) if ans != INF else print(-1)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 68860
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  vector<int> A(4);
  string S;
  cin >> S;
  for(int i=0;i<4;i++) A.at(i) = S.at(i) - '0';
  
  for (int tmp = 0; tmp < (1 << 3); tmp++) {
//    cout << tmp << endl;
    int sum = A.at(0);
    for(int j=0;j<3;j++){
      if(tmp & (1 << j)) sum += A.at(j+1);
      else  sum -= A.at(j+1);
    }
    if(sum==7){
      cout << A.at(0);
      for(int j=0;j<3;j++){
        if(tmp & (1 << j)) cout << '+';
        else cout << '-';
        cout << A.at(j+1);
      }
      cout << "=7" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3592
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/02/20 00:02:53
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n,k; cin>>n>>k;
  vector<int> A(n); for (auto& a:A) cin>>a;
  vector<ll> ca(n);
  ca[0] = A[0];
  for (int i = 1; i < n; i++)
    ca[i] = A[i] + ca[i-1];
  vector<ll> nca(n);
  nca[0] = max(A[0], 0);
  for (int i = 1; i < n; i++) {
    nca[i] = max(A[i], 0) + nca[i-1];
  }
  ll ans = 0;
  for (int i = 0; i < n-k+1; i++) {
    ll sum = i>0 ? nca[i-1] : 0;
    sum += nca[n-1]-nca[i+k-1];
    ll op = ca[i+k-1]-(i>0 ? ca[i-1] : 0);
    ans = max({ans, sum, sum+op});
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2176
# input
section = raw_input()

# map the height of the section
height = 0
heights = [0]
for p in xrange( len(section) ):
    if   section[p] == '/':
        height += 1
    elif section[p] == '\\':
        height -= 1
    heights.append(height)

# search the pools
pools = []
water = []
p = 0
while p < len(section):
    if section[p] == '\\':
        try:
            pr = heights[p+1:].index( heights[p] )
            pools.append([p, p+1+pr])
            p = p+1+pr
        except:
            p+=1
    else:
        p+=1

# count
for pool in pools:
    tp = section[pool[0]:pool[1]]
    depth = 0
    s = 0
    for p in xrange( len(tp) ):
        if   tp[p] == '/':
            depth -= 1
        elif tp[p] == '\\':
            depth += 1
            s += 2*(depth-1)+1
        else:
            s += depth
    water.append(s)

# print
print sum(water)
if len(water) == 0:
    print len(water)
else:
    print len(water), " ".join(map(str, water))

Measured memory_bytes: 7124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n;
		n = sc.nextInt();

		sc.close();

		int ans = 0, i = 0, tmp = 1;

		while (true) {
			if (n < tmp)
				break;
			if (n == tmp)
				ans = tmp;
			tmp *= 2;
		}

		if (ans == 0)
			ans = tmp / 2;
		System.out.println(ans);

	}

}


Measured memory_bytes: 22740
#include <iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main()
{
    int a,b,c,d,e,s=0,ls,mi=10,j,i;
    vector<int>zs;
    cin>>a>>b>>c>>d>>e;
    if(a%10==0)
        s=s+a;
    else
        zs.push_back(a);
    if(b%10==0)
        s=s+b;
    else
        zs.push_back(b);
    if(c%10==0)
        s=s+c;
    else
        zs.push_back(c);
    if(d%10==0)
        s=s+d;
    else
        zs.push_back(d);
    if(e%10==0)
        s=s+e;
    else
        zs.push_back(e);
    for(i=0;i<zs.size();i++)
    {
        ls=zs[i]%10;
        if(ls<mi)
        {
            mi=ls;
            j=i;
        }
    }
    for(i=0;i<zs.size();i++)
    {
        if(i!=j)
            s=s+zs[i]-(zs[i]%10)+10;
        else
            s=s+zs[i];
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {		

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long C = sc.nextLong();
		long sushi[][] = new long[N][2];		
		for(int i=0;i<N;i++) {
			sushi[i][0] = sc.nextLong();//dist x
			sushi[i][1] = sc.nextLong();//calorie v
		}
		sc.close();
		
		Arrays.sort(sushi, (s1,s2)->Long.compare(s1[0], s2[0]));
		
		//右回りのcalorie累積和
		long sumVR[] = new long[N+1];
		sumVR[0]=0;
		for(int i=0;i<N;i++)sumVR[i+1] = sumVR[i]+sushi[i][1];
		//x累積和
		long sumXR[] = new long[N+1];
		sumXR[0] = 0;
		for(int i=0;i<N;i++) sumXR[i+1] = sushi[i][0];
		
		//左回りのcalorie累積和
		long sumVL[] = new long[N+1];
		sumVL[0]=0;
		for(int i=0;i<N;i++)sumVL[i+1] = sumVL[i]+sushi[N-1-i][1];
		//x累積和
		long sumXL[] = new long[N+1];
		sumXL[0] = 0;
		for(int i=0;i<N;i++) sumXL[i+1] = C - sushi[N-1-i][0];
		
		
		//右回りの累積Max（戻る場合）
		long sumR2[] = new long[N+1];
		sumR2[0]=0;
		for(int i=1;i<N+1;i++) {
			sumR2[i] = Math.max(sumR2[i-1], sumVR[i] - 2*sumXR[i]);
		}
		//右回りの累積Max（戻らない場合）
		long sumR1[] = new long[N+1];
		sumR1[0]=0;
		for(int i=1;i<N+1;i++) {
			sumR1[i] = Math.max(sumR1[i-1], sumVR[i] - sumXR[i]);
		}
		//左回りの累積Max（戻る場合）
		long sumL2[] = new long[N+1];
		sumL2[0]=0;
		for(int i=1;i<N+1;i++) {
			sumL2[i] = Math.max(sumL2[i-1], sumVL[i] - 2*sumXL[i]);
		}
		//左回りの累積（戻らない場合）
		long sumL1[] = new long[N+1]; 
		sumL1[0]=0;
		for(int i=1;i<N+1;i++) {
			sumL1[i] = Math.max(sumL1[i-1],sumVL[i] - sumXL[i]);
		}		

		
		long ans = 0;
		for(int i=0;i<N;i++) {
			long tmp = sumR2[i]+sumL1[N-i];
			long tmp2 = sumL2[i]+sumR1[N-i];
			long tmpMax = Math.max(tmp, tmp2);
			ans = Math.max(ans,tmpMax);
		}
		
		System.out.println(ans);
		
	}

	
}

Measured memory_bytes: 95072
n,m = gets.chomp.split(" ").map(&:to_i)
h = gets.chomp.split(" ").map(&:to_i)
abs = m.times.map{ gets.chomp.split(" ").map(&:to_i) }
c = Array.new(n,0)

abs.map{|ab|
  if h[ab[0]-1] < h[ab[1]-1]  
    c[ab[0]-1]+= 1 
  elsif h[ab[0]-1] > h[ab[1]-1] 
    c[ab[1]-1]+= 1 
  else
    c[ab[0]-1]+= 1
    c[ab[1]-1]+= 1 
  end
}

puts c.count(0)

Measured memory_bytes: 24164
n = gets.to_i
cors = gets.split.map(&:to_i).sort

last = cors.uniq[-1]
first = cors.uniq[0]
total1 = 0
total2 = 0

point1 = cors.inject(:+) / n
point2 = point1 + 1

cors.each do |c|
  total1 += (c - point1) ** 2
  total2 += (c - point2) ** 2
end

if total1 > total2
  puts total2
else
  puts total1
end

Measured memory_bytes: 1788
#include <stdio.h>

int main()
{
	int inputA;
	int inputB;
	int inputC;

	scanf("%d%d%d", &inputA, &inputB, &inputC);

	if (inputA + inputB + inputC >= 22)
	{
		printf("bust \n");		
	}
	else
	{
		printf("win \n");
	}
  
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**7)
mo=998244353
n=int(input())
dp=list(map(int,input().split()))#[0,0,0]
for i in range(1,n):
    a,b,c=list(map(int,input().split()))
    dp=[a+max(dp[1],dp[2]),b+max(dp[0],dp[2]),c+max(dp[0],dp[1])]
print(max(dp))

Measured memory_bytes: 3064
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;

#define MAXN 600

typedef array<int,4> tile;

int n;
tile a[MAXN];


int input() {
	if (scanf("%d", &n) < 0) return 0;
	for (int i=0; i<n; i++)
		for (int j=0; j<4; j++)
			scanf("%d", &a[i][j]);
	return 1;
}

void init() {
}

tile rotate(const tile &x, int k=1) {
	tile y;
	for (int i=0; i<4; i++) y[(i+k) % 4] = x[i];
	return y;
}

tile normalize(const tile &x) {
	tile z=x;
	for (int i=1; i<4; i++) {
		tile y=rotate(x, i);
		if (y<z) z=y;
	}
	return z;
}

int mirror(const tile &x) {
	int r = 1;
	for (int i=1; i<4; i++) {
		tile y=rotate(x, i);
		if (y==x) r++;
	}
	return r;
}

tile get_face(tile &u, tile &d, int x, int y) {
	return normalize({u[x], u[y], d[3-y], d[3-x]});
}

long solve() {
	map<tile,long> ct;
	map<tile,long> mi;
	for (int i=0; i<n; i++) {
		a[i] = normalize(a[i]);
		ct[a[i]]++;
		mi[a[i]] = mirror(a[i]);
	}
	long ans = 0;
	for (int i=0; i<n; i++) {
		ct[a[i]]--;
		for (int j=i+1; j<n; j++) {
			ct[a[j]]--;
			for (int k=0; k<4; k++) {
				tile d=a[i], u=rotate(a[j], k);
				tile f[4];
				long r = 1;
				for (int t=0; t<4; t++) {
					f[t] = get_face(u, d, t, (t+3)%4);
					r *= mi[f[t]] * ct[f[t]]--;
				}
				//printf("* %d %d %d: %ld\n", i, j, k, r);
				ans += r;
				for (int t=0; t<4; t++) ct[f[t]]++;
			}
			ct[a[j]]++;
		}
		ct[a[i]]++;
	}
	return ans/3;
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 159872
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

long long P = 1000000007;

class C {
public:
  int n;
  vector<long long> fac, inv, facInv;
  long long power(long long e, long long x) {
    if (x == 0)
      return 1;
    if (x == 1)
      return e;
    if (x % 2 == 0)
      return power((e * e) % P, x / 2);
    return (e * power(e, x - 1)) % P;
  }
  C(int n_) {
    n = n_;
    fac.resize(n + 1);
    inv.resize(n + 1);
    facInv.resize(n + 1);
    fac[0] = fac[1] = 1;
    for (int i = 2; i <= n; i++)
      fac[i] = (i * fac[i - 1]) % P;
    inv[0] = inv[1] = 1;
    for (int i = 2; i <= n; i++)
      inv[i] = power(i, P - 2);
    facInv[0] = facInv[1] = 1;
    for (int i = 2; i <= n; i++)
      facInv[i] = (inv[i] * facInv[i - 1]) % P;
  }
  long long comb(int N, int K) {
    if (N < K || K < 0 || N < 0)
      return 0;
    if (N == 0 || K == 0 || K == N)
      return 1;
    return ((fac[N] * facInv[K]) % P * facInv[N - K]) % P;
  }
  long long hcomb(int N, int K) {
    if (N == 0 && K == 0)
      return 1;
    return comb(N + K - 1, K);
  }
  long long mul(long long a, long long b) { return (a * b) % P; }
  long long add(long long a, long long b) { return (a + b) % P; }
  long long div(long long a, long long b) { return (a * power(b, P - 2)) % P; }
};

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  C c(n + 2);
  long long d[100002] = {0};
  long long sum[100002] = {0};
  d[0] = 0;
  d[1] = 1;
  for (int i = 2; i <= n; i++)
    d[i] = c.div(1, i);
  sum[0] = 0;
  for (int i = 0; i <= n; i++)
    sum[i + 1] = (sum[i] + d[i + 1]) % P;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (a[i] * sum[i + 1]) % P;
    ans %= P;
    ans += (a[i] * sum[n - i]) % P;
    ans %= P;
    ans += (P - a[i]);
    ans %= P;
  }
  cout << (ans * c.fac[n]) % P << endl;
  return 0;
}


Measured memory_bytes: 4992
n = int(input())
a = []

for i in range(n):
    a.append(int(input()))

b = []
chain = 0
for i in range(n):
    if(chain>=1 and a[i]==0):
        b.append(chain)
        chain = 0
    elif(a[i]>=1):
        chain += a[i]
ans=0
b.append(chain)
for i in b:
    ans += i//2
    #print(i)
print(ans)





Measured memory_bytes: 52056
#include<cstdio>
using namespace std;
const int maxN=2e5 + 100;
int a[maxN+1],vis[maxN+1],sum[maxN+1];
int n,m,pos;
int main()
{
    scanf("%d%d",&n,&m);
    int ans=n;
    for(int i=1;i<=n;i++) 
    {
        scanf("%d",&a[i]);
        sum[a[i]]++;
        pos=a[i]-sum[a[i]];
        if(pos>=0)
        {
            if(!vis[pos]) ans--;
            vis[pos]++;
        }
    }
    while(m--)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        pos=a[x]-sum[a[x]];
        if(pos>=0)
        {
            vis[pos]--;
            if(!vis[pos]) ans++;
        }
        sum[a[x]]--;
        a[x]=y;
        sum[y]++;
        pos=a[x]-sum[a[x]];
        if(pos>=0)
        {
            if(!vis[pos]) ans--;
            vis[pos]++;
        }
        printf("%d\n",ans);
    }
    return 0;
 } 

Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
using namespace std;
int n;
int num[100005];
int main()
{
	scanf("%d",&n);
	register int a,b,c,d;
	for(a=1;a<=n;a++)
	scanf("%d",&num[a]);
	ll p=2,q=2;
	for(a=n;a>=1;a--)
	{
		if(p%num[a]!=0)
		p=(p/num[a])*num[a]+num[a];
		q=(q/num[a]+1)*num[a]-1;
	}
	if(q>=p)
	cout<<p<<" "<<q<<endl;
	else
	puts("-1");
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long 
#define dd cout<<endl
#define lll __int128
const int mod=1e9+7;
const int inf=1e9+7;

//const int maxn=

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	int m;
	int d;
	
	cin>>m>>d;
	
	int ans=0;
	
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=d;j++)
		{
			string str=to_string(j);
			if(str.size()<2)
				continue;
			int ge=str[1]-'0';
			int shi=str[0]-'0';
			if(ge>=2&&shi>=2&&ge*shi==i)
				ans++;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

int main() {
	ll N; cin >> N;
	vector<ll> A(N); rep(i, N)cin >> A[i];

	ll sum = 0;
	vector<ll> dis(N + 1);
	for (int i = 0; i <= N;i++) {
		if (i == 0) {
			sum += abs(A[i]);
			dis[i] = abs(A[i]);
		}
		else if (i == N) {
			sum += abs(A[N - 1]);
			dis[i] = abs(A[N - 1]);
		}
		else {
			sum += abs(A[i] - A[i-1]);
			dis[i] = abs(A[i] - A[i-1]);
		}
	}

	for(int i = 0; i < N;i++){
		ll tmp = sum;
		tmp -= (dis[i] + dis[i + 1]);
		if (i == 0) tmp += abs(A[1]) ;
		else if (i == N - 1) tmp += abs(A[i - 1]);
		else tmp += abs(A[i - 1] - A[i + 1]);

		cout << tmp << endl;
	}
}

Measured memory_bytes: 2816
str = input()

n1 = int(str[0])
n2 = int(str[1])
n3 = int(str[2])
n4 = int(str[3])

if n1 + n2 + n3 + n4 == 7:
  print(str[0]+"+"+str[1]+"+"+str[2]+"+"+str[3]+"=7")
elif n1 - n2 + n3 + n4 == 7:
  print(str[0]+"-"+str[1]+"+"+str[2]+"+"+str[3]+"=7")
elif n1 + n2 - n3 + n4 == 7:
  print(str[0]+"+"+str[1]+"-"+str[2]+"+"+str[3]+"=7")
elif n1 + n2 + n3 - n4 == 7:
  print(str[0]+"+"+str[1]+"+"+str[2]+"-"+str[3]+"=7")
elif n1 - n2 - n3 + n4 == 7:
  print(str[0]+"-"+str[1]+"-"+str[2]+"+"+str[3]+"=7")
elif n1 - n2 + n3 - n4 == 7:
  print(str[0]+"-"+str[1]+"+"+str[2]+"-"+str[3]+"=7")
elif n1 + n2 - n3 - n4 == 7:
  print(str[0]+"+"+str[1]+"-"+str[2]+"-"+str[3]+"=7")
elif n1 - n2 - n3 - n4 == 7:
  print(str[0]+"-"+str[1]+"-"+str[2]+"-"+str[3]+"=7")

Measured memory_bytes: 3064
//Two Arrays

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define YN(flag) (flag?"Yes":"No")
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;cin>>n;
    vecrep(n,a,int);
    vecrep(n,b,int);
    int g=0;
    rep(i,0,n){
        if(a[i]>b[i])g-=(a[i]-b[i]);
        if(a[i]<b[i])g+=(b[i]-a[i])/2;
    }
    cout<<YN(g>=0)<<nnn;
    return 0;
}

Measured memory_bytes: 3780
// inputに入力データ全体が入る
function Main(input) {
     input = input.split("\n");
  var n= parseInt(input[0], 10);
    var tmp = input[1].split(" ");
     var a = [];
for (var i = 0; i < n ; i++){
  var r= parseInt(tmp[i], 10);
   a[i] = r;}
  
 var ct = 0;
  var p = 0;
 for (var i = 0;i < n ;i ++){ if( a[i] >= a[i+1]){ct = ct + 1;
                                                 // console.log(i,ct);
                                                  }
                                         else if (p < ct){ var p =ct;
                                               var ct = 0;}else{var ct = 0;}
                               }
                   console.log(p);
 }
   //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  

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

using cd = complex<double>;
const double PI = acos(-1);

void fft(vector<cd> & a, bool invert) {
    int n = a.size();
    if (n == 1)
        return;

    vector<cd> a0(n / 2), a1(n / 2);
    for (int i = 0; 2 * i < n; i++) {
        a0[i] = a[2*i];
        a1[i] = a[2*i+1];
    }
    fft(a0, invert);
    fft(a1, invert);

    double ang = 2 * PI / n * (invert ? -1 : 1);
    cd w(1), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++) {
        a[i] = a0[i] + w * a1[i];
        a[i + n/2] = a0[i] - w * a1[i];
        if (invert) {
            a[i] /= 2;
            a[i + n/2] /= 2;
        }
        w *= wn;
    }
}

vector<long long> multiply(vector<int> const& a, vector<int> const& b) {
    vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size())
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<long long> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

const int g = 2;
const int p = 200003;

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

    int a[n];
    int dlog[p];
    int po[p - 1];

    int cur = 1;
    for(int i = 0; i<p - 1; i++){
        dlog[cur] = i;
        po[i] = cur;
        cur *= g;
        cur %= p;
    }

    vector<int> coeff(p - 1);
    fill(coeff.begin(), coeff.end(), 0);

    for(int i = 0; i<n; i++){
        cin >> a[i];
        if(a[i] != 0){
            coeff[dlog[a[i]]]++;
        }
    }

    long long ans = 0;
    vector<long long> mult_coeff = multiply(coeff, coeff);

    for(int i = 0; i<coeff.size(); i++){
        mult_coeff[2*i] -= coeff[i];
    }

    for(int i = 0; i<mult_coeff.size(); i++){
        ans += (mult_coeff[i] / 2) * po[i % (p - 1)];
    }

    cout << ans;

}


Measured memory_bytes: 39676
#include <stdio.h>                      // use string s; getline(cin>>ws,s); where cin>>ws eats the white spaces.
#include <stdlib.h>                             // this above method is important when we need to string s ="hi my name is blah blah....\n"
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <iomanip>
#include <cmath>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include<math.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define ld long double
#define inf 1000000007
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<iii,int>
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define vv vector
#define endl "\n"
#define ld long double
using namespace std;

// 1944 324 54 9 18 3 6 1
int main(){
ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
int n,ans=0;
cin>>n;
int arr[n+1];
for(int i=1;i<=n;i++)
{
    cin>>arr[i];
    if(i%2!=0)
    {
        if(arr[i]%2!=0)
            ans++;
    }
}
cout<<ans;
}


Measured memory_bytes: 3620
#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;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main(){
  string s;
  cin>>s;
  bool ans=false;
  int l=s.size()-1;
  rep(i,l){
    if(s[i]=='A' && s[i+1]=='C'){
      ans=true;
      break;
    }
  }
  cout<<(ans?"Yes":"No")<<endl;
}

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

int main(){
	int n,s=0,ma=-1;
	
	cin>>n;
	int a[n+1];
	cin>>a[1];
	ma=a[1];
	for(int i=2;i<=n;i++){
		cin>>a[i];
		if(a[i]>=ma){
			ma=a[i];
			s++;
		}
	}
	cout<<s+1<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

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

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

llong Round(llong x){
	double y = (double)x;

	y /= 1000;
	
	y = ceil(y);

	x= (llong)y*1000;

	return x;
}

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

	int n;
	llong m = 100000;

	cin >> n;

	for (int i = 0; i < n; i++){
		m = m + (llong)m/20;
		m = Round(m);
	}

	cout << m << endl;
}

Measured memory_bytes: 3096
import sys
from collections import deque
from bisect import bisect_left
input = sys.stdin.buffer.readline

N, K = map(int, input().split())
Ps = list(map(int, input().split()))

downs = []
for i in range(N-1):
    if Ps[i+1] < Ps[i]:
        downs.append(i)

if not downs:
    print(1)
    exit()

min_wait = deque()
max_wait = deque()
for i in range(K):
    while min_wait and min_wait[-1] > Ps[i]:
        min_wait.pop()
    min_wait.append(Ps[i])
    while max_wait and max_wait[-1] < Ps[i]:
        max_wait.pop()
    max_wait.append(Ps[i])
    
change_nothing = (downs[0] >= K-1)
if change_nothing:
    ans = 0
else:
    ans = 1
    
for i in range(K, N):
    while min_wait and min_wait[-1] > Ps[i]:
        min_wait.pop()
    min_wait.append(Ps[i])
    while max_wait and max_wait[-1] < Ps[i]:
        max_wait.pop()
    max_wait.append(Ps[i])

    if min_wait[0] != Ps[i-K] or max_wait[0] != Ps[i]:
        t = bisect_left(downs, i-K+1)
        if t < len(downs):
            if downs[t] >= i:
                change_nothing = True
            else:
                ans += 1
        else:
            if downs[-1] + K < N:
                change_nothing = True
            break
    
    if min_wait[0] == Ps[i-K]:
        min_wait.popleft()
    if max_wait[0] == Ps[i-K]:
        max_wait.popleft()


if change_nothing:
    ans += 1

print(ans)

Measured memory_bytes: 20728
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 998244353 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 300010


ll factmemo[SIZE+1];
void initFact(int n, int M){
  factmemo[0] = 1;
  for(int i=1;i<=n;i++) factmemo[i] = (factmemo[i-1] * i) % mod;
}

ll factorial(int n,int M){
  if(n<=1) return 1;
  return factmemo[n];
}

ll power(int k,int n,int M){
  if(n==0) return 1;
  if(n==1) return (ll)k;
  
  ll ret = power(k,n/2,M);
  
  ret=(ret*ret)%M;
  
  if(n%2==1)
    ret=(ret*k)%M;
  
  return ret;
}


//nCm nPm nHm (mod M)

int counter = 0;

/*Combination*/
int combmemo[SIZE];
bool visitedComb[SIZE];
int C(int n,int m,int M){
  if(n<m) return 0;
  if(m==0 || n==m) return 1;
  if(visitedComb[m]) return combmemo[m];
  
  ll chi = factorial(n,M);
  ll mot = (factorial(m,M) * factorial(n-m,M))%M;
  
  mot = power((int)mot,M-2,M);
  
  ll ret = (chi*mot)%M;
  
  visitedComb[m] = true;
  return combmemo[m] = (int)ret;
}

int main(){
  int n;
  ll a, b, k, ans = 0;

  cin >> n >> a >> b >> k;

  initFact(n, mod);
  
  for(int i=0;i<=n;i++){
    if (k >= i*a && (k - i*a)%b == 0 && (k-i*a)/b <= n) {
      ll p = (k - i*a)/b;
      ans = (ans + (ll)C(n, i, mod) * C(n, p, mod) % mod) % mod;
    }
  }

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



Measured memory_bytes: 3712