akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

#define N 25

typedef struct{
  int par, left, right, status, depth, sibling, degree, height;
}Node;

Node tree[N];
int n;
char root[N];

void calc_depth(int p, int d){
  tree[p].depth = d;
  if(tree[p].right != -1) calc_depth(tree[p].right, d + 1);
  if(tree[p].left != -1) calc_depth(tree[p].left, d + 1);
}

int calc_height(int p){
  int a = 0, b = 0;
  if(tree[p].left != -1) a = calc_height(tree[p].left) + 1;
  if(tree[p].right != -1) b = calc_height(tree[p].right) + 1;
  if(a < b) tree[p].height = b;
  else tree[p].height = a;
  return tree[p].height;
}

main(){
  int i, r;
  scanf("%d", &n);
  memset(root, 1, n);
  for(i=0;i<n;i++) tree[i].left = tree[i].right = tree[i].sibling = -1;
  for(i=0;i<n;i++){
    int idx, l, r;
    scanf("%d %d %d", &idx, &l, &r);
    if(l != -1){
      tree[idx].left = l;
      tree[l].par = idx;
    }
    if(r != -1){
      tree[idx].right = r;
      tree[r].par = idx;
    }
    if(l == -1 && r == -1){
      tree[idx].status = 1;
      tree[idx].degree = 0;
    }else if(l == -1 || r == -1){
      tree[idx].status = 2;
      tree[idx].degree = 1;
    }else{
      tree[idx].status = 2;
      tree[idx].degree = 2;
      tree[l].sibling = r;
      tree[r].sibling = l;
    }
    root[l] = root[r] = 0;
  }
  for(i=0;i<n;i++) if(root[i]) r = i;
  tree[r].par = -1;
  tree[r].status = 0;
  calc_depth(r, 0);
  calc_height(r);
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", i, tree[i].par, tree[i].sibling, tree[i].degree, tree[i].depth, tree[i].height);
    if(tree[i].status == 0) printf("root\n");
    else if(tree[i].status == 1) printf("leaf\n");
    else if(tree[i].status == 2) printf("internal node\n");
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

struct edge {
    int to, cost;
};

int V;
vector<int> G[1000000];
int st[1000000];
int en[1000000];
int t;

void DFS(int n) {
    t++;
    st[n] = t;
    int s = G[n].size();
    for (int i = 0; i < s; i++) {
        if (st[G[n][i]] == intmax) {
            DFS(G[n][i]);
        }
    }
    t++;
    en[n] = t;
}

int main() {
    int N;
    cin >> N;
    V = N;
    fill(st, st + V + 10, intmax);
    fill(en, en + V + 10, intmax);
    t = 0;
    for (int i = 0; i < N; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int n;
            cin >> n;
            G[i].push_back(n - 1);
        }
    }
    for (int i = 0; i < N; i++) {
        if (st[i] == intmax) {
            DFS(i);
        }
    }
    for (int i = 0; i < N; i++) {
        cout << i + 1 << " " << st[i] << " " << en[i] << endl;
    }
}



Measured memory_bytes: 26560
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 100005
using namespace std;

typedef long long ll;
ll n, cnt, a[N], b[N], c[N], bb[N];
int main()
{
	ll i;
	cin >> n;
	for (i = 0; i < n; i++) scanf("%lld", &a[i]);
	for (i = 0; i < n; i++) scanf("%lld", &b[i]);
	for (i = 0; i < n; i++) scanf("%lld", &c[i]);
	sort(b, b + n);
	sort(c, c + n);
	for (i = n - 1; i >= 0; i--) bb[i] = bb[i + 1] + n - (upper_bound(c, c + n, b[i]) - c);
	for (i = n - 1; i >= 0; i--) cnt += bb[upper_bound(b, b + n, a[i]) - b];
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3328
import sys
from collections import deque

N, M = map(int, sys.stdin.readline().strip().split())

paths = [[] for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().strip().split())
    paths[a].append(b)
    paths[b].append(a)

q = deque([(1, 0)])
visited = set()
while q:
    p, c = q.popleft()
    if p in visited:
        continue
    visited.add(p)
    if c > 2:
        continue
    if p == N:
        print("POSSIBLE")
        sys.exit()
    for next_p in paths[p]:
        q.append((next_p, c+1))

print("IMPOSSIBLE")

Measured memory_bytes: 51416
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
bool dfs(int x,int sum){
	if(sum>n){
		return false;
	}
	if(sum==n){
		return true;
	}
	return dfs(x+1,sum+x+1);
}

int main(){
	while(cin>>n,n){
		int ans = 0;
		for(int i =1; i <=n/2;i++){
			if(dfs(i,i)){
				ans++;
			}
		}
		cout <<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
#define mod         (ll)1000000007
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = (ll)1e18;
ld pi = 3.141592653589;
using namespace std;

ll bpow(ll x, ll v) {   
    if (v == 0)
        return 1 % mod;
    if (v % 2 == 1)
        return (x * bpow(x, v - 1)) % mod;
    ll r = bpow(x, v / 2);
    return (r * r) % mod;   
}

ll solve(){ 
    ld l; cin>>l;
    ld ans = (l/3)*(l/3)*(l/3);
    cout<<fixed<<setprecision(10)<<ans;
}

int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 256
#define  _USE_MATH_DEFINES

#define  rep(i, n) for(int i = 0; i < n; i++)
#define  repx(i, a, n) for(int i = a; i < n; i++)
#define  loop while(1)
#define  lli long long int
 
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <utility>
#include <set>

using namespace std;
  
int main() {

  int n;
  cin >> n;
  
  vector<int> v1(n, 0);
  vector<int> v2(n, 0);
  
  rep (i, n) cin >> v1[i];
  rep (i, n) cin >> v2[i];
  
  rep (i, n) {
    if (i > 0) v1[i] = v1[i - 1] + v1[i];
    if (i < n - 1) v2[n - i - 2] = v2[n - i - 2] + v2[n - i - 1];
  }
  
  int ans = 0;
  rep (i, n) ans = max(ans, v1[i] + v2[i]);
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
using namespace std;
const int mod=1000000007;
int main()
{
  int x;
  cin>>x;
  
  string ans="ABC";
  if(x>=1200)
  {
	  ans="ARC";
	  
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  vector<int> a(3);
  for(int i = 0; i < 3; i++)
  cin >> a.at(i);
  int ans = 0;
  
  sort(a.begin(), a.end()); 
  cout << a.at(2) - a.at(0)  << endl;
}

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

int main()
{
    int n, i, j, a[100], p[100], s, t;

    cin >> n;

    for(i = 0; i < n; i++){
        cin >> a[i];
        p[i] = a[i];
    }

    for(i = 0; i < n - 1; i++){
        for(j = i + 1; j < n; j++){
            if(a[i] > a[j]){
                t = a[i];
                a[i] = a[j];
                a[j] = t;
            }
        }
    }

    s = 0;

    for(i = 0; i < n; i++){
        if(a[i] != p[i]){
            s++;
        }
    }

    if(s == 0 || s == 2){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
 
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int f;
  cin>>f;
  
  cout<<(f-30)/2<<endl;
      
  return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using u32 = unsigned int;
typedef pair<int, int> p;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int Inf = (1<<30);
ll inf = (1LL<<60);
int main(){
	int n;
	cin >> n;
	vector<int> dp(110000, Inf);
	dp[0] = 0;
	int i;
	for (i = 0; i < 100000; i++) {
		dp[i + 1] = min(dp[i + 1], dp[i] + 1);
		for (int s = 1; s <= 8; s++) {
			int S = pow(6, s);
			if (S + i >= 100000) break;
			dp[i + S] = min(dp[i + S], dp[i] + 1);
		}
		for (int ni = 1; ni <= 6; ni++) {
			int Ni = pow(9, ni);
			if (Ni + i >= 100000) break;
			dp[i + Ni] = min(dp[i + Ni], dp[i] + 1);
		}
	}
	cout << dp[n];
	return 0;
}

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

typedef long long ll;

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

    int n; cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    bool ok = true;
    for(int i=0;i<n;i++){
        if(a[i]%2==0){
            if(a[i]%3==0 || a[i]%5==0){
                ok = true;
            }else{
                ok = false;
                break;
            }
        }
    }
    if(ok) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N := sc.nextInt()
	X := sc.nextIntSlice(N)
	ans := INF
	for i := 1; i <= 100; i++ {
		sum := 0
		for j := 0; j < N; j++ {
			sum += pow(abs(X[j]-i), 2)
		}
		if sum < ans {
			ans = sum
		}
	}

	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans = 0;
		for (int i = 1; i <= N; i++) {
			String[] s = String.valueOf(i).split("");
			int sum = 0;
			for (int j = 0; j < s.length; j++) {
				sum += Integer.parseInt(s[j]);
			}
			if (sum >= A && sum <= B) {
				ans += i;
			}
		}
		System.out.println(ans);
	}
}



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

int main() {
  int n,in;
  while(cin>>n, n) {
    set<int> taro,hanako;
    for(int i=0; i<n; ++i) {
      cin>>in;
      taro.insert(in);
    }


    for(int i=1; i<=2*n; ++i) {
      if(taro.find(i) == taro.end()) {
	hanako.insert(i);
      }
    }

    int state = 0;
    set<int>::iterator it;
    while(!(hanako.empty() || taro.empty())) {
      it = lower_bound(taro.begin(), taro.end(), state);
      if(it == taro.end()) {
	state = 0;
      } else {
	state = *it;
	taro.erase(it);
      }
      if(taro.empty()) break;

      it = lower_bound(hanako.begin(), hanako.end(), state);
      if(it == hanako.end()) {
	state = 0;
      } else {
	state = *it;
	hanako.erase(it);
      }
    }

    cout<<hanako.size()<<endl;
    cout<<taro.size()<<endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  int ans=1;
  for(int i=0;i<n-1;i++){
    if(s[i]!=s[i+1]){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 512
N = gets.chomp.to_i
p = Array.new(N+1)
str = gets.split
for i in 0...N do
    a = str[i].to_i
    p[a] = i+1
end

q = Array.new(3,N+1)
q[0] = 0
q[1] = p[N]
answer = 0

for i in 2..N do
    a = p[-i]
    l = 1
    r = i
    while l != r
        c = (l+r)/2
        if a < q[c]
            r = c
        else
            l = c+1
        end
    end
    q.insert(l,a)

    b = N-i+1
    if q[l-1] == 0
        answer += b*(q[l]-q[l-1])*(q[l+2]-q[l+1])
    elsif q[l+1] > N
        answer += b*(q[l-1]-q[l-2])*(q[l+1]-q[l])
    else
        answer += b*((q[l-1]-q[l-2])*(q[l+1]-q[l])+(q[l]-q[l-1])*(q[l+2]-q[l+1]))
    end
end
puts answer

Measured memory_bytes: 11540
import java.util.Scanner;

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

        int i = 1;
        while(true) {
            int n = sc.nextInt();
            if (n == 0) break;
            System.out.printf("Case %d: %d\n", i, n);
            i++;
        }
    }
}

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

int main(){
  int n,k,q;
  cin >> n >> k >> q;
  VI c(n);
  rep(i,q){
    int a;
    cin >> a;
    c[a-1]++;
  }
  rep(i,n){
    if(q-c[i] < k) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1024
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)

long long Ftr(int x){
    if(x == 0) return 1;
    else return ((x % 1000000007) * (Ftr(x - 1) % 1000000007)) % 1000000007;
}

int main(){
    long long n, m;
    cin >> n >> m;

    long long ans = 1;
    if(abs(n - m) <= 1){
        ans *= Ftr(n) % 1000000007;
        ans *= Ftr(m) % 1000000007;
        if(n == m) ans = (ans * 2) % 1000000007;
    }else ans = 0;
    cout << ans % 1000000007 << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>ai(n);
    vector<int>bi(n);
    vector<int>ci(n);
    for(int i=0;i<n;i++)
    {
        cin>>ai[i]>>bi[i]>>ci[i];
    }
    int dp[3][n];
    dp[0][0]=ai[0];
    dp[1][0]=bi[0];
    dp[2][0]=ci[0];
    for(int i=1;i<n;i++)
    {
        dp[0][i]=ai[i]+max(dp[1][i-1],dp[2][i-1]);
        dp[1][i]=bi[i]+max(dp[0][i-1],dp[2][i-1]);
        dp[2][i]=ci[i]+max(dp[0][i-1],dp[1][i-1]);
    }
    cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<endl;
}

Measured memory_bytes: 5644
#include <bits/stdc++.h>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=512;
const int zero=250;
int fa[maxn],siz[maxn],oud[maxn],ind[maxn];
bool h[maxn];
int find(int k)
{
	if(fa[k]!=k)fa[k]=find(fa[k]);
	return fa[k];
}
inline int read(){
	int x=0;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return x;
}
inline void merge(int x,int y){
    x=find(x);y=find(y);
    if(x==y){++siz[x];return;}
    fa[x]=y;siz[y]+=siz[x] + 1;
}
int main(){
    int n,H;n=read();H=read();
    for(int i=1;i<=H;i++)  fa[i+zero]= i+zero,siz[i+zero]= 1;
    for(int i=-H;i<=-1;i++)fa[i+zero]= i+zero,siz[i+zero]= 1;
    int a,b,c,d;
    for(int i=1;i<=n;i++){
        int x,y;
        a=read();b=read();c=read();d=read();
        if(c==0)x=a;else x=-c;
        if(d==0)y=-b;else y=d;
        ++oud[x+ zero];++ ind[y + zero];
        merge(x+zero,y+zero);
    }
    for(int i=1;i<=H;i++)  if(oud[i+zero]<ind[i+zero])return puts("NO"),0;
    for(int i=-H;i<=-1;i++)if(ind[i+zero]<oud[i+zero])return puts("NO"),0;
    for(int i=1;i<=H;i++)  h[find(i+zero)]|=(ind[i+zero]!=oud[i+zero]);
    for(int i=-H;i<=-1;i++)h[find(i+zero)]|=(ind[i+zero]!=oud[i+zero]);
    for(int i=1;i<=H;i++)  if(siz[find(i+zero)]>1&&(find(i+zero)==i+zero)&&(h[i+zero]==false))return puts("NO"),0;
    for(int i=-H;i<=-1;i++)if(siz[find(i+zero)]>1&&(find(i+zero)==i+zero)&&(h[i+zero]==false))return puts("NO"),0;
    puts("YES");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
#define MAX 1000001
#define mod 1000000007
#define pie 3.14159265358979323846
bool visited[200005]={false};
int cnt;
vector<int> adj[200005];
void DFS(int v) 
{  
    visited[v] = true;  
    for(int i=0;i<adj[v].size();i++)
	{
		if(visited[adj[v][i]]==false){
			cnt++;
			DFS(adj[v][i]);		
		}
	}
}
vector<int> fun(int N) 
{ 
	vector<int> vec;
    for (int v = 1; v <= N; v++) { 
        if (visited[v] == false) {
			cnt=1; 
            DFS(v); 
            vec.push_back(cnt);
        } 
    } 
    return vec; 
} 
 
void solve(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	vector<int> res;
	res=fun(n);
	cout<<*max_element(res.begin(),res.end());	
}
int main()
{ 
    cool;
    int t;
    //cin>>t;
    t=1;
    while(t--){
    	solve();
	}
    return 0;
}


Measured memory_bytes: 20948
#include <iostream>
#include <cmath>

using namespace std;
int main(){
  
  int N;
  cin >> N;
  int A[N];
  int max_1=0, max_2=0;
  int id_max_1 = -1;
  int id_max_2 = -1;
  
  for(int i=0;i<N;i++){
    cin >> A[i];
    if(A[i]>max_1){
      max_1 = A[i];
      id_max_1 = i;
    }else if(A[i]>=max_2){
      max_2 = A[i];
      id_max_2 = i;
    }
  }
  for(int i=0;i<N;i++){
    A[i] = max_1;
    if(i == id_max_1){
      A[i] = max_2;
    }
    cout << A[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 2432
#include<stdio.h>
int main()
{
  int a,b,i,j;
  while(1)
	   {
  scanf("%d%d",&a,&b);
  if(a==0&&b==0){break;}

  for(i=1;i<=a;i++)
    {
      for(j=1;j<=b;j++)
	{
	  if(i>1&&i<a&&j<b&&j>1)printf(".");
	  else printf("#");
	}
      printf("\n");
    }
  printf("\n");
    
	   }
  return 0;
}


Measured memory_bytes: 2104
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) (lower_bound(ALL(a), (x)) - a.begin())
#define bisect_right(a, x) (upper_bound(ALL(a), (x)) - a.begin())
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

const int INF = 2e9;
// const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL n, a, b;
  cin >> n >> a >> b;
  LL m = a*(n-1)+b, M = a+b*(n-1);
  cout << max(0LL, M-m+1) << endl;

  return 0;
}


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

using namespace std;

# define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;

# define S second
# define F first
# define kill(x) return(cout << x << endl, 0)
# define debug(x) cerr<< #x << " : " << x << endl
# define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)

const int MAXN = 100 * 1000 + 10;
int x[MAXN], w[MAXN], 
    ans[MAXN];

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

	int n, l, t;
	cin >> n >> l >> t;
	for (int i = 0; i < n; i ++)
	{
		cin >> x[i] >> w[i];
		w[i] --;
	}

	for (int i = 0; i < n; i ++)
		ans[i] = ((x[i] + (w[i] ? -1 : 1) * t) % l + l) % l;
	sort(ans, ans + n);

	int ind = 0;
	for (int i = 0; i < n; i ++)
	{
		if (!w[i])
		{
			ind += t / l;
			if (x[i] + t % l >= l)
				ind ++;
		}
		else
		{
			ind -= t / l;
			if (x[i] - t % l < 0)
				ind --;
		}
		ind = (ind % n + n) % n;
		
	}

	for (int i = 0; i < n; i ++)
		cout << ans[(ind + i) % n] << "\n";

	return 0;
}


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

using namespace std;
typedef long long ll;

int main(void) {
	int num, i;
	ll ans = 0;
	cin >> num;
	vector<int> d(3 * num);
	for (i = 0; i < 3 * num; i++)
		scanf("%d", &d[i]);
	sort(d.begin(), d.end());
	for (i = 3 * num - 2; i >= num; i -= 2)
		ans += (ll)d[i];
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1408
import sys
n=int(input())
c=[]
s=[]
f=[]
if n==1:
    print(0)
    sys.exit()
for i in range(n-1):
    C,S,F=map(int,input().split())
    c.append(C)
    s.append(S)
    f.append(F)
for i in range(n-1):
    tmp=0
    while i<n-1:
        if tmp<=s[i]:
            a=s[i]
        elif (tmp-s[i])%f[i]==0:
            a=tmp
        elif tmp>s[i]:
            b=f[i]-(tmp-s[i])%f[i]
            a=tmp+b
        tmp=a+c[i]
        i+=1
    print(tmp)
print(0)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
/******************************************
* AUTHOR : PANDRAVISAM SHIVA SANTHOSH *
* Handle : santhosh_80 *
* INSTITUTION : IIT Palakkad *
******************************************/
#define ll long long int 
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vll vector<long long >
#define umap unordered_map
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define inf LLONG_MAX
#define neg_inf LLONG_MIN
#define next_line cout << "\n"
#define what_is(x) cerr << #x << " is " << x << "\n";
#define rep(i,a,b) for(int i = a; i < b; i++)
#define repj(j,a,b) for(int j = a; j < b; j++)

inline void read0(auto &v, int n) {
	for(int i = 0; i < n; i++){cin >> v[i];}
}
inline void read1(auto &v, int n) {
	for(int i = 1; i <= n; i++){cin >> v[i];}
}
inline void out0(auto &v, int n) {
	for(int i = 0; i < n; i++){cout << v[i] << " ";}
}
inline void out1(auto &v, int n){
	for(int i = 1; i <= n; i++){cout << v[i] << " ";}
}
inline void auto_print(auto &v){
	for(auto x: v)cout << x << " ";
}

const ll mod = 1000000007;
const ll N = 1e5+3;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n; cin >> n;
	vll v(n+1);
	map<ll,ll> m;
	ll sum = 0;
	rep(i,1,n+1){
		cin >> v[i];
		m[v[i]]++;
		sum+=v[i];
	}
	int q;cin >> q;
	while(q--){
		ll x,y; cin >> x >> y;
		ll rem = m[x]*x;
		ll add = m[x]*y;
		m[y]+=m[x];
		m[x] = 0;
		sum = sum - rem + add;
		cout << sum << "\n";
	}
 	return 0;
}

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

int main(){
  long long a, b, x;
  cin >> a >> b >> x;
  long long ans;
  ans = b/x - (a-1)/x;
  if(a==0) ans = b/x+1;
  if(b==0) ans = 1;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>



using namespace std;

int main() {
	int a, b, i;
	cin >> a >> b;
	for ( i = 0; i < 1009; i++) {
		if (i * 8 / 100 == a && i / 10 == b) {
			break;
		}
	}
	if (i == 1009) {
		cout << -1 << endl;
	}
	else
	{
		cout << i << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def prime_numbers(n):
    if n < 2:
        return []

    m = (n + 1) // 2
    p = [1] * m
    for i in range(1, int((n ** 0.5 - 1) / 2) + 1):
        if p[i]:
            p[2 * i * (i + 1) :: 2 * i + 1] = [0] * (((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1)

    return {2} | {2 * i + 1 for i in range(1, m) if p[i]}


def main():
    primes = prime_numbers(10 ** 5)
    A = [1 if n in primes and (n + 1) // 2 in primes else 0 for n in range(10 ** 5 + 1)]
    A = tuple(accumulate(A))

    Q, *LR = map(int, open(0).read().split())
    ans = []
    for l, r in zip(*[iter(LR)] * 2):
        ans.append(A[r] - A[l - 1])

    print('\n'.join(map(str, ans)))
    return


if __name__ == '__main__':
    main()


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    long long ans = 0;
    for (int i = n - 1; i >= 0; i--){
        if ((a[i] + ans) % b[i] != 0) ans += b[i] - ((a[i] + ans) % b[i]);
    }
    cout << ans << endl;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

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

    ll a;
    cin >> a;

    string s;
    cin >> s;

    if (a >= 3200) {
        cout << s << endl;
    } else {
        cout << "red" << endl;
    }
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, w;
vector<int> P, V;
int dp[101][100005];

int32_t main()
{
	cin >> n >> w;
	for(int i = 0; i < n; i++)
	{
		int p, v;
		cin >> p >> v;
		P.push_back(p);
		V.push_back(v);
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= w; j++)
			if(i or j)
			{
				if(P[i - 1] <= j)
					dp[i][j] = max(dp[i - 1][j], V[i - 1] + dp[i - 1][j - P[i - 1]]);
				else 
					dp[i][j] = dp[i - 1][j];
			}
	cout << dp[n][w] << '\n';

	return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define setval(arr,v) memset(arr,v,sizeof(arr));
#define lli long long int
#define ll long long
#define mod 1000000007
#define v vector
#define pb push_back
#define pf pop_front;
#define fi first
#define se second
using namespace std;

void solve()
{
    lli n,d,cnt = 0;
    cin>>n>>d;
    for (int i = 0; i < n; ++i)
    {
        int a,b;
        cin>>a>>b;
        lli td;
        td = pow(a,2)+pow(b,2);
        if(td <= pow(d,2))
            cnt++;
    }
    cout<<cnt;



}


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();



    }
    return 0;

}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int n,h[100000],dp[100000];
int cost(int i)
{
	int k1,k2;
	if(i==n-1)
	return 0;
	
	if(dp[i+1]==-1)
	k1=(dp[i+1]=cost(i+1))+abs(h[i]-h[i+1]);
	else
	k1=dp[i+1]+abs(h[i]-h[i+1]);
	k2=INT_MAX;
	if((i+2)<=n-1)
	{
	if(dp[i+2]==-1)
	k2=(dp[i+2]=cost(i+2))+abs(h[i]-h[i+2]);
	else
	k2=dp[i+2]+abs(h[i]-h[i+2]);
	}
	
	return min(k1,k2);
}



int main()
{
	int i;
	cin>>n;
	
	for(i=0;i<n;i++)
	cin>>h[i];
	memset(dp,-1,sizeof(dp));
	cout<<cost(0);
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N; 
  int Ans=0;
  vector<int> a(N);
  for(int i=0;i<N;i++) cin >> a.at(i);
  for(int i=0;i<N;i++){
    while(a.at(i)/2*2==a.at(i)){
      a.at(i)/=2;
      Ans++;
    }
  }
    cout << Ans << endl;

}



Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
using namespace std;
vector<int>g[100000];
int n, u, v, a, b, ans;
int du[100000], dv[100000];
void dfs(int x, int y, int z) {
	dv[x] = z;
	for (int i = 0; i < g[x].size(); i++) {
		if (g[x][i] != y)dfs(g[x][i], x, z + 1);
	}
}
int main() {
	scanf("%d%d%d", &n, &u, &v);
	u--; v--;
	for (int i = 0; i < n - 1; i++) {
		scanf("%d%d", &a, &b);
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(u, -1, 0);
	for (int i = 0; i < n; i++)du[i] = dv[i];
	dfs(v, -1, 0);
	for (int i = 0; i < n; i++) {
		if (dv[i] > du[i]) {
			if (dv[i] > ans)ans = dv[i];
		}
	}
	printf("%d\n", ans - 1);
}

Measured memory_bytes: 11648
from collections import Counter
n = int(input())
ls = list(map(int,input().strip().split()))

freq_dic = Counter(ls)
ans = 0
for key,val in freq_dic.items():
    if val>1:
        ans += (val*(val-1))//2
for val in ls:
    currans = ans
    if freq_dic[val]>1:
        tempval = freq_dic[val]
        tempans = (tempval*(tempval-1))//2
        newans = 0
        if tempval>2:
            newans += ((tempval-1)*(tempval-2))//2
        currans -= tempans
        currans += newans
    print(currans)
        
    


Measured memory_bytes: 26780
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define llu unsigned long long 
#define ll long long 
ll read() { ll  x; if (scanf("%lld", &x) == -1)exit(0); return x; }
#define vi vector<int>
#define vb vector<bool>
const long long INF = 5e18;

#define LOCAL_JUDGE
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}


int main() {
    //c_p_c();
    int k = read();
    string s;
    cin >> s;

    if (s.length() <= k) cout << s << endl;
    else {
        s  = s.substr(0, k) + "...";
        cout << s << endl;
    }

    return 0;
}



Measured memory_bytes: 3692
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int a[200010],ans[200010];
int top,sta[200010];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read();
    for(int i=1;i<=n;i++)a[i]=read();
    for(int i=n;i>=1;i--)
    {
    	int sum=0;
    	for(int j=2*i;j<=n;j+=i)sum+=ans[j];
    	sum%=2;
    	if(sum!=a[i]){ans[i]=1;sta[++top]=i;}
    }pr2(top);
    for(int i=1;i<=top;i++)pr1(sta[i]);
    return 0;
}

Measured memory_bytes: 2688
N=int(input())
C=[]
S=[]
F=[]
for i in range(N-1):
    c,s,f=map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for j in range(N):
    t=0
    for i in range(j,N-1):
        if t<=S[i]:
            t=S[i]+C[i]
        else:
            t1=S[i]
            while(t1<t):
                t1+=F[i]
            t=t1+C[i]
    print(t)


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

class B
{
    static void Main()
    {
        var s = Console.ReadLine();
        var a = new long[s.Length];
        for (int i = 0; i < s.Length; i++) a[i] = long.Parse(s[i].ToString());
        Console.WriteLine(a.Sum() % 9 == 0 ? "Yes" : "No");
    }
}

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

int main()
{
    ll N; cin >> N;
    map<ll, ll> mp1, mp2;
    ll A;
    for(int i=0;i<N;i++)
    {
        cin >> A;
        mp1[i + A]++; mp2[i - A]++;
    }

    ll ans = 0;

    for(auto [key, value] : mp1)
    {
        ans += mp1[key] * mp2[key];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 37896
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char *s, *read;
    int n, r = 0, b = 0;
    scanf("%d", &n);
    s = malloc(sizeof(char)*(n+1));
    scanf("%s", s);
    read = s;
    while(*read != '\0'){
        if(*read == 'R') r++;
        else b++;
        read++;
    }
    if(r > b) printf("Yes\n");
    else printf("No\n");

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    int n;
    int i;
    char s[100000];
    scanf("%d", &n);
    scanf("%s", s);
    for(i = 0;s[i] != '\0';i ++){
        if(s[i] + n <= 90){
            s[i] = s[i] + n;
        }
        else{
            s[i] = s[i] + (n - 26);
        }
    }
    printf("%s\n", s);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
int main(void){
    double a,b,c,s,l,h;
    scanf("%lf %lf %lf",&a,&b,&c);
    c=c*3.14159265/180.0;
    s=a*b*sin(c)/2;
    l=a+b+(sqrt(a*a+b*b-2*a*b*cos(c)));
    h=b*sin(c);
    printf("%.8f\n%.8f\n%.8f\n",s,l,h);
    return 0;
}


Measured memory_bytes: 2048
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
//using
using namespace std;
/*using vi = vector<int>;
using vs = vector<string>;
using vc = vector<char>;*/
//define
#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
//グローバル変数宣言
int a=0,b=0,c=0,d=0,n=0;

//int sa(int n,int p){if(n>=p)return n-p;else return p-n;}

signed main(){
    
        cin>>n;
        a=n/27;
        b=n%27;
        if(b==13||b==26)cout<<":("<<endl;
        else if(b==0)c=a*25;
        else if(b>13)c=n-(2*a+1);
        else c=n-(2*a);
        if(b!=13&&b!=26) cout<<c<<endl;

}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll LL_INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, H;
  cin >> N >> H;
  vector<pair<int,int> > a(N);
  int maxa = 0, maxai;
  REP(i,N){
    cin >> a[i].first >> a[i].second;
    if(maxa < a[i].first){
      maxa = a[i].first;
      maxai = i;
    }
  }
  sort(a.begin(), a.end(), [](pair<int,int>& a, pair<int,int>& b){
      return a.second > b.second;
    });
  int ct = 0;
  REP(i,N){
    if(maxa < a[i].second){
      ct++;
      H -= a[i].second;
      if(H <= 0){
        break;
      }
    }else{
      break;
    }
  }
  if(H <= 0) cout << ct << endl;
  else cout << ct + (H + maxa - 1) / maxa << endl;
  return 0;
}


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

using namespace std;


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

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

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (P[i] != i + 1) {
            ++cnt;
        }
    }
    if (cnt <= 2) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }

    return 0;
}

Measured memory_bytes: 256
//long long使う！！！！！！
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;

ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}

const ll big=998244353;
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x);
    ll t=exp(x,y/2);
    return (t*t);
}
 
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

typedef pair<int,int> p;



int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(0);
    /*--------------------------------*/
    
    int x,y;cin >> x >> y;
    if(x*2<=y&&y<=4*x&&y%2==0)cout << "Yes";
    else cout<< "No";
    cout << endl;
}

Measured memory_bytes: 3636
# include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long ll;

int main(){
  ll K;
  cin >> K;
  ll base=70;
  if(K%2==0 || K%5==0){
    cout << "-1";
    return 0;
  }
  
  ll res=2;
  ll mod1=7%K;
  ll mod2=7%K;
  if(mod2==0){
    cout << 1;
    return 0;
  }
  
  ll i=2;
  while(true){
    mod1 =  (mod1)*10 % K;
    if(mod1+mod2==K) break;
    base *= 10;
    mod2 = (mod1+mod2)%K;
    res++;
    //i++;
  }
  
  
  cout << res;
  return 0;
}

Measured memory_bytes: 3624
def countFactors(n):
  count = 0
  for i in range(1, n + 1):
    if n % i == 0:
      count += 1
  return count

X = int(input())

count = 0
for i in range(1, X + 1, 2):
  if countFactors(i) == 8:
    count += 1

print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    int k;
    cin >> k;
    vi as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }
    vi dp(n);
    for (int i = 1; i < n; i++) {
        i64 nin = 1e9;
        for (int j = 1; j <= k; j++) {
            if (i - j >= 0) {
                nin = min(nin, dp[i - j] + abs(as[i] - as[i - j]));
            }
        }
        dp[i] = nin;
    }
    cout << dp.back() << endl;
}

Measured memory_bytes: 1792
n,q = map(int, input().split())

d = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    d[a-1].append(b-1)
    d[b-1].append(a-1)

c = [0]*n

for i in range(q):
    p,x = map(int,input().split())
    c[p-1]+=x

ans = [0]*n
visited = [0]*n

que = []

que.append(0)
visited[0]=1
ans[0]+=c[0]

while que:
    x = que.pop()
    for y in d[x]:
        if visited[y]==1:
            continue
        else:
            ans[y]+=ans[x]+c[y]
            visited[y]=1
            que.append(y)



print(' '.join(map(str,ans)))


Measured memory_bytes: 130196
#include<iostream>
#include<algorithm>
using namespace std;
int a[150];
int main()
{int n;
 cin>>n;
 for(int i=0;i<n;i++)
 cin>>a[i];
 int ans=1;
 for(int i=1;i<n;i++){
 sort(a,a+n);
 if(a[i]!=a[i-1])
 ans++;} 
 cout<<ans;
 system("pause");
 return 0;
 }        

Measured memory_bytes: 504
#pragma region include
#include <stdio.h>
#include <string>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#pragma endregion
using namespace std;

#pragma region 定数
#define INF_VAL (2147483647 - 1)
#define INF_VAL_MINUS -INFVAL
#pragma endregion

#pragma region マクロ
// 配列の長さを取得する(ただし関数内ではポインタサイズに注意)
#define SIZE_OF_ARRAY(array) sizeof(array) / sizeof(*array)

// ソート
#define Sort(array, length) sort(array, array + length)
#define SortDESC(array, length) sort(array, array + length, greater<>())

// 配列の最大値、最小値取得
#define MAX_OF_ARRAY(array, length) *max_element(array, array + length)
#define MIN_OF_ARRAY(array, length) *min_element(array, array + length)
#pragma endregion

#pragma region Utility
#pragma region 配列要素の合計値を取得
template <typename T>
T getSum(T array[], int length)
{
    T sum = 0;
    for (int i = 0; i < length; i++)
    {
        sum += array[i];
    }
    return sum;
}
#pragma endregion

#pragma region ToString(int)
string ToString(int i)
{
    char buffer[1000];
    sprintf(buffer, "%d", i);
    return string(buffer);
}
#pragma endregion

#pragma region 10進数からN進数(<= 10) へ変換
string convertToN(long n, int base)
{
    string ans = "";
    while (n != 0)
    {
        int temp = n % base; // 1桁取得
        ans = ToString(temp) + ans;
        n /= base;
    }
    return ans;
}
#pragma endregion
#pragma endregion

int main()
{
    // ***  問題のpathを記載 ***
    // https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/1/ITP1_1_D

    // 標準入力から値を取得
    int n;
    cin >> n;

    // 入力数がN個の場合
    // int array[n];
    // for (int i = 0; i < n; i++)
    // {
    //     cin >> array[i];
    // }

    // 入力数が決まっている場合
    // scanf("%d %d %d", &a, &b, &c);

    // 結果出力
    if (n % 2 == 0)
    {
        n /= 2;
    }
    else
    {
        n = n / 2 + 1;
    }
    
    printf("%d\n", n);
    // printf("%s\n", result.c_str());
    //puts("Yes");

    // 成功時は必ず0を返す
    return 0;
}


Measured memory_bytes: 256
N = int(input())
hlist = list(map(int, input().split()))

dp = [-1 for _ in range(N)]
dp[0] = 0
for n in range(N-2):
  cost = dp[n] + abs(hlist[n]-hlist[n+1])
  dp[n+1] = min(dp[n+1], cost) if dp[n+1] != -1 else cost
  cost = dp[n] + abs(hlist[n]-hlist[n+2])
  dp[n+2] = min(dp[n+2], cost) if dp[n+2] != -1 else cost
cost = dp[-2] + abs(hlist[-2]-hlist[-1])
dp[-1] = min(dp[-1], cost) if dp[-1] != -1 else cost
print(dp[-1])

Measured memory_bytes: 13908
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int MAXN = 1e5 + 10;
const int MAXM = 2e6 + 10;
const ll mod = 1e9 + 7;

int a[MAXN];

int main()
{
//#ifdef local
//    freopen("data.txt","r",stdin);
////    freopen("data.txt","w",stdout);
//#endif
    int n;
    cin>>n;
    string s;

    cout<<0<<endl;
    fflush(stdout);
    cin>>s;
    if(s == "Vacant") return 0;
    else if(s == "Male")   a[0] = 1;
    else if(s == "Female") a[0] = 2;

    cout<<n-1<<endl;
    fflush(stdout);
    cin>>s;
    if(s == "Vacant") return 0;
    else if(s == "Male")   a[n-1] = 1;
    else if(s == "Female") a[n-1] = 2;

    int l = 0, r = n - 1;
    while(l < r - 1) {
        int mid = (l + r) / 2;
        cout<<mid<<endl;
        fflush(stdout);
        cin>>s;
        if(s == "Vacant") return 0;
        else if(s == "Male")   a[mid] = 1;
        else if(s == "Female") a[mid] = 2;
        if((mid - l + 1) % 2 ==0 && a[l] == a[mid]) {
            r = mid;
            continue;
        }
        if((mid - l + 1) % 2 == 1 && a[l] != a[mid]) {
            r = mid;
            continue;
        }
        if((r - mid + 1) % 2 == 0 && a[r] == a[mid]) {
            l = mid;
            continue;
        }
        if((r - mid + 1) % 2 == 1 && a[r] != a[mid]) {
            l = mid;
            continue;
        }
    }
    return 0;
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  string s,t;
  cin >> s >> t;
  int cnt=0;
  rep(i,3){
    if(s[i]==t[i])cnt++;
  }
  cout << cnt << endl;
  return 0;     
}


Measured memory_bytes: 256
#include<cstdio>
#define sc scanf
#define maxn 505
char mp[maxn][maxn];
int n,m;
int a[maxn][maxn],b[maxn][maxn];
inline char inchar(){
	char ch=getchar();
	while(ch!='#'&&ch!='.') ch=getchar();
	return ch;
}
void readin(){
	sc("%d%d",&n,&m);
	char tp;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			tp=inchar(),a[i][j]=(tp=='#'),b[i][j]=(tp=='#');

}

void work(){
	for(int i=1;i<=n;i++)
		a[i][1]=1,b[i][m]=1;

	for(int i=1;i<=n;i++){
		if(i&1){
			for(int j=1;j<m;j++)
				a[i][j]=1;
		}
	}

	for(int i=1;i<=n;i++){
		if((i&1)==0){
			for(int j=2;j<=m;j++)
				b[i][j]=1;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
			if(a[i][j]) putchar('#');
			else putchar('.');
		putchar(10);
	}
	putchar(10);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
			if(b[i][j]) putchar('#');
			else putchar('.');
		putchar(10);
	}

}

int main(){
	readin();
	work();
}

Measured memory_bytes: 2688
# include<stdio.h>

int main(){

  int a;
  int b;
  int r;

  scanf("%d %d", &a, &b);

  if((b-1) % (a-1) == 0){
    r = (b-1) / (a-1);
  }else{
    r = (b-1) / (a-1) + 1;
  }  
  
  printf("%d", r);
  return 0;
}

Measured memory_bytes: 256