akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) (v).begin() (v).end()
#define m 998244353
#define pb push_back
#define sz(v) (v).size()
#define ll long long

int main()
{
        ll n;
        cin>>n;
        ll ans=-1;
        ll a[n+1],b[n+1],c[n+1];
        for(int i=0;i<n;i++)
                cin>>a[i];
        if(n==1)
                {cout<<a[0]; return 0;}
        
                b[0]=a[0];
                c[n-1]=a[n-1];
        for(int i=1;i<n;i++)
        {
                b[i]=max(a[i],b[i-1]);
        }
        for(int i=n-2;i>=0;i--)
        c[i]=max(a[i],c[i+1]);

        cout<<c[1]<<"\n";
        for(int i=1;i+1<n;i++)
        {
              
                cout<<max({b[i-1],c[i+1]})<<"\n";

        }
        cout<<b[n-2]<<"\n";
}





Measured memory_bytes: 6272
import heapq

n = int(input())
v = map(int, input().split(' '))

h = []
for value in v:
  heapq.heappush(h, value)

for i in range(n-1):
  v1 = heapq.heappop(h)
  v2 = heapq.heappop(h)
  mixed = (v1 + v2) / 2
  heapq.heappush(h, mixed)

print(h[0])

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int , int>
#define fast ios_base::sync_with_stdio(0)
#define mx 402
ll dp[mx][mx], arr[mx], sum[mx];
ll fun(int b, int e)
{
    if(b==e) return 0;
    if(b+1 == e) return arr[b] + arr[e];
    ll& ret = dp[b][e];
    if(ret!=-1) return ret;
    ret = 1000000000000000LL;
    for(int i=b; i<e; i++){
        ret = min(ret, fun(b,i) + fun(i+1,e));
    }
    ret+=(sum[e] - sum[b-1]);
    return ret;
}
int main()
{
    fast;
    int n;
    cin>>n;
    sum[0] = 0;
    for(int i=1; i<=n; i++){
        cin>>arr[i];
        sum[i] = sum[i-1] + arr[i];
    }
    memset(dp, -1, sizeof dp);
    cout<<fun(1,n)<<endl;
}



Measured memory_bytes: 1536
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ON			1										// 汎用フラグ - ON
#define D_OFF			0										// 汎用フラグ - OFF
#define D_MASS_MAX		52										// 最大マス数
#define D_MOD			1000000007								// 剰余

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// マス数取得
	int liMCnt;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &liMCnt);

	// マス内容取得
	char lc1Mass[D_MASS_MAX + 5];
#ifdef D_TEST
	fgets(lc1Mass, sizeof(lc1Mass), szpFpT);
#else
	fgets(lc1Mass, sizeof(lc1Mass), stdin);
#endif

	// １文字目
	long long llPCnt;
	int liNo, liX;
	if (lc1Mass[0] == lc1Mass[1]) {			// 次と一致(横)
		llPCnt = 6;								// パターン数
		liNo = 2;								// 開始位置
		liX = D_ON;								// 横
	}
	else {									// 次と不一致(縦)
		llPCnt = 3;								// パターン数
		liNo = 1;								// 開始位置
		liX = D_OFF;							// 縦
	}

	// ２文字目以降
	for (i = liNo; i < liMCnt; i++) {
		if (lc1Mass[i] == lc1Mass[i + 1]) {		// 次と一致(横)
			if (liX == D_ON) {						// 前回横
				llPCnt = llPCnt * 3 % D_MOD;			// パターン数
			}
			else {									// 前回縦
				llPCnt = llPCnt * 2 % D_MOD;			// パターン数
			}
			liX = D_ON;								// 横
			i++;									// １つ次へ
		}
		else {									// 次と不一致(縦)
			if (liX == D_OFF) {						// 前回縦
				llPCnt = llPCnt * 2 % D_MOD;			// パターン数
			}
			liX = D_OFF;							// 縦
		}
	}

	// 結果セット
	sprintf(lc1Out, "%lld\n", llPCnt);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
def gcd(a,b):
    if a==0 :return b
    else : return gcd(b%a,a)

A,B=map(int,input().split())
p=set([1])
g=gcd(A,B)
for d in range(2,g):
    while g%d==0:
        p.add(d)
        g//=d
    if (d*d>=g): break
if g>=2:
    p.add(g)
print(len(p))


Measured memory_bytes: 9192
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

void pr(string s) {
    cout << s << endl;
    exit(0);
}

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

    int N;
    cin >> N;
    vi a(N);
    int mi = INT_MAX, ma = -1;
    rep(i, N) {
        cin >> a[i];
        smin(mi, a[i]);
        smax(ma, a[i]);
    }
    if (mi + 1 < ma)pr("No");

    int x = 0, y = 0;
    rep(i, N) {
        if (a[i] == mi)x++;
        if (a[i] == ma)y++;
    }

    if (mi == ma) {
        if (mi == N - 1)pr("Yes");
        if (N >= 2 * ma)pr("Yes");
    } else {
        if (y < 2)pr("No");
        int lb = x + !!max(0, y - x);
        int ub = x + y/2;
        if (lb <= ma&&ma <= ub)pr("Yes");
    }

    pr("No");
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < 5; i++) {
            int tmp = sc.nextInt();
            if (tmp < min) {
                min = tmp;
            }
            if (tmp > max) {
                max = tmp;
            }
        }
        int k = sc.nextInt();
        sc.close();

        if (max - min > k) {
            System.out.println(":(");
        } else {
            System.out.println("Yay!");
        }
    }

}


Measured memory_bytes: 23636
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
a,b,c = LI()
print(min(b//a,c))
"""

#B
"""
a,b,k = LI()
i = 1
ans = [1]
while i <= min(a,b):
    i += 1
    if a%i == 0 and b%i == 0:
        ans.append(i)
print(ans[-k])
"""

#C
"""
s = S()
n = len(s)
while len(s)>1:
    i = 0
    f = True
    while s[i] == s[i+1]:
        if i+1 == len(s)-1:
            f = False
            break
        i += 1
    if not f:break
    s.pop(i)
    s.pop(i)
print(n-len(s))
"""

#D
def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])
    return par[x]
def unite(x,y):
    x = root(x)
    y = root(y)
    if x == y:
        ans.append(ans[-1])
        return
    sx = s[x]
    sy = s[y]
    if rank[x] < rank[y]:
        par[x] = y
        s[y] += s[x]
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1
        s[x] += s[y]
    ans.append(ans[-1]+sx*sy)
n,m  = LI()
v = LIR(m)
v = v[::-1]
par = [i for i in range(n)]
rank = [0 for i in range(n)]
s = [1 for i in range(n)]
k=n*(n-1)//2
ans = [0]
v.pop(-1)
for a,b in v:
    if ans[0]==k:
        ans.append(k)
        continue
    a -= 1
    b -= 1
    unite(a,b)
for i in ans[::-1]:
    print(k-i)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


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

using namespace std;

typedef pair<int, int> P;

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> v;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v.emplace_back(b, a);
  }
  sort(v.begin(), v.end());
  int ans = 0, cur = 0;
  for (int i = 0; i < m; i++) {
    int b = v[i].first;
    int a = v[i].second;
    if (cur < a) {
      ans++;
      cur = b - 1;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main()
{
	int n;
	int a[201];
	cin >> n;
	REP(i, 0, n) cin >> a[i];

	int cnt = 0;
	bool flag = true;
	while (flag) {
		REP(i, 0, n) {
			if (a[i] % 2 != 0) {
				flag = false;
				break;
			}
			a[i] /= 2;
		}
		if (flag) cnt++;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"io"
	"os"

	"fmt"
)

func dpow(x int) int {
	if x == 0 {
		return 1
	}

	if x == 1 {
		return 100
	}

	return 10000
}

func Solve(in io.Reader, out io.Writer) {
	var d, n int
	fmt.Fscan(in, &d, &n)

	dx := dpow(d)
	if n != 100 {
		fmt.Fprintln(out, dx*n)
	} else {
		fmt.Fprintln(out, dx*(n+1))
	}
}

func main() {
	Solve(os.Stdin, os.Stdout)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//数字の入力
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		int[] A = new int[N];
		int maxA = A[0];
		for (int i = 0; i < N; i++) {
			A[i] = Integer.parseInt(sc.next());
			if (A[i] > maxA) {
				maxA = A[i];
			}
		}
		//K回のカットですべてを長さXにできるか？
		//二分探索
		int x = maxA;//初期値最大値
		int y = 0;//初期値0
		int mid = 0;
		while (x - y > 1) {
			mid = (x + y) / 2;//中間値
			//
			double sumCn = 0;//回数の合計
			for (int i = 0; i < N; i++) {
				sumCn += (int)Math.ceil((double) A[i] / mid) - 1;
			}
			//xとyを更新
			if(sumCn<=K) {
				x = mid;
			}else {
				y = mid;
			}
		}
		System.out.println(x);

	}

}


Measured memory_bytes: 60168
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> dp(n + 1, n);
    dp.at(0) = 0;
    dp.at(1) = 1;
    for(int i = 2; i <= n; ++i){
        dp.at(i) = dp.at(i - 1) + 1;
        for(ll j = 6; j <= i; j *= 6){
            dp.at(i) = min(dp.at(i), 1 + dp.at(i - j));
        }
        for(ll j = 9; j <= i; j *= 9){
            dp.at(i) = min(dp.at(i), 1 + dp.at(i - j));
        }
    }
    cout << dp.at(n) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//型名省略
typedef long long ll;
typedef vector<long long> vl;
typedef vector<vector<long long>> vvl;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
//定数
const ll MOD = 1e9+7;
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rep2(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define all(A) A.begin(), A.end()
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}


//main関数
int main() {
    ll h, w; cin >> h >> w;
    ll ch, cw, dh, dw; cin >> ch >> cw >> dh >> dw;
    ch--;cw--;dh--;dw--;
    vvc map(h, vc(w));
    rep(i,h){
        rep(j,w){
            cin >> map[i][j];
        }
    }

    vvl count(h,vl(w,1e9)); //必要な魔法の回数
    count[ch][cw] = 0;

    queue<ll> h1,w1,h2,w2;
    h1.push(ch);
    w1.push(cw);

    vl dy = {1,0,-1,0};
    vl dx = {0,1,0,-1};

    while(!h1.empty()){
        while(!h1.empty()){
            ll nowh = h1.front(), noww = w1.front();
            h1.pop();
            w1.pop();

            //移動A
            rep(i,4){
                ll toh = nowh + dy[i], tow = noww + dx[i];
                if(toh < 0 || toh >= h || tow < 0 || tow >= w) continue;
                if(count[toh][tow] > count[nowh][noww] && map[toh][tow] == '.'){
                    count[toh][tow] = count[nowh][noww];
                    h1.push(toh);
                    w1.push(tow);
                }
            }

            //移動B
            rep2(i,-2,3){
                rep2(j,-2,3){
                    ll toh = nowh + i, tow = noww + j;
                    if(toh < 0 || toh >= h || tow < 0 || tow >= w) continue;
                    if(count[toh][tow] > count[nowh][noww] + 1 && map[toh][tow] == '.'){
                        count[toh][tow] = count[nowh][noww] + 1;
                        h2.push(toh);
                        w2.push(tow);
                    }
                }
            }
        }

        swap(h1,h2);
        swap(w1,w2);
    }

    if(count[dh][dw] == 1e9) count[dh][dw] = -1;
    cout << count[dh][dw] << endl;

}

Measured memory_bytes: 12492
#include <iostream>
using namespace std;
int main(void){
int N,L;
cin >> N >> L;

int sumALL = 0;

sumALL = 0.5*(2*L+N-1)*N;

int min=10000;
int minNUM = 1000;

for (int n=1;n<N+1;n++) {
if (min>abs(L+n-1)) {
    min = abs(L+n-1);
    minNUM = n;

}
}


cout << sumALL-(L+minNUM-1) << endl;

}


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

using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int k;
	string s;
	cin >> k >> s;
	
	if (k >= s.size())
		cout << s << endl;
	else {
		for (int i = 0; i < k; i++)
			cout << s[i];
		cout << "..." << endl;
	}
		
	

}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using Graph = vector< vector<int> >;

int main(){
	int h1,h2,m1,m2,k;
	cin >> h1 >> m1 >> h2 >> m2 >> k; 
	int h,m,t;
	h = h2-h1;
	m = m2-m1;
	t = h*60+m;
	cout << t - k << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
 
int main(){
    int countTable[256] = {0};
    char ch;
 
    while((ch = getchar()) != EOF){
                countTable[ch]++;
    }
    for(int i = 97; i <=122;i++)printf("%c : %d\n",i,countTable[i]+countTable[i-32]);
}


Measured memory_bytes: 2616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int mod = 1e9 + 7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1 ;
	//cin >> t;
	while(t--){
		int row,col;
		cin >> row >> col;
		char grid[row][col];
		for(int i = 0; i < row; i++)
			for(int j = 0; j < col; j++)
				cin >> grid[i][j];
		int dp[row+1][col+1];
		for(int i = 0; i <= row;i++)
			for(int j = 0; j<= col ; j++)
				dp[i][j] = 0;
		dp[0][1] = 1;
		for(int i = 1; i <= row; i++)
			for(int j = 1; j<= col; j++)
				if(grid[i-1][j-1] != '#')
					dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
				else dp[i][j] = 0;
		cout << dp[row][col] << endl;
	}
	return 0;
}


Measured memory_bytes: 8424
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 

int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n;cin>>n;
  int tmp=n;
  int s=0;
  while(tmp>0){
    s+=tmp%10;
    tmp/=10;
  }
  string ans="No";
  if(n%s==0)ans="Yes";
  cout(ans);
  return 0;
}

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

function main()
	a = readline() |> parseInt
	b = readline() |> parseInt
	if 1!=a&&1!=b
		println(1)
	elseif 2!=a&&2!=b
		println(2)
	else
		println(3)
	end
end

main()

Measured memory_bytes: 167544
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define ALL(v) v.begin(), v.end()

int main() {
	int R, G, B, N;
	cin >> R >> G >> B >> N;
	int ans = 0;
	for (int i = 0; i <= 3000; i++) {
		for (int j = 0; j <= 3000; j++) {
			if (R*i + G * j > N) break;
			if ((N - (R*i + G * j)) % B == 0) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}


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

int a, b;

int main() {
  cin >> a >> b;
  if(a >= 13)
    cout << b << endl;
  else if(a >= 6)
    cout << b / 2 << endl;
  else
    cout << 0 << endl;
  return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int>p(n);
    
    for(int i=0;i<n;i++){
        cin>>p.at(i);
    }
    int count=0;
    for(int i=1;i<n-1;i++){
        if(p.at(i-1)<p.at(i) && p.at(i)<p.at(i+1)){
            count+=1;

        }
        else if(p.at(i+1)<p.at(i) && p.at(i)<p.at(i-1)){
            count+=1;
        }
        else{
            int unko=0;
        }
    }
    cout<<count<<endl;
}

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

int main() {
  int a, b, c;
  while( cin >> a >> b >> c, a+b+c ) {
    int n;
    int sum = a+b+c+1;
    int data[sum];
    for(int i=1; i<sum; i++) data[i] = 2;
    cin >> n;
    vector<int> i_, j_, k_;

    for(int x=0; x<n; x++) {
      int i, j, k, r;
      cin >> i >> j >> k >> r;
      if( r ) {
	data[i] = data[j] = data[k] = 1;
      }
      else {
	i_.pb(i); j_.pb(j); k_.pb(k);
      }
    }

    for(int x=0; x<i_.size(); x++) {
      int i = i_[x], j = j_[x], k = k_[x];
      if( data[i] == 1 && data[j] == 1 ) {
	data[k] = 0;
      }
      if( data[j] == 1 && data[k] == 1 ) {
	data[i] = 0;
      }
      if( data[k] == 1 && data[i] == 1 ) {
	data[j] = 0;
      }
    }

    for(int i=1; i<sum; i++) {
      cout << data[i] << endl;
    }
  }
} 

Measured memory_bytes: 1236
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

ll mod=1e9+7;
ll fac[210];

void modfac(ll n){
    fac[0]=1;
    for(ll i=1;i<n;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
}

ll modinv(ll a){
    ll b=mod,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b; swap(a,b);
        u-=t*v; swap(u,v);
        }
        u%=mod;
        if(u<0) u+=mod;
    return u;
}

ll dp[210][100010];

int main(){
  ll n,x;
  cin >> n >> x;
  ll a[n];
  for(ll i=0;i<n;i++) cin >> a[i];
  sort(a,a+n);
  reverse(a,a+n);
  ll inv[n+1];
  for(ll i=1;i<=n;i++) inv[i]=modinv(i);
  for(ll i=0;i<=x;i++) dp[n][i]=i;
  for(ll i=n-1;i>=0;i--){
    for(ll j=0;j<=x;j++){
      ll p=n-i;
      dp[i][j]=inv[p]*(dp[i+1][j%a[i]]+(p-1)*dp[i+1][j]%mod)%mod;
    }
  }
  modfac(210);
  cout << dp[0][x]*fac[n]%mod << endl;
}

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

map <int,int> mp;
int main(){
    int ans;
    int n;
    cin>>n;
    int a[100001];
    int x;
    rep(i,n){
        cin>>x;
        mp[x]=i+1;
    }
    for( auto i = mp.begin(); i != mp.end() ; ++i ) {
      cout<<i->second <<" ";
  }cout<<endl;
    
    
    return 0;
}

Measured memory_bytes: 5504
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	p := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		p[i], _ = strconv.Atoi(sc.Text())
	}

	min := n
	count := 0
	for i := 0; i < n; i++ {
		if min >= p[i] {
			count++
			min = p[i]
		}
	}
	fmt.Println(count)
}


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

int main() {
  vector<int64_t> L(100);
  L.at(0) = 2;
  L.at(1) = 1;
  for(int i = 2; i < 99; i++)
    L.at(i) = L.at(i-2) + L.at(i-1);
  int j;
  cin >> j;
  cout << L.at(j) <<endl;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ii, null_type,less<ii>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>
#define Mod 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define T int t;cin>>t;rep(i,t)

void solve() {

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = 0;
	if (d > a) {
		ans += a;
		d -= a;
	}
	else{
		ans += d;
		d = 0;
	}
	
	if (d > b)
		d -= b;
	else
		d = 0;
		
	if (d > 0)
		ans -= d;
		
	cout << ans;
		
}

int main()
{
    fastio;
//    T
    solve();
	//code
	return 0;
}


Measured memory_bytes: 3652
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  if(n==1) {
    cout << 1 << endl;
  }
  else {
    ll ans,l[100]={};
    l[0]=2,l[1]=1;
    for(int i=2; i<=n; i++) {
      l[i]=l[i-1]+l[i-2];
    }
    cout << l[n] << endl;
  }
}

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

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

	map<string, int> mp;
	mp["SUN"]=7;
	mp["MON"]=6;
	mp["TUE"] =5;
	mp["WED"] = 4;
	mp["THU"] = 3;
	mp["FRI"] = 2;
	mp["SAT"] = 1;
	
	cout << mp[s]; 	  
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed  main()
{
  int a,b,c=1,d=0;
  cin>>a>>b;
  while(1){
    if(c>=b){
      break;
    }else{
      c=c-1+a;
      d++;
    }
  }
  cout<<d<<"\n";
}


Measured memory_bytes: 256
/* kop Chy_Chy*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll , ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define si(x)   scanf("%d", &x)
#define sl(x)   scanf("%lld", &x)
#define pi(x)   printf("%d\n", x)
#define pl(x)   printf("%lld\n", x)
#define deb(x)  cout<< #x << " = " << x << endl // debugging kop 
#define mp      make_pair
#define pb      push_back
#define MOD     1000000007
#define PI      acos(-1)
#define ff      first
#define ss      second
#define newline printf("\n")
ll binpow(ll a, ll b); // binary exponentiation kop
void prime_factorization(ll n, vll &prime_factors); // prime factorization kop
ll gcd(ll a, ll b); // greatest common divisor kop. Use LONG LONG
void speedup() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

int main(){
    speedup();
    int t = 1;
    // cin>> t;
    while(t--){
        // khela final Mamooo
        string s,t; cin>> s >> t;
        int n = s.size();
        int cnt = 0;
        for(int i = 0; i < n; i++){
            if(s[i] != t[i]){
                cnt++;
            }
        }
        cout<< cnt << "\n";
        
        
    }
    // kop kop return 
    return 0;
}


// kop kop functions:
ll binpow(ll a, ll b){
    ll res = 1;
    while(b > 0){
        if(b & 1) res *= a;
        a = a* a;b = b >> 1;}
    return res;
}
/*---------------------------------------------------------------------------------------------------------------*/
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a%b);
}
/*---------------------------------------------------------------------------------------------------------------*/
void prime_factorization(ll n, vll &prime_factors){
    // first two step taking care of composite number
    // taking care of 2
    while(n%2 == 0){
        prime_factors.pb(2);
        n = n / 2;
    }
    // now n must be odd. And the remaining prime divisors are odd. so we start from 3 and increamenting 2
    for(ll i = 3; i <= sqrt(n); i = i + 2){
        while(n%i == 0){
            prime_factors.pb(i);
            n = n / i;
        }
    }
    // now we are taking care of  n is prime number and greater than 2
    if(n > 2){
        prime_factors.pb(n);
    }
}
/*---------------------------------------------------------------------------------------------------------------*/














Measured memory_bytes: 3776
n,k=map(int,input().split())
p=list(map(int,input().split()))

e=[0]*n

for i in range(n):
  e[i]=(1+p[i])/2
  if i!=0:
    e[i]+=e[i-1]

arr=[]

if n==k:
  print(e[-1])
  exit()

for i in range(k,n):
  s=i-k
  arr.append(e[i]-e[s])

print(max(arr))

Measured memory_bytes: 80008
n = int(input())
P = list(map(int, input().split()))

ans = 0
for i in range(1, n - 1):
    if P[i - 1] < P[i] < P[i + 1] or P[i + 1] < P[i] < P[i - 1]:
        ans += 1
print(ans)

Measured memory_bytes: 40460
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

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

#define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << " "
#define dumpL(x) cout << #x << " : " << x << '\n'
#define LINE cout << "line : " << __LINE__ << " "
#define LINEL cout << "line : " << __LINE__ << '\n'
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " "
#define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) 
#define dumpL(x) 
#define LINE 
#define LINEL 
#define dumpV(v) 
#define dumpVL(v) 
#define STOP assert(false)
#endif
#define mp make_pair
 
namespace std {
template<class S, class T>
ostream &operator <<(ostream& out, const pair<S, T>& a) {
    out << '(' << a.fi << ", " << a.se << ')';
    return out;
}
}

int main(){
    int n;
    string s;
    cin >> n >> s;
    ll ans = 0;
    vector<set<int>> st(3);
    rep(i, n) {
        int x = s[i] - '0';
        repr(i, 2) {
            for(auto&& a: st[i]) st[i+1].insert(a*10+x);
        }
        st[0].insert(x);
    }
    cout << st[2].size() << endl;
    // dumpVL(st[2]);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int bubbleSort(int a[], int n)
{
	bool flag = true;
	int count = 0;
	for (int i = 0; i < n - 1 && flag; i++) {
		flag = false;
		for (int j = n - 1; j > i; j--) {
			if (a[j - 1] > a[j]) {
				swap(a[j - 1], a[j]);
				flag = true;
				count++;
			}
		}
	}
	return count;
}


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

	int A[100];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int count;
	count = bubbleSort(A, N);

	for (int k = 0; k < N; k++) {
		if (k > 0) cout << ' ';
		cout << A[k];
	}
	cout << '\n' << count << endl;

	return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,D;
  cin >> N >> D;
  
  int a=2*D+1;
  int b=N%a;
  
  if(b==0){
  cout << N/a << endl;
  }else{
    cout << ((N-b)/a)+1 << endl;
  }
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
 
const int MAXN=4e5+5;
 
int R,C,n;
 
int seq[MAXN];
inline int getp(int r,int c)
{
	if(!r) return c;
	if(c==C) return C+r;
	if(r==R) return C+R+C-c;
	if(!c) return C+R+C+R-r;
	return -1;
}
 
std::map<int,int> mp;
int st[MAXN],tp;
inline bool jud()
{
	for(std::map<int,int>::iterator i=mp.begin();i!=mp.end();i++) if(i->second)
		i->second^st[tp]?st[++tp]=i->second:tp--;
	return !tp;
}
 
int main()
{
	int i;scanf("%d%d%d",&R,&C,&n);
	for(i=1;i<=n;i++)
	{
		int x1,y1,x2,y2;scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		int p1=getp(x1,y1),p2=getp(x2,y2);
		if(~p1&&~p2) mp[p1]=mp[p2]=i;
	}
	puts(jud()?"YES":"NO");
	return 0;
}

Measured memory_bytes: 9984
N, K = map(int, input().split())
ls = []
for i in range(N):
  x, y = map(int, input().split())
  ls += [(x,y)]
m = -1
for i in range(N):
  for j in range(i+1,N):
    for p in range(N):
      for q in range(p+1,N):
        
        x1, y1 = ls[i]
        x2, y2 = ls[j]
        x3, y3 = ls[p]
        x4, y4 = ls[q]
        cnt = 0
        flag = False
        X1 = min(x1, x2)
        X2 = max(x1, x2)
        Y1 = min(y3, y4)
        Y2 = max(y3, y4)
        for a in range(N):
          x, y = ls[a]
          """
          print('"""""""')
          print(cnt)
          print(X1,X2,x)
          print(Y1,Y2,y)
          """
          if X1<=x<=X2 and Y1<=y<=Y2:
            cnt += 1
          if cnt>=K:
            n = (X2-X1)*(Y2-Y1)
            if m==-1 or n<m:
              m = n
            break
print(m)

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


def main():
    n = int(input())
    p = list(map(int, input().split()))
    value_min = float('inf')
    ans = 0

    for pi in p:
        if value_min > pi:
            ans += 1
            value_min = pi

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24744
N,A,B = map(int, input().split())

#print(N,A,B)
if A>B:
  print(0)
elif (N==1 and A!=B):
  print(0)
elif (N==1 and A==B):
    print(1)
else:
  print((B-A)*(N-2)+1)
  
  

            
 
        

Measured memory_bytes: 2940
N = gets.chomp.to_i
ss = []
N.times do
  ss << gets.chomp
end
M = gets.chomp.to_i
ts = []
M.times do
  ts << gets.chomp
end

max = -1000
count = 0
ss.each_with_index do |s, i|
  count = 1
  ss[(i+1)..(ss.size - 1)].each do |s2|
    count +=1 if s2 == s
  end
  ts.each do |t|
    count -= 1 if t == s
  end
  max = count if count > max
end
puts [max, 0].max


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

using namespace std;

struct edge {
    int to;
    int cost;
    edge(int a, int b) : to(a), cost(b) {}
};

vector<vector<edge>> e;
int N;

pair<int, int> dfs(int p, int par = -1)
{
    pair<int, int> res = make_pair(0, p);
    for (auto x : e[p]) {
        if (x.to == par) continue;
        auto t = dfs(x.to, p);
        t.first += x.cost;
        res = max(res, t);
    }
    return res;
}

int main()
{
    cin >> N;
    e.resize(N);
    for (int i = 0; i < N-1; i++) {
        int s, t, w;
        cin >> s >> t >> w;
        e[s].emplace_back(t, w);
        e[t].emplace_back(s, w);
    }
    auto res = dfs(0);
    res = dfs(res.second);
    cout << res.first << endl;
}


Measured memory_bytes: 15900
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<random>
#define rep(N) for (int i = 0; i < N; ++i)
#define For(i, N) for (i = 0; i < N; ++i)
#define rev(N) 	for (int i = N - 1; i >= 0; --i)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;

template<typename T>
void say(T s) {
	cout << s << endl;
}

template<typename T1, typename T2>
void say(T1 s1, T2 s2) {
	cout << s1 << " " << s2 << endl;
}

int main() {
	int a, b;
	int ans;
	cin >> a >> b;
	if (b / 100 > 0)ans = 1000 * a + b;
	else if (b / 10 > 0)ans = 100 * a + b;
	else ans = 10 * a + b;
	int i = 0;
	while (++i*i <= ans)if (i*i == ans) {
		say("Yes");
		re;
	}
	say("No");
}

Measured memory_bytes: 256
import numpy as np

def main():
    K, _ = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    # 最後の家と最初の家の距離
    A.append(K+A[0])
    X = np.diff(np.array(A))
    print(X.sum() - X.max())

if __name__ == "__main__":
    main()


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

using namespace std;

int main() {
#ifdef LOCAL_PROJECT
  freopen("Test0.in", "r", stdin);

  cout << "\033[2J\033[1;1H";
#endif
  long double H, A;
  cin >> H >> A;
  cout << ceil(H / A) << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author varunvats32
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FEncloseAll solver = new FEncloseAll();
        solver.solve(1, in, out);
        out.close();
    }

    static class FEncloseAll {
        static int n;
        static int[] x;
        static int[] y;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            n = in.nextInt();
            x = new int[n];
            y = new int[n];

            for (int i = 0; i < n; i++) {
                x[i] = in.nextInt();
                y[i] = in.nextInt();
            }

            double l = 0, r = 1000;
            for (int i = 1; i <= 80; i++) {
                double m1 = l + (r - l) / 3;
                double m2 = r - (r - l) / 3;
                if (g(m1) > g(m2))
                    l = m1;
                else r = m2;
            }

            double ans = g(l);
            out.printf("%.10f\n", ans);
        }

        double g(double x) {
            double l = 0, r = 1000;
            for (int i = 1; i <= 80; i++) {
                double m1 = l + (r - l) / 3;
                double m2 = r - (r - l) / 3;
                if (f(x, m1) > f(x, m2))
                    l = m1;
                else r = m2;
            }

            return f(x, l);
        }

        double f(double x1, double y1) {
            double res = 0;
            for (int i = 0; i < n; i++) {
                res = Math.max(res, dist(x[i], y[i], x1, y1));
            }
            return res;
        }

        double dist(double x1, double y1, double x2, double y2) {
            double dx = x1 - x2;
            double dy = y1 - y2;

            return Math.sqrt(dx * dx + dy * dy);
        }

    }
}



Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main ()
{
    int a,b;
    int m,n,j,k;
    cin>>a>>b;
    m=a+(a-1);
    n=b+(b-1);
    k=a+b;
    if( m>n && m>k)
        cout<<m<<endl;
    else if (n>m &&n>k)
        cout<<n<<endl;
    else
        cout<<k<<endl;
    return 0;
}






Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int K,S;
  cin >> K >> S;

  ll cnt = 0;
  REP(i,K+1){
    REP(j,K+1){
      if(i+j<=S&&S-i-j<=K){
        cnt++;
      }
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val num = io.StdIn.readInt
    val str = io.StdIn.readLine
    var count = 0

    (0 until num - 2).foreach { i =>
      if(str(i) == 'A') {
        if(str(i + 1) == 'B' && str(i + 2) == 'C') count += 1
      }
    }
    println(count)
  }
}

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

int main(){
    ll n,ans;
    cin >> n;
    vector<ll> p(n);
    rep(i,n) cin >> p[i];
    ll minimum = 1e9;
    rep(i,n){
        if(minimum > p[i]){
            ans++;
            minimum = p[i];
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

// MainT1P2018C
public class Main {

    private static boolean isOdd(int val) {
        return ((val & 1) != 0);
    }

    public static void main(String[] args) {
        try (
                Scanner in = new Scanner(System.in);
                PrintWriter out = new PrintWriter(System.out))
        {
            final int N = in.nextInt();
            final int[] A = new int[N];
            Arrays.setAll(A, i -> Integer.parseInt(in.next()));

            final int halfN = N / 2;
            long result = 0L;
            Arrays.sort(A);
            if (isOdd(N)) {

                long r1 = 0L;
                r1 -= 2 * Arrays.stream(A, 0, halfN).asLongStream().sum();
                r1 += 2 * Arrays.stream(A, halfN, N).asLongStream().sum();
                r1 -= A[halfN];
                r1 -= A[halfN + 1];

                long r2 = 0L;
                r2 -= 2 * Arrays.stream(A, 0, halfN + 1).asLongStream().sum();
                r2 += 2 * Arrays.stream(A, halfN + 1, N).asLongStream().sum();
                r2 += A[halfN - 1];
                r2 += A[halfN];

                result = Math.max(r1, r2);

            } else {
                result -= 2 * Arrays.stream(A, 0, halfN).asLongStream().sum();
                result += 2 * Arrays.stream(A, halfN, N).asLongStream().sum();
                result += A[halfN - 1];
                result -= A[halfN];
            }
            out.println(result);
        }
    }
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main()
{
    int32 n;
    cin >> n;
    vector<int64> a(n);
    bool zero = false;
    int32 minusCnt = 0;
    REP(i,n){
        cin >> a[i];
        if(a[i] == 0)zero = true;
        if(a[i] < 0){
            minusCnt++;
            a[i] *= -1;
        }
    }
    int64 ans = 0;
    if(zero || minusCnt % 2 == 0){
        REP(i,n)ans += a[i];
    }else{
        sort(ALL(a));
        ans -= a[0];
        FOR(i,1,n)ans += a[i];
    }
    ANS(ans);
    return 0;
}

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

N = int(input())
vvv = list(map(int, input().split()))

if len(set(vvv)) == 1:
    print(N // 2)
    exit()

vvv_odd = vvv[::2]
vvv_even = vvv[1::2]

dp_odd = [0] * max(vvv_odd)
dp_even = [0] * max(vvv_even)

for v_odd, v_even in zip(vvv_odd, vvv_even):
    dp_odd[v_odd - 1] += 1
    dp_even[v_even - 1] += 1

max_appear_odd = max(dp_odd)
max_appear_even = max(dp_even)

max_odd_val = dp_odd.index(max_appear_odd) + 1
max_even_val = dp_even.index(max_appear_even) + 1

if max_odd_val == max_even_val:
    next_appear_odd = sorted(dp_odd, reverse=True)[1]
    next_appear_even = sorted(dp_even, reverse=True)[1]
    if next_appear_odd > next_appear_even:
        max_appear_odd = next_appear_odd
    else:
        max_appear_even = next_appear_even

n_replace = N // 2 - max_appear_odd
n_replace += N // 2 - max_appear_even

print(n_replace)


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

int main(){
	string s;
	cin >> s;
	int i;
	for(i=0;i<3;i++){
		if(s.at(i)=='7'){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	
}

Measured memory_bytes: 3624
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
 char s[1002];
 scanf("%s",s);
 for(int i=0;i<strlen(s);i++){
 if(s[i]<='C') s[i]+=26;
 printf("%c",s[i]-3);
}
printf("\n");
}

Measured memory_bytes: 932
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define SIZE 200010
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define print(x) for(auto el: x) cout<<el<<" ";cout<<endl
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<int,vector<int>,greater<int> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define mitr map<int,int>:: iterator
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
const int N=30;
vi adj[N];

int32_t main()
{
    fast;
    string s,t;cin>>s>>t;
    int n=s.size();
    int m=t.size();
    for(int i=0;i<n;i++)
        adj[s[i]-'a'].pb(i);

    for(int i=0;i<m;i++)
    {
        if(adj[t[i]-'a'].size()==0)
        {
            cout<<-1;
            return 0;
        }
    }

    int complete_rounds=0;
    int prev=-1;
    for(int i=0;i<m;i++)
    {
        int val=t[i]-'a';
        int id=upper_bound(all(adj[val]),prev)-adj[val].begin();
        if(id==adj[val].size())
        {
            complete_rounds++;
            prev=adj[val][0];
        }
        else
            prev=adj[val][id];
    }

    cout<<n*complete_rounds+prev+1;

}

Measured memory_bytes: 1736
#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()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

//しっかり制約確認したか?
int main()
{
    ll n; cin >> n;
    ll ans = n*(n+1)/2;
    for(int i = 2; i <= n; i++){
        for(int j = i; j <= n; j+=i){
            ans += j;
        }
    }
    cout << ans << endl;
    system("pause");
}
/*vector<ll> v(n+1, 1);//1-index
    for(int i = 2; i <= n; i++){
        for(int j = i; j <= n; j += i){
            v[j]++;
        }
    }
    ll ans = 0;
    rep(i, n){
        ans += (i+1)*v[i+1];
    }
    cout << ans << endl;*/

Measured memory_bytes: 3680
import java.util.*;


public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static long mod = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long D = sc.nextLong();
        long T = sc.nextLong();
        long S = sc.nextLong();

        if(S*T < D){
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }

    }

}




Measured memory_bytes: 35592
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,s,e) for(int i=s;i<e;i++)
#define endl '\n'
int main(){
    int N;cin>>N;
    vector<lli> A(N);
    lli res=0;
    cin>>A[0];
    lli Amax=A[0];
    rep(i,1,N){
        cin>>A[i];
        if(Amax>A[i]){
            res+=Amax-A[i];
        }else{
            Amax=A[i];
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 4840
#include <iostream>
#include <cmath>
using namespace std;
#define MAX 1000000

int main(){
	bool p[MAX+1];
	int n, ans;

	for(int i=0 ; i<=MAX ; i++){
		p[i] = (i<=1)? false : true ;
	}

	for(int i=2 ; i<=sqrt(MAX)+1 ; i++){
		if(p[i]){
			for(int j=i*2 ; j<=MAX ; j+=i){
				p[j] = false;
			}
		}
	}

	while( cin >> n ){
		ans = 0;
		for(int i=1 ; i<=n ; i++){
			if( p[i] && p[n-i+1] ){
				ans++;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define dump(x)  cout << #x << " = " << (x) << endl;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
//             0123456789 - digits. check the limits, int vs long
const int MX = 100001;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;
    // freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    int n;
    cin >> n;

    vector<vi> g(n, vi(0));
    vector<pi> e;
    int a, b;
    for (int i = 0; i < n - 1; i++) {
        cin >> a >> b;
        --a;--b;
        if (a > b) swap(a, b);
        e.push_back(mp(a, b));
        g[a].push_back(b);
        g[b].push_back(a);
    }
    map<pi, int> edgeColors;
    vector<bool> used(n, false);
    queue<int> q;
    q.push(0);
    used[0] = true;
    vi rootColor(n, -1);
    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        int curColor = 0;
        for (auto u : g[cur]) {
            if (!used[u]) {
                q.push(u);
                used[u] = true;
                if(rootColor[cur] == curColor) curColor++;
                rootColor[u] = curColor;
                edgeColors[mp(cur, u)] = curColor;
                edgeColors[mp(u, cur)] = curColor;
                curColor++;
            }
        }
    }
    int mx = 0;
    for (auto u : e) {
        mx = max(edgeColors[u], mx);
    }
    cout << mx + 1 << "\n";
    for (auto u : e) {
        cout << edgeColors[u] + 1 << "\n";
    }
    

    return 0;
}

Measured memory_bytes: 19704