akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> index = vector<int>(N, 0);
  vector<int> next_index = vector<int>(N, 0);
  vector<vector<int>> A = vector<vector<int>>(N, vector<int>(N - 1));
  REP(i, N) {
    REP(j, N - 1) {
      int n;
      cin >> n;
      n--;
      A[i][j] = n;
    }
  }

  int cnt = 0;
  while(true) {
    bool change = false;
    REP(i, N) {
      if(index[i] == N - 1) continue;
      int m = A[i][index[i]];
      if(A[m][index[m]] == i) {
        next_index[m]++;
        change = true;
      }
    }
    if(!change) {
      break;
    }
    cnt++;
    index = next_index;
  }
  bool end = true;
  REP(i, N) {
    if(index[i] != N - 1) {
      end = false;
      break;
    }
  }
  if(end) {
    cout << cnt << endl;
  } else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 6272
from math import sqrt
from collections import deque

def sub(a, b):
    return [a[0] - b[0],a[1] - b[1]]

def cross(a, b):
    return  a[0] * b[1] - a[1] * b[0]

def ccw(a, b, c):
    x = sub(b, a)
    y = sub(c, a)
    return cross(x, y) > 0

n = int(input())
c = [list(map(int, input().split())) for i in range(n)]
c.sort(key=lambda x: (x[0], x[1]))
U = deque(c[:2])

for i in range(2, n):
    j = len(U)
    while j >= 2 and ccw(U[-1],U[-2],c[i]):
        U.pop()
        j -= 1
    U.append(c[i])

c = c[::-1]
L = deque(c[:2])

for i in range(2, n):
    j = len(L)
    while j >= 2 and ccw(L[-1], L[-2], c[i]):
        L.pop()
        j -= 1
    L.append(c[i])

ans = U
for i in range(1,len(L)-1):
    x, y = L[i]
    ans.append([x,y])

print(len(ans))
i = ans.index(sorted(ans, key=lambda x: (x[1],x[0]))[0])
ans = list(ans)
for x,y in ans[i:] + ans[:i]:
    print(x, y)


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    int a, b; cin >> a >> b;
    a--;b--;
    cout << a * b << endl;

    

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<stack>
#include<vector>
#define INFTY 10000000000
using namespace std;

int main(){
  int N,W;
  cin>>N>>W;
  int w[120],v[120];
  long long dp[120][120000]={0};
  for(int i=1;i<=N;i++){
    cin>>w[i]>>v[i];
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<=W;j++){
      dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
      if(w[i+1]+j>W) continue;
      dp[i+1][w[i+1]+j]=max(dp[i+1][w[i+1]+j],dp[i][j]+v[i+1]);
    }
  }
  cout<<dp[N][W]<<endl;

}


Measured memory_bytes: 112896
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program {
    static void Main() {
        var h = NextInt();
        var w = NextInt();

        var cnt = 0;
        foreach (var i in Enumerable.Range(0, h)) {
            var a = NextString();
            foreach (var c in a) {
                if (c == '#') { cnt++; }
            }
        }
        if (cnt == h + w - 1) {
            WriteLine("Possible");
        } else {
            WriteLine("Impossible");
        }
    }

    static int NextInt() {
        return int.Parse(NextString());
    }

    static string NextString() {
        var result = new List<char>();
        while (true) {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll n,k;
vector<ll> a;

void input(){
    cin >> n >> k;
    a.resize(n);
    for(int i=0;i<n;i++) cin >> a[i];
}

ll GCD(ll a, ll b){
    if(b == 0) return a;
    else return GCD(b, a%b);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    ll tmp = a[0]; // {a}の最大公約数を求める
    ll mx = a[0];
    for(int i=1;i<n;i++){
        tmp = GCD(tmp, a[i]);
        mx = max(mx, a[i]);
    }
    if(k > mx){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    if(k % tmp == 0){
        cout << "POSSIBLE" << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

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

using namespace std;

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

    int cnt = 0;
    string s;

    cin >> s;

    for(int i=0;i<s.length();i++)
    {
    	if(s[i]=='o')
    	{
    		cnt++;
    	}
    }

    if(cnt + (15 - s.length())>=8)
    {
    	cout << "YES" << '\n';
    }
    else
    {
    	cout << "NO" << '\n';
    }

    return 0;
}

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

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

  int A, B;
  int CurrentInt = 1;
  for (int i = 0; i < N; i++) {
    A = 2 * CurrentInt;
    B = K + CurrentInt;
    CurrentInt = min(A, B);
  }

  cout << CurrentInt << endl;

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.txt"


int main() {
	string st;
	while (getline(cin,st)) {
		string ans;
		for (int i = 0; i < st.size(); ++i) {
			if (st[i] == '@') {
				int num = st[i + 1] - '0';
				for (int j = 0; j < num; ++j) {
					ans.push_back(st[i + 2]);
				}
				i += 2;
			}
			else {
				ans.push_back(st[i]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3112
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val Mod = 1000000007L
  val (a, c, g, t) = (0, 1, 2, 3)
  val dp = Array.ofDim[Long](n + 1, 4, 4, 4)
  dp(0)(t)(t)(t) = 1

  def valid(p3: Int, p2: Int, p1: Int, cur: Int): Boolean = !(
               p2 == a && p1 == g && cur == c ||
               p2 == g && p1 == a && cur == c ||
               p2 == a && p1 == c && cur == g ||
    p3 == a &&            p1 == g && cur == c ||
    p3 == a && p2 == g &&            cur == c)

  for {
    i <- (1 to n)
    p3 <- (0 to 3)
    p2 <- (0 to 3)
    p1 <- (0 to 3)
    cur <- (0 to 3)
    if (valid(p3, p2, p1, cur))
  } {
    dp(i)(p2)(p1)(cur) = (dp(i)(p2)(p1)(cur) + dp(i - 1)(p3)(p2)(p1)) % Mod
  }
  println(dp(n).map(_.map(_.sum % Mod).sum % Mod).sum % Mod)
}

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

int main() {
	int a, b, c;
	
	cin >> a >> b >> c;
	if((c > a && c < b) || (c > b && c < a)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

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

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

    if(S == "SUN") cout << "7" << endl;
    else if(S == "MON") cout << "6" << endl;
    else if(S == "TUE") cout << "5" << endl;
    else if(S == "WED") cout << "4" << endl;
    else if(S == "THU") cout << "3" << endl;
    else if(S == "FRI") cout << "2" << endl;
    else cout << "1" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		FastReader in = new FastReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		long a = in.nextLong();
		long b = in.nextLong();
		long k = in.nextLong();
		for (int i = 1; i <= k; i++) {
			if (i % 2 != 0) {
				if (a % 2 != 0) {
					a -= 1;
					a = a / 2;
					b += a;
				} else {
					a = a / 2;
					b += a;
				}
			} else {
				if (b % 2 != 0) {
					b -= 1;
					b = b / 2;
					a += b;
				} else {
					b = b / 2;
					a += b;
				}
			}
		}
		out.println(a + " " + b);
		out.flush();
		out.close();

	}
	// 70376445703718

	static class FastReader {
		StringTokenizer st;
		BufferedReader br;

		public FastReader(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public FastReader(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}

}

Measured memory_bytes: 22996
#include <iostream>
#include <unordered_set>

using namespace std;

int main(){
	int n;
	cin >> n;
	unordered_set<string> col;
	while(n--){
		string s;
		cin >> s;
		col.insert(s);
	}
	cout << col.size() << endl;
	return 0;
}



Measured memory_bytes: 13964
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
  int n,x;
  cin>>n>>x;
  int a[n];
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  int ans=0,f=2;
  rep(i,n){
  //  if(x<a[i]) break;
  //  tmp=i;
    x-=a[i];
    if (x==0) {f=0;break;}
    if (x<0) {f=1;break;}
    ans++;}
    if (f==0) ans++;
    if (f==2) ans--;

   cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	long long n,m,ans=0;
	scanf("%lld%lld",&n,&m);
	if(n>m)
	{
		cout<<"0"<<endl;
		return 0;
	}
	if(m%n==0)
	{
		cout<<m/n<<endl;
		return 0;
	}
	for(long long i=1;i<=m;i++)
	{
		if(m%i==0&&m/i>=n)
		ans=i;
		if(m/i<n) break;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
# 座標A、速度V
a, v = map(int, input().split())

# 座標B、速度W
b, w = map(int, input().split())

# 時間T
t = int(input())

# 座標の差と速度の差
sa_x = abs(b-a)
sa_v = v-w

# 速度の差×時間が座標の差以上ならOK
if (sa_v * t >= sa_x):
  print('YES')
else:
  print('NO')

Measured memory_bytes: 9176
n = int(input())
a = list(map(int, input().split()))

cnt = 0

while True:
  exist_odd = False
  for index in range(len(a)):
    if a[index] % 2 != 0:
      exist_odd = True
    a[index] /= 2
    
  if exist_odd: break
    
  cnt = cnt + 1

print(cnt)

Measured memory_bytes: 9076
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, h, w);
    Cinm(char, h*w, m);
    Cout((m['#'] == h+w-1) ? "Possible" : "Impossible");
}


Measured memory_bytes: 256
# 行列への数値入力メソッド
def deter_ins (a, b, deter)
	for i in 0..a - 1
		imput = gets.chomp.split("\s")
		for j in 0..b - 1
			deter[i][j] = imput[j].to_i
		end
	end
	return deter
end

imput = gets.chomp.split("\s")
n, m, l = imput[0].to_i, imput[1].to_i, imput[2].to_i

determinant_A = Array.new(n) { Array.new(m) }	#<= n行m列
determinant_B = Array.new(m) { Array.new(l) }	#<= m行l列

# 行列作成
a = deter_ins(n, m, determinant_A)
b = deter_ins(m, l, determinant_B)

# 計算
det_ans = Array.new(n) { Array.new(l) }	#<= n行l列の行列(回答)

for p in 0..n - 1
	for q in 0..l - 1
		sum = 0
		for r in 0..m - 1
			sum += a[p][r] * b[r][q]
		end
		det_ans[p][q] = sum
	end
end

# 出力
for k in 0..p
	puts det_ans[k].join("\s")
end

Measured memory_bytes: 6336
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  vector<int> l(n);
  for(int &c : l) {
    cin >> c;
  }
  int counter = 0;
  
  for(int i = 0; i < n -2; i++) {
    for(int j = i +1; j < n -1; j++) {
      for(int k = j +1; k < n; k++) {
        if(l.at(i) != l.at(j) && l.at(i) != l.at(k) && l.at(j) != l.at(k)) {
          vector<int> tri(3);
          tri.at(0) = l.at(i);
          tri.at(1) = l.at(j);
          tri.at(2) = l.at(k);
          sort(tri.begin(), tri.end());
          if(tri.at(2) < tri.at(1) + tri.at(0)) {
            counter++;
          }
        }
      }
    }
  }
  cout << counter << endl;
}

Measured memory_bytes: 3576
fn main() {
    let scan = std::io::stdin();

    let mut line = String::new();

    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();

    let a: i32 = vec[0].parse().unwrap_or(0);
    let b: i32 = vec[1].parse().unwrap_or(0);

    if a < b {
        println!("a < b");                                                                                                                                                                                                                       } else if a > b {
        println!("a > b");
    } else if a == b {
        println!("a == b");
    }
}


Measured memory_bytes: 5020
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
	char S[200];
	scanf("%s", S);
	int l = strlen(S);
	int ll = l / 2;
	int n = 0;
	for (int i = 0; i < ll; i++) {
		if (S[i] != S[l-i-1])
			++n;
	}
	printf("%d\n", n);
	return 0;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    string S;
    cin >> S;
    if (S[0] == 'C')
        cout << "Rainy" << endl;
    else if (S[0] == 'R')
        cout << "Sunny" << endl;
    else
        cout << "Cloudy" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb emplace_back
#define mr make_pair
#define N 1010
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
int m,n,x,y,mi[N][N],ma[N][N],vi[N][N],p[1000010],q[1000010];
vector<int> a[N];
void d1(int be,int x){
	vi[be][x]=1;
	for (auto y:a[x])if (!vi[be][y]) d1(be,y);
}
void d3(int be,int zh,int x){
	if (mi[be][x]) return ;
	mi[be][x]=zh;
	for (auto y:a[x])if (!mi[be][y]) d3(be,zh,y);
}
void d2(int be,int zh,int x){
	if (ma[be][x]) return ;
	ma[be][x]=zh;
	for (auto y:a[x])if (!ma[be][y]) d2(be,zh,y);
}
int main(){
	read(n);read(m);
	for (int i=1;i<=m;i++){read(p[i]);read(q[i]);a[p[i]].pb(q[i]);}
	for (int i=1;i<=n;i++)d1(i,i);
	for (int i=1;i<=n;i++){
		sort(a[i].begin(),a[i].end());
		ma[i][i]=mi[i][i]=i;
		for (int j=0;j<a[i].size();j++)d3(i,a[i][j],a[i][j]);
		for (int j=a[i].size()-1;j>=0;j--)d2(i,a[i][j],a[i][j]);
	}
	for (int i=1;i<=m;i++){
		int x=p[i],y=q[i];
		if (vi[y][x]^(ma[x][y]!=y||mi[x][y]!=y))puts("diff");else puts("same");
	}
	return 0;
}

Measured memory_bytes: 21248
// C++(Clang 10.0.0)

//GCC用 ナゾです
//#pragma GCC target("avx")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <stdio.h>
#include <stdlib.h> //rand() 0~RAND_MAX2147483647
#include <math.h>
#include <time.h>   //srand((unsigned int)time(NULL));
#include <unistd.h> //sleep
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <unordered_map>
#include <set>
#include <cassert> //assart(x>=0) -> x<0の時異常終了
#include <numeric>
#include <iterator>
#include <list>
#include <tuple>
#include <queue>

using namespace std;
#define ll long long int
#define FOR(i,min,max) for(ll i=(min);i<(max);i++)
#define FOReq(i,min,max) for(ll i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(ll i=(max)-1;i>=(min);i--)
#define FORREVeq(i,max,min) for(ll i=(max);i>=(min);i--)

#define all(vec) (vec).begin(),(vec).end()

const int MOD=1e9+7;
const int MOD2=998244353;
const int not0=1;
const int INF=2000000001;
const ll INFll=2e18;
//const int MAX_V=10000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INFll || MOD2 || not0){;}
    return 0;
}

#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
//#define br printf("\n");
#define br cout<<"\n";
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}
#define elif else if

#define issame(a,b,c,d) ((a)==(b) and (b)==(c) and (c)==(d))
#define isdiff3(a,b,c) ((a)!=(b) and (b)!=(c) and (c)!=(a))
#define isdiff4(a,b,c,d) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c))
#define isdiff5(a,b,c,d,e) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c) and (e)!=(a) and (e)!=(b) and (e)!=(c) and (e)!=(d))
#define Func3(f,a,b,c) (f)((f)((a),(b)),(c))
#define Func4(f,a,b,c,d) (f)((f)((f)((a),(b)),(c)),(d))

inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
inline ll samepair(ll x){return x*(x-1)/2;}
inline void printD(double d){printf("%15.15lf ",d);}
inline ll  gcd(ll a,ll b){ if(b==0)return a;else return gcd(b,a%b);}//最大公約数 なお一方が0なら答えは他方になるので番兵は０で良い また、負の数もOK -4%3=-1となるため
inline ll  lcm(ll a,ll b){return a*b/gcd(a,b);}//MODやオーバーフローには注意！
//inline ll  ceil(double a){return (ll)a+1;}
//ans = accumulate(A, A+N, 0, [](int a, int b) {return gcd(a,b);});
//auto count = std::count_if(v.begin(), v.end(), [](int x) { return x == 1 || x == 3; } );

ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

//番兵　累積和　しゃくとり法　木構造　DP キュー　乱択アルゴリズム　嘘解法　ハッシュ　next_permulation

//課題：DP 木構造　Xor




ll probNow(){
    double ans;ans=0;
    ll N;
    cin>>N;
    
    ll a[N];
    inarray(a, 0, N);
    
    ans=INF;
    ll order=0;
    FOR(i, 0, N){//i+1番目！
        if(a[i]==order+1)order++;
    }
    
    OutputAndReturn0( order==0 ? -1 : N-order);
    
    return 0;
}


signed main(){
    cin.tie(0);    //cinとcoutの結び付き解除（cout時にcinの内容を吐き出さなくなる）
    ios::sync_with_stdio(false);  //coutとprintfの結び付き解除（coutとprintfを同時に使うな！）
    probNow();
    return 0;
}


Measured memory_bytes: 1792
from collections import deque,defaultdict
import bisect
N = int(input())
S = [input() for i in range(N)]

def bend(s):
    res = 0
    k = 0
    for th in s:
        if th == '(':
            k += 1
        else:
            k -= 1
        res = min(k,res)
    return res

species = [(bend(s),s.count('(')-s.count(')')) for s in S]

ups = [(b,u) for b,u in species if u > 0]
flats = [(b,u) for b,u in species if u == 0]
downs = [(b,u) for b,u in species if u < 0]


ups.sort()
high = 0
for b,u in ups[::-1] + flats:
    if high + b < 0:
        print('No')
        exit()
    high += u

rdowns = [(b-u,-u) for b,u in downs]
rdowns.sort()
high2 = 0
for b,u in rdowns[::-1]:
    if high2 + b < 0:
        print('No')
        exit()
    high2 += u

if high == high2:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 243264
#include <iostream>

using namespace std;

int f3(int x) {
    int x_m = x % 10;
    if (x_m == 0) {
        return x;
    }
    return x - x_m + 10;
}

bool f2(int x, int y1, int y2, int y3, int y4) {
    if (x == 0) {
        return false;
    }
    if (y1 > 0 && x >= y1) {
        return false;
    }
    if (y2 > 0 && x >= y2) {
        return false;
    }
    if (y3 > 0 && x >= y3) {
        return false;
    }
    if (y4 > 0 && x >= y4) {
        return false;
    }
    return true;
}

int f(int a, int b, int c, int d, int e) {
    int a_m = a % 10;
    int b_m = b % 10;
    int c_m = c % 10;
    int d_m = d % 10;
    int e_m = e % 10;
    
    int a_r = f3(a);
    int b_r = f3(b);
    int c_r = f3(c);
    int d_r = f3(d);
    int e_r = f3(e);

    if (f2(a_m, b_m, c_m, d_m, e_m)) {
        return a + b_r + c_r + d_r + e_r;
    }
    if (f2(b_m, a_m, c_m, d_m, e_m)) {
        return b + a_r + c_r + d_r + e_r;
    }
    if (f2(c_m, b_m, a_m, d_m, e_m)) {
        return c + b_r + a_r + d_r + e_r;
    }
    if (f2(d_m, b_m, c_m, a_m, e_m)) {
        return d + b_r + c_r + a_r + e_r;
    }
    return e + b_r + c_r + d_r + a_r;
}

int main() {

    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;

    int result = f(a, b, c, d, e);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#define E 0.01
#define zero(n)(fabs(n)<E)
main(n,a,b,c,d,p,q,r,D,f){
	for(scanf("%d",&n);n;n--){
		scanf("%d%d%d%d",&a,&b,&c,&d);//fx=ax3+bx2+cx+d
		if(a<0)a=-a,b=-b,c=-c,d=-d;   //won't lose generality
		p=3*a,q=2*b,r=c,D=q*q-4*p*r;  //f'x=3ax2+2bx+c D: f'x=0?
		if(D>0){
			double x1=(-q-sqrt(D))/p/2,x2=(-q+sqrt(D))/p/2;
			double y1=a*x1*x1*x1+b*x1*x1+c*x1+d;
			double y2=a*x2*x2*x2+b*x2*x2+c*x2+d;
			if(!zero(y1)&&!zero(y2)>E&&y1*y2>0)goto one;
			puts(
				zero(x1)?(
					d==0?"1 0":
					"2 1"
				):zero(x2)?(
					d==0?"0 1":
					"1 2"
				):x1>0?(
					d>0?"2 1":
					d<0?"3 0":
					"2 0"
				):x2<0?(
					d>0?"0 3":
					d<0?"1 2":
					"0 2"
				):(
					d>0?"2 1":
					d<0?"1 2":
					"1 1"
				)
			);
		}else if(D==0)puts(
			d>0?"0 1":
			d<0?"1 0":
			"0 0"
		);else{one:
			puts(d>0?"0 1":d<0?"1 0":"0 0");
		}
	}
	exit(0);
}

Measured memory_bytes: 584
#include<iostream>
using namespace std;
#include<vector>
#define int long long int
int32_t main()
{
	int n;
	cin>>n;
	int x;
	cin>>x;
	int j,arr[n];
	for(j=0;j<n;j++)
	     cin>>arr[j];
	int answer=0;
	for(j=1;j<n;j++)
	{
		if(arr[j]+arr[j-1]>x)
		{
			int diff=-(x-arr[j]-arr[j-1]);
			answer+=diff;
			if(arr[j]>=diff)
			{
				arr[j]-=diff;
			}
			else
			   arr[j]=0;
		}	
	}
	cout<<answer<<endl;
}


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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;
//const int MOD = 998244353;

// Lib
//

int N;
vector<long long> A;

void solve() {
    // +, - に分ける
    vector<long long> plus, minus;
    for (int i = 0; i < N; ++i) {
        if (A[i] >= 0) plus.push_back(A[i]);
        else minus.push_back(A[i]);
    }
    sort(plus.begin(), plus.end(), greater<long long>());
    sort(minus.begin(), minus.end());
    if (minus.empty()) minus.push_back(plus.back()), plus.pop_back();
    if (plus.empty()) plus.push_back(minus.back()), minus.pop_back();

    // 復元
    vector<P> res;
    long long cur = minus[0];
    for (int i = 0; i+1 < plus.size(); ++i) {
        res.push_back({cur, plus[i]});
        cur -= plus[i];
    }
    res.push_back({plus.back(), cur});
    cur = plus.back() - cur;

    for (int i = 1; i < minus.size(); ++i) {
        res.push_back({cur, minus[i]});
        cur -= minus[i];
    }

    cout << cur << endl;
    for (auto p : res) cout << p.first << " " << p.second << endl;
}


int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    cin >> N;
    A.resize(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    solve();
}


Measured memory_bytes: 5872
h, w = map(int,input().split())
picture = [input() for _ in range(h)]
flag = True

for i in range(h):
    for j in range(w):
        if picture[i][j] == "#":
            if i == 0:
                if j == 0:
                    if picture[i+1][j] != "#" and picture[i][j+1] != "#":
                        flag = False
                        break
                elif j == w-1:
                    if picture[i+1][j] != "#" and picture[i][j-1] != "#":
                        flag = False
                        break
                else:
                    if picture[i+1][j] != "#" and picture[i][j+1] != "#" and picture[i][j-1] != "#":
                        flag = False
                        break
            elif i == h-1:
                if j == 0:
                    if picture[i-1][j] != "#" and picture[i][j+1] != "#":
                        flag = False
                        break
                elif j == w-1:
                    if picture[i-1][j] != "#" and picture[i][j-1] != "#":
                        flag = False
                        break
                else:
                    if picture[i-1][j] != "#" and picture[i][j+1] != "#" and picture[i][j-1] != "#":
                        flag = False
                        break
            else:
                if j == 0:
                    if picture[i+1][j] != "#" and picture[i-1][j] != "#" and picture[i][j+1] != "#":
                        flag = False
                        break
                elif j == w-1:
                    if picture[i+1][j] != "#" and picture[i-1][j] != "#" and picture[i][j-1] != "#":
                        flag = False
                        break
                else:
                    if picture[i+1][j] != "#" and picture[i-1][j] != "#" and picture[i][j+1] != "#" and picture[i][j-1] != "#":
                        flag = False
                        break

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3192
import copy
N, K=list(map(int,input().split()))
A=list(map(int,input().split()))
a=max(A)
l=1
y=copy.copy(a)
a=a-1
while l<=a:
    x=(l+a)//2
    m=0
    for i in range(N):
        if A[i]%x==0:
            m+=A[i]//x-1
        else:
            m+=A[i]//x
    if m<=K:
        a=x-1
        y=copy.copy(x)
    else:
        l=x+1
print(y)

Measured memory_bytes: 103840
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {
  
  int N;
  cin>>N;
  
  vector<long long> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  
  long long ans=GCD(A[0],A[1]);
  
  for(int i=0;i<N-2;i++){
    ans=GCD(ans,A[i+2]);
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 4020
#include<functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string.h>
#include <string>
#include <math.h>
#include <time.h>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
int n, k;
vector<int> v;
int dp[100005];
bool calc(int stones) {
	if (stones == 0)
		return false;
	int &ret = dp[stones];
	if (ret != -1)
		return ret;
	ret = 0;
	for (int i = 0; i < n; ++i)
		if (stones - v[i] >= 0)
			ret |= !calc(stones - v[i]);
	return ret;
}
int main() {
	//freopen("src.txt", "r", stdin);
	memset(dp, -1, sizeof dp);
	cin >> n >> k;
	v.resize(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	if (calc(k))
		puts("First");
	else
		puts("Second");

	return 0;
}

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

int padding(int n){
  int d=0;
  int m=n;
  while(m>0){
    m/=10;
    d++;
  }
  return 6-d;
}

int main(){
  long N,M;
  cin>>N>>M;
  vector<vector<long>> a(M,vector<long>(4));


  for(int i=0;i<M;i++){
    cin>>a[i][0]>>a[i][1];
    a[i][2]=i;
  }

  sort(a.begin(),a.end());
  vector<vector<long>> b(M,vector<long>(4));
  int idx=0;
  for(int p=1;p<=N;p++){
    int num=1;
    int c=0;
    while(idx<M&&p==a[idx][0]){
      a[idx][3]=num;
      num++;
      idx++;
      c++;

    }
  }

  for(int i=0;i<M;i++){
    b[i][0]=a[i][2];
    b[i][1]=a[i][0];
    b[i][2]=a[i][1];
    b[i][3]=a[i][3];
  }
  sort(b.begin(),b.end());

  for(int i=0;i<M;i++){
    int pad=padding(b[i][1]);
    for(int i=0;i<pad;i++) cout<<'0';
    cout<<b[i][1];
    pad=padding(b[i][3]);
    for(int i=0;i<pad;i++) cout<<'0';
    cout<<b[i][3]<<endl;

  }



}


Measured memory_bytes: 15616
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#define rep(i,a,b) for(int i = a; i < b; i++)
#define rep2(i,a,b) for(int i = a; i >= b; i--)
using namespace std;

int main(){
	int n;
	cin >> n;
	vector <int> ans(n);
	rep(i,0,n){
		cin >> ans[i];
	}
	int b= ans[0];
	rep(i,1,n){
		if (i%2==0){
			b+= ans[i];
		} else {
			b-= ans[i];
		}
	}
	b/=2;
	rep2(i,n-1,0){
		ans[i] -= b;
		b = ans[i];
	}
	rep (i,0,n-1){
		cout << ans [i] * 2<< " ";
	}
	cout << ans [n-1] * 2 << endl;
	
}


Measured memory_bytes: 1664
#include <stdio.h>

int MONEY[3];

int main(){
    int n1, n2, money = 0;

    MONEY[0] = 300000;
    MONEY[1] = 200000;
    MONEY[2] = 100000;


    scanf("%d %d", &n1, &n2);
    if(n1 <= 3){
        money += MONEY[n1-1];
    }

    if(n2 <= 3){
        money += MONEY[n2-1];
    }
    if(n1 == 1 && n2 == 1){
        money = 1000000;
    }

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

    return 0;
}

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

N , X = [int(i) for i in input().split()]

x = [int(i) for i in input().split()]

ret = x[0]- X

for num in x:
    ret = gcd(ret,num - X)

print(ret)


Measured memory_bytes: 14228
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <array>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

template <typename T, typename U>
using P = pair<T, U>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;

#define DOUBLE(n) static_cast<double>(n)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
// Usual REP runs from 0 to n-1 (R: n-1 to 0)
// Natural REP runs from 1 to n (R: n to 1)

/* ---------- ここまでマクロ ----------*/

// bのn乗を再帰的に求める
ll mypow(ll b, ll n) {
    return n == 0 ? 1 : b * mypow(b, n - 1);
}

// 桁和を求める(B問題を参照)
ll dsum(ll n) {
    ll ret = 0;
    while (n > 0) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

// n以上で最小のすぬけ数を求める
ll snuke(ll n) {
    GPQ<P<double, ll>> val;
    // 逆順priority_queue, 一番上が最小の要素
    // (g(m), m)

    ll dig = 0;
    // 9が連続する桁数

    while (mypow(10, dig) <= n) {
        NREP(i, 9) {
            ll v = n - n % mypow(10, dig + 1) + i * mypow(10, dig) - 1;
            // 下dig桁が9
            // 1つ上は1~9
            // それより上はnと一致

            if (v >= n) {
                val.push(make_pair(DOUBLE(v) / dsum(v), v));
            }
        }
        dig++;
    }
    
    dig--;
    NREP(i, 100) {
        ll v = i * mypow(10, dig) - 1;
        if (v >= n) {
            val.push(make_pair(DOUBLE(v) / dsum(v), v));
        }
    }

    auto ret = val.top();
    // g(m)とmが最小となる(g(m), m)の組

    return ret.second;
}


int main() {
    ll K;
    cin >> K;
    ll pre = 1;
    REP(_, K) {
        cout << pre << endl;
        pre = snuke(pre + 1);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <limits>
#include <math.h>
#include <cmath>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vll = vector<long long>;
#define PI 3.141592653

int main(){
  long double a, b, x, t, r;
  cin >> a >> b >> x;

  long double eps = 1.0E-10;

  t = (a)/((b-(x/(a*a)))*2);
  if(x < a * a * b / 2){t = (2 * x)/(a * b * b);}
  r = atan(t);

  cout << fixed << setprecision(8);
  cout << 90 - (r/PI)*180 << endl;

}

Measured memory_bytes: 256
def B():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    cnt = 0
    for i in range(N - 1):
        cnt += L[i]
    if L[-1] < cnt:
        print("Yes")
    else:
        print("No")
#B()

def C():
    N, M = map(int, input().split())
    X = list(map(int, input().split()))
    X.sort()
    tmp = []
    for i in range(1, len(X)):
        tmp.append(X[i] - X[i - 1])
    X.sort()
    ans = X[-1] - X[0]
    #ans -= N
    tmp.sort()
    tmp = tmp[::-1]
    if N - 1 >= len(tmp):
        print(0)
        return 0
    for i in range(N - 1):
        ans -= tmp[i]
    print(ans)
C()

Measured memory_bytes: 13960
n,m,x,y = map(int,input().split())

x_li = list(map(int,input().split()))
y_li = list(map(int,input().split()))

flag = 0
for i in range(x+1,y+1):
    if max(x_li) < i:
        if min(y_li) >= i:
            flag = 1

print(['War','No War'][flag])


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

int main() {
    int n;
    cin >> n;
    map<int, int> m;
    for (int i=0; i<n; i++) {
        int a; cin >> a;
        m[a]++;
    }
    int ma = 0;
    for (int i=1; i<1e5; i++) {
        ma = max(ma, m[i-1]+m[i]+m[i+1]);
    }
    cout << ma << endl;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <string.h>

int main(void) {
    int i, N;
    const double BTC = 380000.0;
    double x[20], T;
    char u[20][5];
    scanf("%d", &N);
    for (i=1;i<=N;i++) {
        scanf("%lf %s", &x[i], &u[i]);
    }

    T = 0.0;
    for (i=1;i<=N;i++) {
        if (!strcmp(u[i], "BTC")) T += BTC * x[i]; 
        else T += x[i];
    }
    printf("%.7lf\n", T);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
#define ALL(V) V.begin(), V.end()


int Main(int N, int K, string S)
{
    int ans = 0;
    VI chunks(1, -1);
    int counter = 0;
    char before = S[0];
    chunks[0]++;
    REP2(i, 1, N) {
        if(S[i] == before) {
            chunks[counter]++;
        }
        else {
            counter++;
            chunks.push_back(0);
        }
        before = S[i];
    }
    int subsum = accumulate(ALL(chunks), 0);
    return min(N-1, subsum + 2 * K);
}

int main(void){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    cout << Main(N, K, S) << endl;
    return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
#define N 100020
#define ll long long
using namespace std;
inline int read(){
  int x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}
int main(int argc, char const *argv[]) {
  ll a = read(), b = read(), c = read();
  ll ans = (a & 1) ? b * c : 0;
  ans = min(ans, (b & 1) ? a * c : 0);
  ans = min(ans, (c & 1) ? a * b : 0);
  printf("%lld\n", ans);
  return 0;
}

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

int main() 
{    int a,b,m,n,r,t;
   
  while(scanf("%d%d",&a,&b)!=EOF)
{  
	if(a<b)
	{    t=b;
	     b=a;
		 a=t;
	}
	m=a;
	n=b;
	while((r=a%b)!=0)
	{   a=b;
	    b=r;
	}
	cout<<b<<" "<<m/b*n<<endl;

	
}
	return 0;
}

Measured memory_bytes: 3108
import math
t = int(input())
if t%2==0 or t%5==0:
    print(-1)
else:
    i=1
    s=7
    while 1:

        if s%t==0:
            print(i)
            break

        else:
            i += 1
            s = (s * 10 + 7) % t
            continue

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

#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e2 + 5;
const int M=1e5 + 5;


int main()
{
	ios_base::sync_with_stdio(false);
	int n,i;
	bool dn[N];
	cin>>n;
	vector <int> v,s;
	for(i=1;i<=n;i++){
		int f;
		cin>>f;
		s.pb(f);
		
	}

	while(s.size()>0){
		bool ok = false;
		for(i=0;i<s.size();i++){
			dn[i]=false;
		}
		for(i=s.size()-1;i>=0;i--){
			if(s[i]==i+1){
				ok=true;
				v.pb(s[i]);
				dn[i]=true;
				break;
			}
		}
		vector <int> tmp;
		for(i=0;i<s.size();i++){
			if(!dn[i]){
				tmp.pb(s[i]);
			}
		}
		s=tmp;
		if(!ok){
			cout << -1 << endl;
			return 0;
		}
	}	
	reverse(v.begin(),v.end());
	for(i=0;i<n;i++) cout << v[i] <<endl;
		
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  double ax,ay,bx,by,cx,cy,dx,dy,r1,r2;
  while(cin >> ax >> ay >> bx >> by >> cx >> cy >> dx >> dy){
    if(bx-ax == 0){
      if(dy-cy == 0) cout << "YES" << endl;
      else cout << "NO" << endl;
    }else if(dx-cx == 0){
      if(by-ay == 0) cout << "YES" << endl;
      else cout << "NO" << endl;
    }else{
      r1 = (by-ay) / (bx-ax);
      r2 = (dy-cy) / (dx-cx);
      if(r1 * r2 == -1) cout << "YES" << endl;
      else cout << "NO" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int main() {
  int N, M;
  cin >> N >> M;
  if(N == M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr>void dump(Itr begin, Itr end) {
  for(;begin != end; ++begin) clog << ' ' << *begin;
  clog << LF;
}

signed main()
{
  int N, M;
  bool f[33] {};

  memset(f, true, sizeof(f));

  cin >> N >> M;
  for (int i = 0; i < N; ++i) {
    int K; cin >> K;

    bool t[33] {};
    for (int j = 0; j < K; ++j) {
      int a; cin >> a;
      t[a] = true;
    }

    for (int j = 0; j <= M; ++j) f[j] &= t[j];
  }

  cout << count(f, f+M+1, true) << endl;

  return 0;
}



Measured memory_bytes: 256
//region Template
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../debug_prettyprint.hpp"
#else
#define debug(...) 42
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#endif
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout<<fixed<<setprecision(12);
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
#define EXIT(answer) { cerr<<"EXIT #"<<__LINE__<<endl; cout<<answer<<endl; exit(0); }
#define sz(v) int(v.size())
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> istream& operator>>(istream& in, pair<T,U> &p) { in>>p.first>>p.second; return in; }
template<typename T> inline vector<T> READ(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
//endregion

const int MAXP = 1e6+5;
int spf[MAXP+5];
void sieve() {
    for (int i=2; i<MAXP; i++)
        spf[i] = i;
    for (int p = 2; p * p<MAXP; p++)
        if (spf[p]==p)
            for (int j = p * p; j<MAXP; j += p)
                if(spf[j]==j) spf[j] = p;
}

int main() {
    FASTIO

    sieve();
    
    int n; cin>>n;
    vi a = READ<int>(n);

    int setgcd=a[0];
    FOR(i,n)
        setgcd = __gcd(setgcd, a[i]);

    if(setgcd > 1)
        EXIT("not coprime");

    map<int,int> occ;

    FOR(i,n) {
        int x = a[i];
        while(x>1) {
            int p = spf[x];
            occ[p]++;
            if(occ[p] >= 2)
                EXIT("setwise coprime");

            while(x % p==0)
                x /= p;
        }
    }

    cout<<"pairwise coprime"<<endl;
}

Measured memory_bytes: 11536
#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;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll a,b,c,k; cin>>a>>b>>c>>k;
	if(k&1) cout<<b-a<<'\n';
	else cout<<a-b<<'\n';
}	


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace C
{
  class Program
  {
    static void Main(string[] args)
    {
      int c = int.Parse(Console.ReadLine());
      string[] array = Console.ReadLine().Split(' ');
      var input = new List<string>();
      input.AddRange(array);
      var values = input.Select(i => double.Parse(i)).ToList();
      while (values.Count != 1)
      {
        values.Sort();
        var nval = values.Take(2).Sum() / 2.0;
        var tmp = values.Skip(2).ToList();
        tmp.Add(nval);
        values = tmp;
      }
      Console.WriteLine(values[0]);
    }
  }
}


Measured memory_bytes: 13524
import java.util.BitSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int W = in.nextInt();
		BitSet wbit = new BitSet(W);
		int h = in.nextInt();
		BitSet hbit = new BitSet(h);
		for (int i = 0; i < n; i++) {
			int x = in.nextInt();
			int y = in.nextInt();
			int w = in.nextInt();
			wbit.set(Math.max(0, x - w), Math.min(W, x + w));
			hbit.set(Math.max(0, y - w), Math.min(h, y + w));
			// System.out.println(wbit);
			// System.out.println(hbit);
		}
		if (wbit.cardinality() == W || hbit.cardinality() == h) {
			System.out.println("Yes");
			System.exit(0);
		}
		System.out.println("No");

	}

}

Measured memory_bytes: 96284