akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

const int N = 1005;
const int mo = 1000000007;
const int INF = 1e18;

struct Point {
	int x, y;
};
int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
bool M[N][N];

int dis[N][N];
int dp[N][N];

void bfs(int h, int w, Point p) {
	queue<Point> q;
	rep(i, N) rep(j, N) dis[i][j] = INF;

	dis[p.y][p.x] = 0;
	q.push(p);

	Point u;
	while (not q.empty()) {
		u = q.front();
		q.pop();
		rep(i, 4) {
			Point next;
			next.x = u.x + dx[i];
			next.y = u.y + dy[i];
			if (next.x < 0 || next.x >= w || next.y < 0 || next.y >= h)
				continue;
			if (dis[next.y][next.x] == INF) {
				dis[next.y][next.x] = dis[u.y][u.x] + 1;
				q.push(next);
			}
		}
	}
}

int h, w;
int dfs(Point c, vector<string>& s) {
	if (dp[c.y][c.x] != -1) return dp[c.y][c.x];
	// rep(i, h) { rep(j, w) { cout << dp[i][j] << ' '; } cout << endl; } cout
	// << endl;

	int sum = 0;
	rep(d, 4) {
		int nx = c.x + dx[d];
		int ny = c.y + dy[d];
		if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
		if (dis[ny][nx] == dis[c.y][c.x] - 1 and s[ny][nx] == '.') {
			sum = sum + dfs(Point{nx, ny}, s) % mo;
		}
	}
	return dp[c.y][c.x] = sum;
}

signed main() {
	cin >> h >> w;

	vector<string> s(h);
	rep(i, h) cin >> s[i];

	bfs(h, w, Point{0, 0});
	// rep(i, h) { rep(j, w) { cout << dis[i][j] << ' '; } cout << endl; }
	rep(i, h) {
		rep(j, w) { dp[i][j] = -1; }
	}
	dp[0][0] = 1;
	cout << dfs(Point{w - 1, h - 1}, s) % mo << endl;
}


Measured memory_bytes: 17920
x, k, d = map(int, input().split())
x = abs(x)
dis = x
mov_num = min(round(x / d), k)
k -= mov_num
dis -= d * mov_num
if k % 2 == 0:
    print(abs(dis))
else:
    print(min(abs(dis - d), abs(dis + d)))

Measured memory_bytes: 61800
# https://atcoder.jp/contests/abc079/tasks/abc079_c


def solve(S):
    for a in ['+', '-']:
        for b in ['+', '-']:
            for c in ['+', '-']:
                if eval('{}{}{}{}{}{}{}'.format(
                        S[0], a, S[1], b, S[2], c, S[3]
                )) == 7:
                    return '{}{}{}{}{}{}{}=7'.format(
                        S[0], a, S[1], b, S[2], c, S[3]
                    )


if __name__ == '__main__':
    S = input()
    print(solve(S))


Measured memory_bytes: 3060
#include <iostream>
#include <map>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;
int main(){
        int H,W;
        char s[55][55];
        cin >> H >> W;
        rep(j,W+2) {
                s[0][j]='.';
                s[H+1][j]='.';
        }
        rep(i,H+2){
                s[i][0]='.';
                s[i][W+1]='.';
        }
        rep(i,H) rep(j,W){
                cin >> s[i+1][j+1];
        }
        REP(i,1,H+1) REP(j,1,W+1){
                if(s[i][j]=='#') continue;
                int count = 0;
                REP(k,-1,2) REP(l,-1,2){
                        if(s[i+k][j+l]=='#') count++;
                }
                s[i][j]='0'+count;
        }

        REP(i,1,H+1){
                REP(j,1,W+1){
                        cout << s[i][j];
                }
                cout << endl;
        }
        return 0;
}


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

int main(){
	int N,M;
	cin >> N >> M;
	ll ans = pow(2,M)*(100*(N-M)+1900*M);
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007
int ans=0;
int F[9][9];
int N;
int A[9]={0,};

void route(int start, int count){
	
	if(count==N){
		ans++;
		
	}else{
		fyg(N+1,1){
			if(A[y]==0&&F[start][y]==1){
				//F[start][y]=0;
				//F[y][start]=0;
              A[y]=1;
				route(y,count+1);
				//F[start][y]=1;
				//F[y][start]=1;
              A[y]=0;
			}
		}
		
	}
	
}

int main() {
	
	int M;
	cin>>N>>M;
	fx(M){
		int a,b;
		cin>>a>>b;
		F[a][b]=1;
		F[b][a]=1;
	}
	A[1]=1;
	route(1,1);
	ce(ans)

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    int a,b;cin>>a>>b;
    if (a<=9 && b<=9)
    {
        cout << a*b << endl;
    }
    else
    {
        cout<< -1 << endl;
    }
    
}


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

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int N;
    cin >> N;
    vector<lli> a(3 * N);
    REP (i, 0, a.size()) cin >> a[i];
    sort(a.begin(), a.end(), greater<lli>());
    int rest = 1;
    lli sum = 0;
    int cnt = 0;
    REP (i, 1, a.size()) {
        if (rest >= 1) {
            rest--;
            sum += a[i];
            cnt++;
        } else {
            rest++;
        }
        if (cnt >= N) break;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
bool can[80][80][6401];
int main(){
    int h,w;
    scanf("%d%d",&h,&w);
    int a[h][w];
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            scanf("%d",&a[i][j]);
        }
    }
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            int x;
            scanf("%d",&x);
            a[i][j] -= x;
            if (a[i][j] < 0) a[i][j] = -a[i][j];
        }
    }
    can[0][0][a[0][0]] = 1;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            for (int k = 0; k <= 6400; k++){
                if (i) can[i][j][k] |= can[i-1][j][abs(k-a[i][j])];
                if (j) can[i][j][k] |= can[i][j-1][abs(k-a[i][j])];
                if (k+a[i][j] > 6400) continue;
                if (i) can[i][j][k] |= can[i-1][j][k+a[i][j]];
                if (j) can[i][j][k] |= can[i][j-1][k+a[i][j]];

            }
        }
    }
    for (int i = 0; i <= 6400; i++){
        if (can[h-1][w-1][i]){
            printf("%d",i);
            return 0;
        }
    }

}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N;
    string S;
    cin >> N>>S;

    if(N>=3200){
        cout << S << endl;
    }
    else{
        cout << "red" << endl;
    }
}


Measured memory_bytes: 3608
K=int(input())
if K%2==0 or K%5==0:
    print(-1)
    exit()
if K==7 or K==1:
    print(1)
    exit()
if K==3:
    print(3)
s=7%K
for i in range(1000001):
    tmp=(10*(K-s))%K
    s=K-tmp+7
    #print(s)
    if s==0 or s==K:
        print(i+2)
        exit()

Measured memory_bytes: 9196
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

m = [[0] * 2005 for i in range(4005)]

def f():
    K, N = map(int, raw_input().split())
    MOD = 998244353

    for i in range(4001):
        m[i][0] = 1
    for i in range(2001):
        m[i][i] = 1
    for i in range(1, 4001):
        for j in range(1, 2001):
            m[i][j] = (m[i - 1][j] + m[i - 1][j - 1]) % MOD

    m2 = [1] * 4005
    for i in range(1, 4001):
        m2[i] = (m2[i - 1] * 2) % MOD

    ls = []
    for i in range(2, K + 2):
        ans = 0
        if i % 2 == 0:
            rem = i / 2 - 1
            for j in range(rem + 1):
                ans += m[N + K - 2 - rem * 2][K - 2 - rem * 2 + j] \
                * m[rem][j] * m2[j]
                ans += m[N + K - 3 - rem * 2][K - 2 - rem * 2 + j] \
                * m[rem][j] * m2[j]
                ans %= MOD
        else:
            rem = i / 2
            for j in range(rem + 1):
                ans += m[N + K - 1 - rem * 2][K - 1 - rem * 2 + j] \
                * m[rem][j] * m2[j]
                ans %= MOD
        ls.append(ans % MOD)

    ls += ls[:-1][::-1]

    for num in ls:
        print num

f()


Measured memory_bytes: 96924
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

#define PI 3.141592653589793238
#define INF 1050000000

using namespace std;



//cout << fixed << setprecision(15) << << endl;
//cout << << endl;

int main() {

	int a, b, c;

	cin >> a >> b >> c;

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



	return 0;
}

Measured memory_bytes: 256
// Problem : D - Friends
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

int n, m;
vi graph[maxN];
bool used[maxN];

int BFS(int start) {
	used[start] = true;
	queue<int> Q;
	Q.push(start);
	int ans = 0;
	while (!Q.empty()) {
		int u = Q.front(); Q.pop();
		ans++;
		// cout << ans << " " << u << endl;
		for (auto x: graph[u]) {
			if (!used[x]) {
				used[x] = true;
				Q.push(x);
			}
		}
	}
	// cout << endl;
	return ans;
}
// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		graph[a].pb(b);
		graph[b].pb(a);
	}
	int ans = 1;
	RI(i, n) {
		if (!used[i]) {
			ans = max(ans, BFS(i));
		}
	}
	cout << ans;
	return 0;
}
 


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

int main(){
    int A,B;
    cin>>A>>B;
    if(A==B){
        cout<<"Draw"<<endl;
    }else if(A==1){
        cout<<"Alice"<<endl;
    }else if(B==1){
        cout<<"Bob"<<endl;
    }else if(A<B){
        cout<<"Bob"<<endl;
    }else if(A>B){
        cout<<"Alice"<<endl;
    }
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

int main() {
  ll n;
  cin >> n;
  vector<vector<P>> eds(n);
  vll visited(n, -1);

  rep(i, n) {
    ll u, v, w;
    cin >> u >> v >> w;
    eds[u-1].emplace_back(v-1, w);
    eds[v-1].emplace_back(u-1, w);
  }

  queue<ll> que;
  que.push(0);
  visited[0] = 0;
  while (!que.empty()) {
    ll u = que.front();
    que.pop();
    for (auto& p : eds[u]) {
      ll v, w;
      tie(v, w) = p;
      if (visited[v] != -1) continue;
      que.push(v);
      if (w % 2 == 0)
        visited[v] = visited[u];
      else
        visited[v] = 1 - visited[u];
    }  // p
  }

  rep(i, n) { cout << visited[i] << endl; }

  return 0;
}


Measured memory_bytes: 9728
#include <stdio.h>

int main(void)
{
    int N,i,M,m,a[4800];
    //a[4800]={0};
    m=0;
    int b[9]={0};
    
    scanf("%d",&N);
    
    for(i=0;i<N;i++)
    {
        scanf("%d",&a[i]);
    }
    
    
    
    for(i=0;i<N;i++)
    {
        if(a[i]<400)
        {
            b[0]=1;
        }
        if((a[i]>=400)&&a[i]<800)
        {
            b[1]=1;
        }
        if((a[i]>=800)&&a[i]<1200)
        {
            b[2]=1;
        }
        if((a[i]>=1200)&&a[i]<1600)
        {
            b[3]=1;
        }
        if((a[i]>=1600)&&a[i]<2000)
        {
            b[4]=1;
        }
        if((a[i]>=2000)&&a[i]<2400)
        {
            b[5]=1;
        }
        if((a[i]>=2400)&&a[i]<2800)
        {
            b[6]=1;
        }
        if((a[i]>=2800)&&a[i]<3200)
        {
            b[7]=1;
        }
        if(a[i]>=3200)
        {
            b[8]++;
        }
    }
    
    
    for(i=0;i<8;i++)
    {
        m=m+b[i];
    }
    
    M=m+b[8];

    if(m==0)
    {
        m=1;
    }
    
    printf("%d %d",m,M);
    
    return 0;
}

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

typedef struct city{
  int i;
  int p;
  int x;
  int y;
}CITY;

int main(){
  vector<CITY>  city;
  CITY c = {0};
  int n, m, x, pp;

  cin >> n >> m;
  for(int i = 0; i < m; ++i){
    cin >> c.p >> c.y;
    c.i = i;
    city.push_back(c);
  }

  sort(city.begin(), city.end(),  [](const CITY &a, const CITY &b) {
        return a.y < b.y;
    });

  stable_sort(city.begin(), city.end(),  [](const CITY &a, const CITY &b) {
        return a.p < b.p;
    });

  pp = city[0].p;
  x = 1;
  for(vector<CITY>::iterator it = city.begin(); it != city.end(); ++it){
    if(it->p != pp){
      x = 1;
      pp = it->p;
    }
    it->x = x++;
  }

  sort(city.begin(), city.end(),  [](const CITY &a, const CITY &b) {
        return a.i < b.i;
    });

  for(vector<CITY>::iterator it = city.begin(); it != city.end(); ++it){
    printf("%06d%06d\n", it->p, it->x);
  }

  return 0;
}

Measured memory_bytes: 3176
import java.io.PrintWriter
import java.util.ArrayDeque

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

/** edge info */
data class Edge(val from: Int, val to: Int, val cost: Long)

fun solve(out: PrintWriter) {
    val n = readInteger()

    /** graph[fromNodeIndex]: edges to other node */
    val graph = Array(n) { mutableListOf<Edge>() }
    repeat(n - 1) {
        val (a, b) = readIntegerList().map { it - 1 }
        graph[a].add(Edge(a, b, 1))
        graph[b].add(Edge(b, a, 1))
    }

    // 1からnへの最短経路を求める
    val costArray = IntArray(graph.size)
    val nearestFrom = IntArray(graph.size)
    val isUnchecked = BooleanArray(graph.size) { true }
    val nodeQueue = ArrayDeque<Int>()
    nodeQueue.addLast(0)
    isUnchecked[0] = false
    while (nodeQueue.isNotEmpty()) {
        val node = nodeQueue.removeFirst()
        for (edge in graph[node]) {
            if (isUnchecked[edge.to]) {
                costArray[edge.to] = costArray[node] + 1
                nearestFrom[edge.to] = node
                isUnchecked[edge.to] = false
                nodeQueue.addLast(edge.to)
            }
        }
    }

    // 1からnへの最短経路の中央でグラフを切る
    val blackLast = costArray[n - 1] / 2
    val whiteMoveCount = costArray[n - 1] - blackLast - 1
    var cutFrom = 0
    var cutTo = 0
    var last = n - 1
    repeat(whiteMoveCount) {
        last = nearestFrom[last]
    }
    cutFrom = nearestFrom[last]
    cutTo = last

    //Unionfindで数えて比較
    val uf = UnionFind(n)
    for (eList in graph) {
        for (e in eList) {
            if (e.from == cutFrom && e.to == cutTo) {
                continue
            }

            if (e.from == cutTo && e.to == cutFrom) {
                continue
            }
            uf.unite(e.from, e.to)
        }
    }

    val ans = if (uf.getSize(0) > uf.getSize(n - 1)) "Fennec" else "Snuke"
    println(ans)
}

/**　Union find 0 ~ (n - 1)　*/
class UnionFind(n: Int) {
    val parent = IntArray(n) { it }
    val rank = IntArray(n)
    val size = IntArray(n) { 1 }

    /** O(α(n)) */
    fun findRoot(x: Int): Int {
        if (parent[x] == x) return x

        parent[x] = findRoot(parent[x])
        return parent[x]
    }

    /** O(α(n)) */
    fun sameRoot(x: Int, y: Int) = findRoot(x) == findRoot(y)

    /** O(α(n)) */
    fun unite(x: Int, y: Int) {
        val x = findRoot(x)
        val y = findRoot(y)
        if (x == y) return

        if (rank[x] < rank[y]) {
            parent[x] = y
            size[y] += size[x]
        } else {
            parent[y] = x
            if (rank[x] == rank[y]) rank[x]++

            size[x] += size[y]
        }
    }

    /** O(α(n)) */
    fun getSize(x: Int) = size[findRoot(x)]
}



fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 87764
#include <stdio.h>

int main(void){

    int x,y;
    int flag=0;
    int X,Y;

    scanf("%d",&X);
    scanf("%d",&Y);

    for(int i=0;i<=400;i++){
        for(int j=0;j<=400;j++){
            x=i;
            y=j;
            if(x+y==X && 2*x+4*y==Y){
                flag=1;
                break;
            }
        }
    }

    if(flag==1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 2084
N=input()

MM=0
mm=0


if int(N[0])>1 or (int(N[0])==1 and int(N[1])>2) or N[0:2]=="00":
    MM=0
else:
    MM=1
if int(int(N[2]))>1 or (int(N[2])==1 and int(N[3])>2 or N[2:4]=="00"):
    mm=0
else:
    mm=1

if MM+mm==2:
    print("AMBIGUOUS")
elif MM==1:
    print("MMYY")
elif mm==1:
    print("YYMM")
else:
    print("NA")
    

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

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

    for (int i = min(a, b); i >= 1; i--) {
        if (a%i == 0 && b%i == 0) {
            k--;
            if (k == 0) {
                cout << i << "\n";
                break;
            }
        }
    }
}


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

int main() {
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];

    int ans = 1;
    int u = 0;

    rep(i, n - 1) {
        if (a[i + 1] == a[i]) {
            if (i == u) u++;
            continue;
        }
        if (a[i + 1] > a[i] != a[u + 1] > a[u]) {
            ans++;
            u = i + 1;
        }
    }

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


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

public class Main {
    public static void main(String[] args) {

      Scanner sc = new Scanner(System.in);



      int n = sc.nextInt();

      int[] order = new int[n];


      for(int i = 1; i <= n; i++) {
          int num = sc.nextInt();

          order[num-1] = i;
      }

      String output = "";

      for(int i = 0; i < n; i++) {
          System.out.print(order[i] + " ");

      }


    }
}

Measured memory_bytes: 62840
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a,_b=(b);i<=_b;i++)
#define op freopen("in.inp","r",stdin);freopen("ou.out","w",stdout);
#define m(s) memset(s,0,sizeof s);
#define RE return 0;
#define fd(i,a,b) for(int i=a,_b=(b);i>=_b;i--)
typedef long long ll;
const int N=2+1e5;
const int BASE=1e9+7;
int m, n;
char a[N], b[N];
ll A[N], B[N], M[N];

void hash_build(char a[], int n, ll H[])
{
    f(i,1,n)H[i] = (H[i-1] * M[1] + a[i]) % BASE;
}

ll hash_range(ll H[], int L, int R)
{
    return (H[R] - H[L-1]*M[R-L+1]+ 1ll*BASE*BASE) % BASE;
}
int main()
{
//    freopen("A.inp","r",stdin);
//    freopen("A.out","w",stdout);

    int n;cin>>n;
    M[0]=1; M[1]=2309;
    f(i,1,N-1)
    M[i] = M[i-1] * M[1] % BASE;

    scanf("%s", a+1);
    scanf("%s", b+1);
    hash_build(a, n, A);
    hash_build(b, n, B);
    fd(i,n,1)
    {
        if(hash_range(B,1,i)==hash_range(A,n-i+1,n))
        {
            cout<<n-i+n;
            RE
        }
    }
cout<<2*n;
}


Measured memory_bytes: 1024
from itertools import combinations
import numpy as np

H, W, K = map(int, input().split())

C = []
base = 0
for i in range(H):
	string = input()
	string = string.replace('.', '0')
	string = string.replace('#', '1')
	lst = list(string)
	lst = [int(c) for c in lst]
	C.append(lst)
	base += sum(lst)

C = np.array(C)
orig = C.copy()
count = 0

for i in range(H+1):
	for j in range(W+1):
		for c in combinations(range(H), i):
			for d in combinations(range(W), j):
				for row in c:
					C[row] = [0] * W
				for col in d:
					C[:, col] = [0] * H
				if np.sum(C) == K:
					count += 1
				C = orig.copy()

print(count)

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    string s; cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=998244353,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}


int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int ans=0;
    for(int i=2; i*i<=n; i++){
        if(n%i==0){
            int cnt=0;
            while(n%i==0){
                n/=i;
                cnt++;
            }
            ans+=(sqrt(8*cnt + 1)-1)/2;
        }
    }
    if(n>1) ans++;
    cout << ans;
    return 0;
}


Measured memory_bytes: 3680
import itertools

N = int(input())
List  = list(map(int,input().split()))
List_triangle = []
count = 0

for triangle in itertools.combinations(List,3):
    List_triangle.append(triangle)

for i in range(len(List_triangle)):
    if len(set(List_triangle[i])) == len(List_triangle[i]):
        if sorted(List_triangle[i])[-1] < sorted(List_triangle[i])[-2] + sorted(List_triangle[i])[-3]:
            count += 1
        else:
            pass
    else:
        pass

print(count)

Measured memory_bytes: 20592
import sys
input = sys.stdin.readline
from collections import deque
import numpy as np

n, u, v = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]

graph = [[] for _ in range(n)]
for a, b in ab:
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)


def dfs(graph, start):
    stack = deque([start])
    dist = [-1]*n
    dist[start] = 0
    while stack:
        node = stack.pop()
        dist_x = dist[node] + 1
        for child in graph[node]:
            if dist[child] != -1:
                continue
            dist[child] = dist_x
            stack.append(child)
    return dist

distance1 = np.array(dfs(graph, u-1))
distance2 = np.array(dfs(graph, v-1))

distance = distance2[distance1<distance2]
ans = max(distance)-1
print(ans)



Measured memory_bytes: 55076
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: print('Yes' if b else 'No')
YESNO=lambda b: print('YES' if b else 'NO')

def main():
    N,M=map(int,input().split())
    c=list(map(int,input().split()))
    dp=[[INF]*10**6 for _ in range(M+1)]
    dp[0][0]=0
    ans=INF
    for i in range(M):
        for money in range(N+1):
            dp[i+1][money]=min(dp[i+1][money],dp[i][money])
            if money-c[i]>=0:
                dp[i+1][money]=min(dp[i+1][money],dp[i][money-c[i]]+1,dp[i+1][money-c[i]]+1)
    print(dp[M][N])

if __name__ == '__main__':
    main()



Measured memory_bytes: 199696
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 //   freopen("input.txt","r",stdin);
//    freope//n("output.txt","w",stdout);
	long long int a,b,k;
	cin>>a>>b>>k;
	bool chance = 1;
	while(k--)
	{
		if(chance)
		{
			if(a%2!=0)
			{
				a--;
			}
			b+=a/2;
			a = a/2;
		}	
		else
		{
			if(b%2!=0)
			{
				b--;
			}
			a+=b/2;
			b = b/2;
		}
		chance = !chance;
	}
	cout<<a<<" "<<b;
	return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int n;cin>>n;
	vi a(n);
	rep(i,n)cin>>a[i];
	map<int,int> m;
	rep(i,n){
		m[a[i]]++;
	}
	int t=0,y=0;//t<=y
	for(auto p:m){
		if(p.second>=4){
			chmax(t,p.first);
			chmax(y,p.first);

		}else if(p.second>=2){
			chmax(t,p.first);
		}
		if(t>y){
			swap(t,y);
		}


	}
	cout<<t*y<<endl;
	return 0;
}



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

int main(){
	ll n,k;
	cin >> n >> k;
	ll ans = k;
	rep(i,n-1){
		ans *= (k-1);
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int arr[234];
    for(int i=0;i<3;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+3);
    cout<<arr[0]<<" "<<arr[1]<<" "<<arr[2]<<"\n";
    return 0;
}


Measured memory_bytes: 3168
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int>C(N), S(N), F(N), ans(N);
    for (int i = 0; i < N - 1; i++)cin >> C[i] >> S[i] >> F[i];

    for (int i = 0; i < N; i++) {
        int time = 0;
        for (int j = i; j < N-1; j++) {
            if (time < S[j])time = S[j];
            else if (time%F[j] != 0)time += (F[j] - time%F[j]);
            time += C[j];
        }
        ans[i] = time;
    }

    for (int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class C
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		foreach (var c in Enumerable.Range(0, h[1]).Select(i => new { i, a = read() }).GroupBy(c => c.a[0]).SelectMany(g => g.OrderBy(c => c.a[1]).Select((c, j) => new { c.i, id = $"{g.Key:D6}{j + 1:D6}" })).OrderBy(c => c.i)) Console.WriteLine(c.id);
	}
}


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

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a


using ll = long long;

int main() {
    bool ans = true;
    IN(int, n);
    int k;
    REP(i, n){
        cin >> k;
        if((k%2 == 0)){
            if((k%3 != 0)&&(k%5 != 0)){
                ans = false;
            }
        }
    }
    if (ans) {
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    string S; cin >> S;

    int ans = 1;
    REP(i, N - 1) if(S[i] != S[i + 1]) ans++;
    Out(ans); 

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	double n,k;cin>>n>>k;
	double ans=0;
	for(double i=1;i<=n;i++){
		if(i>=k) ans+=1/n;
		else{
			double j=k/i;int l=0;
			while(j>1){
				//cout<<j<<endl;
				j/=2;
				l++;
			}
			ans+=1/(n*pow(2,l));
		}
	}
	cout<<fixed<<setprecision(15)<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
using namespace __gnu_pbds;
 
//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!
 
// OT.find_by_order(k-1)
// 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// #define 
 
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(987654319)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long
 
//////////////////////
const int N = 200005;

int abs1(int a) {
	if(a < 0)
		return -a;
	return a;
}

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

    int tt = 1;
    // cin >> tt;
    while(tt--) {
    	int n;
    	cin >> n;
    	vector<int> a(n);
    	rep(i,n) cin >> a[i];

    	vector<int> prefix(n,0);
    	vector<int> suffix(n,0);

    	prefix[0] = a[0];
    	repA(i,1,n-1)
    		prefix[i] = a[i] + prefix[i-1];
    	repD(i,n-2,0)
    		suffix[i] = suffix[i+1] + a[i+1];

    	int mn = inf;
    	rep(i,n) {
    		mn = min(mn, abs1(prefix[i]-suffix[i]));
    	}

    	cout << mn << '\n';
    }
}	

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define vec vector<ll>
#define ms multiset<ll>
#define f(i,x,n) for(int i=x;i<n;i++)
#define int long long
#define mod 998244353
#define endl "\n"
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
multiset<int>se;
int32_t main()
{
    fastio();
    int n;
    cin>>n;
    int a[n];
    f(i,0,n)
    {
    	cin>>a[i];
    }
    int ans=1;
    se.insert(a[0]);
    for(int i=1;i<n;i++)
    {
    	auto aa=se.lower_bound(a[i]);
    	if(aa==se.begin())
    	{
    		ans++;
    		se.insert(a[i]);
    		continue;
    	}
    	aa--;
    	se.erase(aa);
    	se.insert(a[i]);
    }
    cout<<ans;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 4000000000000000000
int dx8[8]={-1,0,1,1,1,0,-1,-1};
int dy8[8]={1,1,1,0,-1,-1,-1,0};
int dx4[4]={-1,0,1,0};
int dy4[4]={0,-1,0,1};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int uni[100010];
int root(int a){
    if(uni[a]<0)return a;
    return uni[a]=root(uni[a]); 
}
bool connect(int a,int b){
    a=root(a);
    b=root(b);
    if(a==b)return false;
    if(uni[a]>uni[b]){
        swap(a,b);
    }
    uni[a]=uni[a]+uni[b];
    uni[b]=a;
    return true;
}
signed main(void){
    int n;cin>>n;
    int V[n+2];//1-index
    rep(i,n){
        int p;cin>>p;
        V[p]=i+1;
    }
    multiset<int>S;//indexの集合であることに注意
    S.insert(0);S.insert(0);
    S.insert(n+1);S.insert(n+1);
    int ans=0;
    for(int i=n;i>=1;i--){
        int now=V[i];
        multiset<int>::iterator right;;
        right=S.upper_bound(now);
        
        int r0=*right;
        right++;int r1=*right;
        right--;right--;
        int l0=*right;
        right--;
        int l1=*right;
        //cout<<r0<<' '<<r1<<' '<<l0<<' '<<l1<<endl;
        
        ans+=i*((l0-l1)*(r0-now)+(now-l0)*(r1-r0));
        S.insert(now);
    }
    cout<<ans<<endl;
}
        


Measured memory_bytes: 5760
N = int(input())
H_list = list(map(int, input().split()))

result = 0
count = 0
for i in range(N - 1):
    if H_list[i + 1] <= H_list[i]:
        count += 1
    else:
        result = max (result, count)
        count = 0
result = max (result, count)

print(result)

Measured memory_bytes: 14252
M, K = map(int,input().split())
if 2**M <= K or (M==1 and K==1):
    print(-1)
    exit()
elif K == 0:
    ls = [str(i//2) for i in range(2**(M+1))]
    print(" ".join(ls))
    exit()
ls = [str(i) for i in range(2**M)]
ls2 = [str(2**M-i-1) for i in range(2**M)]
ls.remove(str(K))
ls2.remove(str(K))
ls.append(str(K))
for elem in ls2:
    ls.append(elem)
ls.append(str(K))
print(" ".join(ls))


Measured memory_bytes: 25496
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int l=s.length();
    if(s[0]==s[l-1])
    {
        if(l%2==0)
        {
            cout<<"First"<<endl;
        }
        else
        {
            cout<<"Second"<<endl;
        }
    }
    else
    {
        if(l%2==0)
        {
            cout<<"Second"<<endl;
        }
        else
        {
            cout<<"First"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=1e5+9;
ll arr[maxn];
ll sum[maxn];
ll sz[maxn];
ll n,k;
int main(){
        ll a,b,c,d,e,f,g,h;
        ios::sync_with_stdio(0);
        ll k,s;
        cin>>k>>s;
        g=0;
        for(int i=0;i<=k;i++){
                a=s-i;
                if(a>k*2||a<0)continue;
                h=a+1;
                if(a>k){
                        h-=(a-k)*2;
                }
                g+=h;
        }
        cout<<g<<endl;
        return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=200005;
int h,w,n,sx,sy,a,b,c,d; char s1[N],s2[N];
int main()
{
	RI i; scanf("%d%d%d%d%d%s%s",&h,&w,&n,&sx,&sy,s1+1,s2+1);
	for (i=n;i;--i)
	{
		switch (s2[i])
		{
			case 'U': if (b) --b; break;
			case 'D': if (a) --a; break;
			case 'L': if (d) --d; break;
			case 'R': if (c) --c; break;
		}
		switch (s1[i])
		{
			case 'U': ++a; break;
			case 'D': ++b; break;
			case 'L': ++c; break;
			case 'R': ++d; break;
		}
		if (a+b>=h||c+d>=w) return puts("NO"),0;
	}
	return puts(a<sx&&sx<=h-b&&c<sy&&sy<=w-d?"YES":"NO"),0;
}

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

int main() {
  string A, B;
  cin >> A >> B;
  if(A.size()>B.size()) puts("GREATER");
  else if(A.size()<B.size()) puts("LESS");
  else if (A>B) puts("GREATER");
  else if (A<B) puts("LESS");
  else puts("EQUAL");
}

Measured memory_bytes: 256
import java.io.*;
public class Main{
	public static void main(String [] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		char ope;
		int a,b;
		String[] st=new String[3];
		while(true){
		st=br.readLine().split(" ");
		a=Integer.parseInt(st[0]);
		b=Integer.parseInt(st[2]);
		ope=st[1].charAt(0);
		if(ope=='?')break;
		System.out.println(keisan(a,b,ope));}
		}

		static int keisan(int a,int b,char operator){
		int result=0;
		switch(operator){
		case '+':result=a+b;break;
		case '-':result=a-b;break;
		case '*':result=a*b;break;
		case '/':result=a/b;break;
		}
		return (int)result;
		}
		}
		

Measured memory_bytes: 17096
while(<STDIN>){
	chomp;
    @line = split(/ /, $_);
    push(@dat,$line[0]);
    push(@dat,$line[1]);
}

$cnt[0] = 0;
$cnt[1] = 0;
$cnt[2] = 0;
$cnt[3] = 0;
foreach $tmp (@dat) {
	$cnt[$tmp-1]++;
}

@cnt = sort {$b <=> $a} @cnt;

if ($cnt[0] < 3) {
	print "YES\n";
} else {
	print "NO\n";
}


Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int A =sc.nextInt();
        int B =sc.nextInt();
        int C =sc.nextInt();
        int D =sc.nextInt();
        
        
        
        int sw =0;
        
        while(A>0 &&C>0){
            
            if(sw==0&&C>=0){
                C=C-B;
                sw =1;
            }else if(sw==1&&A>=0){
                A = A-D;
                sw =0;
            }
            
        }
        
        if(A<=0){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
        
        
    }
    
    
}


Measured memory_bytes: 35852
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


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

    int N;
    cin >> N;
    vector<int> dp(N + 1, N + 123);

    dp[0] = 0;
    for (int i = 0; i < N; ++i) {
        dp[i + 1] = min(dp[i + 1], dp[i] + 1);
        for (auto x : {6, 9}) {
            int p = x;
            while (i + p <= N) {
                dp[i + p] = min(dp[i + p], dp[i] + 1);
                p *= x;
            }
        }
    }

    cout << dp[N] << '\n';

    return 0;
}

Measured memory_bytes: 640
using System;
using System.IO;
using System.Text;

class Program{
    static void Main(string[] args){
        var N = int.Parse(Console.ReadLine());
        var A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var arr = new int[N];
        for (int i = 0; i < N; i++) arr[A[i] - 1] = i + 1;
        var sb = new StringBuilder();
            for (int i = 0; i < N; i++){
                sb.Append(arr[i]).Append(" ");}
        var answer = sb.ToString();
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 36572