akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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 (a > b) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int t[3];
  rep(i, 3) cin >> t[i];

  sort(t, t+3);

  int ans = 0;
  rep(i, 2) ans += abs(t[i] - t[i+1]);

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 3616
#include<stdio.h>

long a,b,d,r;
double c,e,f;

int main(void){
scanf("%d %d",&a,&b);
d = a/b;
r = a%b;
c = a; 
e = b;
f = c/e;
printf("%d %d %lf\n",d,r,f);

return 0;
}


Measured memory_bytes: 2136
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<int> a(N + 1);
    rep(i, 1, N+1) cin >> a[i];

    vector<int> b(N+1, 0);

    vector<int> ans;

    for (int i = N; i > 0; i--) {
        int sum = 0;
        for (int j = i; j <= N; j += i) {
            sum += b[j];
        }
        if (sum % 2 != a[i]) {
            b[i]++;
            ans.push_back(i);
        }
    }

    reverse(ans.begin(), ans.end());
    cout << ans.size() << endl;
    for (auto v : ans) cout << v << endl;

    return 0;
}

Measured memory_bytes: 3064
# 部分、平衡二分木
n,m = map(int, input().split())
a = [ int(i) for i in input().split() ]
from itertools import accumulate
from collections import Counter
A = Counter([0] + [x%m for x in accumulate(a)])
ans = 0
for a in A.values():
    ans += a * (a-1) // 2 # n個ある中から二つ選ぶ順列
print(ans)


Measured memory_bytes: 16596
#include <iostream>
#include <string>
#include <stack>
using namespace std;

class RPN //reverse_polish_notation
{
private:
    stack<int> number;

public:
    void push(string input);
    int answer(void);
};

//inputはオペランドまたは演算子
void RPN::push(string input)
{
    string operator_char = "+-*";
    if (operator_char.find(input) == string::npos)
    {
        int num = stoi(input); //inputをintに変換
        number.push(num);
    }
    else if (input == "+")
    {
        int plus = number.top();
        number.pop();
        plus += number.top();
        number.pop();
        number.push(plus);
    }
    else if (input == "-")
    {
        int minus = number.top();
        number.pop();
        minus = number.top() - minus;
        number.pop();
        number.push(minus);
    }
    else if (input == "*")
    {
        int multiply = number.top();
        number.pop();
        multiply = number.top() * multiply;
        number.pop();
        number.push(multiply);
    }
    else
    {
    }
    //逆ポーランド記法で計算した結果を返す関数
}

int RPN::answer()
{
    return number.top();
}

int main()
{
    RPN rpn;
    while (1)
    {
        string input;
        cin >> input;
        if (cin.eof())
        {
            break;
        }
        rpn.push(input);
    }
    cout << rpn.answer() << endl;
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
#define N 300010
using namespace std;
int n,a[N],s[N];
bool check(int x){
	int no=0;
	for (int i=1;i<=n;i++){
		if (i%2==1)no-=a[i];
		else if (no<x&&no+a[i]>0)no=0;else no+=a[i];
	}
	if (no<x) return 0;
	return 1;
}
int ch(int x){x++;if (x<0&&x%2)x-=2;return x/2;}
int main(){
	cin>>n;
	for (int i=1;i<=n;i++){cin>>a[i];s[i]=a[i];if (i>2)s[i]+=s[i-2];}
	if (n%2==0)cout<<max(s[n],s[n-1])<<' '<<min(s[n],s[n-1])<<endl;
	else{
		int l=-n*1000,r=n*1000,mid;
		while (l<r){
			mid=ch(l+r);
			if (check(mid))l=mid;else r=mid-1;
		}
		cout<<s[n-1]-l<<' '<<s[n]+l<<endl;
	}
	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>

int main(){
  int a;
  int b;
  int c;
  int tmp;
  scanf("%d %d %d",&a, &b, &c);
  if(a<b){
    tmp = b;
    b = a;
    a = tmp;
  }
  if(b<c){
    tmp = c;
    c = b;
    b = tmp;
  }
  if(a<b){
    tmp = b;
    b = a;
    a = tmp;
  }
  printf("%d %d %d\n",c,b,a);
}



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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef int64_t ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;
const ll MOD = 1e9 + 7;


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

  ll dp[101][4][4][4];
  REP(i, 101)REP(j, 4)REP(k, 4)REP(l, 4) dp[i][j][k][l] = 0;
  dp[0][3][3][3] = 1;

  REP(len, N)REP(c1, 4)REP(c2, 4)REP(c3, 4) {
    REP(a, 4) {
      if(           c2 == 0 && c3 == 2 && a == 1) continue;
      if(           c2 == 0 && c3 == 1 && a == 2) continue;
      if(c1 == 0            && c3 == 1 && a == 2) continue;
      if(c1 == 0    && c2 == 1         && a == 2) continue;
      if(           c2 == 1 && c3 == 0 && a == 2) continue;
      dp[len + 1][c2][c3][a] += dp[len][c1][c2][c3];
      dp[len + 1][c2][c3][a] %= MOD;
    }
  }

  ll ret = 0;
  REP(c1, 4)REP(c2, 4)REP(c3, 4){
    ret += dp[N][c1][c2][c3];
    ret %= MOD;
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
    int n, m, l, r;
    cin >> n >> m;
    int a = 1;
    int b = n;
    for(int i = 1; i <= m; i++){
        cin >> l >> r;
        a = max(a, l);
        b = min(b, r);
    }
    if(b < a){
        cout << 0 << endl;
    } else {
        cout << b - a + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

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

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MOD = 1e9 + 7;

int N, K;

LL fpm(LL base, LL exp)
{
    LL ret = 1;
    for (; exp; exp >>= 1) {
        if (exp & 1)
            (ret *= base) %= MOD;
        (base *= base) %= MOD;
    }
    return ret;
}

void input()
{
    read(N); read(K);
}

void solve()
{
    vector<int> val;

    for (int i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            val.push_back(i);
            if (N / i != i)
                val.push_back(N / i);
        }
    }
    std::sort(ALL(val));

    vector<LL> dp;
    LL ans = 0;

    for (int i = 0; i < SZ(val); ++i) {
        dp.push_back(fpm(K, (val[i] + 1) / 2));
        for (int j = 0; j < i; ++j) {
            if (val[i] % val[j] == 0)
                (dp[i] -= dp[j]) %= MOD;
        }
        if (val[i] & 1)
            (ans += dp[i] * val[i]) %= MOD;
        else
            (ans += dp[i] * val[i] / 2) %= MOD;
    }
    (ans += MOD) %= MOD;

    printf("%lld\n", ans);
}

int main()
{
#ifdef __DEBUG
    freopen("F.in", "r", stdin);
    freopen("F.out", "w", stdout);
#endif

    input();
    solve();
}

// 上窗风动竹，月微明。
//     -- 吕渭老《小重山·七夕病中》


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

int N; long long L, T;
vector<long long> X;
vector<int> W;

int main() {
    cin >> N >> L >> T;
    X.resize(N); W.resize(N); for (int i = 0; i < N; ++i) cin >> X[i] >> W[i];
    vector<long long> tmp(N);
    for (int i = 0; i < N; ++i) {
        if (W[i] == 1) tmp[i] = (X[i] + T) % L;
        else tmp[i] = ((X[i] - T) % L + L) % L;
    }
    sort(tmp.begin(), tmp.end());
    long long count = 0;
    for (int i = 0; i < N; ++i) {
        if (W[i] == 1) count -= (T - (L - X[i]) + L) / L;
        else count += (T - (X[i] + 1) + L) / L;
    }
    count = (count % N + N) % N;
    vector<long long> res(N);
    for (int i = 0; i < N; ++i) res[(i+count)%N] = tmp[i];
    for (int i = 0; i < N; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 5880
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		if ((a + b) > (c + d)) {
			System.out.print("Left");
		} else if ((a + b) < (c + d)) {
			System.out.print("Right");
		} else {
			System.out.print("Balanced");
		}
	}
}

Measured memory_bytes: 21076
module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------

trampOrder = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]

main :: IO ()
main = do
  [a, b] <- map (fromJust . flip findIndex trampOrder . (==)) <$> readInts
  putStrLn $ case compare a b of
               LT -> "Bob"
               EQ -> "Draw"
               GT -> "Alice"

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"


Measured memory_bytes: 508
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=2005;
vector<int>v[N];
int n,m,a,b,dist[N][N];
inline bool cmp(vector<int>x,vector<int>y){return x.size()>y.size();}
void bfs()
{
    for(int i=0;i<N;i++)for(int j=0;j<N;j++)dist[i][j]=1e9;
    queue<int>q;
    for(int i=0;i<n;i++)
    {
        q.push(0);
        q.push(i);
        q.push(i);
    }
    while(!q.empty())
    {
        int move=q.front();q.pop();
        int org=q.front();q.pop();
        int now=q.front();q.pop();
        if(dist[org][now]<=move)continue;
        dist[org][now]=move;
        for(int i=0;i<v[now].size();i++)
        {
            int to=v[now][i];
            q.push(move+1);
            q.push(org);
            q.push(to);
        }
    }

}
void solve()
{
    bfs();
    int pnt=0,ans=0;
    vector<int>e[N];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if(dist[i][j]>m)
                e[i].pb(j),pnt++;
    for(int i=0;i<n;i++)sort(e[i].begin(),e[i].end());
    while(pnt)
    {
        int MAX=0,num=-1;
        for(int i=0;i<n;i++)
        {
            if(MAX<e[i].size())
            {
                num=i;
                MAX=e[i].size();
            }
        }
        for(int i=0;i<e[num].size();i++)
        {
            int to=e[num][i];
            e[to].erase(lower_bound(e[to].begin(),e[to].end(),num));
        }
        ans++;
        pnt-=e[num].size()*2;
        e[num].clear();
    }
    cout<<ans<<endl;
    return;
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<n-1;i++)
    {
        cin>>a>>b;
        a--,b--;
        v[a].pb(b);
        v[b].pb(a);
    }
    solve();
    return 0;
}

Measured memory_bytes: 67332
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long LL;

const int maxn=2e5+5;

int n,a[maxn],num[maxn][2],num0;

int main()
{
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	
	sort(a+1,a+1+n);
	int cnt=1;
	fo(i,2,n) if (a[i]!=a[i-1])
	{
		num[++num0][0]=a[i-1];
		num[num0][1]=cnt;
		cnt=1;
	} else cnt++;
	num[++num0][0]=a[n], num[num0][1]=cnt;
	
	if (num0>3) puts("No");
		else if (num0==3)
		{
			if (n%3) {puts("No"); return 0;}
			if (num[1][1]!=num[2][1] || num[1][1]!=num[3][1]) {puts("No"); return 0;}
			if ((num[1][0]^num[2][0])!=num[3][0]) {puts("No"); return 0;}
			puts("Yes");
		} else if (num0==2)
		{
			if (n%3) {puts("No"); return 0;}
			if (num[1][0]==0 && num[2][1]==2*num[1][1] || num[2][0]==0 && num[1][1]==2*num[2][1])
				puts("Yes");
			else puts("No");
		} else
		{
			puts((num[1][0]==0) ?"Yes" :"No");
		}
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
   int n,i;
   cin>>n;
   int a[n];
   int max1=-1,max2=-1;
   int ind;
   for(i=0;i<n;i++)
   {
       cin>>a[i];
     if(a[i]>max1)
     {
         max1=a[i];
         ind=i;
     }
   }
   for(i=0;i<n;i++)
   {
     if(i!=ind)
     {
         if(a[i]>max2)
            max2=a[i];
     }
   }
   for(i=0;i<n;i++)
   {
       if(a[i]==max1)
        cout<<max2<<e;
       else
        cout<<max1<<e;
   }
}


Measured memory_bytes: 2432
#include <cstdio>

const int MN = 105;

int N;
int A[MN], Ans[MN];

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i)
		scanf("%d", &A[i]);
	for (int i = 1; i <= N; ++i)
		if (A[i] > i)
			return puts("-1"), 0;
	for (int i = N; i >= 1; --i) {
		int p = 0;
		for (int j = 1; j <= i; ++j)
			if (A[j] == j) p = j;
		Ans[i] = A[p];
		for (int j = p; j < i; ++j)
			A[j] = A[j + 1];
	}
	for (int i = 1; i <= N; ++i)
		printf("%d\n", Ans[i]);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <ctype.h>

int read() {
	char ch;
	int ret, fl = 1;
	while(!isdigit(ch = getchar()))
		(ch == '-') && (fl = -1);
	ret = ch - '0';
	while(isdigit(ch = getchar()))
		ret *= 10, ret += ch - '0';
	return ret * fl;
}

void print(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x > 9) print(x / 10);
	putchar(x % 10 + '0');
}

int main() {
	int n = read(), a = read();
	return print(n * n - a), 0;
}

Measured memory_bytes: 128
program main;
var
    i, x, y, smallest, count : integer;
    total : int64;
    A : array[1..1000] of integer;
    B : array[1..1000] of boolean;
begin
    readln(x, y);
    total := 0;
    for i := 1 to x do 
        B[i] := false;
    for i := 1 to x do
        read(A[i]);
    while y > 0 do begin
        smallest := 1001;
        count := 0;
        for i := 1 to x do 
            if (A[i] < smallest) and (B[i] = false)
                then begin
                    smallest := A[i];
                    count := i;
                end;
        B[count] := true;
        total := total + smallest;
        y := y - 1;
    end;
    writeln(total);
end.

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

int main()
{
    uint32_t nn;
    uint32_t kk;
    std::cin >> nn >> kk;
    
    std::cout << ((uint32_t)((log(nn)/log(kk)) * 10) / 10) + 1 << std::endl;
    //std::cout << (round(log(nn)/log(kk)) * 10) / 10 << std::endl;
    return 0;
}


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

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

using namespace std;
using lint=long long;

const lint MOD=1000000007;

lint xgcd(lint a,lint b,lint &x,lint &y){
	if(b==0){ x=1; y=0; return a; }
	lint g=xgcd(b,a%b,y,x); y-=a/b*x;
	return g;
}

lint modinv(lint a,lint m){
	lint x,y;
	if(xgcd(a,m,x,y)==1) return (x+m)%m;
	return -1;
}

map<lint,int> prime_factorize(lint a){
	map<lint,int> res;
	for(lint p=2;p*p<=a;p++) if(a%p==0) {
		int cnt=0;
		do{ a/=p; cnt++; }while(a%p==0);
		res[p]=cnt;
	}
	if(a>1) res[a]=1;
	return res;
}

lint fact[100101];

lint nCr(int n,int r){
	return fact[n]*modinv(fact[r],MOD)%MOD*modinv(fact[n-r],MOD)%MOD;
}

lint nHr(int n,int r){
	return nCr(n+r-1,r);
}

int main(){
	fact[0]=1;
	rep(i,100100) fact[i+1]=fact[i]*(i+1)%MOD;

	int n,m; cin>>n>>m;

	auto pf=prime_factorize(m);

	lint ans=1;
	for(auto a:pf) ans=ans*nHr(n,a.second)%MOD;

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i,N) cin >> A[i];
  vector<int> B=A;
  sort ALL(B);
  reverse ALL(B);
  int no_1=B[0];
  if(B[0]==B[1]) REP(i,N) cout << no_1 << endl;
  else {
    int no_2=B[1];
    REP(i,N) {
      if(A[i]==no_1) cout << no_2 << endl;
      else cout << no_1 << endl;
    }
  }
}

Measured memory_bytes: 3200
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    int N, D; cin >> N >> D;
    int M = 2*D + 1;
    cout << (N + M - 1) / M << endl;
    return 0;
}


Measured memory_bytes: 256
from heapq import heappush,heappop

def main():
  n,m,s,t=map(int,input().split())
  INF=10**20
  G1,G2 = [{} for _ in range(n)],[{} for _ in range(n)]
  for i in range(m):
    u,v,a,b=map(int,input().split())
    G1[u-1][v-1] = G1[v-1][u-1] = a
    G2[u-1][v-1] = G2[v-1][u-1] = b

  def dijkstra(G,start = 0):
      d = [INF for i in range(len(G))]
      d[start] = 0
      que = []
      heappush(que, (0, start))

      while len(que):
          p = heappop(que)
          v = p[1]
          if d[v] < p[0]:
              continue
          for u in G[v].keys():
              if d[u] > d[v] + G[v][u]:
                  d[u] = d[v] + G[v][u]
                  heappush(que, (d[u], u))
      return d

  d1 = dijkstra(G1,s-1)
  d2 = dijkstra(G2,t-1)

  ans=[]
  MIN = INF
  for i in range(n-1,-1,-1):
    MIN = min(MIN,d1[i]+d2[i])
    if i == s-1:
      MIN = min(MIN,d2[s-1])
    if i == t-1:
      MIN = min(MIN,d1[t-1])

    ans.append(MIN)

  for a in reversed(ans):
    print(10**15-a)
  
if __name__=="__main__":
  main()

Measured memory_bytes: 93700
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>

using namespace std;

void ABC051C()
{
	int x0, y0, x1, y1;
	cin >> x0 >> y0 >> x1 >> y1;
	int dx = x1 - x0;
	int dy = y1 - y0;
	string s;
	for (int i = 0; i < dx; ++i)
	{
		s += 'R';
	}
	for (int i = 0; i < dy; ++i)
	{
		s += 'U';
	}
	for (int i = 0; i < dx; ++i)
	{
		s += 'L';
	}
	for (int i = 0; i < dy; ++i)
	{
		s += 'D';
	}
	s += 'D';
	for (int i = 0; i < dx + 1; ++i)
	{
		s += 'R';
	}
	for (int i = 0; i < dy + 1; ++i)
	{
		s += 'U';
	}
	s += 'L';
	s += 'U';
	for (int i = 0; i < dx + 1; ++i)
	{
		s += 'L';
	}
	for (int i = 0; i < dy + 1; ++i)
	{
		s += 'D';
	}
	s += 'R';
	cout << s << endl;

}
int main()
{
	ABC051C();
	return 0;
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)

const LL mod=(1e9)+7;
int main()
{
    LL n;
    cin>>n;
    LL a[n+1];
    LL s[n+1];
    MEM(s,0);
    for(LL i=1; i<=n; i++)
    {
        cin>>a[i];
        s[i]=s[i-1]+a[i];
//        s[i]=s[i]%mod;
    }
    LL ans=0;
    LL sum=s[n];
    for(LL i=1; i<=n; i++)
    {
        LL x=a[i];
        LL y=sum-s[i];
        ans+=((x%mod)*(y%mod))%mod;
        ans=ans%mod;
    }
    cout<<ans;
}


Measured memory_bytes: 6764
import itertools

N,M,Q = map(int, input().split())
l = [[int(i) for i in input().split()] for j in range(Q)]


hoge = []
kouho = list(range(1,M+1))
for i in itertools.combinations_with_replacement(kouho, N):
    hoge.append(i)

Anss = []*len(hoge)
m = 0
for i in range(0,len(hoge)):
  for j in range(0,Q):
    if(hoge[i][l[j][1]-1] - hoge[i][l[j][0]-1] == l[j][2]):
      m = m + l[j][3]
  Anss.append(m)
  m = 0
  
  
ans = max(Anss)
print(ans)

Measured memory_bytes: 25104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

Measured memory_bytes: 256
// author: Saman Mahdanian
#include <algorithm>
#include <iostream>
#include <numeric>

using namespace std;

const int N = 1e6 + 10;
int n, a[N], b[N], que[N];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i];
	
	iota(que, que + n, 0);
	sort(que, que + n, [] (int i, int j) {
		return a[i] + b[i] > a[j] + b[j];
	});

	long long ans = 0;
	for (int i = 0; i < n; i++)
		if (i & 1)
			ans -= b[que[i]];
		else
			ans += a[que[i]];
	cout << ans << endl;
}

// SamMHD :: Mar5-2019 :: Another HomeWork for Shayan...

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

using namespace std;

int main() {
  int n, m, p;
  while (cin >> n >> m >> p, n) {
    vector<int> x(n);
    m--;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> x[i];
      sum += x[i] * 100;
    }
    sum -= sum / 100 * p;
    if (x[m] == 0) {
      cout << 0 << endl;
    } else {
      cout << sum / x[m] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define ll long long
#define ld long double
#define int ll
#define pb push_back
#define ii pair<int,int>
#define llll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<ii>
#define vllll vector<llll>
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define arrin(x,n) int x[n]; for(int o=0;o<n;o++) cin>>x[o]
#define arrout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<'='<<x<<endl
#define deb2(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
#define deb3(x,y,z) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<" "<<#z<<'='<<z<<endl
#define debarr(arr,n) for(int o=0;o<n;o++) deb2(o,arr[o])
#define IO freopen("input.txt", "r", stdin); freopen("output.txt", "w+", stdout)
const double pi = 3.14159265358979323846;

ll power(ll a, ll b){//a^b
    ll res=1;
    //a=a%MOD;
    while(b>0){
        if(b&1)
		{res=(res*a);
		//res%=MOD;
		b--;}
        a=(a*a);
        //a%=MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int C(int n,int k)
{
	int ans=1;
	if(k>n-k)
	k=n-k;
	for(int i=1;i<=k;i++)
	ans*=(n-i+1),ans/=i;
	return ans;
}

void solve()
{
int q,d;
	double i=0,j=0,k=0,n,m,p,sum=0,cnt=0;
	cin>>q>>d;
	int u,lo=0;
	for(u=0;i<q;i++)
	{
	    cin>>n>>m;
	    if(sqrt(n*n+m*m)<=d)
	    lo++;
	}
	cout<<lo;
}
int32_t main() {
    fast
    //IO;
	//cout<<fixed<<setprecision(6);
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  

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

int main(){
	int a, b, sum;

	while(cin >> a >> b){
		sum = a + b;

		for(int i=1; ; ++i){
			if(sum<10){
				cout << i << endl;
				break;
			}else{
				sum /= 10;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n, k, q;
    cin >> n >> k >> q;
    set<ll> s;
    ll a[n];
    rep(i, n) {
        cin >> a[i];
        s.emplace(a[i]);
    }
    ll ans = LINF;
    for (auto mn : s) {
        auto isOK = [&](ll mx) {
            int sum[n + 1] = {};
            rep(i, n) {
                sum[i + 1] = sum[i] + (a[i] <= mx);
            }
            int cnt = 0, pre = 0;
            rep(i, n) {
                if (a[i] < mn) {
                    cnt += max(0, min(i - pre - k + 1, sum[i] - sum[pre]));
                    pre = i + 1;
                }
            }
            cnt += max(0, min(n - pre - k + 1, sum[n] - sum[pre]));
            return q <= cnt;
        };
        ll ng = -1, ok = LINF;
        while (abs(ok - ng) > 1) {
            ll mid = (ok + ng) / 2;
            if (isOK(mid)) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        ans = min(ans, ok - mn);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
void utilDFS(vector<vector<int>>& graph, vector<int>& dp, vector<bool>& visit, int k) {
	int e = (int) graph[k].size();
	visit[k] = true;
	for (int i = 0; i < e; ++i) {
		if (!visit[graph[k][i]])
			utilDFS(graph, dp, visit, graph[k][i]);
		dp[k] = max(dp[k], 1 + dp[graph[k][i]]);
	}
}
int main() {
	int n; 
	cin >> n;
	int	l, m;
	cin >> m;
	vector<vector<int>> graph(n+1, vector<int>()); 
	vector<int> dp(n+1, 0);
	vector<bool> visit(n+1, false);

	int x, y;
	for (int i = 0; i < m; ++i) {
		cin >> x >> y;
		graph[x].push_back(y);
	}
	for (int i = 1; i <= n; ++i) {
		if (!visit[i])
			utilDFS(graph, dp, visit, i);
	}
	cout << *max_element(dp.begin(), dp.end());
	return 0;
} 


Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define endl '\n'

int main()
{
    ll n,k,i;
    cin>>n>>k;
    ll arr[n];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n,greater<ll>());
    for(i=0;i<min(n,k);i++)
    {
        arr[i]=0;
    }
    ll sum=0;
    for(i=min(n,k); i<n;i++)
    {
        sum+=arr[i];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

import sys
import os


def input_to_list():
    return list(map(int, input().split()))

while True:
    lst = input_to_list()
    if lst[0] == lst[1] == 0:
        break
    else:
        n = lst[0]
        x = lst[1]
        c = 0
        for i in range(1, n + 1):
            for j in range(i+1, n + 1):
                for k in range(j+1, n + 1):
                    if i + j + k == x:
                        c += 1
    print(c)

Measured memory_bytes: 7704
# -*- coding: utf-8 -*-


S = input()
import sys
while True:
    if(len(S)==0):
        print("YES")
        sys.exit()
    if S.endswith("dreamer"):
        S = S[:-7]
    elif S.endswith("eraser"):
                S = S[:-6]
    elif S.endswith("dream"):
        S = S[:-5]
    elif S.endswith("erase"):
        S = S[:-5]
    else:
        print("NO")
        sys.exit()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define f first
// #define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 21;
const ll MOD = 1e9 + 7;
ll n; 
ll a[MAXN][MAXN];
ll dp[MAXN][1LL<<MAXN];

ll rec(ll idx,ll mask){
    if(idx == n){
        if((mask + 1) == (1LL<<n)) return 1;
        return 0;
    }

    ll &ans = dp[idx][mask];

    if(ans != -1) return ans;

    ans = 0;
    FOR(i,0,n-1){
        if((mask>>i) & 1) continue;
        if(a[idx][i] == 0) continue;
        ans = (ans + rec(idx+1,mask|(1LL<<i)))%MOD;
    }

    return ans;
}

void solve(){
    memset(dp,-1,sizeof(dp));
    cin>>n;

    FOR(i,0,n-1) FOR(j,0,n-1) cin>>a[i][j];

    cout<<rec(0,0)<<endl;
}

signed main(){

    ll t;
    t = 1; 
    // cin>>t;
    FOR(tt,1,t){
        solve();
    }
    
}

Measured memory_bytes: 344320
/// 13-03-2018
/// MD:NUR ALAM
/// Eastern University of Bangladesh

#include "bits/stdc++.h"

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define repp(i, a, b) for (int i = (a); i < (b); ++i)
#define fo(i, a, b) for (int i = (a); i <(b); ++i)
#define fors(i, s) for (int i = 0; s[i]; ++i)
#define rs(x) scanf("%s", (x))
#define mp make_pair
#define pb push_back
#define mso(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)

using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef long double lu;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<pii> vpll;
typedef pair<ll,ll> Pll;
typedef map<string,int>msi;
typedef set<ll>se;

template<class t> void _r(t &x) { cin >> x; }
void _r(int &x) { scanf("%d", &x); }
void _r(int64_t &x) { scanf("%lld", &x); }
void _r(double &x) { scanf("%lf", &x); }
void _r(char &x) { scanf(" %c", &x); }
void _r(char *x) { scanf("%s", x); }
void r() {}
template<class t, class... u> void r(t &head, u &... tail) { _r(head); r(tail...); }
template<class t> void _w(const t &x) { cout << x; }
void _w(const int &x) { printf("%d", x); }
void _w(const int64_t &x) { printf("%lld", x); }
void _w(const double &x) { printf("%.16f", x); }
void _w(const char &x) { putchar(x); }
void _w(const char *x) { printf("%s", x); }
template<class t,class u> void _w(const pair<t,u> &x) {_w(x.f); putchar(' '); _w(x.s);}
void w() {}
template<class t, class... u> void w(const t &head, const u &... tail) { _w(head); putchar(sizeof...(tail) ? ' ' : '\n'); w(tail...); }
template<class t, class... u> void debug(const t &head, const u &... tail) {
#ifdef HOME
#endif
}


int main(){

    ll n;
    r(n);
    ll a=n/3;
    w(a);
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <iomanip>
#include <set>
#include <string>

#ifdef MY_LOCAL
  #define MY_NAMESPACE(n) namespace n {
  #define MY_NAMESPACE_   }
#else
  #define MY_NAMESPACE(n)
  #define MY_NAMESPACE_
#endif

//#ifdef MY_LOCAL
//namespace ABC168A {
//#endif
MY_NAMESPACE(ABC168A)

using namespace std;
int main()
{
	int n;
	cin >> n;

	string ans;
	switch (n % 10)
	{
	case 0:
	case 1:
	case 6:
	case 8:
		ans = "pon";
		break;
	case 2:
	case 4:
	case 5:
	case 7:
	case 9:
		ans = "hon";
		break;
	case 3:
		ans = "bon";
		break;
	}

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

MY_NAMESPACE_

Measured memory_bytes: 3596
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,Mod;
#define Maxn 5005
int ans[Maxn],a[Maxn];
int main(){
	scanf("%d%d",&n,&Mod);
	if(n&1){
		int k=(n-1)/2+1;
		for(int i=0;i<=k-2;++i)a[2+i]=i;
		for(int i=k-1,j=1;i>=1;--i,++j)a[k+j]=i;
	}else{
		int k=n/2;
		for(int i=0;i<=k-2;++i)a[2+i]=i;
		a[k+1]=k-1;
		for(int i=k-1,j=1;i>=1;--i,++j)a[k+1+j]=i;
	}
	for(int i=2;i<=n;++i)a[i]++;
	ans[0]=1;
	for(int i=2;i<=n;++i){
		for(int j=a[i];j<n;++j){
			ans[j]+=ans[j-a[i]];
			if(ans[j]>=Mod)ans[j]-=Mod;
		}
	}
	int Ans=0;
	for(int i=0;i<n;++i)Ans=(Ans+1ll*(n-i)*ans[i])%Mod;
	printf("%d\n",Ans);
	return 0;
} 

Measured memory_bytes: 768
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	s = readline() |> chomp
	f = parseInt(s[1:2])
	s = parseInt(s[3:4])
	fy = 0
	fm = 0
	sy = 0
	sm = 0
	if 0<=f
		fy = 1
		if 0<f<13
			fm = 1
		end
	end
	if 0<=s
		sy = 1
		if 0<s<13
			sm = 1
		end
	end
	if fy==0||sy==0
		println("NA")
	elseif fm==0&&sm==0
		println("NA")
	elseif fm==1&&sm==1
		println("AMBIGUOUS")
	elseif fm==1
		println("MMYY")
	else
		println("YYMM")
	end
end
main()


Measured memory_bytes: 166392
A,B,C,D,E=(int(input()) for i in range(5))
def m(x):
    if x%10==0:
        return x
    else:
        return((x//10)+1)*10
      
a=m(A)
b=m(B)
c=m(C)
d=m(D)
e=m(E)
aa=A+b+c+d+e
bb=a+B+c+d+e
cc=a+b+C+d+e
dd=a+b+c+D+e
ee=a+b+c+d+E
print(min(aa,bb,cc,dd,ee))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    string A="abcdefghijklmnopqrstuvwxyz";
    vector<char> ans;
    while(n>0){
        ans.push_back(A[(n+25)%26]);
        if(n%26==0) n--;
        n/=26;
    }
    per(i,ans.size()) cout<<ans[i];
}

Measured memory_bytes: 3672
#include <string.h>
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;
typedef long long unsigned int ll;

#define N 10+1
#define M 10+1

int main() {
    int n,m = 0;
    int k[M];
    int s[M][M] = {0};
    int q[M];
    int index;
    int ans;
    
    cin >> n >> m;

    for(int i = 0; i < m; i++){
        cin >> k[i];
        for(int j =0; j < k[i]; j++){
            cin >> index;
            s[i][index-1] = 1;
        }
    }

    for(int i = 0; i < m; i++){
        cin >> q[i];
    }

    
    for (int tmp = 0; tmp < (1 << n); tmp++) {
        bool true_f = true;
        bitset<N> bit(tmp);
        for(int i = 0; i < m;i++){
            int sum = 0;
            for(int j = 0; j < n;j++){
                if(bit[j]){
                    sum += s[i][j];
                }
            }
            true_f &= (sum % 2 == q[i]);
        }
        if (true_f){
            //cout << bit << endl;
            ans++;
        }
    }
    cout << ans << endl;

}



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

using namespace std;

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

const int MAX = 1e5+5;
const ll MOD = 1e9 + 7;

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

	#ifdef FSOCIETY
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#else
		#define endl "\n"
	#endif

    int n, k; cin >> n >> k;

    vector<ll> v(n);
    ll sum = 0, cur = 0;
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        if(i < k) cur += v[i];
        else if(v[i] > 0) sum += v[i];
    }
    ll ans = 0;
    for(int i = 0, j = k-1; j < n; i++, j++) {
        ans = max(ans, max(sum, sum + cur));
        if(j+1 < n) cur += v[j+1];
        cur -= v[i];
        if(v[i] > 0) sum += v[i];
        if(j+1 < n && v[j+1] > 0) sum -= v[j+1];
    }

    cout << ans << endl;


}


Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
using namespace std;

int n;
int c[100000];
vector<int> v, w;

int main(){
	while(1){
		scanf("%d", &n);
		if(n == 0) return 0;
		v = w;
		int t, s;
		scanf("%d", &t);
		if(t == 0){
			v.push_back(1);
		}else{
			v.push_back(0);
			v.push_back(1);
		}
		for(int i=0; i<n-1; ++i){
			scanf("%d", &s);
			if(t == s) ++v[v.size()-1];
			else{
				if(i % 2 == 0){
					if(v.size() == 1){
						v.push_back(v[0]);
						++v[1];
						v[0] = 0;
					}else{
						v[v.size()-2] += v[v.size()-1];
						++v[v.size()-2];
						v.pop_back();
					}
				}else{
					v.push_back(1);
				}
			}
			t = s;
/*			for(int j=0; j<v.size(); ++j){
				printf("%d\t", v[j]);
			}
			printf("\n");
*/		}

		int ans = 0;
		for(int i=0; i<v.size(); i++){
//			printf("%d\t", v[i]);
			if(i % 2 == 1) continue;
			ans += v[i];
		}
//		printf("\n");
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 2652
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N, M, K; cin >> N >> M >> K;
  vector<ll> A(N+1), B(M+1);
  A[0] = 0, B[0]=0;
  rep(i,N) cin >> A[i+1];
  rep(i,M) cin >> B[i+1];
  
  rep(i,N+1) if (i>0) A[i] += A[i-1];
  rep(i,M+1) if (i>0) B[i] += B[i-1];
  if (A[N]+B[M]<=K){
    cout << N+M << endl;
    return 0;
  }

  int retval = 0;
  rep(i,N+1){
    if (A[i]>K) continue;
    int idx = lower_bound(all(B),K-A[i]+1) - B.begin();
    retval = max(retval, i + idx -1);
  }
  cout << retval << endl;


  // cout << fixed << setprecision(10);
  
  return 0;
}


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

using namespace std;

int main()
{
    #ifdef DEBUG
    //freopen("input.txt", "r", stdin);
    #endif
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a = max(a, c);
    b = min(b, d);
    a = max(b - a, 0);
    cout << a;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

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

        List<Integer> list = new ArrayList<>();
        for(int i =0;i < n;i++){
            list.add(sc.nextInt());
        }
        Collections.sort(list);

        int min=Integer.MAX_VALUE;
        for(int i=0;i < n-k+1;i++){
            min = Math.min(min, list.get(i+k-1)-list.get(i));
        }
        System.out.println(min);

    }
}

Measured memory_bytes: 62260
N = int(input())
p = [int(pi) for pi in input().split()]

def swap(x, y):
    tmp = x
    x = y
    y = tmp
    return x, y

count = 0
for i in range(len(p) - 1):
    if p[i] == i + 1:
        p[i], p[i+1] = swap(p[i], p[i+1])
        count += 1
if p[N-1] == N:
    count += 1
print(count)

Measured memory_bytes: 13880
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int,int>;
using ll=long long;

int main() {
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vector<int> V(N,0);
  for (int i=1; i<N; i++) {
    if (S[i-1]=='A' && S[i]=='C') {
      V[i]=V[i-1]+1;
    }
    else {
      V[i]=V[i-1];
    }
    //cout << V[i]<< endl;
  }
  int l, r;
  for (int i=0; i<Q; i++) {
    cin >> l >> r;
    l--;
    r--;
    cout << V[r]-V[l] << endl;
  }
}

Measured memory_bytes: 3800
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std ;

#define MAXN 200007

int n ;
int a[ MAXN ] ;


void input ( ) {
    scanf ( "%d" , &n ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        scanf ( "%d" , &a[ i ] ) ;
        a[ i ] -= i ;
    }
    sort ( a + 1 , a + n + 1 ) ;
}

void solve ( ) {
    int i ;
    long long ans = 0 ;
    long long cursm = 0 ;
    long long lftsm = 0 ;
    for ( i = 1 ; i <= n ; i ++ ) {
        lftsm += a[ i ] ;
    }
    ans = ( 1LL * n * a[ n ] - lftsm ) ;
    for ( i = n ; i >= 1 ; i -- ) {
        cursm += a[ i ] ;
        lftsm -= a[ i ] ;
        long long aux = a[ i ] ;
        if ( i > 1 && 2 * i - n - 2 >= 0 ) { aux = a[ i - 1 ] ; }
        long long cur = ( 1LL * ( i - 1 ) * aux - lftsm ) + ( cursm - 1LL * ( n - i + 1 ) * aux ) ;
        if ( ans > cur ) { ans = cur ; }
    }
    printf ( "%lld\n" , ans ) ;
}

int main ( ) {
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <iomanip>
using namespace std;

typedef long long ll;
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define memset(v, h) memset((v), h, sizeof(v))
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using P = pair<ll, ll>;

ll m[20][20];

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

struct node
{
    public: ll x;
    public: ll y;

    node(ll xx, ll yy)
    {
        x = xx;
        y = yy;
    }
};

ll comb(int n, int r) {
  std::vector<std::vector<long long>> v(n + 1,std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v[n][r];
}

ll digit(ll num)
{
    if(num < 10)
    {
        return 1;
    }

    ll d = 1;
    ll k = 10;
    while(num >= k)
    {
        d++;
        k *= 10;
    }

    return d;
}

ll digitNum(ll num, ll count)
{
    ll a = (num % (ll) pow((double) 10, (double) count));
    return a / pow(10, count - 1);
}

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

    if(a == b && b == c)
    {
        cout << "No" << endl;
        return 0;
    }

    if(a == b || b == c || a == c)
    {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}

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

const int s=1001;

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	char tmp;
	int ans=700;

	for(int i=0;i<3;i++){
		cin >> tmp;
		if(tmp=='o') ans += 100; 
	}

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

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
kar = max(a)
a.remove(kar)
mid = kar//2
tyu = 10**10
if kar % 2 == 0:
    for i in range(n-1):
        if tyu > abs(mid-a[i]):
            tyu = abs(mid-a[i])
            ans = a[i]
elif kar % 2 == 1:
    for i in range(n-1):
        if tyu > min(abs(mid-a[i]),abs(mid+1-a[i])):
            tyu = min(abs(mid-a[i]),abs(mid+1-a[i]))
            ans = a[i]
print(str(kar) + " " + str(ans))

Measured memory_bytes: 14052
from itertools import permutations
n, m = map(int,input().split())
dist =[[0 for i in range(n)] for j in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    dist[a][b] = 1
    dist[b][a] = 1
ans = 0
for p in permutations([i for i in range(1,n)]):
    t = True
    for i in range(n-2):
        if i == 0:
            if dist[0][p[0]] == 0:
                t = False
                break
        if dist[p[i]][p[i+1]] == 0:
            t = False
            break
    if t:
        ans += 1
        #print(p)

print(ans)

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 8;
vector<int> e[N];
int n, m, f, t, ans;
int dp[1 << N][N];

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> f >> t;
        e[f - 1].push_back(t - 1);
        e[t - 1].push_back(f - 1);
    }
    dp[1][0] = 1;
    for (int i = 0; i < (1 << n); ++i) {
        for (int j = 0; j < n; ++j) {
            if (dp[i][j] != 0) {
                for (int k : e[j]) {
                    if (!(i & (1 << k))) {
                        dp[i ^ (1 << k)][k] += dp[i][j];
                    }
                }
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        ans += dp[(1 << n) - 1][i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600