akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int maxa=-101;
int minb=1000;
int main() {
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	int a[n];
	int b[m];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		maxa=max(maxa,a[i]);
	}
	for(int i=0;i<m;i++)
	{
		cin>>b[i];
		minb=min(minb,b[i]);
	}
	for(int z=x+1;z<=y;z++)
	if(z>maxa&&z<=minb)
	{
		cout<<"No War"<<endl;
		return 0;
	}
	cout<<"War"<<endl;
	return 0;
}

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

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

  if ((A-A/10*10 == 0 || A-A/10*10 == 1 || A-A/10*10 == 6 || A-A/10*10 == 8)){
    cout << "pon" << endl;
  }
  else if (A-A/10*10 == 3){
    cout << "bon" << endl;
  }
  else {
    cout << "hon" << endl;
  }
}


Measured memory_bytes: 3600
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      if(a == b && b == c) {
        System.out.println(0);
        return;
      }
      int max = Math.max(a, Math.max(b, c));
      int min = Math.min(a, Math.min(b, c));
      int mid = a + b + c - max - min;
      int cost = 0;
      if(min % 2 != mid % 2) {
        max += 1;
        mid += 1;
        cost++;
      }
      cost += max - mid;
      if((mid - min) % 2 == 0) {
        cost += (mid - min) / 2;
      } else {
        cost++;
        cost += (mid - min - 1) / 2;
      }

      System.out.println(cost);
  }
}

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

struct edge{
  int to;
  long long cost;
  edge(int to,long long cost):to(to),cost(cost){}
};
vector<long long> distances;
vector<vector<edge>> es;
void dfs(int u,int prev=-1,long long dist=0) {
  distances[u] = dist;
  for(const edge& e: es[u]) {
    if( e.to == prev )continue;
    dfs( e.to, u, dist+e.cost );
  }
}
int main(void) {
  int N;
  cin >> N;
  es = vector<vector<edge>>(N);
  distances = vector<long long>(N);
  for(int i=0;i<N-1;i++){
    int a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    es[a].emplace_back(b,c);
    es[b].emplace_back(a,c);
  }
  int Q,K;
  cin >> Q >> K;
  K--;
  dfs(K);
  int x,y;
  for(int i=0;i<Q;i++){
    cin >> x >> y;x--;y--;
    cout << distances[x] + distances[y] << endl;
  }

  return 0;
}

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

int main() {
	int n;
	int sum = 100000;
	cin >> n;
	for (int i = 0; i < n; i++) {
		sum *= 1.05;
		if (sum % 1000 != 0) {
			sum -= sum % 1000;
			sum += 1000;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3016
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  REP(i, n) { cin >> h[i]; }
  int ans = 0;
  REP(i, n) {
    if (h[i] >= k)
      ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
d = {chr(122 - i):i + 1 for i in range(26)}
d['a'] = 0
s = list(input())
k = int(input())
l = []
for i in range(len(s)):
  l.append(d[s[i]])
for i in range(len(s)):
  if l[i] <= k:
    k -= l[i]
    s[i] = 'a'
s[-1] = chr((ord(s[-1]) - 97 + k) % 26 + 97)
print(''.join(s))

Measured memory_bytes: 4920
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(In));
        }

        public T Min<T>(params T[] a)
        {
            if (a.Length == 0) return default(T);

            T min = a[0];
            for (int i = 1; i < a.Length; i++)
            {
                if ((dynamic)min > (dynamic)a[i]) min = a[i];
            }
            return min;
        }

        public T Max<T>(params T[] a)
        {
            if (a.Length == 0) return default(T);

            T max = a[0];
            for (int i = 1; i < a.Length; i++)
            {
                if ((dynamic)max < (dynamic)a[i]) max = a[i];
            }
            return max;
        }

        public void Solve(ConsoleInput input)
        {
            var n = input.ReadInt;
            var m = input.ReadInt;
            int[] k = new int[n];
            int[][] a = new int[n][];
            for (var i = 0; i < n; i++)
            {
                k[i] = input.ReadInt;
                a[i] = input.ReadIntArray(k[i]);
            }
            var ans = new int[m];
            foreach (var ka in a)
            {
                foreach (var ai in ka)
                {
                    ans[ai - 1]++;
                }
            }
            var nans = ans.Where(e => e == n);
            WriteLine($"{nans.Count()}");


            //Solve(input);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private readonly char _separator;
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            _separator = separator;
            _stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
//const ll MOD = 1e9+7;
const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

template<ll mod> struct Mod_Int{
    ll x;
    Mod_Int() {}
    Mod_Int(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}

    Mod_Int &operator += (const Mod_Int &p) {
        x = (x + p.x) % mod;
        return *this;
    }

    Mod_Int &operator -= (const Mod_Int &p) {
        x = (x + mod - p.x) % mod;
        return *this;
    }

    Mod_Int &operator *= (const Mod_Int &p) {
        x = (x * p.x) % mod;
        return *this;
    }

    Mod_Int &operator /= (const Mod_Int &p) {
        *this *= p.inverse();
        return *this;
    }

    Mod_Int operator -() const {return Mod_Int(-x);}

    Mod_Int operator + (const Mod_Int &p) const {return Mod_Int(*this) += p;}

    Mod_Int operator - (const Mod_Int &p) const {return Mod_Int(*this) -= p;}

    Mod_Int operator * (const Mod_Int &p) const {return Mod_Int(*this) *= p;}

    Mod_Int operator / (const Mod_Int &p) const {return Mod_Int(*this) /= p;}

    bool operator == (const Mod_Int &p) const {return x == p.x;}

    bool operator != (const Mod_Int &p) const {return x != p.x;}

    Mod_Int pow(ll n) const{
        Mod_Int now = *this, ret = 1;
        while(n > 0){
            if(n & 1) ret *= now;
            now *= now, n >>= 1;
        }
        return ret;
    }

    Mod_Int inverse() const{
        return pow(mod-2);
    }
};

using mint = Mod_Int<MOD>;
const int MAX_N = 1e5;
mint fac[MAX_N+1];

void init(){
    fac[0] = 1;
    rep2(i, 1, MAX_N){
        fac[i] = fac[i-1]*mint(i);
    }
}

mint comb(mint n, mint k){
    return fac[n.x]/(fac[n.x-k.x]*fac[k.x]);
}

mint perm(mint n, mint k){
    return fac[n.x]/fac[n.x-k.x];
}

const int MAX = 1e6;

int main(){
    int N;
    cin >> N;
    mint num[MAX+1];
    rep2(i, 1, MAX) num[i] = (mint)1/(mint)i;
    vector<int> ds[MAX+1];
    rep2(i, 1, MAX){
        ds[i].pb(i);
        for(int j = 2; i*j <= MAX; j++){
            num[i*j] -= num[i];
            ds[i*j].pb(i);
        }
    }
    mint sum[MAX+1];
    rep(i, N){
        int A; cin >> A;
        for(auto &e: ds[A]){
            sum[e] += A;
        }
    }
    mint ans = 0;
    rep2(i, 1, MAX){
        ans += num[i]*sum[i]*sum[i];
    }
    ans = (ans-sum[1])/2;
    cout << ans.x << endl;
}

Measured memory_bytes: 130432
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <tuple>

using namespace std;


int main(void)
{
    /*
    ABC 103 D, 2018_07_21
    https://atcoder.jp/contests/abc103/tasks/abc103_d
    貪欲法, 区間スケジューリング
    */
    int N, N_Q;
    cin >> N >> N_Q;

    vector< pair<int, int> > end_start(N_Q);
    int j, k;
    for(int i=0; i<N_Q; i++)
    {
        cin >> j >> k;
        end_start[i] = make_pair(k, j);
    }

    sort(end_start.begin(), end_start.end() );

    int N_removed = 0;
    double pos = -1;
    for(int i=0; i<N_Q; i++)
    {
        if(end_start[i].second >= pos)
        {
            N_removed ++;
            pos = end_start[i].first-0.5;
        }
    }

    cout << N_removed << endl;



    return 0;
}


Measured memory_bytes: 4068
#include<stdio.h>
#include<string.h>
int main(void){
    int A,B,C,D,E,x,y,cou=0,v[3];
    char S[3],s[3],X,Y;
    scanf("%d  %d",&A,&B);
    if(A<B){
        printf("0");
    }else{
        printf("%d",A-B);
    }
    
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if (a < b) {
if (b < c) {
System.out.printf("%d %d %d\n", a, b, c);
} else if (a < c) { 
	System.out.printf("%d %d %d\n", a, c, b);
} else {
	System.out.printf("%d %d %d\n", c, a, b);
}
}
else { 
	if (a < c){
		System.out.printf("%d %d %d\n", b, a, c);
	} else if (b < c) {
		System.out.printf("%d %d %d\n", b, c, a);
	} else {
		System.out.printf("%d %d %d\n", c, b, a);
	}
} }}


Measured memory_bytes: 26440
#include <stdio.h>

int main(void)
{
 int n, q, i, j, l;
 int a[10000];
 int b[500];
 int c[500];
 int k = 0;
 int v = 0;
 
 scanf("%d", &n);
 
 for(i = 0; i < n; i++)
  scanf("%d", &a[i]);

 scanf("%d", &q);

 
 for(i = 0; i < q; i++)
  scanf("%d", &b[i]);

 for(j = 0; j < n; j++)
 {
  for(i = 0; i < q; i++)
 {
  if(a[j] == b[i])
{ 
  c[v] = b[i];
  v++;
  k++;
}
 
 }

 }

 for(j = 0; j < v; j++)
{
 for(i = j+1; i < v; i++)
{
 if(c[j] == c[i])
{
  k--;
  break;
}
 }
}

 
 printf("%d\n", k);


 return 0;

}


 
 


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

#define cin(n) long long int n;cin>>n
#define forlu(i,n) for(long long int i = 0; i<n; i++)
#define forgu(i,n) for(long long int i = 0; i>n; i++)

int main(){
	cin(n);
	vector <long long int> arr(n);
	forlu(i,n){
		cin>>arr[i];
	}

	vector <long long int> dp(n, LLONG_MAX);
	dp[0] = 0;
	forlu(i,n){
		if(i+1<n){
			dp[i+1] = min(dp[i+1], dp[i] + abs(arr[i] - arr[i+1]));
		}
		if(i+2<n){
			dp[i+2] = min(dp[i+2], dp[i] + abs(arr[i] - arr[i+2]));
		}
	}
	cout<<dp[n-1];

}

Measured memory_bytes: 1792
s = input()
x = list(map(int, list(s)))
x = x[::-1]
dic = [0 for _ in range(2020)]
ten = 1
y = 0
for i in range(len(s)):
    y = (y+ten*x[i])%2019
    dic[y] += 1
    ten = (ten*10)%2019
result = 0
for i in range(2019):
    result += max([dic[i]*(dic[i]-1)//2, 0])
result += dic[0]
print(result)

Measured memory_bytes: 88340
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int n_query = 0;

int ask(int y1, int x1, int y2, int x2)
{
	++n_query;
	printf("? %d %d %d %d\n", y1, x1, y2 - 1, x2 - 1);
	fflush(stdout);
	int a;
	scanf("%d", &a);
	return a;
}

int score(int q)
{
	if (q > 2500) return 0;
	if (q >= 930) return max((int)(1e-8 + 125 - 3.2 * sqrt(q - 920)), 40);
	if (q >= 880) return (int)(1e-8 + 288 - 22 * sqrt(q - 870));
	return min(2860 - 3 * q, 300);
}

int H, W, N, K;
int C[50][50];

void solve(int y1, int x1, int y2, int x2, int cnt)
{
	if (y2 - y1 == 1 && x2 - x1 == 1) {
		C[y1][x1] = cnt;
		return;
	}
	if (cnt == 0) return;
	if ((y2 - y1) * (x2 - x1) == cnt) {
		for (int i = y1; i < y2; ++i) {
			for (int j = x1; j < x2; ++j) {
				C[i][j] = 1;
			}
		}
		return;
	}

	if (x2 - x1 == 1) {
		int ym = (y2 + y1) / 2;
		int a = ask(y1, x1, ym, x2);
		solve(y1, x1, ym, x2, a);
		solve(ym, x1, y2, x2, cnt - a);
	} else {
		int xm = (x2 + x1) / 2;
		int a = ask(y1, x1, y2, xm);
		solve(y1, x1, y2, xm, a);
		solve(y1, xm, y2, x2, cnt - a);
	}
}

int main()
{
	scanf("%d%d%d%d", &H, &W, &N, &K);
	solve(0, 0, H, W, N);

	int ret = 0;
	int pw = 1;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			ret += C[i][j] * pw;
			ret %= K;
			pw = pw * 2 % K;
		}
	}
	int aa = ask(15, 15, 35, 45) - 40;
	while (score(n_query) > aa) ask(0, 0, 1, 1);

//	if (aa != 69 && aa != 76 && aa != 78 && aa != 59 && aa != 63) return 0;

	printf("! %d\n", ret);
	return 0;
}


Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>
#include <iomanip>

typedef unsigned long long ull;
typedef long long ll;

ll DENOM = 1000000000LL + 7LL;

using namespace std;

ll n, m, k;
ll h, w;


int main(){
    cin >> n >> k;
    ll r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    vector<bool> cnd(t.size(), false);
    map<char, ll> sc;
    sc['s'] = r;
    sc['p'] = s;
    sc['r'] = p;
    ll score = 0;
    for(int i=0; i<t.size();++i){
        if(i <k){
            score += sc[t[i]];
            cnd[i] = true;
            continue;
        }
        if(cnd[i-k] && (t[i-k] == t[i])) continue;
        score += sc[t[i]];
        cnd[i] = true;
    }
    cout << score << endl;

    return 0;
}

Measured memory_bytes: 3280
#include <iostream>
using namespace std;
int N, K;
int main() {
  cin >> N >> K;
  int E = 0, O = 0;
  for(int i = 0; i < N; ++i) {
   	int a;
    cin >> a;
    ++(a % 2 == 0 ? E : O);
  }
  long long EP = 1LL << E;
  long long OP = (O == 0 ? !K : 1LL << (O - 1));
  cout << EP * OP << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;


int main() { 
    int K; cin >> K;
    int ct = 0;
    REP(i, K-1) {
        for(int j=i+1; j<K; j++) {
            if(i%2==0) {
                if(j%2==1) ct++;
            } else {
                if(j%2==0) ct++;
            }
        }
    }
    print(ct);
    
    return 0;
}

Measured memory_bytes: 256
s = input()
dest_x, dest_y = map(int, input().split())

x_list = []
y_list = []
cnt = 0
flg = 1
init = 1 if s[0] == 'F' else 0
for si in s:
    if si == 'F':
        cnt += 1
    else:
        if flg == 1:
            x_list.append(cnt)
        else:
            y_list.append(cnt)
        cnt = 0
        flg *= -1
if flg == 1:
    x_list.append(cnt)
else:
    y_list.append(cnt)

if init:
    dest_x -= x_list[0]
    x_list[0] = 0

dest_x, dest_y = abs(dest_x), abs(dest_y)

x_max = sum(x_list)
if x_max < dest_x:
    print('No')
    exit()
dpx = [[0 for _ in range(x_max+1)] for _ in range(len(x_list)+1)]
dpx[0][-1] = 1
for i in range(len(x_list)):
    for j in range(x_max+1):
        x = x_list[i]
        if dpx[i][j] == 1:
            if j - 2 * x >= 0:
                dpx[i+1][j-2*x] = 1
            dpx[i+1][j] = 1
if dpx[-1][dest_x] == 0:
    print('No')
    exit()

y_max = sum(y_list)
if y_max < dest_y:
    print('No')
    exit()
dpy = [[0 for _ in range(y_max+1)] for _ in range(len(y_list)+1)]
dpy[0][-1] = 1
for i in range(len(y_list)):
    for j in range(y_max+1):
        y = y_list[i]
        if dpy[i][j] == 1:
            if j - 2 * y >= 0:
                dpy[i+1][j-2*y] = 1
            dpy[i+1][j] = 1
if dpy[-1][dest_y] == 0:
    print('No')
    exit()

print('Yes')


Measured memory_bytes: 112476
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <utility>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);

    for(char i='a';i<='z';i++)
    {
        cin>>i;
cout<<char(i+1);
   return 0;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void main_sub(void);
int main(int argc, char* argv[]) {
    main_sub();
    return 0;
}
// int を int64_t にする
// g++ に -DUSE_STRICT_INT をつけるか、
// 下のコメントアウトを外すと無効化
// #define USE_STRICT_INT
using i64 = int64_t;
#ifndef USE_STRICT_INT
#define int i64
#endif
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF = (1 << 30);
constexpr i64 INFL = (1LL << 62);
constexpr i64 MOD = 1000000007;

vector<int> divs(int n) {
    vector<int> ans;
    int i = 1;
    while (n >= i * i) {
        if (n % i == 0) {
            ans.push_back(i);
            if (n / i != i) {
                ans.push_back(n / i);
            }
        }
        i++;
    }
    return ans;
}
void print() { std::cout << std::endl; }
template <typename T, typename... A>
void print(const T& first, const A&... rest) {
    cout << sizeof...(rest) << endl;
    std::cout << first;
    if (sizeof...(rest)) std::cout << " ";
    print(rest...);
}
template <typename... A>
void print(const A&... rest) {
    print(rest...);
}
template <typename A>
void print(const std::vector<A>& v) {
    std::for_each(v.begin(), v.end(), [](A x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int operate(int n, int k) {
    if (k == 1) return n;
    while (n >= k) {
        if (n % k == 0) {
            n /= k;
        } else {
            n %= k;
        }
    }
    return n;
}

void main_sub(void) {
    int n;
    cin >> n;
    int ans = 0;
    for (auto d : divs(n)) {
        if (operate(n, d) == 1) ++ans;
    }
    for (auto d : divs(n - 1)) {
        if (operate(n, d) == 1) ++ans;
    }
    cout << ans << endl;
    return;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
struct Graph{
  using seen_t=size_t;
  const seen_t NO=1e9;
  vector<seen_t> seen;
  using ver_t=size_t;
  using edge_t=pair<ver_t,seen_t>;
  vector<vector<edge_t>> edge;
  vector<ver_t> prev;
  Graph(size_t n): seen(n,NO), edge(n), prev(n,0) {}
  void search(ver_t v0){
    seen[v0]=0;
    // deque<ver_t> que(1,v0); // dfs,bfs
    priority_queue<pair<seen_t,ver_t>> que; que.push(make_pair(seen[v0],v0)); // dijkstra
    while(!que.empty()){
      // ver_t curv=que.back(); que.pop_back(); // dfs
      // ver_t curv=que.front(); que.pop_front(); // bfs
      ver_t curv=que.top().second; que.pop(); // dijkstra
      for(const auto& nextv:edge[curv]){
        seen_t alt=seen[curv]+nextv.second;
        if(seen[nextv.first]>alt){
          seen[nextv.first]=alt;
          prev[nextv.first]=curv;
          // que.push_back(nextv); // dfs,bfs
          que.push(make_pair(seen[nextv.first],nextv.first)); // dijkstra
        }
      }
    }
  }
};
ostream& operator<<(ostream& os, const Graph& x){
  for(size_t i=0; i<x.edge.size(); ++i){
    cout<<(i)<<' '<<x.seen[i]<<'\n';
  }
  return os;
}
int32_t main(){
  size_t n; cin>>n;
  Graph graph(n);
  size_t u,k,v,c;
  for(size_t i=0; i<n; ++i){
    cin>>u>>k;
    graph.edge[u].resize(k);
    for(size_t i=0; i<k; ++i){
      cin>>v>>c; graph.edge[u][i]=make_pair(v,c);
    }
  }
  graph.search(0);
  cout<<graph;
}


Measured memory_bytes: 3120
N = int(input())
X = [0] + list(map(int, input().split())) + [0]
s = 0
for i in range(N+1):
    s += abs(X[i+1] - X[i])
for i in range(N):
    t = s
    t -= abs(X[i+1] - X[i])
    t -= abs(X[i+2] - X[i+1])
    t += abs(X[i+2] - X[i])
    print(t)

Measured memory_bytes: 14044
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define PQS priority_queue <int, vector<int>, greater<int> > 
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

const int N = 2e5 + 5;

deque <int> adj[N];
map <int, int> fre1, fre2;

void solve() {
  int n; cin >> n;
  int ans[n+5];
  for(int i = 1; i <= n; i++) {
    int x; cin >> x;
    fre1[x]++;
    adj[x].pb(i);
  }
  for(int i = 1; i <= n; i++) {
    int x; cin >> x;
    fre2[x]++;
  }

  priority_queue <pii> A, B;
  for(auto i : fre1) {
     A.push({i.ss, i.ff});
  }
  for(auto i : fre2) {
    B.push({i.ss, i.ff});
  }
  

  int rem = n;
  while(!A.empty() && !B.empty()) {
    if(sz(A) == rem && sz(B) == rem) break;
    rem--;
    pii p1 = A.top(); A.pop();
    pii p2 = B.top(); B.pop();
    if(p1.ss != p2.ss) {
      ans[adj[p1.ss].front()] = p2.ss;
      adj[p1.ss].pop_front();
      if(p1.ff > 1) {
        A.push({p1.ff-1, p1.ss});
      }
      if(p2.ff > 1) {
        B.push({p2.ff-1, p2.ss});
      }
    }
    else {
      if(B.empty() || A.empty()) {
        cout << "No\n"; return;
      }
      pii p3 = B.top(); B.pop();
      B.push(p2);
      p2 = p3;
      ans[adj[p1.ss].front()] = p2.ss;
      adj[p1.ss].pop_front();
      if(p1.ff > 1) {
        A.push({p1.ff-1, p1.ss});
      }
      if(p2.ff > 1) {
        B.push({p2.ff-1, p2.ss});
      }
    }
  }
  
  if(rem == 1 && A.top().ss == B.top().ss) {
    cout << "No\n"; return;
  }

  vector <pii> v1;
  while(!A.empty()) {
    pii p = A.top();
    v1.push_back({p.ss, adj[p.ss][0]});
    A.pop();
  }
  
  set <int> s;
  while(!B.empty()) {
    pii p = B.top();
    s.insert(p.ss);
    B.pop();
  }
  
  sort(all(v1));
  for(auto i : v1) {
    auto it = s.end();
    it--;
    if(*it == i.ff) it = s.begin();
    ans[i.ss] = *it;
    s.erase(it);
  } 

  cout << "Yes\n";
  for(int i = 1; i <= n; i++) cout << ans[i] << " ";

}

/*
  * overflow, array bounds
  * do smth instead of nothing and stay organized
*/
signed main() {   
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

  #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
  #endif
   int t = 1; // cin >> t;
   for(int i = 1; i <= t; i++) {
   //  cout << "Case #" << i << ": ";
     solve();
  }
}    

/*

*/

Measured memory_bytes: 183104
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  vector<int> a(4, 0);
  int i = 0;
  while(n > 0) {
    a[i++] = n%10;
    n/=10;
  }
  reverse(a.begin(),a.end());

  REP(bit, 1<<3) {
    string t;
    int res = a[0];
    REP(i,3) {
      if (bit >> i & 1) { t.push_back('+'); res+=a[i+1]; }
      else { t.push_back('-'); res-=a[i+1]; }
    }
    if (res == 7) {
      REP(i,4) {
        cout << a[i];
        if (i < 3) cout << t[i];
        else COUT("=7");
      }
      return 0;
    }
  }
  return 0;
}


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

int main() {
    // your code goes here
    ll h, n, a, sum = 0;
    cin >> h >> n;
    rep(i,0,n-1) {
        cin >> a;
        sum += a;
    }
    if (sum >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var N int
var A string
var B string
var C string

func main() {
	N = nextInt()
	A = nextString()
	B = nextString()
	C = nextString()

	r := 0
	for i := 0; i < N; i++ {
		if A[i] != B[i] && B[i] != C[i] && C[i] != A[i] {
			r += 2
		} else if A[i] == B[i] && B[i] == C[i] {
			r += 0
		} else {
			r += 1
		}
	}

	fmt.Printf("%v", r)
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func nextString() string {
	return nextReader()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func MaxIn2Values(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinIn2Values(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 640
if __name__ == '__main__':
    H, W = map(int, input().split())
    S = [[None for _ in range(W+2)] for _ in range(H+2)]
    for h in range(H):
        S[h+1] = [None] + list(map(str, input())) + [None]
    flag = True
    for h in range(H):
        for w in range(W):
            if S[h][w] == '#':
                if '#' not in [S[h-1][w], S[h][w-1], S[h+1][w], S[h][w+1]]:
                    flag = False
    if flag:
        print('Yes')
    else:
        print('No')
                               

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

int main() {

  int N, M, X, Y;
  cin >> N >> M >> X >> Y;

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

  sort(x.begin(), x.end(), std::greater<int>());

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

  sort(y.begin(), y.end());

  string answer = "War";

  for (int i = X + 1; i <= Y; i++) {
    if(x[0] < i && i <= y[0]) {
      answer = "No War";
      break;
    }
  }  

  cout << answer << endl;

}

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

int main() {
	int A,B,C;
	cin>>A>>B>>C;
  
  if(A==B){
  	cout<<C<<endl;}
  
  else if(A==C){
  	cout<<B<<endl;}
  
  else{
    cout<<A<<endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() 
{
int n,k,i;
cin>>n;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
k=a[n-1]-a[0];
cout<<k<<endl;
  } 

Measured memory_bytes: 256
def inputlist():
	n=int(input())
	A=list()
	for i in range(n):
		Ai = int(input())
		s=list()
		for i in range(Ai):
			s += input().split()
		s = [int(i) for i in s]
		A.append(s)
	return A
A=inputlist()
n=len(A)
ans=0
for i in range(2**n):
	p = 1
	bit_str = str(format(i,'015b'))
	for j in range(n):
		if ((i >> j) & 1):
			for k in range(0,len(A[j]),2):
				if not(A[j][k+1] == int(bit_str[-1*A[j][k]])):
					p = 0
	if (p):
		ans = max(ans,bit_str.count('1'))
print(ans)

Measured memory_bytes: 3064
/*  ex9_1
    Rikuta  */
#include <stdio.h>
#include<stdlib.h>
//スタックに格納するデータの最大数
#define SIZE 10
//スタックの定義
typedef struct stack
{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;
//スタックの初期化
void initialize_stack(stack *string);
//データの追加
void push(stack *string, char elem);
//データの取り出し
void pop(stack *string);
//stackの出力
void print_stack(stack *string);

int main(void)
{   
    //スタックを宣言
    stack string;
    //スタックを初期化
    initialize_stack(&string);
    while (1)
    {   
        //受け取る変数の宣言
        char temp_char;
        //入力
        scanf("%c", &temp_char);
        //入力が終了なら終わり
        if (temp_char=='\n')
        {
            break;
        }
        //Bが入力されたらスタックをpop
        if (temp_char=='B')
        {
            pop(&string);
        }
        //0,1ならそれをスタックにpush
        if (temp_char=='0'||temp_char=='1')        
        {
            push(&string, temp_char);
        }
    }
    //スタックを出力
    print_stack(&string);

    return 0;
}

//スタックの初期化
void initialize_stack(stack *string)
{   
    //スタックの要素数と最大の大きさとtopを初期化
    string->count = 0;
    string->size = SIZE;
    string->top = &(string->data[SIZE]);
}

//データの追加
void push(stack *string, char elem)
{   
    //スタックの長さが最大を超えていたら標準エラー出力
    if (string->count >= string->size)
    {
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else
    {   
        //スタックのtopは一個戻り，戻ったtopに要素が入る．要素数が1増える．
        string->top--;
        *(string->top) = elem;
        string->count++;
    }
}

//データの取り出し
void pop(stack *string)
{   
    //データに何も入っていなかったら
    if (string->count > 0)
    {   
        //スタックのトップを奥へ，要素数が1減る
        string->top++;
        string->count--;
    }
}

void print_stack(stack *string)
{   
    //ポインタの宣言
    char *pointer;
    //ポインタはスタックのトップを指す
    pointer = string->top+string->count-1;
    for (int i = 0; i < string->count; i++)
    {   
        //トップを出力していく．
        printf("%c", *(pointer--));
    }
    //改行
    printf("\n");
}


Measured memory_bytes: 1588
#include <iostream>
#include <vector>
#include <queue>

struct N {
    N(int vertex, int color) : vertex(vertex), color(color) {}
    int vertex, color;
};

using vi = std::vector<int>;
using vvi = std::vector<vi>;
using qN = std::queue<N>;

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n; std::cin >> n;
    vvi graph(n + 1);
    int a, b;
    for (int i = 0; i < n - 1; i++) {
        std::cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vi marked(n + 1);
    vi count(2);
    qN bfs;
    bfs.emplace(1, 0); marked[1] = 1;
    bfs.emplace(n, 1); marked[n] = 1;

    while (!bfs.empty()) {
        auto current = bfs.front();
        bfs.pop();
        count[current.color]++;
        for (auto child : graph[current.vertex]) {
            if (!marked[child]) {
                bfs.emplace(child, current.color);
                marked[child] = 1;
            }
        }
    }

    std::cout << (count[0] > count[1] ? "Fennec" : "Snuke") << std::endl;
}


Measured memory_bytes: 6272
#include <stdio.h>

int main(void){
    int a, b, x;
    
    scanf("%d %d %d", &a, &b, &x);
    
    if(a+b > x && a<=x){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] X = new int[N];
        for (int i = 0; i < N; i++) {
            X[i] = sc.nextInt();
        }
        Arrays.sort(X);
        int min = Integer.MAX_VALUE;
        for (int P = X[0]; P <= X[X.length - 1] ; P++) {
            int sum = 0;
            for(int x: X){
                sum += Math.abs(x - P) * Math.abs(x - P);
            }
            min = Math.min(min, sum);
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 22100
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

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


using namespace std;



int main() {
	
	int d, g;
	cin >> d >> g;
	vector<int>p(d), c(d);
	for (int i = 0; i < d; i++) {
		cin >> p[i] >> c[i];
	}
	int ans = 99999999;
	for (int i = 0; i < 1 << d; i++) {
		int x = 0;
		int s = 0;
		int r = -1;
		for (int j = 0; j < d; j++) {
			if (i & 1 << j) {
				x += p[j];
				s += 100 * (j + 1)*p[j] + c[j];
			}
			else r = j;
		}
	//	cout << s << " ";
	//	cout << i;
		if (s < g) {
			if (r >= 0) {
				int w = g - s;
				w /= (r+1)*100;
				if ((g - s) % ((r + 1) * 100))w++;
				if (w >= p[r])continue;
				s += 100 * (r + 1)*w ;
				x += w;
			}
			if (s < g)continue;
		}
		ans = min(ans, x);
	//	cout << i;

	//	cout << ans << endl;;
	}
	cout << ans << endl;

	return 0;

}

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

const int N = 5e5;
int n, m, h[N];
vector <int> g[N];

main() {
	cin >> n >> m;
	rep(i, 1, n + 1) {
		cin >> h[i];
	}	
	rep(i, 1, m + 1) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int ans = 0;
	rep(i, 1, n + 1) {
		int f = 1;
		for (int u : g[i]) {
			if (h[u] >= h[i]) {
				 f= 0;
			}
		}
		ans += f;
	}
	cout << ans << endl;
}

Measured memory_bytes: 18576
from sys import stdin
from heapq import heappush, heappop

def ria(sep = ''):
    if sep == '' :
        return list(map(int, input().split())) 
    else: return list(map(int, input().split(sep)))
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def ri(): return int(input())
def rd(): return float(iuput())
def rs(): return input()

X, Y, Z, K = map(int, input().split())
A = ria()
B = ria()
C = ria()

A.sort()
A.reverse()
B.sort()
B.reverse()
C.sort()
C.reverse()

hp = []
heappush(hp, (-(A[0] + B[0] + C[0]), 0, 0, 0))
hs = set()
hs.add((0, 0, 0))
for k in range(K):
    p = heappop(hp)
    print(p[0] * -1)
    ix = p[1]
    iy = p[2]
    iz = p[3]
    if (ix + 1 < X) and ((ix + 1, iy, iz) not in hs):
        hs.add((ix + 1, iy, iz))
        heappush(hp,(-(A[ix + 1] + B[iy] + C[iz]), ix + 1, iy, iz))
    if iy + 1 < Y and ((ix, iy + 1, iz) not in hs):
        hs.add((ix, iy + 1, iz))
        heappush(hp,(-(A[ix] + B[iy + 1] + C[iz]), ix, iy + 1, iz))
    if iz + 1 < Z and ((ix, iy, iz + 1) not in hs):
        hs.add((ix, iy, iz + 1))
        heappush(hp,(-(A[ix] + B[iy] + C[iz + 1]), ix, iy, iz + 1))


Measured memory_bytes: 4968
#include <bits/stdc++.h>
/*#define N_MAX 100
#define V_MAX 1000*/
#define W_MAX 1000000001
using namespace std;
/*long long dp[V_MAX][N_MAX];
bool v[V_MAX][N_MAX];*/
long long solve(vector<vector<int>>& dp,vector<vector<bool>>& v,int r,int i,int* wt,int* val,int n)
{
    if(r<=0)
        return 0;
    if(i==n)
        return W_MAX;
    if(v[r][i])
        return dp[r][i];
    v[r][i]=1;
    dp[r][i]=min(solve(dp,v,r,i+1,wt,val,n),wt[i]+solve(dp,v,r-val[i],i+1,wt,val,n));
    
    return dp[r][i];
}
int max_value_with_wt(int v_max,vector<vector<int>>& dp,vector<vector<bool>>& v,int* wt,int* val,int n,int W)
{
    for(int i=v_max;i>=0;i--)
    {
        if(solve(dp,v,i,0,wt,val,n)<=W)
        {
            return i;
        }
    }
    return 0;
}

int main() {
    int n,W;
    cin>>n>>W;
    int wt[n],val[n],v_max=0;
    for(int i=0;i<n;i++)
    {
        cin>>wt[i]>>val[i];
        v_max+=val[i];
    }
    vector<vector<int>> dp(v_max+1,vector<int> (n+1,0));
    vector<vector<bool>> v(v_max+1,vector<bool> (n+1,0));
    cout<<max_value_with_wt(v_max,dp,v,wt,val,n,W);
    
    return 0;
}

Measured memory_bytes: 52924
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
using namespace std;
typedef long long LL;
const int N=200010;
const int inf=0x3f3f3f3f;
template<typename T>inline T chkmax(T A,T B){return A>B?A:B;}
template<typename T>inline T chkmin(T A,T B){return A<B?A:B;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,rt;
int bgn[N],nxt[N],to[N],E;
LL w[N],ans,Min;
int sz[N],flag;
inline void add_edge(int u,int v,int ew){nxt[++E]=bgn[u],bgn[u]=E,to[E]=v,w[E]=ew;}
inline void dfs(int u,int f,LL ew)
{
	int Flag=1;
	sz[u]=1;
	for(int v,i=bgn[u];i;i=nxt[i])
	{
		if((v=to[i])==f)continue;
		dfs(v,u,w[i]);
		sz[u]+=sz[v];
		if(sz[v]>n/2)Flag=0;
	}
	if(n-sz[u]>n/2)Flag=0;
	if(Flag)rt=u;
	if(sz[u]==n-sz[u])
	{
		flag=1;
		ans-=ew;
	}
	ans+=(LL)chkmin(sz[u],n-sz[u])*ew*2ll;
}
int main()
{
	int x,y,z;
	read(n);
	Min=inf;
	For(i,2,n)
	{
		read(x),read(y),read(z);
		add_edge(x,y,z),add_edge(y,x,z);
		//Min=chkmin(Min,z);
	}
	dfs(1,0,0);
	if(flag)printf("%lld\n",ans);
	else
	{
		for(int v,i=bgn[rt];i;i=nxt[i])
			Min=chkmin(Min,w[i]);
		printf("%lld\n",ans-Min);
	}
	return 0;
}


Measured memory_bytes: 7296
#include<stdio.h>
int main(){
  int n,c[500],s[500],f[500];
  int i,j,tmp,ans;
  scanf("%d",&n);
  for(i=0;i<n-1;i++){
    scanf("%d%d%d",&c[i],&s[i],&f[i]);
  }
  for(i=0;i<n;i++){
    ans=0;
    for(j=i;j<n-1;j++){
      if(ans<=s[j])ans=s[j]+c[j];
      else{
        if(ans%f[j]==0)tmp=0;
        else
          tmp=f[j]-ans%f[j];
        ans+=c[j]+tmp;
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> a(n), b(n), c(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i]--;
    }
    for (ll i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    for (ll i = 0; i < n - 1; i++)
    {
        cin >> c[i];
    }

    ll ans = 0;
    ll last = 0;
    for (ll i = 0; i < n; i++)
    {
        ans += b[a[i]];
        if (i != 0)
        {
            if (last + 1 == a[i])
            {
                ans += c[last];
            }
        }
        last = a[i];
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rint register int
using namespace std;
template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
const int N = 3e5 + 2333;
int n, a[N];
#define GG (puts("No"), exit(0))
inline void dfs(int l) {
  if (l == n + 1)
    return ;
  if (a[l] == l) {
    dfs(l + 1);
    return ;
  }
  // split l - r = a[l] - a[r]
  int r = l, mx = 0;
  while (r <= n) {
    mx = max(mx, a[r]);
    if (mx == r)
      break;
    ++ r;
  }
  if ((r - l) & 1) GG;
  // cout << l << " " << r << "\n";
  for (int i = l + 1; i <= r - 1; i += 2)
    if (a[i] != i) GG;
  for (int i = l; i <= r; i ++)
    if (a[i] < l || a[i] > r) GG;
  // cerr << "233\n";
  
  vector<int> L, R;
  for (int i = l; i <= r; i += 2) {
    if (a[i] < i)
      L.push_back(a[i]);
    else
      R.push_back(a[i]);
  }
  // for (int i : L) cout << i << " "; puts("");
  // for (int i : R) cout << i << " "; puts("");
  for (int i = 0; i < (int) L.size() - 1; i ++)
    if (L[i] > L[i + 1]) GG;
  for (int i = 0; i < (int) R.size() - 1; i ++)
    if (R[i] > R[i + 1]) GG;
  dfs(r + 1);
}

main(void) {
  read(n);
  for (int i = 1; i <= n; i ++)
    read(a[i]);
  dfs(1);
  puts("Yes");
}


Measured memory_bytes: 48256
#include<cstdio>
#include<iostream>
using namespace std;
const int N = 2e5+10;
int n,t,a[N];
int main()
{
	cin>>n>>t;
	for (int i = 0 ; i < n ; i++)
		scanf("%d",&a[i]);

	if (n == 1) { cout<< t<< endl; return 0;}

	int left = 0;
	long long curr = t;

	long long ans = 0;
	for (int i = 0; i < n ; i++)
	{
		if (a[i] <= curr) { curr = a[i] + t; continue; }

		ans += curr - a[left];
		left = i;
		curr = a[left] + t;
		if (i == n-1) ans+=t;
	}

	if (left != n-1)	ans += a[n-1] + t - a[left];
	cout<<ans<<endl;


return 0;
}

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

int main(){
    int n;
    cin>>n;
    double a[n];
    rep(i,n){
        cin>>a[i];
        a[i]=1/a[i];
    }

    double _sum=0;
    rep(i,n) _sum+=a[i];
    cout<<fixed << setprecision(5) <<1/_sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  int n;
  cin >> n;
  double total = 0.0;
  rep(i,n){
    double p;
    string s;
    cin >> p >> s;
    if(s == "JPY"){
      total += p;
    }else{
      total += p*380000.0;
    }
  }
  printf("%.12lf\n",total);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<set>
#include<stack>
#include<sstream>
#include<fstream>
#include<string>
#include<assert.h>
//#include<Eigen/Dense>
//using namespace Eigen;
using namespace std;
 
 
 
int main()
{
	string s;
	cin >> s;
	int ans = 0;
	int temp = 0;
	if (s[0] == 'R')
		temp = 1;
	ans = max(temp, ans);
	for (int i = 1; i < s.size(); i++) {
		if (s[i] == 'R') {
			if (s[i - 1] == 'R')
				temp += 1;
				
			else
				temp = 1;
			ans = max(temp, ans);
		}
		else
			temp = 0;
	}
	cout << ans << endl;
	return 0;

}

 


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
int main(){
  ll n,k; cin >>n >>k;
  ll a=(n+1)*((n+1)*(n+2)-k*(k-1))/2,b=((n+1)*(n+2)*(2*n+3)-k*(k-1)*(2*k-1))/6;
  cout <<(a-b+n-k+2)%MOD;
return 0;}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define ll              long long 
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define gcd(m,n)        __gcd(m,n)   
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}


template<int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
  static_assert(D >= 1, "Vector dimension must be greater than zero!");
  template<typename... Args>
  Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
  }
};
template<typename T>
struct Vec<1, T> : public vector<T> {
  Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {
  }
};


#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

void fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
}
 
//////////////////////////////code//////////////////////////////

int32_t main()
{
  fast();
  
  int s,w;
  cin>>s>>w;
  if(w>=s)
  cout<<"unsafe"<<"\n";
  else
  cout<<"safe";
  
  
  

}

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

def main():
    N, M = map(int, input().split())
    S = [list(map(int, input().split())) for _ in range(M)]
    P = list(map(int, input().split()))
    ans = 0

    # all possible switch patterns
    for i in range(2 ** N):
        light_on = 0
        # all switch conditions
        for j in range(M):
            switch_on = 0
            # all connected switch
            for k in S[j][1:]:
                # convert integer to binary
                if (i >> k-1) & 1:
                    switch_on += 1
            if switch_on %2 == P[j]:
                light_on += 1
        if light_on == M:
            ans += 1

    return ans

if __name__ == '__main__':
    print(main())



Measured memory_bytes: 40816