akhauriyash/Code-Regression huggingface dataset:
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

#define MAXN 200
int N;
char str[MAXN+5];
vector<int> G[MAXN+5];

int dep[MAXN+5];
bool fa[MAXN+5][MAXN+5];
bool bfs(int S){
    queue<int> Q;
    Q.push(S);dep[S]=1;
    while(!Q.empty()){
        int u=Q.front();Q.pop();
        for(int i=0;i<int(G[u].size());i++){
            int v=G[u][i];
            if(fa[v][u])
                continue;
            if(dep[v]){
                if(dep[v]!=dep[u]+1)
                    return 1;
                fa[u][v]=1;
                continue;
            }
            dep[v]=dep[u]+1;
            fa[u][v]=1;
            Q.push(v);
        }
    }
    return 0;
}

int Solve(int u){
    memset(fa,0,sizeof fa);
    memset(dep,0,sizeof dep);
    if(bfs(u))
        return -1;
    return *max_element(dep+1,dep+N+1);
}

int main(){
    scanf("%d",&N);
    for(int i=1;i<=N;i++){
        scanf("%s",str+1);
        int len=strlen(str+1);
        for(int j=1;j<=N;j++)
            if(str[j]=='1')
                G[i].push_back(j);
    }
    int Ans=-1;
    for(int i=1;i<=N;i++)
        Ans=max(Ans,Solve(i));
    printf("%d\n",Ans);
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final long k = scanner.nextLong();

        if (k == 0) {
            System.out.println(2);
            System.out.println("0 0");
        } else if (k == 1) {
            System.out.println(2);
            System.out.println("2 0");
        } else if (k <= 50) {
            System.out.println(k);
            for (long i = 1; i <= k; i++) {
                System.out.print(i + " ");
            }
            System.out.println();
        } else {
            System.out.println(50);
            final long div = k / 50L;
            final long mod = k % 50L;
            for (long l = 1; l <= 50; l++) {
                System.out.print(50 - l + div + (l <= mod ? 1 : 0));
                System.out.print(" ");
            }
            System.out.println();
        }
    }
}


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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

const int N = 100005;
int a[N], b[N];

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n; cin >> n;
	REPU(i, 0, n) {
		cin >> a[i] >> b[i];
	}
	ll s = 0, ans = 0;
	REPD(i, n - 1, -1) {
		ll x = a[i] + s;
		ll y = (x + b[i] - 1) / b[i] * b[i] - x;
		s += y, ans += y;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
n = int(input())
l = list(map(int,input().split()))
cost = [float('inf')]*(n+1)
cost[0]= 0
cost[1]=abs(l[0]-l[1])
for i in range(n):
  if i==1:
  	cost[i]=abs(l[i-1]-l[i])
  if i>1:
  	cost[i]=min(cost[i],cost[i-2]+abs(l[i]-l[i-2]),cost[i-1]+abs(l[i]-l[i-1]))
print(cost[n-1])


Measured memory_bytes: 20580
#include <iostream>
#include <algorithm>
#include <cstdio>
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
using namespace std;

bool check(int n){
	if(n%3 == 0) return true;
	while(n != 0){
		if(n % 10 == 3) return true;
		n /= 10;
	}
	return false;
}
int main() {
	int n;
	cin >> n;
	FOR(i, 1, n+1){
		if(check(i)){
			cout << " " << i;
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint N;
    cin >> N;
    vec<vec<lint>> num_candies(2, vec<lint>(N, -1));
    range(i, 0, N) cin >> num_candies.at(0).at(i);
    range(i, 0, N) cin >> num_candies.at(1).at(i);
    vec<vec<lint>> pref_sum_num_candies(2, vec<lint>(1, 0));
    range(i, 0, 2) range(j, 0, N) {
        lint n = num_candies.at(i).at(j);
        pref_sum_num_candies.at(i).emplace_back(pref_sum_num_candies.at(i).at(j) + n);
    }
    // cout << num_candies << "\n";
    // cout << pref_sum_num_candies << "\n";

    lint max_total_num = 0;
    range(j, 1, N + 1) {
        lint total_num = pref_sum_num_candies.at(0).at(j) + (pref_sum_num_candies.at(1).at(N) - pref_sum_num_candies.at(1).at(j - 1));
        max_total_num = max(max_total_num, total_num);
    }
    cout << max_total_num << "\n";
}

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

int main(void){
	int h,w;
	while(true){
		cin >> h >> w;
		if(h == 0 && w == 0){
			break;
		}
		for(int i = 0;i < h;i++){
			for(int j = 0;j < w;j++){
				if(i % 2 == 0){
					if(j % 2 == 0){
						cout << "#";
					}else{
						cout << ".";
					}
				}else{
					if(j % 2 == 0){
						cout << ".";
					}else{
						cout << "#";
					}
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

int main() {
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    vi d;
    int c=1;
    if (s[0]=='0')d.push_back(0);
    int now=s[0]-'0';
    for (int i=1;i<n;i++){
        if (now!=s[i]-'0'){
            d.push_back(c);
            c=1;
            now=s[i]-'0';
        }
        else c+=1;
    }
    d.push_back(c);
    if (s[n-1]=='0')d.push_back(0);
    int ans1=0,ans=0;
    ans1+=d[0];
    int num=d.size();
    if (k>=num/2){
        cout<<n<<endl;
        return 0;
    }
    for (int i=1;i<2*k;i+=2){
        ans1+=d[i]+d[i+1];
    }
    ans=ans1;
    for (int i=1;2*k+1+i<num;i+=2){
        ans1-=d[i-1]+d[i];
        ans1+=d[2*k+i]+d[2*k+i+1];
        ans=max(ans,ans1);
    }
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 1020
#include<iostream>
#include<algorithm> 
using namespace std;
int main()
{
	int k=0,n,a[200006];
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n-1;i++)
	{
		if(a[i]==a[i+1])
		{
			k++;
			break;
		}
	}
	if(k)
	cout<<"NO";
	else cout<<"YES";
 } 

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

const long long INF = 1001001001001001001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int H, W; long long K; cin >> H >> W >> K;
	int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
	--x1; --y1; --x2; --y2;

	vector<vector<char>> c(H, vector<char>(W));
	for(int i=0; i<H; ++i) {
	    for(int j=0; j<W; ++j) cin >> c[i][j];
	}

	vector<vector<vector<long long>>> dist(H, vector<vector<long long>>(W, vector<long long>(4, INF)));
	for(int i=0; i<4; ++i) dist[x1][y1][i] = 0;

	using tup = tuple<long long, int, int, int>;
	priority_queue<tup, vector<tup>, greater<tup>> Q;
	for(int i=0; i<4; ++i) Q.emplace(0, x1, y1, i);
	while(!Q.empty()) {
	    auto [cost, x, y, d] = Q.top(); Q.pop();
		if(dist[x][y][d] < cost) continue;

		int nx = x + dx[d], ny = y + dy[d];
		if(nx >= 0 && nx < H && ny >= 0 && ny < W &&
		   c[nx][ny] == '.' && dist[nx][ny][d] > cost + 1) {
		    dist[nx][ny][d] = cost + 1;
			Q.emplace(dist[nx][ny][d], nx, ny, d);
		}

		for(int i=0; i<4; ++i) {
			long long ncost = (cost + K - 1) / K * K;
			if(dist[x][y][i] > ncost) {
			    dist[x][y][i] = ncost;
				Q.emplace(dist[x][y][i], x, y, i);
			}
		}
	}

	long long res = INF;
	for(int i=0; i<4; ++i) {
	    if(dist[x2][y2][i] == INF) continue;
	    res = min(res, (dist[x2][y2][i] + K - 1) / K);
	}
	cout << (res == INF ? -1 : res) << '\n';
}


Measured memory_bytes: 144768
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    int n,len = 0,cnt = 1;
    cin >> n;
    vector<int> q(n);
    for(int i = 0;i < n;i ++){
        int p;
        cin >> p;
        q[p-1] = i;
    }
    for(int i = 1;i < n;i ++){
        if(q[i]>q[i-1]) cnt ++;
        else {
            len = max(len,cnt);
            cnt = 1;
        }
    }
    len = max(len,cnt);
    cout << n-len << endl;
    return 0;
}

Measured memory_bytes: 1024
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

def lcm(a, b):
    return a * b // gcd(a, b)

n, m = map(int, input().split())
s = str(input())
t = str(input())
g = gcd(n, m)
l = lcm(n, m)
for i in range(g):
    if s[i*n//g] != t[i*m//g]:
        print(-1)
        break
else:
    print(l)


Measured memory_bytes: 3316
// Problem : A - Remaining Balls
// Contest : AtCoder Beginner Contest 154
// URL : https://atcoder.jp/contests/abc154/tasks/abc154_a
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
#define ll                    long long int
#define pb                    push_back
#define F                     first
#define S                     second
#define mp                    make_pair
#define MOD                   1000000007
#define vi                    vector<int>
#define vll                   vector<ll>
#define pll                   pair<ll,ll>
#define pii                   pair<int,int>
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define eb                    emplace_back
#define ull                   unsigned long long
#define bug(x)				  cout<<"  [ "#x<<" = "<<x<<" ]"<<endl;
#define KAMEHAMEHA            ios_base::sync_with_stdio(0);
#define RASENGAN              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    KAMEHAMEHA
//    #ifdef _soumik
//        freopen("input.txt", "r", stdin);
//    #endif
	string s,t,u;
	int a,b;
	cin>>s>>t>>a>>b>>u;
	if(s==u)
		cout<<a-1<<" "<<b<<endl;
	else
		cout<<a<<" "<<b-1<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={-1,1,0,0};
int dw[4]={0,0,1,-1};
int main(){
    int h,w,n;cin>>h>>w>>n;
    int sh,sw;cin>>sh>>sw;
    string s,t;cin>>s>>t;
    int nh=sh;
    rep(i,0,n){
        if(s[i]=='U')nh--;
        if(nh==0){
            cout<<"NO"<<endl;
            return 0;
        }
        if(t[i]=='D')nh=min(h,nh+1);
    }
    nh=sh;
    rep(i,0,n){
        if(s[i]=='D')nh++;
        if(nh==h+1){
            cout<<"NO"<<endl;
            return 0;
        }
        if(t[i]=='U')nh=max(1,nh-1);
    }
    int nw=sw;
    rep(i,0,n){
        if(s[i]=='L')nw--;
        if(nw==0){
            cout<<"NO"<<endl;
            return 0;
        }
        if(t[i]=='R')nw=min(w,nw+1);
    }
    nw=sw;
    rep(i,0,n){
        if(s[i]=='R')nw++;
        if(nw==w+1){
            cout<<"NO"<<endl;
            return 0;
        }
        if(t[i]=='L')nw=max(1,nw-1);
    }
    cout<<"YES"<<endl;
    
}


Measured memory_bytes: 776
#include <iostream>

int main() {
	int N, M;
	std::cin >> N >> M;
	if (N >= 2 && M >= 2) std::cout << N * (N - 1) / 2 + M * (M - 1) / 2 << '\n';
	else if (N >= 2) std::cout << N * (N - 1) / 2 << '\n';
	else if (M >= 2) std::cout << M * (M - 1) / 2 << '\n';
	else std::cout << "0\n";
return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define eps 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
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<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



string s;

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

  int zero_num = 0;
  int one_num = 0;

  Rep(i, n) {
    if (s[i] == '0') zero_num++;
    else one_num++;
  }

  cout << 2 * min(zero_num, one_num) << "\n";

}

Measured memory_bytes: 512
# DPを用いて解く。
# 少し複雑なので、自分の解説と照らし合わせて読むこと。
MOD = 10**9+7
N = int(input())

# AGCT→0123として扱う

# dpテーブルの作成shape=(101, 3,3,3) #長さが0~100まで扱いたいため
import numpy as np
dp = np.zeros((N+1, 4, 4, 4), dtype="int64")

dp[0, 3, 3, 3] = 1  # 解説放送流テクニカルな楽な初期化
# 末尾がc3,c2,c1で終わる長さlの文字列の通りの数を計算していく
# print(dp)
for l in range(N):
    for c3 in range(4):
        for c2 in range(4):
            for c1 in range(4):
                # すでに条件を満たしていないのでスキップ(なくても多分平気)
                if dp[l, c3, c2, c1] == 0:
                    continue
                # 最後につける一文字を考える
                for a in range(4):
                    # あかん条件
                    if a == 1 and c1 == 2 and c2 == 0:
                        continue
                    if a == 2 and c1 == 1 and c2 == 0:
                        continue
                    if a == 2 and c1 == 0 and c2 == 1:
                        continue
                    if a == 2 and c1 == 1 and c3 == 0:
                        continue
                    if a == 2 and c2 == 1 and c3 == 0:
                        continue
                    dp[l + 1, c2, c1, a] += dp[l, c3, c2, c1] % MOD
                    dp[l + 1, c2, c1, a] %= MOD

print(dp[N, :, :, :].sum() % MOD)


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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a =scan.nextInt();
		int b =scan.nextInt();
		if(a>b)System.out.println("a > b");
		else if(a<b)System.out.println("a < b");
		else System.out.println("a == b");
        scan.close();
	}

}


Measured memory_bytes: 26172
a = list(map(int,input()))

if a[0]+a[1]+a[2]+a[3] == 7:
  print("{0}+{1}+{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()
if a[0]-a[1]+a[2]+a[3] == 7:
  print("{0}-{1}+{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()
if a[0]+a[1]-a[2]+a[3] == 7:
  print("{0}+{1}-{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()
if a[0]+a[1]+a[2]-a[3] == 7:
  print("{0}+{1}+{2}-{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()
if a[0]-a[1]-a[2]+a[3] == 7:
  print("{0}-{1}-{2}+{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()
if a[0]-a[1]+a[2]-a[3] == 7:
  print("{0}-{1}+{2}-{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()
if a[0]+a[1]-a[2]-a[3] == 7:
  print("{0}+{1}-{2}-{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()
if a[0]-a[1]-a[2]-a[3] == 7:
  print("{0}-{1}-{2}-{3}=7".format(a[0],a[1],a[2],a[3]))
  exit()


Measured memory_bytes: 3188
#include<stdio.h>
int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a+b==c+d){
		printf("Balanced\n");
	}else if(a+b<c+d){
		printf("Right");
	}else{
		printf("Left\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200010;
int a[N], n;
ll sum[N];
ll get(int l, int r){
	return sum[r] - sum[l - 1];
}
inline void chkmin(ll& a, ll b){
	if(a > b) a = b;
}
inline void chkmax(ll& a, ll b){
	if(a < b) a = b;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	for(int i = 1; i <= n; i++)
		sum[i] = sum[i - 1] + a[i];
	ll ans = 1LL << 60;
	for(int i = 3; i <= n - 1; i++){
		ll a[4];
		int low = i, high = n - 1;
		int step = 100;
		int mid1, mid2;
		while(step-- && low <= high){
			mid1 = (low + low + high) / 3;
			mid2 = (low + high + high) / 3;
			ll s1 = get(i, mid1), s2 = get(mid1 + 1, n);
			ll s3 = get(i, mid2), s4 = get(mid2 + 1, n);
			if(abs(s1 - s2) > abs(s3 - s4))
				low = mid1 + 1;
			else
				high = mid2;
		}
		vector<pair<ll, ll> > vp1;
		for(int j = -2; j <= 2; j++){
			int nh = high + j;
			if(nh >= i && nh + 1 <= n)
				vp1.emplace_back(get(i, nh), get(nh + 1, n));
		}
		
		low = 2, high = i - 1;
		step = 100;
		while(step-- && low <= high){
			mid1 = (low + low + high) / 3;
			mid2 = (low + high + high) / 3;
			ll s1 = get(mid1, i - 1), s2 = get(1, mid1 - 1);
			ll s3 = get(mid2, i - 1), s4 = get(1, mid2 - 1);
			if(abs(s1 - s2) > abs(s3 - s4))
				low = mid1 + 1;
			else
				high = mid2;
		}
		
		a[2] = get(high, i - 1), a[3] = get(1, high - 1);
		
		vector<pair<ll, ll> > vp2;
		for(int j = -2; j <= 2; j++){
			int nh = high + j;
			if(nh <= i - 1 && 1 <= nh - 1)
				vp2.emplace_back(get(nh, i - 1), get(1, nh - 1));
		}
		for(auto it : vp1) for(auto jt : vp2){
			ll a[4] = {it.first, it.second, jt.first, jt.second};
			ll xv = 0, nv = 1LL << 60;
			for(int j = 0; j < 4; j++)
				chkmax(xv, a[j]), chkmin(nv, a[j]);
			chkmin(ans, xv - nv);
		}
	}
	cout << ans << "\n";
	return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i);
  }
  if(n%2==0)
  {
    for(i = n-1; i >= 0; i -= 2)
    {
      if(i != n-1)cout << ' ';
      cout << a.at(i);
    }
    for(i = 0; i < n; i += 2)
    {
      cout << ' ' << a.at(i);
    }
    cout << endl;
  }
  else
  {
    for(i = n-1; i >= 0; i -= 2)
    {
      if(i != n-1)cout << ' ';
      cout << a.at(i);
    }
    for(i = 1; i < n; i += 2)
    {
      cout << ' ' << a.at(i);
    }
    cout << endl;
  }
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int a=0,b=0,c,i;
int main(void)
{
    for(i=1,c;i<=3;i++)
	{
        scanf("%d",&c);
        if(c==5)a++;
        else if(c==7)b++;
    }
    if(a==2&&b==1)puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <functional>

using namespace std;

int rec(int *d, int left, int right){
    int l = right - left + 1;
    if (l == 1) {
        return 1;
    } else {
        if (d[left] == d[left + 1]) {
            return rec(d, left + 1, right);
        } else {
            return 1 + rec(d, left + 1, right);
        }
    }
}

int main(){
    int n, i, N;
    int d[100];
    scanf("%d", &n);
    for(i = 0; i < n; ++i){
        scanf("%d", &d[i]);
    }

    std::sort(d, d + n, std::greater<int>());

    N = rec(d, 0, n - 1);
    printf("%d", N);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;
//Attack Survival

int main() {

	int n = 0, k = 0, q = 0, a = 0, num[100000] = {};
	
	cin >> n >> k >> q;

	for (int i = 0; i < q; i++) {
		cin >> a;
		num[a-1]++;
		

	}

	for (int i = 0; i < n; i++) {
		num[i] += k - q;
	}


	for (int i = 0; i < n; i++) {
		if (num[i]>0) {
			cout << "Yes"<<endl;
		}
		else {
			cout << "No"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
# define INF 0x3f3f3f3f
#define MOD 1000000007
#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d%d",&x,&y)
#define siii(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d%d",x,y)
#define piii(x,y,z) printf("%d%d%d",x,y,z) 
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld%lld",&x,&y)
#define slll(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld%lld",x,y)
#define plll(x,y,z) printf("%lld%lld%lld",x,y,z) 
 
#define ll long long
#define mp make_pair
#define pb push_back
#define pp pop_back
#define nl printf("\n");
#define sf scanf
#define pf printf
#define rep(i,n) for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define vint vector<int> 
#define tci int t;scanf("%d",&t);while(t--)
const int maxn=10e6+4;

int main()
{
    ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }

    int n,k;
    sii(n,k);
    int p=1;
    while(n--)
    {
    	if(p>k)
    	{
    		p+=k;
    	}
    	else
    	{
    		p+=p;
    	}
    }
    cout<<p;
    return 0;
}	

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      (int)1e9+7
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;

int main(){
	int n;
	cin>>n;
	
	vector<int> yen(1,1);
	for(int i=6;i<=n;i*=6) yen.push_back(i);
	for(int i=9;i<=n;i*=9) yen.push_back(i);
	sort(ALL(yen));
	//REP(i,yen.size()) cout<<yen[i]<<endl;//!!!
	
	vi dp(n+1,INF);
	dp[0]=0;
	for(int i=1;i<=n;++i){
		for(int j=0;yen[j]<=i&&j<yen.size();++j) dp[i]=min(dp[i],dp[i-yen[j]]+1);
	}
	
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 640
S = input()
T = input()

letters = 'abcdefghijklmnopqrstuvwxyz'
res = "Yes"
for st in letters:
    temp = ""
    for i in range(len(S)):
        if S[i] == st:
            if temp and T[i] != temp:
                res = "No"
                break
            else:
                temp = T[i]
    if res == "No":
        break

for st in letters:
    temp = ""
    for i in range(len(T)):
        if T[i] == st:
            if temp and S[i] != temp:
                res = "No"
                break
            else:
                temp = S[i]
    if res == "No":
        break

print(res)

Measured memory_bytes: 3632
/*
ID: jerrywcy
LINK: https://atcoder.jp/contests/abc126/tasks/abc126_d
LANG: C++
STATUS:
*/
#include <bits/stdc++.h>

#define init(array,x) memset(array,x,sizeof(array))
#define pb push_back

using namespace std;

const int inf=0x3f3f3f3f;
const int maxn=100010;

struct edge{
	int u,v,w,nxt;
}e[maxn*2];

int n;
int head[maxn],tot;
bool c[maxn];

void add(int u,int v,int w){
	tot++;
	e[tot].u=u,e[tot].v=v,e[tot].w=w,e[tot].nxt=head[u];
	head[u]=tot;
}

void dfs(int u,int fa){
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].v;
		bool w=e[i].w&1;
		if (v!=fa){
			c[v]=c[u]^w;
			dfs(v,u);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1;i<n;i++){
		int u,v,w;
		cin>>u>>v>>w;
		add(u,v,w);
		add(v,u,w);
	}
	
	dfs(1,0);
	
	for (int i=1;i<=n;i++)cout<<c[i]<<endl;

	return 0;
}



Measured memory_bytes: 6144
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int N = 200003;

int n, m;
int a[N], b[N];
char s[N];

int main()
{
    scanf("%s", s + 1);
    if (s[1] == '7' || s[2] == '7' || s[3] == '7') puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3760
#include<stdio.h>
int main()
{
    int A,B,C,D;
    int S[2];
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&D);
    if(A>B)
        S[0]=B;
    else
        S[0]=A;
    if(C>D)
        S[1]=D;
    else
        S[1]=C;
    printf("%d\n",S[0]+S[1]);
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {
            var a = cin.ReadInt.ToString();
            var b = cin.Read.ToString();

            var tmp = a + b;
            var c = Convert.ToInt64(tmp);

            double x = Sqrt((double)c);

            if (x == (int)x) WriteLine("Yes");
            else WriteLine("No");
        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
    cin >> s;
    int slen = s.length();
    vector<int> a;
    vector<int> z;
    for(int i = 0; i < slen; ++i) {
        if(s.at(i) == 'A') {
            a.push_back(i);
        }else if(s.at(i) == 'Z') {
            z.push_back(i);
        }
    }

    cout << z.back() - a.front() + 1 << endl;
}

Measured memory_bytes: 1364
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using static System.Console;
using static System.Math;
using static Utils;
class Program
{


    void Solve()
    {
        var N = io.Int;
        WriteLine(
            (double)(Enumerable.Range(1, N).Count(x => x % 2 != 0)) / N
            );

    }


    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Program().Stream();
    private void Stream()
    {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //SetIn(exStdIn);
        Solve();
        io.Flush();
    }

}

class SimpleIO
{
    string[] _nextBuffer;
    int _bufferCnt;
    char[] cs = new char[] { ' ', '"', ',' };
    StreamWriter sw = new StreamWriter(OpenStandardOutput())
    {
#if DEBUG
        AutoFlush = true
#else
        AutoFlush = false
#endif
    };
    public SimpleIO()
    {
        _nextBuffer = new string[0];
        _bufferCnt = 0;
        SetOut(sw);
    }
    string Next()
    {
        if (_bufferCnt < _nextBuffer.Length) return _nextBuffer[_bufferCnt++];
        var st = ReadLine();
        while (st == string.Empty) st = ReadLine();
        _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        _bufferCnt = 0;
        return _nextBuffer[_bufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void Flush() => Out.Flush();
}
class Utils
{
    public static T id<T>(T x) => x;
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

bool isPrime(ll n) {
    if(n == 0 || n == 1) {
        return false;
    }
    for(ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    ll num = x;
    while(1) {
        if(isPrime(num)) {
            cout << num << endl;
            break;
        }
        num++;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

const int max_n = 100000+19;
int N,M;
int S,T;
vector<pair<int,int>> G[max_n][3];
bool visited[max_n][3];
int dist[max_n][3];

int main(void) {
    cin>>N>>M;

    int inf = TEN(8);

    for(int i = 1;i <= N;i++) {
        for(int j = 0;j < 3;j++) {
            dist[i][j] = inf;
        }
    }

    for(int i = 0;i < M;i++) {
        int u,v;
        cin>>u>>v;
        G[u][0].push_back({v,1});
        G[u][1].push_back({v,2});
        G[u][2].push_back({v,0});
    }
    cin>>S>>T;

    priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>> Q; //dist, node, state
    Q.push({0, make_pair(S, 0)});
    
    while(!Q.empty()) {
        pair<int,pair<int,int>> p = Q.top();Q.pop();
        if(visited[p.second.first][p.second.second])
            continue;
        visited[p.second.first][p.second.second] = true;

        for(auto u: G[p.second.first][p.second.second]) {
            int node = u.first;
            int state = u.second;
            if(p.first+1 < dist[node][state]) {
                dist[node][state] = p.first+1;
            }
            Q.push({p.first+1,make_pair(node, state)});
        }
    }

    if(dist[T][0] == inf)
        cout<<-1<<endl;
    else
        cout<<dist[T][0]/3<<endl;


    return 0;
}


Measured memory_bytes: 18176
n = int(input())
s = [input() for _ in range(n)]
ans = {}
for i in range(n):
    if s[i] in ans.keys():
        ans[s[i]] += 1
    else:
        ans[s[i]] = 1


if 'AC' in ans.keys():
    print('AC x %d' % ans['AC'])
else:
    print('AC x %d' % 0)

if 'WA' in ans.keys():
    print('WA x %d' % ans['WA'])
else:
    print('WA x %d' % 0)

if 'TLE' in ans.keys():
    print('TLE x %d' % ans['TLE'])
else:
    print('TLE x %d' % 0)

if 'RE' in ans.keys():
    print('RE x %d' % ans['RE'])
else:
    print('RE x %d' % 0)


Measured memory_bytes: 16268
import numpy as np
N = int(input())
S = np.array([list(input()) for _ in range(N)], dtype="U1")
S = np.concatenate([S, S], axis=1)


def check(x):
    tmp = S[:, x: x + N]
    if (tmp == tmp.T).all():
        return N
    return 0


ans = 0
for x in range(N):
    ans += check(x)

print(ans)


Measured memory_bytes: 15620
import math
a,b = [float(i) for i in input().split()]
ans = 1000000000
flag = False

for i in range(1,10000):
    ans8 = int(math.floor(i*0.08))
    ans10 = int(math.floor(i*0.1))
#     print(ans8,ans10)
    if ans8 == a and ans10 == b:
        ans = min(ans, i)
        flag = True

if flag is True:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 9080
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
#include <deque>
#include <math.h>
#include <tgmath.h>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << "\n";}
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

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 aabs(ll a) {
    if (a < 0) return -a;
    return a;
}

//fast power
ll calc(ll a, ll b) {
    if (b == 0) return 1;
    else if (b % 2 == 0) {
        ll d = calc(a, b / 2);
        return (d * d) % MOD;
    }
    else return (a * calc(a, b - 1)) % MOD;
}

//fast combination
ll comb(ll n, ll a) {
    ll b = 1, c = 1;
    for (ll i = 1; i <= a; ++i) {
        b = b * i % MOD;
        c = c * (n - i + 1) % MOD;
    }

    return c * calc(b, MOD - 2) % MOD;
}

ll comb2(ll a) {
    ll b = a / 2;
    if (a % 2) {
        b = (a - 1) / 2;
        return (b * a);
    }
    return (b * (a - 1));
}

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

    deque<ll> deq;

    rep (i, 0, n) {
        cin >> a;
        if (i % 2) deq.push_front(a);
        else deq.push_back(a);
    }

    if (n % 2) reverse(deq.begin(), deq.end());

    rep (i, 0, n) cout << deq[i] << ' ';
    cout << endl;

    return 0;
}


Measured memory_bytes: 3840
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int N;
    int[] A;

    private void solve() {
        N = nextInt();
        A = new int[N];
        for(int i = 0;i < N;i++) {
            A[i] = nextInt();
        }

        long[] sum = new long[N + 1];
        for(int i = 0;i < N;i++) {
            sum[i+1] = sum[i] + A[i];
        }

        HashMap<Long,Long> map = new HashMap<>();
        for(int i = 1;i < N+1;i++) {
            if(map.containsKey(sum[i])) {
                map.put(sum[i], map.get(sum[i]) + 1);
            } else {
                map.put(sum[i], 1L);
            }
        }

        long ans = 0;
        for(long v : map.keySet()) {
            if (v == 0) {
                ans += map.get(v);
            }
            ans += map.get(v) * (map.get(v) - 1) / 2;
        }
        out.println(ans);
    }
    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

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


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

const int mxN = 2e5 + 5;
vector<int> adj[mxN];
long long cnt[mxN];

void dfs(int node, int parent = - 1, long long add = 0) {
	int cur = cnt[node];
	cnt[node] += add;
	add += cur;
	for(int x : adj[node]) {
		if(x == parent)
			continue;
		dfs(x, node, add);
	}
}

int main() {
	int n, q;
	cin >> n >> q;
	for(int i = 1; i < n; ++i) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	while(q--) {
		int v, c;
		cin >> v >> c;
		cnt[v] += c;
	}
	dfs(1);
	for(int i = 1; i <= n; ++i)
		cout << cnt[i] << ' ';
}

Measured memory_bytes: 25468
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	
	if(s.length()==2)
	{
		if(s[0]==s[1])
		{
			cout<<"1 2\n";
		}	
		else
		{
			cout<<"-1 -1\n";
		}
		
		
		return 0;
	}
	
	
	for(int i=0;i<=s.length()-3;i++)
	{
		string p= s.substr(i,3);
		if(p[0]==p[1] or p[0]==p[2] or p[1]==p[2])
		{
			cout<<i+1<<" "<<i+3<<"\n";
			return 0;
		}
	}
	
	cout<<"-1 -1\n";
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    string s;

    cin >> s;

    if (s == "ABC")
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }
}


Measured memory_bytes: 3624
##N本の棒を持っています。i番目の棒の長さは liです。
##K本の棒を選んでつなげて、ヘビのおもちゃを作りたいです。
##ヘビのおもちゃの長さは選んだ棒たちの長さの総和で表されます。
##ヘビのおもちゃの長さとしてありうる長さのうち、最大値を求めなさい。

##入力は以下の形式で標準入力から与えられる。
##N K
##l1 l2 l3 ... lN
n, k = gets.chomp.split(" ").map(&:to_i)
a_l  = gets.chomp.split(" ").map(&:to_i).sort.reverse

sum = 0
k.times do |idx|
  sum += a_l[idx]
end

p sum

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main (){
	int x,j,ans,s=9999;
	cin>>x;
	if(x==1){cout<<x;return 0;}
	for(int i=2;i*i<=x;i++){
		for(j=i;j*i<=x;j=j*i){}
		if(x-j<s) s=x-j;
	}
	ans=x-s;
	cout<<ans;
	return 0;
}


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

int cntPair[2002];
int ans[4002];

int main(){
  for(int i = 0; i <= 1000; i++){
    for(int j = 0; j <= 1000; j++){
      cntPair[i + j]++;
    }
  }

  for(int i = 0; i <= 2000; i++){
    for(int j = 0; j <= 2000; j++){
      ans[i + j] += cntPair[i] * cntPair[j];
    }
  }

  int n;

  while(cin >> n){
    cout << ans[n] << endl;
  }
}

Measured memory_bytes: 1188
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<ll, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

int main(){
    string t;
    cin >> t;
    string nw;
    int n;
    for(int i = 0 ; i < t.size(); i ++ ){
        nw.push_back(t[i]);
        if(nw.size() >= 2){
            n = nw.size();
            if(nw[n-2] == 'B' && nw[n-1] == 'C'){
                nw.pop_back();
                nw.pop_back();
                nw.push_back('D');
            }
        }
    }
    n = nw.size();
    ll res = 0;
    int cnt = 0;
    while(!nw.empty()){
        if(nw.back() == 'D') cnt ++ ;
        else if(nw.back() == 'A'){
            res += cnt;
        }
        else{
            cnt = 0;
        }
        nw.pop_back();
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 776
n, t = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
dp = [[0]*(t+1) for _ in range(n+1)]
for i in range(n):
    for j in range(t+1):
        dp[i+1][j] = max(dp[i][j], dp[i+1][j])
        res = j+ab[i][0]
        if res<=t: dp[i+1][res] = max(dp[i][res], dp[i][j]+ab[i][1])
    dp[i+1][t] = max(dp[i+1][t], dp[i][t], dp[i][t-1]+ab[i][1])
print(dp[n][t])

Measured memory_bytes: 145976
import java.util.*;
public class Main {
 
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    
	    int N;
	    String S;
	    int K;
	    
	    N=sc.nextInt();
	    S=sc.next();
	    K=sc.nextInt();
	    
	    char s=S.charAt(K-1);
	    
	    String ans="";
	    
	    for(int i=0;i<N;i++){
	    	if(!(S.charAt(i)==s)) {
	    		ans=ans+'*';
	    	}else {
	    		ans=ans+S.charAt(i);
	    	}
	    }
	    
	    System.out.println(ans);
	    
	    
	    
	}
 
}

Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    ll n,m; cin>>n>>m;
    vector<bool> broken(n,false);
    rep(i,m){
        ll a;
        cin>>a;
        broken[a-1]=true;
    }
    vector<ll> ways(n,0);
    if(broken[0]==false) ways[0]=1;
    if(broken[1]==false){
        ways[1]=1;
        ways[1]+=ways[0];        
    }

    for(int i=2; i<n; i++){
        if(broken[i]==false){
            ways[i]=ways[i-1] + ways[i];
            ways[i]=ways[i-2] + ways[i];
            ways[i]%=MOD;
        }
    }
    cout<<ways[n-1]<<endl;
}


Measured memory_bytes: 1024
$N=<>;
@xyi=sort{@$a[0]-@$b[0]||@$a[1]-@$b[1]}map[glob(<>),$_],0..$N-1;
for(@xyi,reverse@xyi[0..$N-2]){
	while(@t>=2&&(@$_[1]-$t[-1][1])*(@$_[0]-$t[-2][0])<(@$_[1]-$t[-2][1])*(@$_[0]-$t[-1][0])){
		pop@t
	}
	push@t,$_
}
pop@t;
for(0..$#t){
	$a=$t[$_][0]-$t[$_-1][0];
	$b=$t[$_][1]-$t[$_-1][1];
	$c=$t[($_+1)%@t][0]-$t[$_][0];
	$d=$t[($_+1)%@t][1]-$t[$_][1];
	if($a*$c+$b*$d){
		$o[$t[$_][2]]=atan2($a*$d-$b*$c,$a*$c+$b*$d)/(2*atan2(0,-1))
	}else{
		if($c==0&&$d==0){
			$o[$t[$_][2]]=atan2($b,$a)/(2*atan2(0,-1))
		}else{
			$o[$t[$_][2]]=1/4
		}
	}
}
print$o[$_]+0,$/for 0..$N-1


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int main()
{
	int N;
	cin >> N;
	while(N--)
	{
		string s;
		cin >> s;

		set<string> ret;
		for(int i=1; i<s.size(); i++)
		{
			string a=s.substr(0,i);
			string b=s.substr(i,s.size()-i);
			string c=a; reverse(c.begin(), c.end());
			string d=b; reverse(d.begin(), d.end());

			ret.insert(a+b);
			ret.insert(b+a);
			ret.insert(a+d);
			ret.insert(d+a);
			ret.insert(b+c);
			ret.insert(c+b);
			ret.insert(c+d);
			ret.insert(d+c);
		}

		cout << ret.size() << endl;
	}
}

Measured memory_bytes: 1000