akhauriyash/Code-Regression huggingface dataset:
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main {
  int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;
  bool f = true;
  f &= 0 <= x - r && x - r <= w;
  f &= 0 <= x + r && x + r <= h;
  f &= 0 <= y - r && y - r <= w;
  f &= 0 <= y + r && y + r <= h;
  cout << (f ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3120
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
class Main{
    List<Integer> A = new ArrayList<Integer>();
    public void run(){
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
            br.lines()
                .forEach(n -> met(n));
        }catch(Exception e){
        }
    }

    public void met(String n){
        String[] tmp = n.split(" ");
        if(Objects.equals(tmp[0],tmp[1]))
            System.out.println("H");
        else
            System.out.println("D");

        // Arrays.stream(n.split(" "))
        //     .forEach(n -> {
        //         if(Objects.equals(n[0],n[1]))
        //             System.out.println("H");
        //         else
        //             System.out.println("D");
        //     });
    }


    public static void main(String[] args){
        new Main().run();
    }
}

Measured memory_bytes: 26836
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <tr1/unordered_set>
using namespace std;

int n , v[20] , ans = 0;

tr1::unordered_set<int> memo[20];

int X[421] , Y[421] , top;
 
int main(){
	while(scanf("%d\n",&n)&& n){
		int dp2[21] = {0};
		for(int i = 0 ; i < n ; i++) scanf("%d",&v[i]) , memo[i].clear();
		sort(v,v+n);
		for(int i = n-1 ; i >= 0 ; i--) dp2[i] = dp2[i+1] + v[i];
		ans = 99999999;
		top = 0;
		X[top] = 0;
		Y[top] = 0;
		while(~top){
			int pos = X[top] , sum = Y[top]; top--;
			if(pos==n) ans = min(ans,sum);
			else{
				if( ( sum >= dp2[pos] && ans <= sum-dp2[pos] ) || memo[pos].count(sum)) continue;
				else memo[pos].insert(sum);
				X[++top] = pos+1;
				Y[top]   = sum+v[pos];
				X[++top] = pos+1;
				Y[top]   = abs(sum-v[pos]);
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

class Main {
	public static void main(String[] args)
	{
		FastScanner in=new FastScanner();
		int n=in.nextInt();
		int k=in.nextInt();
		int[] h=in.readArray(n);
		int[]dp =new int[n];
		for(int i=0;i<n;i++)
			dp[i]=Integer.MAX_VALUE;
		dp[0]=0;
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<=(i+k);j++)
			{
				if(j<n)
				dp[j]=Math.min(dp[j], dp[i]+Math.abs(h[i]-h[j]));
			}
		}
		System.out.println(dp[n-1]);
	}
	
static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}


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

int main()
{
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k<=a)
    cout<<k<<endl;
  else if(k<=a+b)
    cout<<a<<endl;
  else
    cout<<a-k+a+b<<endl;
}

Measured memory_bytes: 3608
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
int main(void)
{
	int i=0;
	char s[101];
	scanf("%s", s);

	while(s[i] != '\0'){
		if(s[i] != 'R' && s[i] != 'U' && s[i] != 'D'){
			puts("No");
			return 0;
		}
		i++;
		if(s[i] == '\0') break;
		if(s[i] != 'L' && s[i] != 'U' && s[i] != 'D'){
			puts("No");
			return 0;
		}
		i++;
	}
	puts("Yes");
	return 0;
}

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

int main() {
   int N,M,sum=0;
  cin>>N>>M;
  vector<int> a(N);
  for(int &x: a) {cin>>x; sum+=x;}
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  if((sum+4*M-1)/(4*M)<=a[M-1]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
  


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <sstream>
#include <map>
#include <deque>
#include <queue>
#include <set>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(b==100) b++;
	for(int i=1;i<=a;i++) b*=100;
	cout<<b<<endl;
	return 0;
}


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

using namespace std;
using myui = uint64_t;
using myint = int64_t;

template<typename T>
T diff(const T& a, const T& b) {
    return a > b ? a - b : b - a;
}

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

    {
        myui n;
        cin >> n;

        myui sum = 0;
        while(n--) {
            myui a;
            cin >> a;
            sum += a - 1;
        }
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn=1e5+100;
const int mod=1e9+7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int H, W, K;///height, vertical lines, exit
ll dp[110][8];
ll solve(int h, int pos)
{
    if(dp[h][pos]!=-1)return dp[h][pos];
    if(h == 0)return pos == K;
    ll tot=0;
    for(int mask=0; mask<(1<<(W-1)); mask++)
    {
        bool chk=true;
        for(int bit=0; bit<W-2; bit++)
            if((mask>>bit&1) && (mask>>(bit+1)&1))
                chk=false;
        if(!chk)continue;
        if(pos!=1 && (mask>>(pos-2)&1))
            tot+=solve(h-1, pos-1), tot%=mod;
        else if(pos!=W && (mask>>(pos-1)&1))
            tot+=solve(h-1, pos+1), tot%=mod;
        else tot+=solve(h-1, pos), tot%=mod;
    }
    return dp[h][pos]=tot;
}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin>>H>>W>>K;
    memset(dp, -1, sizeof dp);
    cout<<solve(H, 1)<<"\n";
    return 0;
}


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

typedef long long ll;
typedef vector <int> vi;
typedef pair< int ,int > pii;
typedef istringstream iss;
typedef ostringstream oss;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ln length()
#define rep(i,n) for(int i=0;i<n;i++)
#define fu(i,a,n) for(int i=a;i<=n;i++)
#define fd(i,n,a) for(int i=n;i>=a;i--)
#define all(a)  a.begin(),a.end() 
#define ESP (1e-9)
#define gi(n) scanf("%d",&n)
#define gl(n) cin >> n
#define pi(n) printf("%d",n)
#define pl(n) cout << n
#define ps printf(" ")
#define pn printf("\n")
#define dg(n,s); printf("%s %d",s,n)
#define imax numeric_limits<int>::max()
#define imin numeric_limits<int>::min()
#define lmax numeric_limits<ll>::max()
#define lmin numeric_limits<ll>::min()
 int n , a ; 
int main () {
	cin >> n >>  a ;
	cout << ( n * n - a )  ; 
	return 0; 
}

Measured memory_bytes: 256
t = [ ('m',1000), ('c',100), ('x',10), ('i',1) ]
s = map fst t

str2dec [] = 0
str2dec str =
  let n = takeWhile (\c -> not $ elem c s) str
      r = dropWhile (\c -> not $ elem c s) str
      h = head r
      h'= snd $ head $ filter (\ e -> h == fst e) t
      n'= if n == [] then 1 else (read n)
      r'= tail r
  in
    n'*h' + (str2dec r')

dec2str' _ [] = []
dec2str' 0 _ = []
dec2str' dec ((s,v):ts) =
  let n = dec `div` v
      r = dec `mod` v
      c = case n of
            0 -> ""
            1 -> [s]
            otherwise -> (show n) ++ [s]
  in
    c ++ (dec2str' r ts)

dec2str dec = dec2str' dec t

ans i =
  dec2str $ sum $ map str2dec i

main = do
  _ <- getLine
  c <- getContents
  let i = map words $ lines c
      o = map ans i
  mapM_ putStrLn o
        



Measured memory_bytes: 4828
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n,d;
  cin>>n>>d;
  if(n%(2*d+1)==0){
    cout<<n/(2*d+1)<<endl;
  }
  else{
    cout<<n/(2*d+1)+1<<endl;
  }
}


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

using ll = long long;
ll modinv(ll a, ll m) {
	assert(m > 0);
	if (m == 1) return 0;
	a %= m;
	if (a < 0) a += m;
	assert(a != 0);
	if (a == 1) return 1;
	return m - modinv(m, a) * m / a;
}

template <int MOD_> struct modnum {
private:
	int v;
public:
	static const int MOD = MOD_;

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int () const { return v; }
	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum operator ~ () const {
		modnum res;
		res.v = modinv(v, MOD);
		return res;
	}

	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= (~o);
	}

	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};

using num = modnum<998244353>;

const int M = 1100000;

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

	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	vector<num> tsum(M, 0);
	for(ll x : a) tsum[x] += x;
	vector<num> mu(M, 0);
	mu[1] = 1;
	vector<num> msum(M, 0);
	for(ll y = 1; y < M; y++){
		for(ll z = y; z < M; z += y){
			msum[y] += tsum[z];
			if(z > y) mu[z] -= mu[y];
		}
	}
	vector<num> res(M, 0);
	for(ll y = 1; y < M; y++){
		for(ll z = y; z < M; z += y){
			res[y] += msum[z] * msum[z] * mu[z/y];
		}
	}
	num ans = 0;
	for(ll y = 1; y < M; y++){
		ans += res[y] / y;
	}
	for(ll x : a){
		ans -= x;
	}
	ans /= 2;
	cout << (int)ans << '\n';
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v;
  rep(i, n) {
    int hp;
    cin >> hp;
    v.push_back(hp);
  }

  sort(v.begin(), v.end(), greater<int>());
  ll total = 0;
  rep(i, n) {
    if (i < k) continue;
    total += v.at(i);
  }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 1400
N,K = map(int,input().split())
ans = 0
for j in range(1,N+1):
  count = 0
  num = int(j)
  if num < K:
    while(num<K):
      num*=2
      count+=1
    ans+=(1/N)*((1/2)**count)
  else:
    ans+=1/N
print(ans)

Measured memory_bytes: 3060
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while(n != 0){
			LinkedList<Line> smpl = new LinkedList<Line>(); 
			
			Line line = new Line();
			int m = sc.nextInt();
			int ox = sc.nextInt();
			int oy = sc.nextInt();
			line.add(new Point(0, 0));
			for(int i = 1; i < m; i++){
				int x = sc.nextInt();
				int y = sc.nextInt();
				line.add(new Point(x - ox, y - oy));
			}
			smpl.add(line);
			smpl.add(rel(line, 0));
			line = rel(line, 90);
			smpl.add(line);
			smpl.add(rel(line, 0));
			line = rel(line, 90);
			smpl.add(line);
			smpl.add(rel(line, 0));
			line = rel(line, 90);
			smpl.add(line);
			smpl.add(rel(line, 0));
/*			for(int j = 0; j < smpl.size(); j++){
				for(Point g : smpl.get(j).list){
					System.out.print("[" + g.x + ":" + g.y + "]");
				}
				System.out.println();
			}
*/			for(int j = 1; j <= n; j++){
				line = new Line();
				m = sc.nextInt();
				ox = sc.nextInt();
				oy = sc.nextInt();
				line.add(new Point(0, 0));
				for(int i = 1; i < m; i++){
					int x = sc.nextInt();
					int y = sc.nextInt();
					line.add(new Point(x - ox, y - oy));
				}
				for(int k = 0; k < smpl.size(); k++){
					if(comp(smpl.get(k), line)){
						System.out.println(j);
						break;
					}
				}
			}
			System.out.println("+++++");
			n = sc.nextInt();
		}
		sc.close();
	}
	static Line rel(Line line, int rec){
		Line tmp = new Line();
		if(rec == 0){
			int ox, oy;
			Point p = line.get(line.size() - 1);
			ox = p.x;
			oy = p.y;
			Point t = new Point(0, 0);
			tmp.add(t);
			for(int i = line.size() - 2; i >= 0; i--){
				p = line.get(i);
				t = new Point(p.x - ox, p.y - oy);
				tmp.add(t);
			}
		}else if(rec == 90){
			for(int i = 0; i < line.size(); i++){
				Point p = line.get(i);
				Point t = new Point((-1) * p.y, p.x);
				tmp.add(t);
			}
		}else if(rec == 180){
			for(int i = 0; i < line.size(); i++){
				Point p = line.get(i);
				Point t = new Point((-1) * p.y,(-1) * p.x);
				tmp.add(t);
			}				
		}else if(rec == 270){
			for(int i = 0; i < line.size(); i++){
				Point p = line.get(i);
				Point t = new Point(p.y, (-1) * p.x);
				tmp.add(t);
			}
		}
		return tmp;
	}
	static boolean comp(Line sm, Line tr){
		if(sm.size() != tr.size()){
			return false;
		}
		for(int i = 0; i < sm.size(); i++){
			Point s = sm.get(i);
			Point t = tr.get(i);
			if(s.x != t.x || s.y != t.y){
				return false;
			}
		}
		return true;
	}
}
class Line{
	LinkedList<Point> list;
	Line(){
		list = new LinkedList<Point>();
	}
	void add(Point p){
		list.add(p);
	}
	Point get(int idx){
		return list.get(idx);
	}
	int size(){
		return list.size();
	}
}
class Point{
	int x;
	int y;
	Point(int x, int y){
		this.x = x;
		this.y = y;
	}
}

Measured memory_bytes: 36500
n = int(input())
x = []
total = 0
for _ in range(n):
    s = int(input())
    total += s
    if s%10 != 0:
        x.append(s)
x.sort()
if total%10 != 0:
    print(total)
elif len(x) != 0:
    print(total-x[0])
else:
    print(0)

Measured memory_bytes: 38256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

dish = []       
for i in range(N):
 dish.append([A[i],B[A[i]-1]])

ans = 0
for i in range(N):
  ans += dish[i][1]
  if(i != N-1):
    if(dish[i][0]+1 == dish[i+1][0]):
      index_ = dish[i][0]-1
      ans += C[index_]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;++i)
int main(){
int n,a=0;cin>>n;vector<string>g(n),h(n);r(i,n)cin>>g[i];
r(i,n){r(j,n)h[(j+i)%n]=g[j];int f=1;
r(p,n){r(q,p){if(h[p][q]!=h[q][p])f=0;}}if(f)a+=n;}
cout<<a<<endl;return 0;}

Measured memory_bytes: 512
import math
a,b,x = map(int,input().split())

#l = bから引いた長さ、三角形の短辺・
#(b-l/2)*a*a = x
if a*a*b/2 < x:
    l =(b-x/(a*a))*2
    # print("M")
    # print(l)
    print(math.degrees(math.atan(l/a)))
#l = aから引いた長さ、三角形の短辺・
#(a-l)*a*b/2 = x
else:
    l =a-(2*x)/(a*b)
    # print("N")
    # print(l)
    print(90-math.degrees(math.atan((a-l)/b)))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define N ()
#define ll long long
#define debug(x) cerr<<#x<<" : "<<x<<endl
#define CM cerr<<(&MOP2-&MOP1)/1024.0/1024.0<<endl
using namespace std;
template <class T> inline T Min(T x, T y){
    return x<y?x:y;
}
template <class T> inline T Max(T x, T y){
    return x>y?x:y;
}
bool MOP1;

bool MOP2;
int main(){
	ll n;
	scanf("%lld",&n);
	printf("%lld\n",n*(n-1)/2);
}






Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = 99999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, ans = 0, w, l;
vl A;
class LCA {
public:
	ll LOG_N = floor(log2(n)) + 1;
	vector<vl> NEXT;
	vl DEPTH;


	void init() {
		DEPTH = vl(n, -1);
		// NEXT[0]を計算
		NEXT = vector<vl>(LOG_N + 2, vector<ll>(n));
		for (ll i = 0; i < n; ++i) {
			NEXT[0][i] = upper_bound(all(A), A[i] + l) - A.begin() - 1;
		}

		// NEXTを計算
		for (ll k = 0; k < LOG_N; k++) {
			for (ll i = 0; i < n; i++) {
				if (NEXT[k][i] == n) {
					NEXT[k + 1][i] = n;
				}
				else {
					NEXT[k + 1][i] = NEXT[k][NEXT[k][i]];
				}
			}
		}
	}

	ll vertex(ll p, ll Q) {
		for (ll k = LOG_N - 1; k >= 0; --k) {
			if (p == -1) {
				break;
			}
			if ((Q >> k) & 1) {
				p = NEXT[k][p];
			}
		}

		return p;
	}

	ll depth(ll x) {
		if (DEPTH[x] == -1) {
			ll ok = n, ng = -1;
			while (ok - ng > 1) {
				if (this->vertex(x, (ok + ng) / 2) > -1)ng = (ok + ng) / 2;
				else ok = (ok + ng) / 2;
			}
			DEPTH[x] = ok;
			return ok;
		}
		else return DEPTH[x];
	}

	ll kyoutuu(ll x, ll y) {
		ll a = this->depth(x);
		ll b = this->depth(y);
		if (a > b) {
			swap(x, y);
			swap(a, b);
		}
		ll t = this->vertex(y, b - a);

		ll ok = n, ng = -1;
		while (ok - ng > 1) {
			ll mid = (ok + ng) / 2;
			if (this->vertex(x, mid) == this->vertex(t, mid))ok = (ok + ng) / 2;
			else ng = (ok + ng) / 2;
		}

		/*祖先を出力したい場合はreturn this->vertex(x, ok);*/
		return b - a + ok * 2 + 1;
	}

	ll saitei(ll x, ll y) {
		if (x > y)swap(x, y);
		ll ok = n, ng = -1;
		while (ok - ng > 1) {
			ll mid = (ok + ng) / 2;
			if (this->vertex(x, mid) >= y)ok = (ok + ng) / 2;
			else ng = (ok + ng) / 2;
		}

		return ok;
	}

};

void input() {
	cin >> n;
	inputv(A, n);
	A.push_back(INF);
	n++;
	cin >> l;
	cin >> q;

	LCA LCA1;
	LCA1.init();
	while (q--) {
		cin >> x >> y;
		cout << LCA1.saitei(x-1, y-1) << endl;
	}
}


void solve() {
}

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

Measured memory_bytes: 17652
h,w,n = gets.split.map(&:to_i)
x,y = gets.split.map(&:to_i)
s = gets.chomp
t = gets.chomp

u = d = x
l = r = y
n.times do |i|
    if s[i] == "L"
        l -= 1
    elsif s[i] == "R"
        r += 1
    elsif s[i] == "U"
        u -= 1
    else
        d += 1
    end
    if l <= 0 || r > w || u <= 0 || d > h
        puts "NO"
        exit
    end
    if t[i] == "L"
        r -= 1
        r = 1 if r <= 0
    elsif t[i] == "R"
        l += 1
        l = w if l > w
    elsif t[i] == "U"
        d -= 1
        d = 1 if d < 1
    else
        u += 1
        u = h if u > h
    end
end
puts "YES"

Measured memory_bytes: 2636
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

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

int main() {
  int N, R;
  cin >> N >> R;
  if (N >= 10)
    cout << R << endl;
  else
    cout << R + 100 * (10 - N) << endl;
}


Measured memory_bytes: 256
using System;
namespace tst
{
    class Program
    {
        public static void Main()
        {
            string[] In = Console.ReadLine().Split(' ');
            int[] num = new int[2];
            for(int i=0; i<2; i++)
            {
                num[i] = int.Parse(In[i]);
            }
            if(1<=num[0] && num[0]<=9 && 1<= num[1] && num[1] <= 9)
            {
                Console.WriteLine(num[0] * num[1]);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }

    }
}

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

int main()
{
  int s;
  cin >> s;
  vector<int> a(1000001);
  a.at(0) = s;
  int i = 1;
  bool can = false;
  while (true)
  {
    if (a.at(i - 1) % 2 == 0)
      a.at(i) = a.at(i - 1) / 2;
    else
      a.at(i) = 3 * a.at(i - 1) + 1;
    int j = 0;
    while (j < i)
    {
      if (a.at(j) == a.at(i))
      {
        can = true;
        break;
      }
      else
        j++;
    }
    if (can)
      break;
    i++;
  }
  cout << i + 1 << endl;
}


Measured memory_bytes: 4096
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

class T{
  public:
    char c;
    int a, b, n;
    T(){ a = 0; b = 0; }
    bool operator < (const T &t) const {
      if(a != t.a) return a > t.a;
      if(b != t.b) return b < t.b;
      return n < t.n;
    }
};

int main() {
  int N;
  while(cin >>N && N){
    vector<T> ts(N);
    REP(i, N){
      char c; cin >>c; ts[i].c = c; ts[i].n = i;
      REP(j, N - 1){
        int n; cin >>n;
        if(n == 0) ++ts[i].a;
        if(n == 1) ++ts[i].b;
      }
    }
    SORT(ts);
    REP(i, N) cout <<ts[i].c <<endl;
  }

  
  return 0;
}

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

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

template<class C> using iodef_rng_t = typename enable_if<decltype(declval<C>().begin(), true_type{})::value && !is_same<C, string>::value>::type;
template<class C, class = iodef_rng_t<C>> istream& operator>>(istream& in, C& c) { for (auto& v : c) { in >> v; } return in; }
template<class C, class = iodef_rng_t<C>> ostream& operator<<(ostream& out, const C& c) { int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    int k;
    cin >> k;
    string s;
    cin >> s;
    if (s.size() <= k) cout << s << '\n';
    else {
        cout << s.substr(0, k) << "..." << '\n';
    }
}


Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>

// https://umbccd.io/challenges


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> b(n);
	rep(i, n) {
		cin >> b[i];
	}
	vector<int> a;

	while(!b.empty()) {
		bool ok = false;
		for (int i = b.size() - 1; i >= 0; i--) {

			if (b[i] == i + 1) {
				b.erase(b.begin() + i);
				a.push_back(i + 1);
				ok = true;
				break;				
			}
		}
		if (ok == false) {
			cout << -1 << endl;
			return 0;
		}

	}
	rep(i, n) {
		cout << a[n - i - 1] << " " << endl;
	}



 	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/adaptor/indexed.hpp>
using namespace std;

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

template <typename T>
std::ostream &operator<<(std::ostream &ostr, const std::vector<T> &v) {
  for (const auto &i : v | boost::adaptors::indexed())
    ostr << (i.index() > 0 ? " " : "") << i.value();
  return ostr;
}

inline void Main() {
  // code
  int n;
  cin >> n;
  vector<int> vi(n);
  rep(i, n) cin >> vi.at(i);
  sort(all(vi));

  if(n%2==1) {
    rep(i, n) {
      if(i==0) {
        if(vi.at(i)==0) {}
        else {
          cout << 0 << endl;
          return;
        }
      } else {
        if(i%2==1) {
          if(vi.at(i) == vi.at(i+1) && vi.at(i) == i+1) {}
          else {
            cout << 0 << endl;
            return;
          }
        }
      }
    }
  } else {
    rep(i, n) {
      if(i%2==0) {
        if(vi.at(i) == vi.at(i+1) && vi.at(i) == i+1) {}
        else {
          cout << 0 << endl;
          return;
        }
      }
    }
  }

  int res = 1;
  rep(i, n/2) {
    res = (res * 2) %  1000000007;
  }

  cout << res << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vec vector<ll>
#define vvec vector<vec>
#define llp(i,x,n) for(i=x;i<n;i++)
#define wi while
#define pb push_back
vec arr(100001,-1);
vec a;
ll recur(ll i,ll n,ll k)
{
	  if(i>n-1)
		return 100000000000;
	  if(i==n-1)
		return 0;
	  else if(arr[i]!=-1)
		return arr[i];
	  else
	  {
		ll z=100000000000;
		for(ll j=i+1;j<=i+k;j++)
	    z=min(z,recur(j,n,k)+abs(a[j]-a[i]));
		arr[i]=z;
		return arr[i];
	  }
}
int main()
{
  ll n,k,i;
  cin>>n>>k;
  a.resize(n);
  for(i=0;i<n;i++)
    cin>>a[i];
  	cout<<recur(0,n,k);
}

Measured memory_bytes: 12632
import math

N, A, B, K = map(int, input().split())
mod = 998244353
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]


def cmb(n, r):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

res = 0
for a in range(0, N+1):
    b = (K - A*a) // B
    if (K - A * a) % B == 0 and 0 <= b <= N:
        res += cmb(N, a) * cmb(N, b) % mod
print(res % mod)

Measured memory_bytes: 38756
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
	int A, B, count = 0;
	char S[10];
	scanf("%d%d", &A, &B);
	for (int i = 0; i <= A + B + 1; i++) {
		scanf("%c", &S[i]);
		if (i == A+1) {
			if (S[A+1] != '-') {
				count = 1;
			}
		}
		else {
			if (S[i]=='-') {
				count = 1;
			}
		}
	}
	if (count == 0) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
#define itn int
#define tin int
#define tni int
bool dbg = false;
int N, a[200010];
int m1, m2;
void solve()
{
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FOR(i, 0, N)
        cin >> a[i];
    FOR(i, 0, N)
    {
        if (a[i] >= m1) {
            m2 = m1;
            m1 = a[i];
        } else if (a[i] >= m2) {
            m2 = a[i];
        }
    }
    FOR(i, 0, N)
    {
        if (a[i] == m1) {
            cout << m2 << endl;
        } else {
            cout << m1 << endl;
        }
    }
    solve();
    return 0;
}


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

#define DEBUG 1

void swap(int &p, int &q) {
  int t = p;
  p = q;
  q = t;
}

int main() {
  map<string, int> box;

  cin >> box["A"] >> box["B"] >> box["C"];

  int &X = box["A"];
  int &Y = box["B"];
  int &Z = box["C"];

  swap(X, Y);
  swap(X, Z);

  cout << X << ' ' << Y << ' ' << Z << endl;
  
  return 0;
}


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

using namespace std;

inline long long f(const long long & b, long long n) {
	long long ans = 0;
	for (; n > 0; n /= b)
		ans += n % b;
	return ans;
}

long long answer(const long long & n, const long long & s) {
	if (n == s)
		return n + 1;
	else if (n > s) {
		vector<long long> vtr;
		long long x = n - s;
		for (int i = 1; i <= x / i; i++) {
			if (x % i == 0) {
				vtr.push_back(i);
				if (i != x / i)
					vtr.push_back(x / i);
			}
		}
		sort(vtr.begin(), vtr.end());
		for (const auto & b : vtr) {
			if (f(b + 1, n) == s)
				return b + 1;
		}
		return -1;
	} else
		return -1;
}

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

	long long n, s;

	cin >> n >> s;

	long long ans = answer(n, s);

	if (ans == -1)
		cout << "-1";
	else
		cout << ans;
	cout << '\n';

	return 0;
}


Measured memory_bytes: 384
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, M = list(map(int, sys.stdin.buffer.readline().split()))
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
Q = int(sys.stdin.buffer.readline())
VDC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(Q)]

# 解説AC
graph = [[] for _ in range(N)]
for a, b in AB:
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

# dp[v, d]: v から距離 d の頂点を塗るタイミングと色
dp = [[None] * 11 for _ in range(N)]
for i, (v, d, c) in reversed(list(enumerate(VDC))):
    v -= 1
    if not dp[v][d]:
        dp[v][d] = i, c

for d in reversed(range(1, 11)):
    for v in range(N):
        if not dp[v][d]:
            continue
        for u in graph[v] + [v]:
            if not dp[u][d - 1] or (dp[u][d - 1] and dp[u][d - 1][0] < dp[v][d][0]):
                dp[u][d - 1] = dp[v][d]

for v in range(N):
    if dp[v][0]:
        print(dp[v][0][1])
    else:
        print(0)

# import numpy as np
# dp = np.array(dp)
# print(dp)


Measured memory_bytes: 114524
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	var s string
	fmt.Fscan(r, &n)
	fmt.Fscan(r, &s)

	var ans []string
	opCount := 0
	clCount := 0
	i := 0
	for i < n {
		if s[i] == '(' {
			ans = append(ans, "(")
			opCount++
			i++

		} else {
			// )が続く回数を調べる
			clCount++
			i++
			for j := i; j < n; j++ {
				if s[j] != ')' {
					break
				}
				clCount++
				i++
			}

			tmpOpCount := max(0, clCount-opCount)
			for tmpOpCount > 0 {
				ans = append([]string{"("}, ans...)
				tmpOpCount--
			}
			opCount = max(0, opCount-clCount)

			for clCount > 0 {
				ans = append(ans, ")")
				clCount--
			}
		}
	}

	for opCount > 0 {
		ans = append(ans, ")")
		opCount--
	}

	fmt.Println(strings.Join(ans, ""))
}

// Union-Find
type unionFind struct {
	d []int
}

func newUnionFind(n int) *unionFind {
	uf := new(unionFind)
	uf.d = make([]int, n)
	for i := 0; i < n; i++ {
		uf.d[i] = -1
	}
	return uf
}

func (uf *unionFind) find(x int) int {
	if uf.d[x] < 0 {
		return x
	}
	uf.d[x] = uf.find(uf.d[x])
	return uf.d[x]
}

func (uf *unionFind) unite(x, y int) bool {
	rootX := uf.find(x)
	rootY := uf.find(y)
	if rootX == rootY {
		return false
	}

	if uf.d[rootX] < uf.d[rootY] {
		uf.d[rootX] += uf.d[rootY]
		uf.d[rootY] = rootX
	} else {
		uf.d[rootY] += uf.d[rootX]
		uf.d[rootX] = rootY
	}

	return true
}

func (uf *unionFind) same(x, y int) bool {
	return uf.find(x) == uf.find(y)
}

func (uf *unionFind) size(x int) int {
	return -uf.d[uf.find(x)]
}

// mod combination
func modpow(a, n, mod int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % mod
		}
		a = a * a % mod
		n = n / 2
	}
	return res
}

func modcomb(n, a, mod int) int {
	x := 1
	y := 1
	for i := 0; i < a; i++ {
		x = x * (n - i)
		x %= mod
		y = y * (i + 1)
		y %= mod
	}
	return x * modpow(y, mod-2, mod) % mod
}

func modfactorial(n, mod int) int {
	result := 1
	for i := 1; i <= n; i++ {
		result = (result * i) % mod
	}
	return result
}

// Utility

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

func primeFactor(x int) map[int]int {
	res := make(map[int]int)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			res[i]++
			x = x / i
		}
	}
	if x != 1 {
		res[x] = 1
	}
	return res
}

func divisor(x int) []int {
	res := make([]int, 0)
	for i := 1; i*i <= x; i++ {
		if x%i == 0 {
			res = append(res, i)
			if i != x/i {
				res = append(res, x/i)
			}
		}
	}
	return res
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

func reverseString(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}


Measured memory_bytes: 768
#include <cmath>
#include <cstdio>
#include <vector>

using namespace std;

#define int long long
#define dotimes(i, n) for (int i = 0, i##max__ = (n); i < i##max__; i++)
#define whole(f, x, ...) ([&](decltype((x)) c) { return (f)(begin(c), end(c), ## __VA_ARGS__); })(x)

int rint() {
  int x;
  scanf("%lld", &x);
  return x;
}

void wint(int x) {
  printf("%lld\n", x);
}

template<typename T> int size(T const& c) { return static_cast<int>(c.size()); }
template <typename T> bool maxs(T& a, T const& b) { return a < b ? a = b, true : false; }
template <typename T> bool mins(T& a, T const& b) { return a > b ? a = b, true : false; }

signed main() {
  const int N = rint();
  int p = sqrt(1 + 8 * N);
  if (p * p != 1 + 8 * N) {
    puts("No");
    return 0;
  }
  int k = (1 + p) / 2;
  vector<int> S[k];
  dotimes(i, k)
    S[i].reserve(k-1);
  int c = 0;
  dotimes(j, k)
    dotimes(i, j) {
      c++;
      S[i].emplace_back(c);
      S[j].emplace_back(c);
    }
  puts("Yes");
  wint(k);
  dotimes(i, k) {
    printf("%lld", ::size(S[i]));
    for (int s : S[i])
      printf(" %lld", s);
    puts("");
  }
  return 0;
}


Measured memory_bytes: 4628
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007

int main() {
    long long a,b,n;
    cin>>a>>b>>n;

    if(b <= n)
        n = b-1;
    //cout<<n;
    long long res = floor(a*n/b);
    cout<<res;
}


Measured memory_bytes: 3588
import bisect
 
n = int(input())
bar_list = list(map(int,input().split()))

#リストをソートする
bar_list.sort()

cnt = 0

#１本目の棒を決める
for i in range(n):
    #２本目の棒を決める
    for j in range(i+1,n):
        #２本の棒を足して値がリストのどこに挿入できるかを調べる
        x = bisect.bisect_left(bar_list,bar_list[i]+bar_list[j])
        
        #挿入できる箇所よりも左側の棒は全て三角形に使える
        cnt += x-j-1
 
print(cnt)

Measured memory_bytes: 3188
#include<stdio.h>
int main()
{
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
	if(a==b&&a!=c){
		printf("Yes\n");
	}
	else if(a==c&&a!=b){
		printf("Yes\n");
	}
	else if(b==c&&b!=a){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
  return 0;
}    

Measured memory_bytes: 128
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
ans = int(math.sqrt(N))
print(ans**2)

Measured memory_bytes: 12484
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

/* 奇数長の閉路を検出 */
bool dfs(int p, int v, int t, vector<vector<int>> &G, vector<int> &used) {
    bool ret = false;
    if(!used[v])
        used[v] = t;
    else if((used[v] % 2) == (t % 2))
        return false;
    else
        return true;
    for(int nv : G[v]) {
        if(nv == p)
            continue;
        ret |= dfs(v, nv, t + 1, G, used);
    }
    return ret;
}

int main() {
    int N;
    cin >> N;
    vector<vector<char>> S(N, vector<char>(N));
    vector<vector<int>> G(N, vector<int>());
    vector<vector<int>> d(N, vector<int>(N));
    rep(i, N) rep(j, N) {
        cin >> S[i][j];
        if(S[i][j] == '1') {
            G[i].pb(j);
            d[i][j] = 1;
        } else {
            d[i][j] = 1e5;
        }
        if(i == j)
            d[i][j] = 0;
    }

    vector<int> used(N, 0);
    if(dfs(-1, 0, 1, G, used)) {
        cout << -1 << endl;
        return 0;
    }

    rep(k, N) rep(i, N) rep(j, N) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); }
    int res = 0;
    rep(i, N) rep(j, N) {
        if(d[i][j] != 1e5)
            res = max(res, d[i][j] + 1);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <map>
using namespace std;
#define PI 3.14159265359

int main() {
    int n;
    cin>>n;
    vector<int> count(n);
    for(int i=0; i<n-1; ++i) {
        int a;
        cin>>a;
        ++count[a-1];
    }

    for(int i=0; i<n; ++i) {
        cout<<count[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 4052
#include <stdio.h>
    
int main(void)
{
char str[1001], p[1001], cmd[10];
int a, b, q;
    
scanf("%s", str);
    
scanf("%d", &q);
    
while (q > 0)
{
scanf("%s", cmd);
scanf("%d", &a);
scanf("%d", &b);
if (cmd[0] == 'p')
{
 while (a <= b)
 {
 putchar(str[a]);
 a++;
 }
 putchar('\n');
    
} else if (cmd[2] == 'v')
{
 while (a < b)
 {
  p[0] = str[a];
  str[a] = str[b];
  str[b] = p[0];
  a++;
  b--;
 }
} else {
 scanf("%s", p);
 while (a <= b)
 {
  str[b] = p[b - a];
  b--;
 }
}
q--;
}
    
return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>   
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int x1, x2, ans;
  cin >> x1 >> x2;
  ans = x1 * x2;
  cout << ans << endl;
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	double probs[n];
	for(int i =0;i<n;i++)
		cin >> probs[i];
	double dp[n+1][n+1];
	memset(dp,0,sizeof(dp));
	dp[0][0] = 1.0;
	for(int i =1;i<=n;i++){
		dp[0][i] = 0.0;
	}

	for(int i =1;i<=n;i++){
		for(int j =i-1;j>=0;j--){
			dp[i][j+1]+= dp[i-1][j] * probs[i-1];
			dp[i][j] += dp[i-1][j]*(1-probs[i-1]);
		}
	}
	double ans = 0.0;
	for(int i = 1;i<=n;i++){
		if(i>n/2)
			ans+=dp[n][i];
	}
	cout <<fixed << setprecision(12) <<  ans << endl;
}

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}
    
int main()
{    
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        ld a,b,x,PI=3.14159265358979323846;

        cin>>a>>b>>x;

        ld tp=a*a*b-x;

        ld tp2=(x*2)/(a*b);

        ld h=tp/(a*a);

        ld ans;

        if(h<=b/2)
            ans=atan(h/(a/2));

        else
            ans=atan(b/tp2);

        cout<<fixed<<setprecision(10)<<ans*(180/PI);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int n;
  string s, t;
  cin >> n;
  cin >> s >> t;
  vector<string> x(2*n);
  rep(i,n){
      x[2*i] = s[i];
      x[2*i+1] = t[i];
  }

  rep(i,2*n){
      cout << x[i];
  }

  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int a, b, c;
  int mode = 0;
  
  scanf("%d %d %d", &a, &b, &c);
  
  if( a == b && b != c && c != a ){
    mode = 1;
  }
  if( a != b && b == c && c != a ){
    mode = 1;
  }
  if( a != b && b != c && c == a ){
    mode = 1;
  }
  
  if( mode == 1 ){
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  
  return 0;
}
     

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;
 
public class Main {
	
	long[] Ni = null;
	
	
	public void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		Ni = new long[N+1];
		Arrays.fill(Ni, -1);
		Ni[N] = 1;
		Ni[N-1] = 1;
		
		for (int i=0; i<M; i++) {
			Ni[in.nextInt()] = 0;
		}
		in.close();
		
		
		for (int i=N-2; i>=0; i--) {
			if (Ni[i] != 0) {
				Ni[i] = (Ni[i+1] + Ni[i+2]) % 1000000007;
			}
		}
		
		System.out.println(Ni[0]);
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}
 
}


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

int main() {

	int n;
	cin >> n;
	vector<int> h(n);

	for (int i = 0; i < n; i++) {
		cin >> h.at(i);
	}

	int ans = 1;

	for (int i = 1; i < n; i++) {
	
		for (int j = 0; j < i; j++) {
			if (h.at(i) - h.at(j) < 0)break;
			if (j == i - 1)ans++;
		}
	
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof(x))
#define sz(x) (int)x.size()
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;

using namespace std;

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

const ll mx = 105;
const ll mod = 998244353;
const ll maxn = 1e5;



void solve(){
   
  ll n, i, j, k;

  cin>>n;

  ll a[n];

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


  ll x[maxn+1];
  clr(x);

  ll s = 0;
  for(i = 0;i < n;i++){
    s += a[i];
    x[a[i]]++;
  }

  ll q;

  cin>>q;
  while(q--){
    ll b, c;

    cin>>b>>c;
    s = s + c*x[b] - x[b]*b;
     x[c] += x[b];
    x[b] = 0;
   

    cout<<s<<"\n";
  }

}   


int main(){

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

    ll t = 1;
    
   // cin>>t;

    while(t--){
        solve();
    }
   
}




Measured memory_bytes: 5208
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include "iomanip"
#include <cstdio>
#include <cstring>
#include <set>
#include <vector>
#include <fstream>
#include <algorithm>

using namespace std;





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

    int a, b;
    cin >> a >> b;
    if ((a + b) % 2 == 0){
        cout << (a + b) / 2;
    } else {
        cout << "IMPOSSIBLE";
    }
}




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

using namespace std;

int main(){

	string s;
	int w;
	cin >>s >>w;
	for(int i = 0; i < s.size(); i++){
		if(i%w == 0){
			cout << s[i];
		}
	}
	cout << '\n';

	return 0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 LN             PIC X(3).
01 a              PIC 9(1).
01 b              PIC 9(1).
01 x              PIC 9(1).
01 i              PIC 9(2).
01 ans            PIC X(9).

PROCEDURE DIVISION.
  ACCEPT LN.
  UNSTRING LN DELIMITED BY SPACE INTO a b.
  IF a < b
      MOVE b TO x
  ELSE
      MOVE a TO x
      MOVE b TO a
  END-IF.
  PERFORM VARYING i FROM 1 BY 1 UNTIL x < i
      MOVE a TO ans(i:1)
  END-PERFORM.
  DISPLAY ans(1:x).
  STOP RUN.


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

using namespace std;

int main(){
  int res = 0,n;
  string s;
  cin >> n >> s;
  for(int i = 0;i < n-2;i++){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')res++;
  }
  cout << res;
  return 0;
}


Measured memory_bytes: 256
(n, m) = map(int, input().split())
stores = sorted([list(map(int, input().split()))
                 for _ in range(n)], key=lambda x: x[0])
cost = 0
for store in stores:
    if store[1] < m:
        cost += store[0] * store[1]
        m -= store[1]
    else:
        cost += store[0] * m
        break
print(cost)


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

//using ul = long long int;
using ul = unsigned long long int;
const ul LL_MAX (1LL<<60);
const ul MOD (1000000007);

#define rep(i,s,e) for(ul i=(s); i<(e); i++) 

using namespace std;

using T = tuple<ul,ul>;
using Graph = vector<vector<T>>;

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

    ul x,y,a,b,c;
    cin >>x >>y>> a>> b>> c;
    vector<ul> p(a);
    vector<ul> q(b);
    vector<ul> r(c);
    priority_queue<ul> v;

    rep(i,0,a)
        cin >> p[i];

    rep(i,0,b)
        cin >> q[i];

    rep(i,0,c)
        cin >> r[i];

    sort(p.begin(), p.end(), greater<ul>());
    sort(q.begin(), q.end(), greater<ul>());
    sort(r.begin(), r.end(), greater<ul>());

    rep(i,0,x)    
        v.push(p[i]);

    rep(i,0,y)    
        v.push(q[i]);

    rep(i,0,c)    
        v.push(r[i]);

    ul ans(0);
    rep(i, 0, x+y)
        ans += v.top(), v.pop();

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8816