akhauriyash/Code-Regression huggingface dataset:
// B. 

#include <sstream>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

LL n;
LL x;
vector<LL> a;

LL cost(LL d) {
	LL tot = 0;
	for (LL i = 0; i < d; ++i) {
		LL k = 0, l = 0;
		for (LL j = ((n - 1) / d) * d + i; j >= 0; j -= d) {
			if (j >= n) {
				continue;
			}
			if (!k) {
				tot += a[j];
			}
			else {
				tot += (k + 1) * (k + 1) * (l - a[j]);
			}
			tot += x;
			++k;
			l = a[j];
		}
		if (l) {
			tot += x;
			tot += (k + 1) * (k + 1) * l;
		}
	}
	return tot;
}

int main(int argc, char *argv[])
{
	cin >> n >> x;
	a.resize(n);
	for (LL i = 0; i < n; ++i) {
		cin >> a[i];
	}
	LL left = 1, right = n;
	for (LL t = 0; t < 100; ++t) {
		if (cost((left * 2 + right) / 3) < cost((left + right * 2) / 3)) {
			right = (left + right * 2) / 3;
		} else {
			left = (left * 2 + right) / 3;
		}
	}
	LL ans = 1LL << 60;
	for (LL d = max(1LL, left - 1); d <= min(n, left + 1); ++d) {
		ans = min(ans, cost(d));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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 maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    ll W,H,x,y; cin>>W>>H>>x>>y;
    ll tmp=0;
    
    if(x*2==W && y*2==H) tmp=1;
    
    printf("%.13f %lld",(W*H)/2.0,tmp);
}


Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int n, m;
	cin >> n >> m;
	if (abs(n - m) >= 2) {
		cout << '0' << endl;
		return 0;
	}

	ll ans1 = 1ll, ans2 = 1ll;
	repr(i, 1, n+1) {
		ans1 = (ans1 * i) % MOD;
	}
	repr(i, 1, m+1) {
		ans2 = (ans2 * i) % MOD;
	}
	ll ans = ans1 * ans2 % MOD;
	if (n == m) {
		ans = ans * 2 % MOD;
	}
	
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.length();

  long long res = 0, now = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A') {
      now++;
    } else if (i + 1 < n && s[i] == 'B' && s[i + 1] == 'C') {
      res += now;
      i++;
    } else {
      now = 0;
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 640
import fractions
import sys

input = sys.stdin.readline


def factorization(n):
    primes = []
    while n % 2 == 0:
        primes.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            primes.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        primes.append(n)
    return primes


def main():
    a, b = list(map(int, input().split()))

    # 素因数分解
    g = fractions.gcd(a, b)
    print(len(set(factorization(g))) + 1)


if __name__ == "__main__":
    main()


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

int main(){
    int x[5];
    cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
    
    for(int i=0; i<5; i++){
        if(x[i] == 0){
            cout << i+1 <<endl;
        }
    }
    
    return 0;
}

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

#define int long long
#define endl '\n'
int32_t main()
{

    int a,b,cnt=0;
    cin>>a>>b;
    while(a--)
    {
    	int x,y;
    	cin>>x>>y;
    	
    	if(x*x+y*y<=b*b)
    		cnt++;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 3608
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑




int main() {
	int a, b, k[15][15], ans = 0;
	cin >> a >> b;
	for (int i = 0; i < a; ++i) {
		for (int j = 0; j < b; ++j) {
			cin >> k[i][j];
		}
	}

	for (int i = 0; i < a; ++i) {
		for (int j = i + 1; j < a; ++j) {
			double mon = 0;
			for (int kk = 0; kk < b; ++kk) {
				mon += (k[i][kk] - k[j][kk])*(k[i][kk] - k[j][kk]);
			}
			if (fmod(sqrt(mon), 1) == 0) { ++ans; }
		}
	}

	cout << ans << endl;
}

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

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

    vector<ll> a, b;

    if (N % 2 == 0) {
        for (ll i = 1; i < N; i++) {
            for (ll j = i + 1; j <= N; j++) {
                if (i + j != N + 1) {
                    a.push_back(i);
                    b.push_back(j);
                }
            }
        }
    } else {
        for (ll i = 1; i < N; i++) {
            for (ll j = i + 1; j <= N; j++) {
                if (i + j != N) {
                    a.push_back(i);
                    b.push_back(j);
                }
            }
        }
    }

    cout << a.size() << endl;
    for (ll i = 0; i < a.size(); i++) {
        cout << a[i] << " " << b[i] << endl;
    }
}


Measured memory_bytes: 384
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

class SumSegTree {
private:

	int _sum(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)return 0;    // 交差しない
		if (a <= l && r <= b)return dat[k];   // a,l,r,bの順で完全に含まれる
		else {
			int s1 = _sum(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
			int s2 = _sum(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
			return s1 + s2;
		}
	}
public:
	int n, height;
	vector<int> dat;

	// 初期化（_nは最大要素数）
	SumSegTree(int _n) {
		n = 1;
		height = 1;
		while (n < _n) {
			n *= 2;
			height++;
		}
		dat = vector<int>(2 * n - 1, 0);
	}

	// 場所i(0-indexed)にxを足す
	void add(int i, int x) {
		i += n - 1; // i番目の葉ノードへ
		dat[i] += x;
		while (i > 0) { // 下から上がっていく
			i = (i - 1) / 2;
			dat[i] += x;
		}
	}

	// 区間[a,b)の総和。ノードk=[l,r)に着目している。
	int sum(int a, int b) {
		return _sum(a, b, 0, 0, n);
	}
};

void Dijkstra(Graph& G, ll s, Array& d) {//O(|E|log|V|)
	d.resize(G.size());
	REP(i, d.size())d[i] = INF;
	d[s] = 0;
	priority_queue<P, vector<P>, greater<P>> q;
	q.push(make_pair(0, s));
	while (!q.empty()) {
		P a = q.top();
		q.pop();
		if (d[a.second] < a.first)continue;
		REP(i, G[a.second].size()) {
			Edge e = G[a.second][i];
			if (d[e.to] > d[a.second] + e.cap) {
				d[e.to] = d[a.second] + e.cap;
				q.push(make_pair(d[e.to], e.to));
			}
		}
	}
}

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

	ll n;
	cin >> n;
	Array a(n, 0);
	REP(i, n) cin >> a[i];

	Array sum(n + 1, 0);
	REP(i, n) sum[i + 1] = sum[i] + a[i];

	ll ans = INF;
	for (int i = 0; i < n-1;i++) {
		ll sum1 = sum[i + 1] - sum[0];
		ll sum2 = sum[n] - sum[i + 1];
		if (abs(sum1 - sum2) < ans) ans = abs(sum1 - sum2);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3456
import sys
input = sys.stdin.readline
N, S = map(int, input().split())
a = list(map(int, input().split()))
mod = 998244353
#print(a)
dp = [0] * (S + 1)
dp[0] = 1
md = pow(2, mod - 2, mod)
for i in range(N):
  for x in range(S, -1, -1):
    if dp[x] == 0: continue
    if x + a[i] <= S:
      dp[x + a[i]] += dp[x] * md % mod
      dp[x + a[i]] %= mod
print(dp[-1] * pow(2, N, mod) % mod)

Measured memory_bytes: 68428
N, M = map(int, input().split())

answered = [False] * N
will_wa = [0]*N
n_ac = 0
n_wa = 0

for _ in range(M):
  p, s = input().split()
  p = int(p)
  p -= 1
  if not answered[p]:
    if s == 'WA':
      will_wa[p] += 1
    else:
      answered[p] = True
      n_wa += will_wa[p]
      n_ac += 1

print(n_ac, n_wa)


Measured memory_bytes: 51160
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		int s = sc.nextInt();
		
		// 計算
		String result = "";
		//StringBuilder sb = new StringBuilder();
		for(int i = 0; i < n; i++){
		    if(i < k){
		        System.out.print(s);
		        System.out.print(" ");
		    }else{
		        if(s != 1000000000)System.out.print(s+1);
		        if(s == 1000000000)System.out.print(s-1);
		        System.out.print(" ");
		    }
		}

		// 出力
		System.out.println(result);
	}
}




Measured memory_bytes: 42044
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

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

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[110][110];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll res = 0;
vector<ll> A(13);
ll p = 0;
ll q, ans;
struct item {
	ll a, b, c, d;
} st[55];


int main() {
	cin >> n;
	vector<ll> a(n);
	ll cnt0 = 0;
	ll cnt2 = 0;
	ll cnt4 = 0;
	rep(i, n) {
		cin >> a[i];
		if (a[i] % 4 == 0) {
			cnt4++;
		}
		else if (a[i] % 4 != 0 && a[i] % 2 == 0) {
			cnt2++;
		}
		else {
			cnt0++;
		}
	}
	if (cnt2 > 1) {
		cnt2 = 1;
	}
	if (cnt4 + 1 >= cnt2 + cnt0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 1024
n = int(input())
s = list(input())

former = set(s[0])
latter = set(s[1:])
ans = len(former & latter)

for i in range(2, n):
	former = set(s[:i])
	latter = set(s[i:])
	if len(former & latter) > ans:
		ans = len(former & latter)
        
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string str;
  cin >> str;
  int q,i;
  cin >> q;
  string s1,s2;
  int a,b;
  for(i=0;i<q;i++){
    cin >> s1 >> a >> b;
    if(s1=="print"){
      cout << str.substr(a,b-a+1) << endl;
    }else if(s1=="reverse"){
      string s3=str.substr(a,b-a+1);
      reverse(s3.begin(),s3.end());
      str=str.substr(0,a)+s3+str.substr(b+1,str.size()-a-1);
    }else{
      cin >> s2;
      str=str.substr(0,a)+s2+str.substr(b+1,str.size()-a-1);
    }
  }
}


Measured memory_bytes: 3240
import java.util.*;

@SuppressWarnings("unused")
public class Main {

  private static void solve() {
    int n = ni();
    for (int i = 0; i < n; i++) {
      System.out.print("ACL");
    }
    System.out.println();
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 25508
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		String ans = "No";
		
		if ((Math.abs(a - b) <= d && Math.abs(c - b) <= d) || Math.abs(a - c) <= d) {
			ans = "Yes";
		}
		
		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 21460
package main

import (
	"fmt"
)

func main() {
	var x, y int
	fmt.Scan(&x, &y)
	if x == 4 || x == 6 || x == 9 || x == 11 {
		if y == 4 || y == 6 || y == 9 || y == 11 {
			fmt.Println("Yes")
			return
		}
	}
	if x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12 {
		if y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12 {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 998244353;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    vvl dp(c + 1, vl(d + 1));
    dp[a][b] = 1;
    FOR(i, a, c + 1) FOR(j, b, d + 1) {
        if (i > a) {
            dp[i][j] += (dp[i - 1][j] * j) % MOD;
            dp[i][j] %= MOD;
        }
        if (j > b) {
            dp[i][j] += (dp[i][j - 1] * i) % MOD;
            dp[i][j] %= MOD;
        }
        if (i > a and j > b) {
            dp[i][j] -= (((dp[i - 1][j - 1] * (i - 1)) % MOD) * (j - 1)) % MOD;
            if (dp[i][j] < 0) dp[i][j] += MOD;
        }
    }
    cout << dp[c][d] << endl;
}


Measured memory_bytes: 73596
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
  
#define mp make_pair
#define f first
#define s second
#define ll long long
#define pb push_back
 
using namespace std;
/*
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  */
const int inf = 2e9+7, mod=1e9+7;
const int N = 1e3;
 
ll xx[8]={1, 1, -1, -1, 1, -1, 0, 0};
ll yy[8]={1, -1, 1, -1, 0, 0, 1, -1};

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,k;
	cin >> n >> k;
	cout << min(n%k, k-(n%k));
	
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    if(n % k == 0)
        cout << 0 << endl;
    else
        cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

#define ll long long 
#define ld long double
#define ull unsigned long long

#define sz(x) (int)x.size()
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define sagyndym_seni ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define damn exit(0)

using namespace std;

const ll N = 25005, INF = 1e9+5, mod = 998244353;

signed main() {
// 	ifstream cin("input.txt"); 
	sagyndym_seni;
	string s; cin>>s;
	int cnt = 0;
	for(int i = 0; i < sz(s); i++){
		if(s[i] == '?'){ s[i] = 'D';};
	}
	cout<<s;
//	for(int i = 0; i < sz(s); i++){
//		if(s[i] == 'D'){ cnt++;}
//	}
//	for(int i = 0; i < sz(s) - 1; i++){
//		if(s[i] == 'P' && s[i + 1] == 'D'){ cnt++;}
//	}
//	cout<<cnt;
	return 0;
}

/* TIMUS: 292220YC*/

Measured memory_bytes: 3724
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

//??°?????????????????°

void function()
{
    //??¢??°
}
 
int main(){
	int a, b;
	while(cin >> a >> b){
		int sum = a + b;
		int cnt = 1;
		while(true){
			sum /= 10;
			if(sum == 0){
				break;
			}
			cnt++;
		}
		cout << cnt << endl;
	}
    return 0;
}

Measured memory_bytes: 1160
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100001
#define INF (ll)1e18
#define pll pair<ll,ll>
#define pii pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);
#define pi 3.1415926535897


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

    get(d);

    vector<vector<ll>> dp(d, vector<ll>(2,0));
    dp[0][1] = 1;

    for(ll i=0;i<s.length();i++) {
        vector<vector<ll>> dp2(d, vector<ll>(2,0));
        for(ll j=0;j<=9;j++) {
            for(ll k=0;k<d;k++)
                dp2[(k+j)%d][0] = (dp2[(k+j)%d][0] + dp[k][0])%N; 
        }

        ll digi = s[i]-'0';
        for(ll j=0;j<digi;j++) {
            for(ll k=0;k<d;k++)
                dp2[(k+j)%d][0] = (dp[k][1] + dp2[(k+j)%d][0])%N;
        }

        for(ll k=0;k<d;k++)
            dp2[(k+digi)%d][1] = (dp2[(k+digi)%d][1] + dp[k][1])%N;

        dp = dp2;
    }

    ll ans = (dp[0][1]+dp[0][0]-1)%N;

    printf("%lld\n",(N+ans)%N);
    return 0;  
}

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

int main() {
  string s;
  cin >> s;
  if (s[0] == s[1] && s[0] != s[2] && s[2] == s[3]) {
    cout << "Yes" << endl;
  } else if (s[0] == s[2] && s[0] != s[1] && s[1] == s[3]) {
    cout << "Yes" << endl;
  } else if (s[0] == s[3] && s[0] != s[1] && s[1] == s[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
//g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG caddi/d.cpp
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define scint(x) scanf("%d", &x)
#define scll(x) scanf("%lld", &x)

typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする

    int N;
    // vector<int> v(N);
    cin >> N;
    int flag = 0;
    rep(i, N){
        int k;
        cin >> k;
        if(k % 2 != 0){
            flag = 1;
            break;
        }
    }
    if(flag){
        cout << "first" << "\n";
    }else{
        cout << "second" << "\n";
    }
    
    return 0;
}

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

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  rep(i, n) scanf("%d", &a[i]);

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


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int m;
  cin >> m;
  vector<int> b(m);
  rep(i, m) cin >> b[i];

  vector<int> result;
  set_difference(all(a), all(b), back_inserter(result));
  for (auto r : result)
    cout << r << endl;
  return 0;
}



Measured memory_bytes: 5472
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  vector<pair<ll, ll> > b(m);
  vector<ll> ruiseki(n);

  rep(i, n)  cin >> a[i];
  rep(i, m){
    cin >> b[i].second >> b[i].first;
  }

  int itr = 0;

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  bool deru = true;

  for(int i = 0; i < m  && itr < n && deru; ++i){
    for(int j = 0; j < b[i].second; ++j){
      if(a[itr] < b[i].first){
        a[itr] = b[i].first;
        itr++;

      } else {
        deru = false;
      }
    }
  }
  ll ans = 0;

  rep(i, n){
    ans += a[i];
  }
  cout << ans << endl;

}


Measured memory_bytes: 3328
s = input()
if (s[0]==s[1])or(s[0]==s[2])or(s[0]==s[3]):
    if (s[0]==s[1])and(s[0]==s[2])and(s[0]==s[3]):
        print("No")
    else:        
        if s[0]==s[1]:
            if (s[2]==s[3])and(s[0]!=s[2]):
                print("Yes")
            else:
                print("No")
        if s[0]==s[2]:
            if (s[1]==s[3])and(s[0]!=s[1]):
                print("Yes")
            else:
                print("No")
        if s[0]==s[3]:
            if (s[1]==s[2])and(s[0]!=s[1]):
                print("Yes")
            else:
                print("No")     
else:
    print("No")

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define loop(i, n) for(int i = 0;i < n;i++)
#define IINF 2e9
#define MOD 1e9+7

int main(void){

    int n;
    cin >> n;

    int count = 0;
    for(int i = 1;i <= n;i++){
        count += (n/i);
        if(n%i == 0) count--; 
    }

    cout << count << endl;

    return 0;
}

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

#define ll long long

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    int arr[m];
    int sum=0;
    for(int i=0; i<m; i++){
        cin >> arr[i];
        sum+=arr[i];
    }

    if(sum>n) cout << -1 << "\n";
    else cout << n-sum << "\n";

    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>
#include <iostream>

std::vector<long long> enum_div(long long n){
	std::vector<long long> ret;
	for(long long i=1;i*i<=n;++i){
		if(n%i==0){
			ret.push_back(i);
			if(i*i!=n){
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}
using namespace std;
int main()
{
  long long N;
  scanf("%lld",&N);
  std::vector<long long> r = enum_div(N);
  
  long long value = 0;
  for(long long i=1,ei=r.size();i<ei;i++){
    if((N/(r[i]-1))==(N%(r[i]-1))){
      value += r[i]-1;
    }
  }
  std::cout << value << std::endl;
  return 0;
}


Measured memory_bytes: 384
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
inpr(v1::Tuple{Int,Int},v2::Tuple{Int,Int})=v1[1]*v2[1]+v1[2]*v2[2]
norm(v1::Tuple{Int,Int})=sqrt(v1[1]^2+v1[2]^2)
calc(v1::Tuple{Int,Int},v2::Tuple{Int,Int})=inpr(v1,v2)/(norm(v1)*norm(v2))

function accos(x::Float64)
	if x<-1.0
		3.141592653589793
	elseif x<1.0
		acos(x)
	else
		0.0
	end
end

function main()
	n = readline() |> parseInt
	a = Tuple{Int,Int,Int}[(0,0,0) for i in 1:n]
	for i in 1:n
		x,y = readline() |> split |> parseMap
		a[i] = (x,y,i)
	end
	b = copy(a)
	a = sort(a,by=x->(x[1],x[2]))
	vg = zeros(Float64,n,n,n)
	for i in 1:n
		for j in 1:n-1
			for k in j:n
				v1 = (a[j][1]-a[i][1],a[j][2]-a[i][2])
				v2 = (a[k][1]-a[i][1],a[k][2]-a[i][2])
				val = accos(calc(v1,v2))
				vg[i,j,k] = val
				vg[i,k,j] = val
			end
		end
	end
	cf = Int[1]
	v1 = (0,-1)
	xc = 0
	theta = 0.0
	for i in 2:n
		v2 = (a[i][1]-a[1][1],a[i][2]-a[1][2])
		val = acos(calc(v1,v2))
		if theta<val
			theta = val
			xc = i
		end
	end
	bbxc = 1
	v1 = (a[1][1]-a[xc][1],a[1][2]-a[xc][2])
	push!(cf,xc)
	while xc != 1
		bxc = xc
		theta = 0.0
		for i in 1:n
			if i != bxc
				if theta<vg[bxc,bbxc,i]
					theta = vg[bxc,bbxc,i]
					xc = i
				end
			end
		end
		if xc==bxc
			push!(cf,1)
			break
		end
		bbxc = bxc
		v1 = (a[bxc][1]-a[xc][1],a[bxc][2]-a[xc][2])
		push!(cf,xc)
	end
	nc = zeros(Float64,n)
	l = length(cf)
	nc[a[cf[1]][3]] = 0.5*(pi-vg[cf[1],cf[2],cf[l-1]])/pi
	for i in 2:l-1
		nc[a[cf[i]][3]] = 0.5*(pi-vg[cf[i],cf[i+1],cf[i-1]])/pi
	end
	for i in 1:n
		println(nc[i])
	end
end

main()

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

using namespace std;

typedef long long ll;

int main(){
	ll n, sum=0;
	cin >> n;

	for(ll i=1; i<=(int)pow(n,0.5); i++){
		if(!(n%i)){		
			ll res = n/i-1;
			if(res>i) sum+=n/i-1;
		}
	}
	
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 384
import numpy as np

n = int(input())
jobs = [list(map(int, input().split())) for i in range(n)]

jobs.sort(key=lambda x:x[1])

flg = True

a = np.array(jobs)[:,0]
b = np.array(jobs)[:,1]

s = np.add.accumulate(a)
if sum(s > b):
    print('No')
else:
    print('Yes')

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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

llint n,k;

bool f[105];
void solve(){
	cin >> n >> k;
	for(int i=0;i<k;i++){
		int d;
		cin >> d;
		for(int j=0;j<d;j++){
			llint a;
			cin >> a;
			f[a]=true;
		}
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(!f[i])cnt++;
	}
	cout << cnt << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


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

using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
#define fi first
#define se second
#define endl '\n'
#define y1 holyshit

int d[35]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51,};

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int x; cin>>x;
    cout<<d[x-1];
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,x,y;
  cin >> n >> x >> y;
  x--; y--;
  vi kyori(n - 1, 0);
  for(int i = 0; i < n - 1; i++){
    for(int j = i + 1; j < n; j++){
      int val = min({j - i, 1 + abs(i - x) + abs(j - y), 1 + abs(i - y) + abs(j - x)});
      kyori[val - 1]++;
    }
  }
  rep(i, n - 1) cout << kyori[i] << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	int n;
	int[] a;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
		sc.close();
	}

	Main(Scanner sc) {
		n = sc.nextInt();
		a = new int[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
	}

	void solve() {
		long cnt1 = (a[0]>0)?0:(Math.abs(a[0])+1);
		int sign = 1;
		long sum = (a[0]>0)?a[0]:1;
		for(int i=1;i<n;i++){
			sum += a[i];
			if(sum*sign>=0){
				cnt1 += Math.abs(sum) + 1;
				sum = -sign;
			}
			sign *= -1;
		}
		
		long cnt2 = (a[0]<0)?0:(Math.abs(a[0])+1);
		sign = -1;
		sum = (a[0]<0)?a[0]:-1;
		for(int i=1;i<n;i++){
			sum += a[i];
			if(sum*sign>=0){
				cnt2 += Math.abs(sum) + 1;
				sum = -sign;
			}
			sign *= -1;
		}

		System.out.println(Math.min(cnt1, cnt2));
	}
}

Measured memory_bytes: 53936
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int []a = new int [n];
		int []b = new int [n];
		int []c = new int [n];
		
		int sum = 0;
		
		for(int i = 0; i < n ;i++) {
			a[i]= sc.nextInt();
		}
		for(int i = 0; i < n ;i++) {
			
			b[i]= sc.nextInt();
			sum += b[i];
		}
		for(int i = 0; i < n-1 ;i++) {
			c[i]= sc.nextInt();
		}
		;
		for(int i = 0; i < n-1 ;i++) {
			if(a[i+1] - a[i] == 1) {
				sum += c[a[i]-1];
			} 
		}
		System.out.println(sum);
		

	}

}


Measured memory_bytes: 21204
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        long [] x = new long[n];
        long [] y = new long[n];
        long [] z = new long[n];
        for (int i = 0; i < n; ++i) {
            x[i] = scanner.nextLong();
            y[i] = scanner.nextLong();
            z[i] = scanner.nextLong();
        }
        int[] scale = {-1, 1};
        long result = 0;
        for (int a = 0; a < 2; ++a) {
            for (int b = 0; b < 2; ++b) {
                for (int c = 0; c < 2; ++c) {
                    PriorityQueue<Long> sum = new PriorityQueue<>(Comparator.reverseOrder());
                    long currentSum = 0;
                    for (int i = 0; i < n; ++i) {
                        long current = scale[a] * x[i] +
                                scale[b] * y[i] +
                                scale[c] * z[i];
                        sum.add(current);
                    }
                    for (int i = 0; i < m; ++i) {
                        currentSum += sum.poll();
                    }
                    result = Math.max(result, currentSum);
                }
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 26168
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N , a , b , c , d;
  cin >> N;
  
  a = N / 1000;
  b = N / 100 - a * 10;
  c = N / 10 -a * 100 - b * 10;
  d = N % 10;
 
  if ( ( a == b && b == c ) || ( b == c && c == d ) ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3640
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, k) = (v[0], v[1] as i64);
    let mut a = vec![0; n];
    for i in 0..n {
        a[i] = read::<usize>();
    }

    let mut seg = SegTree::new(300001, 0, std::cmp::max);
    for i in 0..n {
        let search_min = max((a[i] as i64 - k), 0) as usize;
        let search_max = min((a[i] as i64 + k), 300000) as usize;
        let cur = seg.query(search_min, search_max + 1);
        seg.update(a[i], cur + 1);
    }
    let ans = seg.query(0, 300001);
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[derive(Clone)]
struct SegTree<T, F>
where
    F: Fn(T, T) -> T,
    T: std::clone::Clone + std::marker::Copy,
{
    n: usize,
    dat: Vec<T>,
    init: T,
    functor: F,
}

impl<T, F> SegTree<T, F>
where
    F: Fn(T, T) -> T,
    T: std::clone::Clone + std::marker::Copy,
{
    fn new(n: usize, init: T, f: F) -> SegTree<T, F> {
        let mut m = 1;
        // For simplicity, we use 2 ** n sized SegTree.
        while m < n {
            m *= 2;
        }
        SegTree {
            n: m,
            dat: vec![init; 2 * m - 1],
            init: init,
            functor: f,
        }
    }

    // dat[k] = a;
    fn update(&mut self, k: usize, a: T) {
        let mut k = k;
        k += self.n - 1;
        self.dat[k] = a;
        while k > 0 {
            k = (k - 1) / 2;
            self.dat[k] = (self.functor)(self.dat[k * 2 + 1], self.dat[k * 2 + 2]);
        }
    }

    // [a, b)
    fn query(&self, a: usize, b: usize) -> T {
        self.query_inner(a, b, 0, 0, self.n)
    }

    fn query_inner(&self, a: usize, b: usize, k: usize, l: usize, r: usize) -> T {
        if r <= a || b <= l {
            return self.init;
        }
        if a <= l && r <= b {
            return self.dat[k];
        }

        let vl = self.query_inner(a, b, k * 2 + 1, l, (l + r) / 2);
        let vr = self.query_inner(a, b, k * 2 + 2, (l + r) / 2, r);
        (self.functor)(vl, vr)
    }
}


Measured memory_bytes: 6704
#include <stdio.h>

int N(int n){
  return n*(n+1)*(n+2)/6;
}

main(){
  int i,j,n,fx[1000000],d=1,min,fy[1000000],nn=1;

  while(1){
    scanf("%d",&n);
    if(n==0) break;
    
    
    fx[0] = 0;
    fy[0] = 0;
    for(i=nn;i<=n;i++){
      if(i == N(d+1)) d++;
      
      min = -1;
      for(j=1;j<=d;j++){
	if(min == -1 || fx[i-N(j)]+1 < min) min = fx[i-N(j)]+1;
      }
      fx[i] = min;
      
      min = -1;
      for(j=1;j<=d;j++){
	if(N(j)%2 == 0) continue;
	else if(min == -1 || fy[i-N(j)]+1 < min) min = fy[i-N(j)]+1;
      }
      fy[i] = min;
    }
    
    
    if(nn < n) nn = n+1;
    
    printf("%d %d\n",fx[n],fy[n]);
    
  }
  return 0;
}

Measured memory_bytes: 7948
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    string s;
    cin >> s;
    int ans = 0;int renzoku = 0;
    rep(i,s.length())
    {
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')
        {
            ++renzoku;
            ans=max(ans,renzoku);
        }
        else
        {
            renzoku=0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = sorted(list(map(int, input().split())), reverse=True)
    MOD = int(1e9) + 7
    ok = True
    ans = 1
    for i in range(N):
        # print(a[i], N - 1 - i//2)
        if a[i] != N - 1 - 2 * (i//2):
            ok = False
            break
        elif i&1 == 1:
            ans *= 2
            ans %= MOD
    if not ok:
        print(0)
    else:
        print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 14068
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  int N, M; cin >> N >> M;
  vector<bool> covered(N, false);
  REP(i,M){
	int a, l; cin >> a >> l;
	REP(i,l)
	  covered[(a+i)%N] = true;
  }

  for(int i=0;i<N && covered.back();++i){
	covered.insert(covered.begin(), true);
	covered.pop_back();
  }

  VI ans(N+1, 0);
  int num = 0;
  REP(i,N){
	if(covered[i]) ++num;
	else if(num > 0){
	  ans[num]++;
	  num = 0;
	}
  }
  if(num > 0)
	ans[num]++;
  
  for(int i=N;i>0;--i)
	if(ans[i] > 0)
	  cout << i << " " << ans[i] << endl;
  
  return 0;
}


Measured memory_bytes: 1200