akhauriyash/Code-Regression huggingface dataset:
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 105, sigma = 26;
int n, m;
char a[maxn][maxn];

int read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%s", a[i]);
  }
  return true;
}

int cnt[sigma];

void solve() {
  for (int i = 0; i < sigma; i++) {
    cnt[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cnt[a[i][j] - 'a']++;
    }
  }
  for (int i = 0; 2 * i + 1 < n; i++) {
    for (int j = 0; 2 * j + 1 < m; j++) {
      bool found = false;
      for (int c = 0; c < sigma; c++) {
        if (cnt[c] >= 4) {
          cnt[c] -= 4;
          found = true;
          break;
        }
      }
      if (!found) {
        printf("No\n");
        return;
      }
    }
  }
  if (n & 1) {
    for (int j = 0; 2 * j + 1 < m; j++) {
      bool found = false;
      for (int c = 0; c < sigma; c++) {
        if (cnt[c] >= 2) {
          cnt[c] -= 2;
          found = true;
          break;
        }
      }
      if (!found) {
        printf("No\n");
        return;
      }
    }
  }
  if (m & 1) {
    for (int i = 0; 2 * i + 1 < n; i++) {
      bool found = false;
      for (int c = 0; c < sigma; c++) {
        if (cnt[c] >= 2) {
          cnt[c] -= 2;
          found = true;
          break;
        }
      }
      if (!found) {
        printf("No\n");
        return;
      }
    }
  }
  if ((n * m) & 1) {
    bool found = false;
    for (int c = 0; c < sigma; c++) {
      if (cnt[c] >= 1) {
        cnt[c]--;
        found = true;
        break;
      }
    }
    if (!found) {
      printf("No\n");
      return;
    }
  }
  printf("Yes\n");
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

using std::cin;
using std::cout;
using std::endl;

typedef long long ll;
typedef unsigned long long ull;

const int N = 1000000 + 5;
const int M = 3000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const double PI = acos(-1);

template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

int main() {
    int a, b, c;
    scanf("%d/%d/%d", &a, &b, &c);
    int date = a * 10000 + b * 100 + c;
    int h = 20190430;
    if (date <= h) puts("Heisei");
    else puts("TBD");
    return 0;
}

Measured memory_bytes: 256
#if 0
#endif

#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stack>
#include <queue>
using namespace std;

int main()
{
    string word;
    priority_queue<int> Q;
    while (cin >> word && (word != "end"))
    {
        if (word == "insert")
        {
            // 挿入
            int num;
            cin >> num;
            Q.push(num);
        }
        else if (word == "extract")
        {
            // 最大値をpop
            cout << Q.top() << endl;
            Q.pop();
        }
    }
}



Measured memory_bytes: 7080
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli A,B,C,D;
  string a,b,c;
  cin >> A >> B;
  if(B>A)Out(0);
  else Out(A-B);
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::iter::FromIterator;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn readc() -> char {
    let s: String = read();
    return s.chars().nth(0).unwrap();
}

fn read_vec<T: FromStr>(n: usize) -> Vec<T> {
    return (0..n).map(|_| read()).collect();
}

///a と b の最大公約数を求める
fn gcd(a: usize, b: usize) -> usize {
    if a % b == 0 {
        b
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    let mut k: usize = read();
    let a: usize = read();
    let b: usize = read();

    let mut ans;
    if b <= a + 2 || k + 1 <= a {
        ans = k + 1;
    } else {
        ans = a;
        k -= a - 1;
        let change_set = k / 2;
        ans += (b - a) * change_set + k % 2;
    }

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  cout << 2 * b - a << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <bitset>
#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 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

#include <nmmintrin.h>
#ifdef _MSC_VER

#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
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);
}

int cous(int a) {
	int ret = 0;
	while (a) {
		ret += a % 10;
		a /= 10;
	}
	return ret;
}


int main() {
	

	int n;
	cin >> n;
	int a = 1;
	int ans = INT_MAX;

	while (a < n) {
		
		int b = n - a;

		ans = min(ans, cous(a)+ cous(b));
		
		a++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

const int inf=1e9+10;
const int maxn=16;

int dp[1<<maxn][maxn],dp2[1<<maxn],n,m,cost[maxn][maxn]; 
vector <int> g[1<<maxn]; 

vector <int> get_msk(int mask){
	vector <int> v,v2;
	for(int i=0;i<n;i++) 
		if(!(mask&(1<<i))) v.pb(i);
	for(int msk2=0;msk2<(1<<(int)v.size());msk2++){
		int msk3=0;
		for(int i=0;i<v.size();i++) if(msk2&(1<<i))
			msk3|=1<<v[i];	
		if(msk3!=0) g[mask].pb(msk3);
	}
	return v2;
}

int main(){
	for(int i=0;i<maxn;i++) for(int j=0;j<maxn;j++) 
		cost[i][j]=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int u,v,c;
		scanf("%d%d%d",&u,&v,&c);
		u--; v--;
		cost[u][v]=c;
		cost[v][u]=c;
	}
	for(int mask=0;mask<(1<<n);mask++) get_msk(mask);
	for(int mask=0;mask<(1<<n);mask++) 
		for(int i=0;i<n;i++) for(int j=0;j<n;j++)
			if((mask&(1<<i))&&(mask&(1<<j)))
				dp2[mask]=dp2[mask]+cost[i][j];
	for(int mask=0;mask<(1<<n);mask++) dp2[mask]=dp2[mask]/2;
	for(int mask=0;mask<(1<<n);mask++) for(int i=0;i<n;i++) dp[mask][i]=-inf;
	dp[1<<0][0]=0;
	for(int mask=0;mask<(1<<n);mask++)
		for(int i=0;i<n;i++){
			if((dp[mask][i]==-inf)||!(mask&(1<<i))) continue;
			for(int j=0;j<n;j++) if((!(mask&(1<<j)))&&(cost[i][j]>0))
				dp[mask|(1<<j)][j]=max(dp[mask|(1<<j)][j],dp[mask][i]+cost[i][j]);
			for(int j=0;j<g[mask].size();j++){
				int mask2=g[mask][j]|(1<<i);
				dp[mask|mask2][i]=max(dp[mask|mask2][i],dp[mask][i]+dp2[mask2]);
			}
		}
	printf("%d\n",dp2[(1<<n)-1]-dp[(1<<n)-1][n-1]);
	return 0;
}


Measured memory_bytes: 60800
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;

int N, K;
int l[55];

signed main()
{
    cin >> N >> K;
    REP(i,N) cin >> l[i];

    sort(l, l + N, greater<int>());
    int ans = 0;
    REP(i,K) ans += l[i];

    cout << ans << endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int n,k;
	cin>>n>>k;
	if(k==1)cout<<0<<endl;
	else cout<<n-k<<endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    A.sortDescending()

    fun gcd(a: Int, b: Int) : Int {
        if (b == 0) {
            return a
        }
        return gcd(b, a % b)
    }

    val L = mutableListOf<Int>()
    L.add(0)
    L.add(A[0])
    A.reduce { acc, l ->
        val res = gcd(acc, l)
        L.add(res)
        res
    }

    val R = mutableListOf<Int>()
    R.add(0)
    R.add(A[N - 1])
    A.reduceRight { acc, l ->
        val res = gcd(acc, l)
        R.add(res)
        res
    }
    R.reverse()

    var max = 0
    for (i in 0 until N) {
        max = Math.max(max, gcd(L[i], R[i+ 1]) )
    }
    println(max)
}

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

int A[10],B[10];

int main(){
	int n,a,cnt=0,cnt2=0;
	cin >> n;
	
	vector<int> v;
	for(int i=0;i<n;i++){
		cin >> a;
		if(1<=a&&a<=399) A[0]++;
		else if(400<=a&&a<=799) A[1]++;
		else if(800<=a&&a<=1199) A[2]++;
		else if(1200<=a&&a<=1599) A[3]++;
		else if(1600<=a&&a<=1999) A[4]++;
		else if(2000<=a&&a<=2399) A[5]++;
		else if(2400<=a&&a<=2799) A[6]++;
		else if(2800<=a&&a<=3199) A[7]++;
		else v.push_back(a);
	}
	
	for(int i=0;i<10;i++){
		B[i]=A[i];
	}
	
	for(int i=0;i<v.size();i++){
		bool ok2=true;
		for(int i=0;i<8;i++){
			if(A[i]==0){
				A[i]++;
				ok2=false;
				break;
			}
		}
		if(ok2) cnt++;
		bool ok=true;
		for(int i=0;i<8;i++){
			if(B[i]) ok=false;
		}
		if(!ok) continue; 
		
		for(int i=0;i<8;i++){
			if(B[i]==0){
				B[i]++;
				break;
			}
		}
	}
	
	for(int i=0;i<8;i++){
		if(A[i]) cnt++;
		if(B[i]) cnt2++;
	}
	
	cout << cnt2 << " " << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cassert>
#include <unordered_map>
using namespace std;


/*
boolですべての島を用意して１から来れて、ｎへ行ける島があるか調べる
*/
int main(){
    int n, m;
    cin >> n >> m;
    vector<bool> vis(n+1, false);
    //bool型のvector. 要素数n+1, すべてfalseで初期化
    bool can = false;

    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        
        //1から出ている船とき
        if(a == 1){
            if(vis[b]) can = true;
            vis[b] = true;
        }
        //ｎへ行ける船のとき
        else if(b == n){
            if(vis[a]) can = true;
            vis[a] = true;
        }
    }

    
    if(!can) cout << "IM";
    cout << "POSSIBLE" << endl;

}

Measured memory_bytes: 256
/**********************************************
 *Author*        :XzzF
 *Created Time*  : 2018/6/9 11:00:54
 *Ended  Time*  : 2018/6/9 11:16:46
*********************************************/

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <ctime>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const LL MOD = 998244353LL;
const int MaxN = 300000;

int N, A, B;
LL K;
LL Bin[MaxN + 5];

LL qwr(LL x, LL y) {
	LL res = 1LL;
	while(y > 0) {
		if(y & 1) res = (res * x) % MOD;
		x = (x * x) % MOD;
		y = y >> 1;
	}
	return res;
}

void Prepare() {
	Bin[0] = 1LL;
	for(int i = 1; i <= MaxN; i++)
		Bin[i] = Bin[i - 1] * 1LL * i % MOD;
}

LL C (LL N, LL M) {
	LL res = (Bin[N] * qwr(Bin[M], MOD - 2) % MOD) * qwr(Bin[N - M], MOD - 2) % MOD;
	return res;
}

int main()
{
	Prepare();
	while(scanf("%d %d %d %lld", &N, &A, &B, &K) != EOF)
	{
		LL ans = 0LL;
		for(int i = 0; i <= N; i++) {
			LL x = (LL)i;
			LL y = (K - A * x) / B;
			if(x >= 0 && (y >= 0 && y <= N) && A * x + B * y == K) 
				ans = (ans + C(N, x) * C(N, y)) % MOD;
		}
		printf("%lld\n", ans);
	}
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

using mint = atcoder::modint998244353;

const int MAX_N = 312345;
mint power_ten[MAX_N];

struct S {
  mint a;
  int size;
};
S op(S l, S r) { return S{l.a * power_ten[r.size] + r.a, l.size + r.size}; }
S e() { return S{0, 0}; }

struct F {
  mint d;
};
F composition(F l, F r) { if (l.d.val() == 0) return r; else return l; }
F id() { return F{0}; }

S mapping(F f, S x) {
  if (f.d == 0) return x;
  mint ones = (power_ten[x.size] - 1) / 9;
  return S{ ones * f.d, x.size };
}


int main2() {
  int N = nextLong();
  int Q = nextLong();

  atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(N);
  REP(i, N) {
    seg.set(i, S{1, 1});
  }
  REP(qi, Q) {
    int L = nextLong() - 1;
    int R = nextLong() - 1;
    int D = nextLong();
    seg.apply(L, R+1, F{D} );
    S ans = seg.all_prod();
    cout << ans.a.val() << '\n';
  }

  return 0;
}

int main() {
  power_ten[0] = 1;
  for (int i = 1; i < MAX_N; i++) {
    power_ten[i] = power_ten[i-1] * 10;
  }
#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  vector<vector<int>> cnt(h, vector<int>(w));
  rep(i,h) {
	vector<int> done(w);
	rep(j,w) {
	  if (s[i][j] == '#') continue;
	  if (done[j]) continue;
	  int l = 0;
	  while (j+l < w) {
		if (s[i][j+l] == '#') break;
		++l;
	  }
	  rep(k,l){
		cnt[i][j+k] += l;
		done[j+k] = 1;
	  }
	}
  }
  rep(j,w) {
	vector<int> done(h);
	rep(i,h) {
	  if (s[i][j] == '#') continue;
	  if (done[i]) continue;
	  int l = 0;
	  while (i+l < h) {
		if (s[i+l][j] == '#') break;
		++l;
	  }
	  rep(k,l){
		cnt[i+k][j] += l;
		done[i+k] = 1;
	  }
	}
  }
  int ans = 0;
  rep(i,h)rep(j,w) ans = max(ans, cnt[i][j]-1);
  cout << ans << endl;
  return 0;
}



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

typedef long long ll;
const int mod = 1e9+7, N = 2e5+10;
ll q[N], pre[N];
int main() {
	int n;
	scanf("%d", &n);
	ll res = 0;
	for(int i = 1; i <= n; i++) {
		scanf("%lld",&q[i]);
		pre[i] = q[i];
	}
	for(int i = 1; i <= n; i++){
		pre[i] = (pre[i] + pre[i-1]) % mod;
		res = (res + q[i] * pre[i-1] % mod) % mod;
	}
	
	printf("%lld", res);
}

Measured memory_bytes: 6324
#include "bits/stdc++.h"
using namespace std;
vector<int> vec;
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int n,beg;
	int i,count=0;
	scanf("%d",&n);
	vec.resize(n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&vec[i]);
	}
	sort(vec.begin(),vec.end(),cmp);
	beg=vec[0];
	count++;
	for(i=1;i<n;i++)
	{
		if(beg>vec[i])
		{
			count++;
		}
		beg=vec[i];
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>

using namespace std;

typedef complex<double> Point;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, PP> PPP;
typedef pair<double, Point> P2;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;

double dis(Point p1, Point p2){
	return sqrt((p1.real() - p2.real())*(p1.real()-p2.real()) + (p1.imag() - p2.imag())*(p1.imag() - p2.imag()));
}

char field[5][5][4];
string pz[9];
bool used[9];

int dfs(int n){
	if(n == 0) return 1;
	int res = 0;
	int y = (9 - n) / 3 + 1;
	int x = (9 - n) % 3 + 1;
	
	for(int i = 0; i < 9; i++){
		if(used[i]) continue;
		char c1 = field[y][x-1][0];
		char c2 = field[y-1][x][1];
		for(int j = 0; j < 4; j++){
			if((c1 == '*' || abs(c1 - pz[i][(j+2)%4]) == 32) && (c2 == '*' || abs(c2 - pz[i][(j+3)%4]) == 32)){
				field[y][x][0] = pz[i][j];
				field[y][x][1] = pz[i][(j+1)%4];
				field[y][x][2] = pz[i][(j+2)%4];
				field[y][x][3] = pz[i][(j+3)%4];
				used[i] = true;
				res += dfs(n-1);
				used[i] = false;
				for(int k = 0; k < 4; k++)field[y][x][k] = '*';
			}
		}
	}
	return res;
}

int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		fill(&field[0][0][0], &field[4][4][3] + 1, '*');
		memset(used, false, sizeof(used));
		for(int j= 0; j < 9; j++) cin >> pz[j];
		cout << dfs(9) << endl;
	}
	return 0;
}

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

typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ULL;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define __m int mid=(l+r)>>1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1

template<class T>
inline bool rd(T &num) {
    char in;bool IsN = false;
    while(in = getchar(), in != '-' && (in < '0' || in > '9'))if(in == EOF)return false;
    in == '-' ? (IsN = true, num = 0) : num = in - '0';
    while(in = getchar(), in >= '0' && in <= '9')num = num * 10 + in - '0';
    return IsN ? num = -num : num, true;
}
template<class T, class S>
inline bool rd(T &num1, S &num2){return rd(num1)&&rd(num2);}
template<class T, class S, class Z>
inline bool rd(T &num1, S &num2, Z &num3){return rd(num1)&&rd(num2)&&rd(num3);}
template<class T>
inline void _wr(T num){if(num>9)_wr(num/10);putchar('0'+num%10);}
template<class T>
inline void wr(T num){if(num < 0)putchar('-'),num=-num;_wr(num);}

void debug_out(){cerr<<endl;}
string to_string(string s){return '\"'+s+'\"';}
string to_string(char* s){return to_string((string)s);}
string to_string(bool s){return s?"true":"false";}
template<class T>
string to_string(T array);
template<class T,class S>
string to_string(pair<T,S>s){return '('+to_string(s.first)+','+to_string(s.second)+')';}
template<class T>
string to_string(T array){
    bool first=true;string res="[";
    for(const auto&e : array){
        if(!first)res+=",";first=false;res+=to_string(e);
    }
    return res+=']';
}
template<class Head, class... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);}

string nico = "NicoNicoNi";
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define infile(x) freopen(x,"r",stdin)
#define outfile(x) freopen(x,"w",stdout)
#define io ios::sync_with_stdio(0)
#else
#define debug(...)
#define infile(x)
#define outfile(x)
#define io ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#endif

#define rep(a,b,c) for(register int (a)=(b);(a)<(c);++(a))
#define per(a,b,c) for(register int (a)=(b);(a)>=(c);--(a))
#define none(a) memset(a,-1,sizeof(a))
#define clr(a) memset(a,0,sizeof(a))
#define inf(a) memset(a,0x3f,sizeof(a))
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define space putchar(' ')
#define enter puts("")
#define endl '\n'
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define lowbit(x) (x&-x)

const int maxn = 26000;
const int inf  = 0x3f3f3f3f;
const ll  linf  = (1ll*inf)<<32|inf;
const int mod  = 1e9 + 7;
const int none = -1;
const double eps = 1e-7;


int main(){
    io;
    int n;
    cin>>n;
    int tot=0;
    string in;
    cin>>in;
    rep(i,0,n){
        if(in[i]=='R')
            tot++;
    }
    if(tot>n-tot)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String args[]) {
      
      Scanner sc = new Scanner(System.in);
      PrintWriter w = new PrintWriter(System.out);
      
      int n = sc.nextInt();
      int a[] = new int[n]; int do_a[] = new int[n];
      int b[] = new int[n]; int do_b[] = new int[n];
      int c[] = new int[n]; int do_c[] = new int[n];
      
      for(int i = 0; i < n; i++)
      {
          a[i] = sc.nextInt();
          b[i] = sc.nextInt();
          c[i] = sc.nextInt();
      }
      do_a[0] = a[0];
      do_b[0] = b[0];
      do_c[0] = c[0];
      for(int i = 1; i < n; i++)
      {
          do_a[i] = a[i] + Math.max( do_b[i-1], do_c[i-1]);
          do_b[i] = b[i] + Math.max( do_a[i-1], do_c[i-1]);
          do_c[i] = c[i] + Math.max( do_a[i-1], do_b[i-1]);
      }
      w.println( Math.max( do_a[n-1], Math.max( do_b[n-1], do_c[n-1])));
      w.close();
    }
}

Measured memory_bytes: 62392
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

//i???????????????????????????
bool getBit(int num, int i){
    return ((num & (1 << i)) != 0);
}

//i?????????1?????????
int setBit(int num, int i){
    return num | (1 << i);
}

//i?????????0?????????
int clearBit(int num, int i){
    int mask = ~(1 << i);
    return num & mask;
}

//i?????????v??§???????????????
int updateBit(int num, int i, int v){
    int mask = ~(1 << i);
    return (num & mask) | (v << i);
}

const int MAX_N = 16;
double dp[1 << MAX_N][MAX_N], speed[1 << MAX_N];
int pres[1 << MAX_N][MAX_N];

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

    int id[MAX_N], dis[MAX_N], num[MAX_N];
    rep(i,n){
        cin >> id[i] >> dis[i] >> num[i];
    }

    const int N = 1 << n;
    rep(s,N){
        int c = 0;
        rep(i,n){
            pres[s][i] = -1;
            dp[s][i] = 1e11;

            if(getBit(s,i)) c += num[i];
        }
        speed[s] = 2000.0 / (70 + 20 * c);
    }
    rep(i,n) dp[1 << i][i] = 0;

    range(s,1,N){
        rep(i,n){
            rep(j,n){ //i -> j????§????
                //????????°????????\????????¨????????? || ?????????????????§????¨??????????
                if((not getBit(s,i) || getBit(s,j))) continue; 

                double time = dp[s][i] + abs(dis[i] - dis[j]) / speed[s];
                int next_s = setBit(s,j);
                if(dp[next_s][j] > time){
                    dp[next_s][j] = time;
                    pres[next_s][j] = i;
                }
            }
        }
    }

    int cur = 0;
    range(i,1,n){
        if(dp[N - 1][cur] > dp[N - 1][i]){
            cur = i;
        }
    }

    vector<int> v;
    int s = N - 1;
    while(cur != -1){
        v.emplace_back(id[cur]);
        int next = pres[s][cur];
        s = clearBit(s,cur);
        cur = next;
    }

    for(int i = v.size() - 1; i >= 0; i--){
        cout << v[i] << (i == 0 ? '\n' : ' ');
    }
}

Measured memory_bytes: 9492
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    string s;
    cin >> s;
    if(s=="AAA" || s=="BBB"){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

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

using namespace std;


int main() {
    int n;
    cin>>n;
    int count=0;
    for (int i = 0; i < n; ++i) {
        int r,l;
        cin>>r>>l;
        count+=l-r+1;
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(c>=a&&c<=b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define MAXN 100100
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

int n, a[MAXN], dp[MAXN];
ll infi = 1e9;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n;
    for(int i = 0; i < n; i++){
    	cin >> a[i];
    }
    for(int i = n - 2; i >= 0; i--){
    	dp[i] = infi;
    	for(int j = 1; j <= 2; j++){
    		if(i + j >= n) break;
    		dp[i] = min(dp[i], dp[i + j] + abs(a[i] - a[i + j]));
    	}
    }
    cout << dp[0];
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(){
	int n,m;
	cin>>n>>m;
	UnionFind uf(100001);
	for(int i=0;i<m;i++){
		int x,y,z;cin>>x>>y>>z;
		x--;y--;
		uf.unionSet(x,y);
	}
	int ans =0;
	for(int i=0;i<n;i++){
		if(uf.root(i) == i) ans++;
	}
	cout<<ans<<endl;
	return 0;

}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}
using P = pair<int, int>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<P> vec(m);
  rep(i, m) cin >> vec[i].first >> vec[i].second;
  if (n == 1) {
    int ans;
    for (int i = 0; i < m; ++i) {
      if (i == 0) ans = vec[i].second;
      if (ans != vec[i].second) {
        ans = -1;
        break;
      }
    }
    if (m == 0) {
      ans = 0;
    }
    cout << ans << '\n';
  }
  else {
    int print = -1;
    for (int i = pow(10, n - 1); i < pow(10, n); ++i) {
      string s = to_string(i);
      bool ans = true;
      for (int j = 0; j < m; ++j) {
        if (vec[j].first == 1 && vec[j].second == 0) {
          ans = false;
        }
        else if ((s[vec[j].first - 1]) - '0' != vec[j].second) {
          ans = false;
        }
      }
      if (ans) {
        print = i;
        break;
      }
    }
    cout << print << '\n';
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
    string a,b;
    cin >> a >> b;
    int ans=0;
    if(a.size()>b.size()) ans=1;
    else if(a.size()<b.size()) ans=-1;
    else {
        for(int i=0; i<a.size(); i++){
            if(a[i]<b[i]){
                ans=-1;
                break;
            }else if(a[i]>b[i]){
                ans=1;
                break;
            }
        }
    }
    if(ans>0) puts("GREATER");
    else if(ans<0) puts("LESS");
    else puts("EQUAL");
    return 0;
}


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

int main(){
  
  int N,K,count=0;
  cin >> N >> K;
  
  vector<int> h(N);
  
  for(int i=0;i<N;i++){
    cin >> h.at(i);
    if(h.at(i)>=K) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
using namespace std;
struct stu{
    int t,num;
    }a[100010];
int cmp(stu q,stu p)
{
    return q.t<p.t;
}
int main()
{
    int n;scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&a[i].t);
        a[i].num=i;
    }
    sort(a+1,a+n+1,cmp);
    for (int i=1;i<=n;i++)
        printf("%d ",a[i].num);
}



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

int main() {
	int N,m;
    cin >> N;
    int N2 = N;
  for(int i =100000000;i >= 1;i /= 10){
    m += (N2 / i);
    if(N2 >= i){
      N2 %= i;
    }
  }
  if(N % m == 0){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
}

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

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();

        switch (n % 10) {
            case 2:
            case 4:
            case 5:
            case 7:
            case 9:
                out.println("hon");
                return;
            case 0:
            case 1:
            case 6:
            case 8:
                out.println("pon");
                return;
            default:
                out.println("bon");
        }
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 25380
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
const int MOD=998244353;
class mint{
    public:
        long long x;
 
    constexpr mint(long long _x = 0) : x((_x%mod+mod)%mod) {}
    constexpr mint operator-() const{
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long x) const{
        if(!x) return 1;
        mint a = pow(x>>1);
        a *= a;
        if(x&1) a *= *this;
        return a; 
    }
    constexpr mint inv() const{
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a){
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const{
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x; return os;
    }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;cin >> n >> m;
    map<ll,ll> mp;
    ll ans=0,sum=0;
    mp[0]++;
    for(int i=0;i<n;i++){
        ll a;cin >> a;
        sum+=a;
        ans+=mp[sum%m];
        mp[sum%m]++;
    }
    cout << ans << endl;
}

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

int main(){
	string s;
	cin >> s;
	int i, n;
	n = 0;
	rep(i, 4){
		if(s[i] == '+'){
			n++;
			continue;
		}
		n--;
	}
	cout << n << endl;
}

Measured memory_bytes: 256
function Main(input){
	input=input.trim().split(" ");
	A = parseInt(input[0],10);
	B = parseInt(input[1],10);
	C = parseInt(input[2],10);
	var X = parseInt(input[3],10);
	var Y= parseInt(input[4],10);
	var nA, nB, nAB, ans;
	nA = nB = nAB =0;
	function price (nA, nB, nAB){
		return nA * A + nB * B + nAB * C;
	}

	
	if (A >= (2 * C)){
		if (B >= (2 * C)){
			if (X > Y){
				nAB = (Y * 2) + ((X - Y ) * 2);
			} else {
				nAB = (X * 2) + ((Y - X ) * 2);
			}
		} else {
			nAB = X * 2;
			nB = Math.max(Y - X, 0);
		}
	} else {
		if (B >= (2 * C)){
			nAB = Y * 2;
			nA = Math.max(X - Y, 0);
		} else {
			if (A + B > (2 * C)){
				if (X > Y){
					nAB = Y * 2;
					nA = X - Y;
				} else  {
					nAB = X * 2;
					nB = Y - X;
				}
			} else {
				nA = X;
				nB = Y;
			}
		}
	}
	console.log (price(nA, nB, nAB));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
# abc147_c.py
import sys
import time
import unittest
from io import StringIO

# IS_LOCAL = True  # FIXME: delete this


def resolve():
    N = int(input())
    aa = []
    for i in range(N):
        xy = {}
        aa.append(xy)
        for _ in range(int(input())):
            x, y = [int(i) for i in input().split()]
            xy[x - 1] = 1 == y
    maxsum = 0
    for comb in range(2**N - 1, -1, -1):
        sum = 0
        for i in range(N):
            if (comb >> i) & 1:
                sum += 1
                for x in aa[i].keys():
                    if aa[i][x]:
                        if not ((comb >> x) & 1):
                            break
                    else:
                        if (comb >> x) & 1:
                            break
                else:
                    continue
                break
        else:
            maxsum = max(maxsum, sum)
    print(maxsum)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def checkTLE(self, input):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin

    def debugIO(self, input):
        stdin = sys.stdin
        sys.stdin = StringIO(input)
        resolve()
        sys.stdin = stdin

    def setUp(self):
        self.startTime = time.time()

    def tearDown(self):
        t = time.time() - self.startTime
        print('%s: %.3f' % (self.id(), t), flush=True)

    def test_入力例_1(self):
        input = """3
1
2 1
1
1 1
1
2 0"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """2
1
2 0
1
1 0"""
        output = """1"""
        self.assertIO(input, output)


if __name__ == "__main__":
    if "IS_LOCAL" in locals():
        suite = unittest.TestLoader().loadTestsFromTestCase(TestClass)
        unittest.TextTestRunner(verbosity=0).run(suite)
    else:
        resolve()


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;++i)
        cin >> a[i];
        
    sort(a.begin(), a.end());

    int64_t sum = 0;

    for(int i=0;i<n-1;i=i+2)
    {
        if(a[i] <= 0 && a[i+1] <= 0)
            sum += -a[i] - a[i+1];
        else if(a[i] <= 0 && a[i+1] > 0)
        {
            if(-a[i] > a[i+1])
                sum += -a[i] - a[i+1];
            else
                sum += a[i] + a[i+1];
        }
        else
            sum += a[i] + a[i+1];
    }

    if(n % 2 != 0)
        sum += a[n-1];

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--;
  t--;
  vector<vector<vector<int> > > edge(n);
  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    edge[u-1].push_back(vector<int>({v-1, a, b}));
    edge[v-1].push_back(vector<int>({u-1, a, b}));
  }

  vector<ll> stox(n), ttox(n);
  priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > que;
  vector<bool> visited(n);
  que.emplace(0, s);
  while (!que.empty()) {
    auto now = que.top();
    que.pop();
    if (visited[now.second]) continue;
    visited[now.second] = true;
    stox[now.second] = now.first;
    for (auto &x: edge[now.second]) {
      if (!visited[x[0]]) que.emplace(now.first + x[1], x[0]);
    }
  }

  visited = vector<bool>(n);
  que.emplace(0, t);
  while (!que.empty()) {
    auto now = que.top();
    que.pop();
    if (visited[now.second]) continue;
    visited[now.second] = true;
    ttox[now.second] = now.first;
    for (auto &x: edge[now.second]) {
      if (!visited[x[0]]) que.emplace(now.first + x[2], x[0]);
    }
  }

  vector<ll> ans(n);
  priority_queue<pair<ll, int> > rem;
  for (int i = 0; i < n; i++) rem.emplace((ll)1e15 - (stox[i] + ttox[i]), i);
  for (int i = 0; i < n; i++) {
    while (true) {
      auto now = rem.top();
      if (now.second < i) rem.pop();
      else break;
    }
    auto next = rem.top();
    ans[i] = next.first;
  }

  for (auto &x: ans) cout << x << endl;

  return 0;
}


Measured memory_bytes: 21372
// https://atcoder.jp/contests/abc159/tasks/abc159_d

use proconio::input;

fn main() {
    input! {
        n: usize,
        a_s: [usize; n],
    }
    let mut counts: Vec<i32> = vec![0; 200001];
    for &a in &a_s {
        counts[a] += 1;
    }
    counts.shrink_to_fit();
    let combs: Vec<i64> = counts.iter().map(|&c| combinations(c)).collect();
    let sum: i64 = combs.iter().sum();
    for &a in &a_s {
        let c = counts[a];
        let diff = combs[a] - combinations(c - 1);
        println!("{}", sum - diff)
    }
}

fn combinations(x: i32) -> i64 {
    let x = x as i64;
    x * (x - 1) / 2
}


Measured memory_bytes: 7660
#include<iostream>
using namespace std;
int n,a[111],b[111],s,u,d;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
		d+=b[i];
	}
	for(int i=0;i<n;i++)
	{
		u+=a[i];
		s=s<(u+d)?u+d:s;
		d-=b[i];
	}
	cout<<s<<endl;
}

Measured memory_bytes: 764
#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;//往左走w-1,往下走h-1 
const ll mod=1000000007;
ll f[1000000];
ll quick(ll a,ll b)
{
//	cout<<"a"<<a<<"b"<<b<<endl;
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=(ans*a)%mod;
		}
		b>>=1;
		a=(a*a)%mod;
	}
//	cout<<"("<<ans<<endl;
	return ans;
}
ll ni(ll a)
{
//	cout<<"ni"<<endl;
	return quick(a,mod-2);
}
ll c(int n,int m)
{
	ll a=f[n];
//	cout<<"a"<<f[n]<<endl;
	ll b=(f[m]*f[n-m])%mod;
//	cout<<"b"<<b<<endl;
	return (a*ni(b))%mod;
}
int main()
{
	int h,w,a,b;
	f[0]=1;
	for(int i=1;i<=200005;i++)
	{
		f[i]=(f[i-1]*i)%mod;
	}
	cin>>h>>w>>a>>b;
	ll ans=0;
	ll t;
	for(int i=b+1;i<=w;i++)
	{
	//	cout<<"-----"<<endl; 
	//	cout<<"!"<<c(h-a-1+i-1,h-a-1)<<endl;
	//	cout<<"!"<<c(w-i+a-1,a-1)<<endl;
		t=(c(h-a-1+i-1,h-a-1)*c(w-i+a-1,a-1))%mod;
		ans=(ans+t)%mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2424
#include <bits/stdc++.h>
#define fi first
#define se second
#define maxn 200003
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pi;

LL ans;
int n,q;
int tree[2][4*maxn];

void init(int x , int y , int id) {
	tree[0][id] = tree[1][id] = n;
	if(x == y)
		return;
	int mid = (x+y) >> 1;
	init(x,mid,id*2);
	init(mid+1,y,id*2+1);
}

int query(int cx , int cy , int q , int t , int id) {
	if(cy < q || q < cx)
		return maxn;
	if(cx == cy)
		return tree[t][id];
	int mid = (cx+cy) >> 1;
	int l = query(cx,mid,q,t,id*2);
	int r = query(mid+1,cy,q,t,id*2+1);
	int res = min(l,r);
	return min(res,tree[t][id]);
}

void update(int cx , int cy , int qx , int qy , int val , int t , int id) {
	if(cy < qx || qy < cx)
		return;
	if(qx <= cx && cy <= qy) {
		tree[t][id] = min(tree[t][id],val);
		return;
	}
	int mid = (cx+cy)>>1;
	update(cx,mid,qx,qy,val,t,id*2);
	update(mid+1,cy,qx,qy,val,t,id*2+1);
}

int main() {
	scanf("%d%d",&n,&q);
	ans = (LL)(n-2)*(n-2);
	init(1,n,1);
	for( int qq = 0 , t,x ; qq < q ; qq++ ) {
		scanf("%d%d",&t,&x);
		t--;
		if(x == 1)
			continue;
		int sq = query(1,n,x,t,1);
		if(sq > 2) {
			ans -= sq-2;
			update(1,n,2,sq-1,x,1-t,1);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7928
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
      int c=0;
      string s;
      cin>>s;
      for(int i=0;i<s.length()/2;i++)
      {
        if(s[i]!=s[s.length()-i-1])
          c++;
      }
      cout<<c;
      return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
using namespace std;

int main() {
	int n, k, seisu;
	cin >> n;
	cin >> k;
	seisu = 1;
	for (int i = 0; i < n; i++) {
	    if (seisu * 2 - seisu < k) seisu = seisu * 2;
	    else seisu = seisu + k;
	}
	cout << seisu;
	return 0;
}


Measured memory_bytes: 256
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    M, D = map(int, input().split())
    num = 0
    for m in range(1, M + 1):
        for d in range(1, D + 1):
            if d <= 21:
                continue
            else:
                d1 = d % 10
                d2 = (d - d1) // 10
                if d1 < 2:
                    continue
                if d2 < 2:
                    continue
                if d1 * d2 == m:
                    num += 1
    print(num)



if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long LL;
const long long INF = (1LL<<62);

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	LL H, W; cin >> H >> W;
	vector<string> S;
	LL count = 0;
	for(int i=0; i<H; i++){
		string s;
		for(int j=0; j<W; j++){
			char c; cin >> c;
			s.push_back(c);
			if(c == '#'){
				count++;
			}
		}
		S.push_back(s);
	}
	if(count == H-1+W-1+1){
		printf("Possible\n");
	}
	else{
		printf("Impossible\n");
	}
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    str s1, s2, s;
    int a, b;
    cin >> s1 >> s2 >> a >> b >> s;
    if (s == s1)
        a--;
    else
        b--;
    cout << a << ' ' << b << endl;
    GAME_OVER;
}

Measured memory_bytes: 256