akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FASTIO
using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, M, K;
    cin >> N >> M >> K;
    Vl A(N), B(M);
    ll sa = 0, sb = 0;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (ll i = 0; i < M; i++) {
        cin >> B[i];
        sb += B[i];
    }

    ll ans = 0;
    ll idx = M;
    for (ll i = 0; i <= N; i++) {
        if (sa > K) break;
        while (idx >= 0 && sa + sb > K) {
            sb -= B[--idx];
        }
        ans = max(ans, i + idx);
        if (i < N) {
            sa += A[i];
        }
    }

    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 6292
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	ss := strings.Split(s,"")

	count := 0
	for _,v := range ss {
		if v == "o" {
			count++
		}
	}
	fmt.Println(700 + count*100)
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;

int n, x, a, b, ans;
vector<int> g[N];
int dist1[N], dist2[N];

void dfs(int u, int par, int dist[])
{
	dist[u]= dist[par] + 1;
	for(auto &it:g[u])
	{
		if(it == par)
			continue;
		dfs(it, u, dist);
	}
}

int32_t main()
{
	IOS;
	cin >> n >> a >> b;
	for(int i = 1; i <= n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dist1[0] = -1;
	dist2[0] = -1;
	dfs(a, 0, dist1);
	dfs(b, 0, dist2);
	for(int i = 1; i <= n; ++i)
	{
		if(dist1[i] < dist2[i])
		{
			int cur = dist2[i];
			ans = max(ans, cur - 1);
		}
	}
	cout << ans;
}

Measured memory_bytes: 14464
import math

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

    x_2 = (a*math.cos(2*math.pi*(h/12 + m/60/12)) - b*math.cos(2*math.pi*m/60)) ** 2
    y_2 = (a*math.sin(2*math.pi*(h/12 + m/60/12)) - b*math.sin(2*math.pi*m/60)) ** 2
    print((x_2 + y_2)**0.5)


main()


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

int main(){

  double  x1,y1,x2,y2;

  cin>>x1>>y1>>x2>>y2;
  double distance;
  distance =  sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));

  printf("%lf\n",distance);
}


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

signed main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (a >= k) cout << k << endl, exit(0);
	k -= a;
	if (b >= k) cout << a << endl, exit(0);
	k -= b;
	if (c >= k) cout << a - k << endl, exit(0);
	cout << a + c << endl;
}

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

// definitions
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define mod1 998244353
#define mod 1000000007
#define MAX_CHAR 256
#define pi 3.1415926535897932384

using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const ll INF=1e18;
// prevent collisions in unordered_map
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef unordered_map <long long, long long, custom_hash> umap;

// cin and cout overloaded for vectors and sets
template<typename T>             
istream& operator>>(istream& is,  vector<T>& v)
{
    for (auto& i : v) 
        is >> i;        
    return is;
}
template<typename T>             
ostream& operator<<(ostream& os,  vector<T>& v)
{
    for (auto& i : v) 
        os << i << ' '; 
        return os;
}

// standard functions
ll mystoi(string str)
{
    stringstream ss(str);
    ll ans=0;
    ss >> ans;

    return ans;
}

ll exp(ll x, ll ex) 
{
    ll ans = 1ll;
    while (ex > 0) 
    {
        if (ex & 1ll) ans = (ans * x);
        ex >>= 1ll;
        x = (x * x);
    }
    return ans;
}

bool sort_cond(const pair<ll,ll> &a, const pair <ll,ll> &b)
{
    if(a.first==b.first)
        return a.second<b.second;

    return a.first < b.first;
}

vl constructXOR(vl A) 
{   
    ll n=A.size();
    // calculate xor of array 
    ll XOR = 0; 
    for (ll i = 0; i < n; i++) 
        XOR ^= A[i]; 
  
    // update array 
    for (ll i = 0; i < n; i++) 
        A[i] = XOR ^ A[i]; 
    return A;
}

// code beigns in main
int main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;

    while(t--)
    {
        ll n;
        cin >> n;
        vl a(n);
        cin >> a;
        vl ans=constructXOR(a);
        cout << ans << endl;
    }
}

Measured memory_bytes: 6364
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int m,n,k,j,maxx;
int a[111000],l[110000];
int p[110000];
int main()
{
	cin>>m;
	for(int x=1;x<=m;x++)
	{
		cin>>a[x];
		maxx=max(a[x],maxx);
		if(maxx-a[x]>=2)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<29;

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

  sort(h.begin(), h.end(), greater<int>());
  ll res = 0;
  for (int i = K; i < N; ++i){
    res += h[i];
  }
  cout << res << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

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

    if(b<a){
        for (int i = 0; i < a; i++){
            cout<< b;
        }
    }
    else{
        for (int i = 0; i < b; i++){
            cout << a;
        }
        
    }
    return 0;
}


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int V, E; cin >> V >> E;
    int g[20][20];
    rep(i,20) rep(j,20) g[i][j] = -1;
    rep(i,E){
        int s,t,d;
        cin >> s >> t >> d;
        g[s][t] = d;
    }

    vvi dp(1<<V, vi(V, INF));
    dp[0][0] = 0;
    rep(bit,1<<V){
        rep(i,V){
            rep(j,V){
                if(bit>>j & 1 || g[i][j] == -1) continue;
                dp[bit|(1<<j)][j] = min(dp[bit|(1<<j)][j], dp[bit][i] + g[i][j]);
            }
        }
    }
    int ans = dp[(1<<V)-1][0] == INF ? -1 : dp[(1<<V)-1][0];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6240
#include <iostream>
using namespace std;
int main(void){

    int x,y;
    for(int i=0;i<3000;i++){
        cin>>x>>y;
        if(x==0&&y==0){
            break;
        }
        if(x>y){
            swap(x,y);
        }
        cout<<x<<" "<<y<<endl;
    }
}



Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
using namespace std;

#define REP(i,a,n) for(int i = a; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
vector<int> gdnum;
vector<int> gdpnum;

void make(){
  for(int i = 0 ; i <= 300000;i+=7){
    if(i+1 > 300000)break;
    gdnum.push_back(i+1);
    if(i+6 > 300000)break;
    gdnum.push_back(i+6);
  }
  rep(i,gdnum.size()){
    if(i == 0)continue;
    bool f = true;
    for(int j=0;j<gdpnum.size() && gdpnum[j]*gdpnum[j]<=gdnum[i];j++){
      if(gdnum[i] % gdpnum[j] == 0){
        f = false;
        break;
      }
    }
    if(f)gdpnum.push_back(gdnum[i]);
  }
}


void solve(){
}



int main(){
  make();
  int n;
  while(true){
    cin>>n;
    if(n == 1)break;
    cout<<n<<":";
    rep(i,gdpnum.size()){
      //cout<<gdpnum[i]<<endl;
      if(n%gdpnum[i]==0){
        cout<<" "<<gdpnum[i];
      }
    }
    cout<<endl;
  }
}

Measured memory_bytes: 1644
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

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

    if(s[0]==s[N-1]){
        if(N%2==1){
            cout<<"Second"<<endl;
        }else{
            cout<<"First"<<endl;
        }
    }else{
        if(N%2==0){
            cout<<"Second"<<endl;
        }else{
            cout<<"First"<<endl;
        }
    }
}

Measured memory_bytes: 3684
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    vector <string> s(n);
    vector <int> t(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i] >> t[i];
    }

    string X;
    cin >> X;

    int ans = 0;
    bool asleep = false;
    for (int i = 0; i < n; i++) {
        if (asleep) ans += t[i];
        if (s[i] == X) asleep = true;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 888
using System;

public class p0003{
	p0003(){
		int n;
		string str;
		string[] s;
		int[] a = new int[3];
		
		while((str = Console.ReadLine()) != null){
			n = int.Parse(str);
			
			while(0 < n--){
				s = (Console.ReadLine()).Split(' ');
				for(int i = 0; i < 3; ++i){
					a[i] = int.Parse(s[i]);
					a[i] = a[i]*a[i];
				}
				Console.WriteLine("{0}", ((func(a))? "YES": "NO"));
			}
		}
	}
	
	public static int Main(string[] args){
		new p0003();
		return 0;
	}
	
	public bool func(int[] a){
		return (a[0] == a[1]+a[2] || a[1] == a[0]+a[2] || a[2] == a[0]+a[1]);
	}
}

Measured memory_bytes: 5456
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

struct PathData
{
    unsigned long long from;
    unsigned long long to;
    unsigned long long cost;
};

int main()
{
    unsigned long long N;
    cin >> N;
    /*vector<unsigned long long> tmpVec(N, 0);
    vector<vector<unsigned long long>> pathVec(N, tmpVec);*/
    unordered_map<unsigned long long, vector<unsigned long long>> pathMap;
    unordered_map<unsigned long long, vector<unsigned long long>> CheckMap;

    unsigned long long a, b, c;
    for (unsigned long long i = 0; i < N - 1; i++)
    {
        cin >> a >> b >> c;
        a--;
        b--;
        pathMap[a].push_back(c);
        pathMap[b].push_back(c);
        CheckMap[a].push_back(b);
        CheckMap[b].push_back(a);
    }

    unsigned long long Q, K;
    cin >> Q >> K;
    K--;
    unsigned long long x, y;

    stack<PathData> PDStack;
    unordered_set<unsigned long long> CheckSet;
    unordered_map<unsigned long long, unsigned long long> CostMap;

    for (int i = 0; i < CheckMap[K].size(); i++)
    {
        PathData pd;
        pd.from = K;
        pd.to = CheckMap[K][i];
        pd.cost = pathMap[K][i];
        PDStack.push(pd);
    }
    CheckSet.emplace(K);

    while (!PDStack.empty())
    {
        PathData pd = PDStack.top();
        PDStack.pop();
        CostMap[pd.to] = pd.cost;

        for (int i = 0; i < CheckMap[pd.to].size(); i++)
        {
            if (CheckSet.find(CheckMap[pd.to][i]) == CheckSet.end())
            {
                PathData pd_new;
                pd_new.from = pd.to;
                pd_new.to = CheckMap[pd.to][i];
                pd_new.cost = pd.cost + pathMap[pd.to][i];
                PDStack.push(pd_new);
            }
        }
        CheckSet.emplace(pd.to);
    }

    for (unsigned long long i = 0; i < Q; i++)
    {
        cin >> x >> y;
        x--;
        y--;

        cout << CostMap[x] + CostMap[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 28720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    string ans = "";
    string s; cin >> s;

    for(int i=0; i<s.size(); i++){
        if(s[i] == '0') ans += '0';
        else if(s[i] == '1') ans += '1';
        else if(ans.size() > 0) ans.erase(ans.end()-1);
    }

    cout << ans << endl;
}

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

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


Measured memory_bytes: 256
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret

def solve():

    n = getN()
    nums = getList()
    keta = [[0, 0] for i in range(62)]

    for num in nums:
        tmp = num
        for i in range(62):
            if tmp % 2 == 1:
                keta[i][1] += 1
            else:
                keta[i][0] += 1

            tmp //= 2

    ans = 0
    dig = 0
    for k1, k2 in keta:
        ans += ((k1 * k2) * (2**dig)) % MOD
        dig += 1

    print(ans % MOD)


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 110608
import java.util.*;

  public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        Map <Integer,Integer> map = new TreeMap<>();
                for(int i=1;i<=n;i++){
                    map.put(sc.nextInt(),i);
                }

                for(int i=1;i<=n;i++){
                    System.out.print(map.get(i)+" ");
                }

            }
        }

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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	int dp[n+1] ;
	for(int i = 0 ; i <= n ; ++i)
		dp[i] = 1e7 ;
	dp[n] = 0 ;
	for(int i = n ; i >= 1 ; --i)
	{
		dp[i-1] = min(dp[i-1], dp[i]+1) ;
		int now = 1 ;
		for(int j = 1 ; ; ++j)
		{
			now *= 6 ;
			if(now > i)
				break ;
			dp[i-now] = min(dp[i-now], dp[i]+1) ;
		}
		now = 1 ;
		for(; ;)
		{
			now *= 9 ;
			if(now > i)
				break ;
			dp[i-now] = min(dp[i-now], dp[i]+1) ;
		}
	}
	return cout<<dp[0]<<"\n" , 0 ;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
using namespace std;
int main(void){
  string s;
  cin >> s;
  
  for(int i=0;i<5;i++){
    cout << s[i];
  }
  cout << " ";
  for(int i=6;i<13;i++){
    cout << s[i];
  }
  cout << " " << endl;
  for(int i=14;i<19;i++){
    cout << s[i];
  }
  cout << endl;
  
    
  
  return 0;
}

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

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);
		Splice S = new Splice(n);
		for(int i = 0; i < q; i++){
			str = br.readLine().split(" ");
			int op = Integer.parseInt(str[0]);
			if(op == 0){
				int t = Integer.parseInt(str[1]);
				int x = Integer.parseInt(str[2]);
				S.insert(t, x);
			}else if(op == 1){
				int t = Integer.parseInt(str[1]);
				S.dump(t);
			}else{
				int s = Integer.parseInt(str[1]);
				int t = Integer.parseInt(str[2]);
				S.splice(s, t);
			}
		}
	}
}

class Splice{
	private class Node{
		int val;
		Node next = null;
	}
	private Node[] front;
	private Node[] rear;
	Splice(int n){
		front = new Node[n];
		rear = new Node[n];
	}
	public void insert(int t, int x){
		if(front[t] == null){
			front[t] = new Node();
			front[t].val = x;
			rear[t] = front[t];
			return;
		}
		rear[t].next = new Node();
		rear[t].next.val = x;
		rear[t] = rear[t].next;
	}
	public void dump(int t){
		if(front[t] == null){
			System.out.print("\n");
			return;
		}
		Node now = front[t];
		for(;;){
			System.out.print(now.val);
			if(now.next == null){
				System.out.print("\n");
				return;
			}
			System.out.print(" ");
			now = now.next;
		}
	}
	public void splice(int s, int t){
		if(front[t] == null){
			front[t] = front[s];
			rear[t] = rear[s];
		}else{
			rear[t].next = front[s];
			rear[t] = rear[s];
		}
		rear[s] = null;
		front[s] = null;
	}
}



Measured memory_bytes: 177136
#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;
using namespace std;

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>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

#define int long long

const long long M = 1000000007;

//x^n mod M
typedef long long ull;
ull power(ull x, ull n){
	ull res = 1;
	if(n > 0){
		res = power(x, n / 2);
		if(n % 2 == 0) res = (res * res) % M;
		else res = (((res * res) % M) * x ) % M;
	}
	return res;
}

long long combination(long long n, long long r){
	long long res = 1;
	for(long long i = n, j = 0; j < r; i--, j++){
		(res *= i) %= M;
	}
	range(i,1,r + 1){
		(res *= power(static_cast<long long>(i), M - 2)) %= M;
	}
	return res % M;
}

signed main(){
	long long n, d, x;
	while(cin >> n >> d >> x, n||d||x){
		vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 0));
		dp[0][0] = 1;
		vector<long long> sum(n + 1, 0);
		rep(i,n){
			range(j,i,n + 1){
				if(j - x >= 0){
					(dp[i + 1][j] += (sum[j - 1] % M - sum[j - x] % M + M) % M) %= M;
				}else{
					(dp[i + 1][j] += (i == 0 ? 1 : sum[j - 1] % M)) %= M;
				}
			}

			range(j,1,n + 1){
				sum[j] = (sum[j - 1] % M + dp[i + 1][j] % M) % M;
				//cout << sum[j]  << ' ';
			}
			//cout << endl;
		}

		//rep(i,n + 1){ rep(j,n + 1){ cout << dp[i][j] << ' '; } cout << endl; }
		long long ans = 0, com = 1;
		range(i,1,min(d,n) + 1){
			(com *= (d - i + 1) % M * power(i, M - 2) % M) %= M;
			assert(com >= 0);
			//show(com)
			(ans += dp[i][n] % M * com % M) %= M;
		}
		cout << ans << endl;
	}
}



Measured memory_bytes: 34220
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll mod = 998244353LL;

// aのb乗を求める.
ll modpow(ll a, ll b) {
	if (a > mod) a %= mod;
	if (b == 0LL) return 1LL;
	ll tmp = modpow(a, b / 2);
	if (b & 1LL)
		return tmp * tmp % mod * a % mod;
	return tmp * tmp % mod;
}

// aの逆元を求める.
ll inverse(ll a) {
	return modpow(a, mod - 2);
}

// kの階乗を計算する.(sgnを0以外に設定すると逆元を返す)
ll fact(ll k, int sgn = 0) {
	static vector<ll> fac(2, 1LL);
	static vector<ll> inv(2, 1LL);
	static vector<ll> finv(2, 1LL);
	static ll nx = 2LL;
	while (nx <= k) {
		fac.push_back(fac[nx - 1] * nx % mod);
		inv.push_back(mod - inv[mod % nx] * (mod / nx) % mod);
		finv.push_back(finv[nx - 1] * inv[nx] % mod);
		++nx;
	}
	if (sgn == 0)
		return fac[k];
	return finv[k];
}

// aCbを計算する.
ll comb(ll a, ll b) {
	if (b < 0 || b > a) return 0;
	return fact(a) * fact(b, 1) % mod * fact(a - b, 1) % mod;
}

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	ll res = 0;
	for (int i = 0; i <= k; ++i) {
		ll tmp = comb(n - 1LL, i);
		tmp = (tmp * m) % mod;
		tmp = (tmp * modpow(m - 1, n - i - 1)) % mod;
		res = (res + tmp) % mod;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 8096
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define X first
#define Y second
#define PB push_back
#define EM emplace_back
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
typedef long long ll;
typedef double db;
const int P=1000000007;
typedef pair<int,int> PII;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll gen(ll l,ll r){return uniform_int_distribution<ll>(l,r)(rng);}
db gen(db l,db r){return uniform_real_distribution<db>(l,r)(rng);}
int power(int a,ll x){int ans=1;for(;x;x>>=1,a=1LL*a*a%P)if(x&1)ans=1LL*ans*a%P;return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

const int N=100005;
int n,L,a[N];

int main(){
	scanf("%d%d",&n,&L);
	rep(i,1,n)scanf("%d",a+i);
	rep(i,1,n-1)if(a[i]+a[i+1]>=L){
		puts("Possible");
		per(j,n-1,i+1)printf("%d ",j);
		rep(j,1,i)printf("%d ",j);
		return 0;
	}
	puts("Impossible");
}


Measured memory_bytes: 1152
import sys
import math

if __name__ == '__main__':
    a, b, n = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
    old = 0
    if 0 <= b-1 and b-1 <= n:
        x = b - 1
        print(math.floor(a*x/b)-a*math.floor(x/b))
    else:
        x = n
        print(math.floor(a*x/b)-a*math.floor(x/b))

Measured memory_bytes: 9132
import bisect
import sys

SENTINEL = 10 ** 12

a, b, q = list(map(int, input().split()))
lines = sys.stdin.readlines()
sss = [-SENTINEL] + list(map(int, lines[:a])) + [SENTINEL]
ttt = [-SENTINEL] + list(map(int, lines[a:a + b])) + [SENTINEL]
xxx = list(map(int, lines[a + b:]))

nearest_temples = [SENTINEL] + [0] * a + [SENTINEL]
nearest_shrines = [SENTINEL] + [0] * b + [SENTINEL]
for i, s in enumerate(sss[1:-1], start=1):
    ti = bisect.bisect(ttt, s)
    nearest_temples[i] = min(ttt[ti] - s, s - ttt[ti - 1])
for i, t in enumerate(ttt[1:-1], start=1):
    si = bisect.bisect(sss, t)
    nearest_shrines[i] = min(sss[si] - t, t - sss[si - 1])

buf = []
for x in xxx:
    si = bisect.bisect(sss, x)
    ti = bisect.bisect(ttt, x)
    ans = min(x - sss[si - 1] + nearest_temples[si - 1],
              sss[si] - x + nearest_temples[si],
              x - ttt[ti - 1] + nearest_shrines[ti - 1],
              ttt[ti] - x + nearest_shrines[ti])
    buf.append(ans)
print('\n'.join(map(str, buf)))


Measured memory_bytes: 58724
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        int sum = 0;
        for (int i=0;i<n;i++) {
            sum += l+i;
        }
        
        int min = Integer.MAX_VALUE;
        for (int i = 0;i<n;i++) {
            min = Math.min(min, Math.abs(i+l));
        }
      	if (sum > 0) {
        	System.out.println(sum - min);
        } else {
        	System.out.println(sum + min);
        }
        
    }
}

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


// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    cout << n + n * n + n * n * n << endl;


}


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

L = [[0 for x in range(N+1)] for x in range(N+1)]
for i in range(M):
    x, y = map(int,input().split())
    L[x][y] += 1
for x in range(N+1):
    for y in range(N):
        L[x][y+1] += L[x][y]  

for y in range(N+1):
    for x in range(N):
        L[x+1][y] += L[x][y]  
for _ in range(Q):
    x, y = map(int, input().split())
    print(L[N][y]-L[x-1][y])

Measured memory_bytes: 57688
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		StringBuilder str;
		int q;
		String commandline;

		Scanner stdIn = new Scanner(System.in);

		str = new StringBuilder(stdIn.next());
		q = stdIn.nextInt();

		stdIn.nextLine();

		for (int i = 0; i < q; i++) {
			commandline = stdIn.nextLine();
			String[] command = commandline.split(" +");

			int a = Integer.parseInt(command[1]);
			int b = Integer.parseInt(command[2]) + 1;

			switch (command[0]) {
			case "print":
				print(a, b, str);
				break;
			case "reverse":
				reverse(a, b, str);
				break;
			case "replace":
				replace(a, b, command[3], str);
				break;
			default:

			}
		}
		stdIn.close();
	}

	public static void print(int a, int b, StringBuilder str) {
		System.out.println(str.substring(a, b));
	}

	public static void reverse(int a, int b, StringBuilder str) {
		StringBuilder sb = new StringBuilder(str.substring(a, b));
		str.delete(a, b);
		str.insert(a, sb.reverse().toString());
	}

	public static void replace(int a, int b, String p, StringBuilder str) {
		str.delete(a, b);
		str.insert(a, p);
	}
}

Measured memory_bytes: 27924
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = (tx - sx);
    int dy = (ty - sy);

    REP(i,0,dx) cout << "R";
    REP(i,0,dy) cout << "U";
    REP(i,0,dx) cout << "L";
    REP(i,0,dy+1) cout << "D";

    REP(i,0,dx+1) cout << "R";
    REP(i,0,dy+1) cout << "U";
    cout << "L";
    cout << "U";
    REP(i,0,dx+1) cout << "L";
    REP(i,0,dy+1) cout << "D";
    cout << "R" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long k = sc.nextLong();
    long surplus = n%k;
    long ans = Math.min(surplus,Math.abs(surplus-k));
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<climits>
#include<string>
using namespace std;

int main()
{
  vector< vector<int> > table( 8, vector<int>(3) );
  vector<string> name(8);
  vector<int> color(3);
  char c;
  int i, near, dist, t;
  table[0][0] = 0; table[0][1] = 0; table[0][2] = 0;
  table[1][0] = 0; table[1][1] = 0; table[1][2] = 255;
  table[2][0] = 0; table[2][1] = 255; table[2][2] = 0;
  table[3][0] = 0; table[3][1] = 255; table[3][2] = 255;
  table[4][0] = 255; table[4][1] = 0; table[4][2] = 0;
  table[5][0] = 255; table[5][1] = 0; table[5][2] = 255;
  table[6][0] = 255; table[6][1] = 255; table[6][2] = 0;
  table[7][0] = 255; table[7][1] = 255; table[7][2] = 255;
  name[0] = "black";
  name[1] = "blue";
  name[2] = "lime";
  name[3] = "aqua";
  name[4] = "red";
  name[5] = "fuchsia";
  name[6] = "yellow";
  name[7] = "white";

  while (cin>>c, c!='0') {
    color.clear();
    for (i = 0; i < 3; i++) {
      cin>>c;
      if ('a' <= c) color[i] = c-'a'+10;
      else color[i] = c-'0';
      color[i] *= 16;
      cin>>c;
      if ('a' <= c) color[i] += c-'a'+10;
      else color[i] += c-'0';
    }
    dist = INT_MAX;
    near = 0;
    for (i = 0; i < 8; i++) {
      t = (table[i][0]-color[0])*(table[i][0]-color[0]) + (table[i][1]-color[1])*(table[i][1]-color[1]) + (table[i][2]-color[2])*(table[i][2]-color[2]);
      if (t < dist) {
	near = i;
	dist = t;
      }
    }
    cout<<name[near]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
/**
            ▄█▀ ▀█▀ ▄▀▄ █▀ █▄█▄█ ▄▀▄ █▀ ▄█▀
            <⇋⇋⇋⋛∰≓⊂(⌒,_ゝ⌒)⊃≓∰⋛⇋⇋⇋>

    ♔♕♖♗♘♙ ☜❷☞✪ ィℋ६ ≈ ᗫẵℜℵĬŊĞ ✪☜❷☞ ♚♛♜♝♞♟
    ♔♕♖♗♘♙                             ♚♛♜♝♞♟
                ˙·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙
**/

#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 1e5 + 5;

int cnt[500];
string s;

main()
{
    cin >> s;
    if( sz(s) == 26 )
    {
        for( int i = sz(s) - 1; i >= 0; i-- )
        {
            for( int j = int( s[i] ) + 1; j <= 'z'; j++ )
            {
                int fl = 0;
                for( int k = i; k >= 0; k-- )
                    if( s[k] == j )
                    {
                        fl = 1;
                        break;
                    }
                if( !fl )
                {
                    s[ i ] = char( j );
                    for( int k = 0; k <= i; k++ )
                        cout << s[k] ;
                    return 0;
                }
            }
        }
        cout << -1;
        return 0;
    }
    else
    {
        for( auto x : s )
            cnt[ int(x) ] ++;
        for( int i = 'a'; i <= 'z'; i++ )
            if( cnt[ i ] == 0 )
            {
                s += char( i );
                break;
            }
    }
    cout << s;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int all = sc.nextInt();

    int fault = 0;
    for(int i = 0;i<all;i++){
      if(sc.nextInt() != i+1){
        fault++;
      }
    }
    System.out.println(fault<=2 ? "YES" : "NO" );
  }
}
    
    


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

int main() {
  string s;
  cin >> s;
  int counter = 0;
  if (s[0] == '1') counter++;
  if (s[1] == '1') counter++;
  if (s[2] == '1') counter++;
  cout << counter << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b, c, n, k;
string s;



int main()
{
	cin >> n >> k;
	vector<int> A(n);
	rep(i, n)
		cin >> A.at(i);
	sort(all(A), greater<int>());
	int sum = 0;
	rep(i, k)
		sum += A[i];
	printf("%d\n",sum);
	return 0;
}


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

int count(unsigned int n);

int main(void) {
  int n;
  cin >> n;
  n++;
  int A[n];
  int x[n][n];
  int y[n][n];
  for(int i = 1; i < n; i++) {
    cin >> A[i];
    for(int j = 1; j < A[i] + 1; j++) {
      cin >> x[i][j] >> y[i][j];
    }
  }

  int ans = 0;
  for(unsigned int temp_bitmap = 1;
      temp_bitmap < 1 << (n - 1); temp_bitmap++) {
    int cnt = count(temp_bitmap);
    if(cnt <= ans) {
      continue;
    }
    int mask = 1;
    bool contradict = false;
    for(int j = 1; j < n; j++, mask <<= 1) {
      if((temp_bitmap & mask) > 0) {
        for(int k = 1; k < A[j] + 1; k++) {
          int xjk = temp_bitmap & (1 << (x[j][k] - 1));
          if(xjk == 0 && y[j][k] == 1) {
            contradict = true;
          } else if(xjk > 0 && y[j][k] == 0) {
            contradict = true;
          }
          if(contradict) {
            break;
          }
        }
      }
      if(contradict) {
        break;
      }
    }
    if(contradict) {
      continue;
    }
    ans = cnt;
  }
  cout << ans << endl;
  return 0;
}

int count(unsigned int n) {
  int count = 0;
  while(n != 0) {
    if((n & 1) == 1) {
      count++;
    }
    n >>= 1;
  }
  return count;
}

Measured memory_bytes: 256
fun main() {
  val N = readInt()
  var cnt = 0
  repeat(N) {
    val (a, b) = readInts()
    if (a == b) cnt++
    if (a != b) cnt = 0
    if (cnt >= 3) {
      println("Yes")
      return
    }
  }
  println("No")
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 37916
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int l;
cin >> l;
int ara[n];
memset(ara,0,sizeof(ara));
int sum =0;
for(int i= 0  ; i < n; i++){
    ara[i] = l + i;
    sum += ara[i];

}

int diff = 1e9 + 90;
int maxi = 0;
for(int i =0 ; i < n; i++){
        int temp = abs(sum-(sum-ara[i]));
    if(temp<diff){
        diff = temp;
        maxi = sum-ara[i];
    }
}

cout << maxi << endl;
return 0;

}


Measured memory_bytes: 256
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
#include<bits/stdc++.h>
using namespace std;

int main()
{
  string s;
  cin >> s;
  if(s=="ABC")
    cout<<"ARC";
  else 
    cout<<"ABC";
  return 0;
}

Measured memory_bytes: 3620
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))

from collections import Counter
D = dict(Counter(A))

for i in range(M):
    B,C = list(map(int,input().split()))
    D[C]=D.get(C,0)+B

K = sorted(list(D.keys()),reverse=True)

out = 0
cnt = 0
now = 0
while cnt<=N-1:
    if D[K[now]]>0:
        out += K[now]
        D[K[now]] += -1
        cnt+=1
    else:
        now+=1
print(out)

Measured memory_bytes: 115244
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define strall(v) (v).cbegin(),(v).cend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}


int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> cost(n+1,0);
  cost[0] = abs(a[0]);
  ll total = cost[0];
  for(int i=1;i<n;i++) {
    cost[i] = abs(a[i] - a[(i-1)]);
    total += (cost[i] + 0LL);
  }
  cost[n] = abs(a[n-1]);
  total += abs(a[n-1]);
  rep(i,n) {
    ll tmp = total,ans = 0;
    if(i==0) {
      //cout << "begin: ";
      tmp-=(cost[0]+cost[1]);
      ans = tmp + abs(a[i+1]);
      cout << ans << endl;
      continue;
    }else if(i == n-1){
      //cout << "end: " ; 
      tmp-=(cost[i]+cost[i+1]);
      ans = tmp + abs(a[i-1]);
      cout << ans << endl;
      continue;
    }
    tmp-=(cost[i]+cost[i+1]);
    tmp+=abs(a[i+1] - a[i-1]);
    cout << tmp << endl;
  }
   
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n;
    cin >> n;
    vector<int> v(n+2);
    for (int i = 0; i < n; ++i) {
        cin >> v[i+1];
    }
    auto dp = make_v(n+3, 5, INF<ll>);
    dp[0][0] = 0;
    for (int i = 0; i < n+2; ++i) {
        for (int j = 0; j < 5; ++j) {
            if(j <= 0) chmin(dp[i+1][0], dp[i][j]+v[i]);
            if(j <= 1) chmin(dp[i+1][1], dp[i][j]+v[i]%2 + 2*(v[i] == 0));
            if(j <= 2) chmin(dp[i+1][2], dp[i][j]+(v[i]+1)%2);
            if(j <= 3) chmin(dp[i+1][3], dp[i][j]+v[i]%2 + 2*(v[i] == 0));
            if(j <= 4) chmin(dp[i+1][4], dp[i][j]+v[i]);
        }
    }
    cout << dp[n+2][4] << "\n";
    return 0;
}


Measured memory_bytes: 15104
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
for i in range(n):
    if b[i] <= a[i]:
        cnt += b[i]
    else :
        cnt += a[i]
        c = b[i] - a[i]
        if c <= a[i+1]:
            cnt += c
            a[i+1] -= c
        else :
            cnt += a[i+1]
            a[i+1] = 0
print(cnt)


Measured memory_bytes: 19156
N = int(input())
# res = |X - i| + |Y - j|
yakusu = []
for i in range(1, int(N ** (1 / 2))+1):
     if N % i == 0:
         yakusu.append(i)

res = 10**13
for y in yakusu:
    x = N//y
    dist = (y-1)+(x-1)
    res = min(res, dist)

print(res)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = Math.abs(x - sc.nextInt());
        int b = Math.abs(x - sc.nextInt());

        System.out.println(a < b ? "A" : "B");
    }

}

Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <complex>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
const double PI = acos(-1);
inline bool equals(double a, double b) { return abs(b - a) < EPS; }
using Point = complex<double>;
namespace std { bool operator < (const Point &a, const Point &b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } }
struct Line
{
    Point a, b;
    Line(Point a, Point b) : a(a), b(b) {}
};
double dot(const Point &a, const Point &b) { return real(a) * real(b) + imag(a) * imag(b); }
double cross(const Point &a, const Point &b) { return real(a) * imag(b) - imag(a) * real(b); }
bool isParallel(const Line &a, const Line &b) { return equals(cross(a.b - a.a, b.b - b.a), 0.0); }
bool isOrthogonal(const Line &a, const Line &b) { return equals(dot(a.a - a.b, b.a - b.b), 0.0); }
Point projection(const Line &l, const Point &p)
{
    double t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
    return l.a + (l.a - l.b) * t;
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(8);
    double x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    Line L = Line(Point(x1, y1), Point(x2, y2));
    int q; cin >> q;
    while(q--)
    {
        double x, y; cin >> x >> y;
        Point res = projection(L, Point(x, y));
        cout << res.real() << " " << res.imag() << endl;
    }
    return 0;
}




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

using namespace std;

int main(void){
  string S;
  cin >> S;
  if(S[2] == S[3] && S[4] == S[5]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,a,ans;

int main()
{
	cin>>n;
	rep(i,n)
	{
		scanf("%I64d",&a);
		if(i==0) ans=a;
		else ans=__gcd(ans,a);
	}
	cout<<ans<<endl;
	rt0;
}

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

int main() {
	cin.tie(0)->sync_with_stdio(false);
	int n, k; cin >> n >> k;
	vector<int> l(k), r(k);
	REP(i, k) cin >> l[i] >> r[i];
	vector<int> dp(n + 1, 0);
	dp[0] = 1;
	dp[1] = -1;
	// 配る DP
	REP(i, n) {
		dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
		REP(j, k) {
			if (i + l[j] < n)
				dp[i + l[j]] = (dp[i + l[j]] + dp[i]) % MOD;
			if (i + r[j] + 1 < n)
				dp[i + r[j] + 1] = (((dp[i + r[j] + 1] - dp[i]) % MOD) + MOD) % MOD;
		}
	}
	cout << dp[n - 1] << '\n';
	return 0;
}


Measured memory_bytes: 3992
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1},
};

fn dfs(
   i: usize,
   f: bool,
   s: &Vec<String>,
   a: isize,
   b: isize,
   c: isize,
   ans: &mut Vec<&str>,
) -> bool {
   if i == s.len() {
      return true;
   }
   if a < 0 || b < 0 || c < 0 {
      return false;
   }
   if s[i] == "AB" {
      if f {
         if b <= 0 {
            return false;
         } else {
            if dfs(i + 1, true, s, a + 1, b - 1, c, ans) {
            } else if dfs(i + 1, false, s, a + 1, b - 1, c, ans) {
            } else {
               return false;
            }
         }
      } else {
         if a <= 0 {
            return false;
         } else {
            if dfs(i + 1, true, s, a - 1, b + 1, c, ans) {
            } else if dfs(i + 1, false, s, a - 1, b + 1, c, ans) {
            } else {
               return false;
            }
         }
      }
   } else if s[i] == "BC" {
      if f {
         if c <= 0 {
            return false;
         } else {
            if dfs(i + 1, true, s, a, b + 1, c - 1, ans) {
            } else if dfs(i + 1, false, s, a, b + 1, c - 1, ans) {
            } else {
               return false;
            }
         }
      } else {
         if b <= 0 {
            return false;
         } else {
            if dfs(i + 1, true, s, a, b - 1, c + 1, ans) {
            } else if dfs(i + 1, false, s, a, b - 1, c + 1, ans) {
            } else {
               return false;
            }
         }
      }
   } else {
      if f {
         if c <= 0 {
            return false;
         } else {
            if dfs(i + 1, true, s, a + 1, b, c - 1, ans) {
            } else if dfs(i + 1, false, s, a + 1, b, c - 1, ans) {
            } else {
               return false;
            }
         }
      } else {
         if a <= 0 {
            return false;
         } else {
            if dfs(i + 1, true, s, a - 1, b, c + 1, ans) {
            } else if dfs(i + 1, false, s, a - 1, b, c + 1, ans) {
            } else {
               return false;
            }
         }
      }
   }
   //println!("{} {} {}", i, s[i], f);
   ans.push(if s[i] == "AB" {
      if f {
         "A"
      } else {
         "B"
      }
   } else if s[i] == "BC" {
      if f {
         "B"
      } else {
         "C"
      }
   } else {
      if f {
         "A"
      } else {
         "C"
      }
   });
   true
}
#[fastout]
fn main() {
   input! {
      n:usize,a:isize,b:isize,c:isize,
      s:[String;n]
   }
   let mut s1 = vec![];
   let mut s2 = vec![];
   if dfs(0, false, &s, a, b, c, &mut s1) {
      println!("Yes");
      for i in s1.iter().rev() {
         println!("{}", i);
      }
   } else if dfs(0, true, &s, a, b, c, &mut s2) {
      println!("Yes");
      for i in s2.iter().rev() {
         println!("{}", i);
      }
   } else {
      println!("No");
   }
}


Measured memory_bytes: 19028
#include<bits/stdc++.h>
using namespace std;
int mod=7+1e9;
int main()
{  long long n,m;
   cin>>n>>m;
   long long height[n];
   for(int i=0;i<n;i++)
       cin>>height[i];
   long long a,b;
   int arr[n];
   for(int &x:arr)
       x=1;
   while(m--)
   {  cin>>a>>b;
      if(height[a-1]>height[b-1])
          arr[b-1]=0;
      else if(height[a-1]<height[b-1])
          arr[a-1]=0;
      else
      {arr[a-1]=0;
          arr[b-1]=0;}


   }
   long long count=0;
   for(int i=0;i<n;i++)
   {if(arr[i]==1)
           count++;}
   cout<<count;

}


Measured memory_bytes: 4808