prompt
string
response
string
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; int t,n; stack<pii>st; int a[100005]; int main() { scanf("%d",&t); while(t--) { scanf("%d",&n); for(int i=1;i<=n;i++)a[i]=i; ll ans=0; for(int i=1;i<=n/2;i++) swap(a[i],a...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; #define fo(a,b) for(int a=0;a<b;++a) #define pb push_back #define printList(v) for(auto _x:(v)) cout<<_x<<" ";cout<<endl; ////////////// DEBUG UTILS ////////////////// #define debug(...) __print(#__VA_ARGS__, __VA_ARGS__) template<class K,class V> ostream& operator<<(ost...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include"bits/stdc++.h" using namespace std; int a[100005]; int save[100005][2],nn; int main() { int t; cin>>t; while(t--) { int n; cin>>n; for(int i=0;i<=n;i++) { a[i]=i; } long long ans=0; nn=0; for(int i=2;i<=n/2;i++) ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.PrintStream; import java.util.Random; import java.util.ArrayList; import java.util.BitSet; import java.util.Collections; import java.io.InputStream; /** * Built using CHelper plug-in * Actu...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
import sys input = sys.stdin.readline t=int(input()) for tests in range(t): n=int(input()) AA=[] for i in range((n+2)//2,n): AA.append((1,i)) for i in range((n+2)//2-1,0,-1): AA.append((i,n)) L=list(range(1,n+1)) sc=0 for x,y in AA[::-1]: L[x-1],L[y-1]=L[y...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
import java.util.*; import java.io.*; public class Chto_Eto { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; private static final long MOD = 1000L * 1000L * 1000L + 7; private static final int[] dx = {0, -1, 0, 1}; private static final int[] dy = {1, 0, -1, 0}; pri...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; long long worst = 0; vector<pair<int, int>> save; vector<int> bad(n + 1); for (int i = 1; i <= n; ++i) { bad[i] = i; } for (int d = 1, c = n, l = n - 1; d <= c; ++d, --c, --l) { if (l == n -...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
for tests in range(int(input())): n=int(input()) AA=[] for i in range((n+2)//2,n): AA.append((1,i)) for i in range((n+2)//2-1,0,-1): AA.append((i,n)) L=list(range(1,n+1)) sc=0 for x,y in AA[::-1]:L[x-1],L[y-1]=L[y-1],L[x-1];sc+=(x-y)**2 print(sc);print(*L);prin...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
for tests in range(int(input())): n=int(input());AA=[(1,i) for i in range((n+2)//2,n)] + [(i,n) for i in range((n+2)//2-1,0,-1)];L=list(range(1,n+1));sc=0 for x,y in AA[::-1]:L[x-1],L[y-1]=L[y-1],L[x-1];sc+=(x-y)**2 print(sc);print(*L);print(len(AA)) for x,y in AA:print(y,x) if L[x-1]==y else print(x,y)...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
/* #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") //*/ #include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define DEBUG(x) cerr<<#x<<": "<<x<<endl; #define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <iostream> #include <vector> #include <algorithm> using namespace std; void do_test() { int n; cin>>n; long long s=0; const int m=n/2; for (int i=2; i<=m; ++i) { long long r = n-i; r *= r; s += r; } for (int i=m+1; i<=n; ++i) { long long r ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include<bits/stdc++.h> using namespace std; long long ans[100010]; int p[100010]; int main() { int T; cin>>T; while(T--) { int n; cin>>n; if(!ans[n]) { ans[n]=1ll*(n-1)*(n-1); for(int i=0;i<n-2;i++)ans[n]+=1ll*(n-2-i/2)*(n-2-i/2); } cout<<ans[n]<<endl; for(int i=1;i<=n;i++)p[i]=i; p[1]+=p[n];...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <map> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; const int maxn = 2e5 + 7; int a[maxn]; int main() { int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); for(int i = 1; i <= n; i++) { a[i] ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <cstdio> #include <iostream> #include <vector> #include <algorithm> #include <cstring> #include <map> #include <set> #include <cmath> #include <iomanip> #include <queue> #include <climits> #include <stack> #include <sstream> #include <functional> using ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
import sys, io, os if os.environ['USERNAME']=='kissz': inp=open('in.txt','r').readline def debug(*args): print(*args,file=sys.stderr) else: inp=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def debug(*args): pass # SCRIPT STARTS HERE for _ in range(int(inp())): n=int(inp()) ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
from collections import defaultdict from itertools import accumulate import sys input = sys.stdin.readline ''' for CASES in range(int(input())): n, m = map(int, input().split()) n = int(input()) A = list(map(int, input().split())) S = input().strip() sys.stdout.write(" ".join(map(str,ANS))+"\n") ''' inf = 100000000000...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include<bits/stdc++.h> using namespace std; void swap(int &a, int& b){ int t=a; a=b; b=t; } void solve(){ long long int n,ans; scanf("%lld",&n); int p[n]; for(int i=0;i<n;i++) p[i]=i+1; swap(p[0],p[n-1]); ans=(n-1)*(n-1); vector<pair<int,int>> v; v.push_back({1,n}); for(int i=1;i<n/2;i++){ ans+=2*(n-i-1)...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
import java.util.*; import java.util.Map.Entry; import java.util.function.Function; import javax.security.auth.kerberos.KerberosKey; import org.omg.PortableServer.ServantActivator; import java.math.*; import java.time.temporal.ValueRange; import java.awt.image.PixelGrabber; import java.io.*; public class Main { pu...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
//stan hu tao import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; public class x1474E { public static void main(String hi[]) throws Exception { BufferedReader infile = new BufferedReader(new Inpu...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define mp make_pair #define pb push_back #define fi first #define se second #define vi vector<int> #define sz(x) (int)(x).size() typedef long long ll; typedef long double ld; typedef pair<int, i...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> #define int long long using namespace std; #ifdef LOCAL #include "/media/brayand/BrayanD/debugger.h" #else #define db(...) false #define dbl(...) false #define dbg(...) false #define dbm(...) false #define dbs(...) false #define dbas(...) false #endif int32_t main() { ios_base::sync_wi...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; typedef long long ll; int res[100005]; int main(){ cout.sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--){ int n; cin >> n; if(n == 2){ cout << 1 << endl; cout << "2 1" << endl; cout << 1 ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
for _ in range(int(input())): n = int(input()) p = [i for i in range(n+1)] ops = [] for i in range(1, n//2+1): ops.append((i, n)) for i in range(n-1, n//2, -1): ops.append((i, 1)) print(sum([(j-i)**2 for i, j in ops])) for i, j in ops: p[i], p[j] = p[j], p[i] p = ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author */ #include <bits/stdc++.h> using namespace std; #define forn(i,n) for(int i=0;i<(int)(n);i++) #define si(c) ((int)(c).size()) #define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++) #define dforsn(i,s,n) for(int ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> #define endl "\n" using namespace std; void setup() { #ifdef LOCAL freopen("input", "r", stdin); #else ios::sync_with_stdio(0); cin.tie(0); #endif } int main() { setup(); int t; cin >> t; while (t--) { int n; cin >> n; ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> #define watch(x) cout <<(#x)<<" is "<<(x)<<endl #define debug cout <<"hi"<<endl #define maxn 3e5+10 #define inf32 0x3f3f3f3f using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<int,int>pii; const int MOD=1e9+...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define mst(a,b) memset((a),(b),sizeof(a)) #define rush() int TT;scanf("%d",&TT);for(int TTT=1;TTT<=TT;TTT++) #define fastio() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define forrr(i,x,y) for(int i=x;i<=y;++i) #define rofff(i,x,y) for(int i=x;i...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
t = int(input()) for _ in range(t): n = int(input()) c = 0 for i in range(n//2 + 1,n): c += (i-1)**2 for i in range(1,n//2 + 1): c += (n-i)**2 print(c) print(n//2 + 1,end = " ") for i in range(1,n//2): print(i, end = " ") for i in range(n//2 + 2, n+1): print(i, end = " ") print(n//2) print(n-1) for...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
/** * Author: Daniel * Created Time: 2021-01-27 14:46:44 **/ // time-limit: 1000 #include <bits/stdc++.h> using namespace std; #define F first #define S second #define ER erase #define IS insert #define PI acos(-1) #define PB pop_back #define EB emplace_back #define lowbit(x) (x & -x) #define SZ(x) ((int)x.size()...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> PII; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); vector<int> v; for (int i = 1; i <= n; i++) v.push_back(i); ll cost = 0; vector<PII> path; for (int i = n / 2 + 1; i <= n;...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
def solve(): n = int(input()) q = list(range(1, n+1)) q = list(range(1, n+1)) q[0], q[n-1] = q[n-1], q[0] res = (n - 1) ** 2 for i in range(1, n // 2): q[0], q[n - i - 1] = q[n - i - 1], q[0] q[i], q[n - 1] = q[n - 1], q[i] res += 2 * (n - (i + 1)) ** 2 if n % 2:...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<pair<int, int>> vii; typedef pair<int, int> pi; #define MOD 1000000007LL int t, n; int main() { //freopen("feast.in", "r", stdin); //freopen("feast.out", "w", stdout); //ios_base::sync_with_stdio(f...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
# Author: yumtam # Created at: 2021-03-02 22:32 def solve(): n = int(input()) A = list(range(1, n+1)) ops = [] ans = 0 def process(i, j): nonlocal ans A[i], A[j] = A[j], A[i] ops.append((i+1, j+1)) ans += (i-j)**2 process(0, n-1) rem = n-2 d = 2 ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <st...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; void solve(){ int n; scanf("%d", &n); if (n == 2){ printf("1\n2 1\n1\n2 1\n"); } else if (n == 3){ printf("5\n2 3 1\n2\n1 3\n2 3\n"); } else { long long t = 0; vector<int> ans; vector<pair<int, int>> vc; ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
import java.util.ArrayList; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Arrays; import java.util.Random; import java.io.FileWriter; import java.io.PrintWriter; /* Solution Created: 00:28:10...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> PII; const int maxn=111111,mod=998244353; #define MP make_pair #define PB push_back #define lson o<<1,l,mid #define rson o<<1|1,mid+1,r #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define ROF(i,a,b) for(int i=(a);i>=(b);i--) #defi...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> #include <vector> #include <iostream> #include <cstring> #include <algorithm> #include <queue> #include <map> #include <set> #include <stack> #define ll long long #define chushi(a, b) memset(a, b, sizeof(a)) #define endl "\n" const double eps = 1e-8; const ll INF=0x3f3f3f3f; const int mod = 200...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; #define pb(x) push_back(x) #define FOR(i,a,b) for(int i=a;i<b;i++) typedef long long ll; int main(){ ios::sync_with_stdio(false); cin.tie(0); int t; cin>>t; while(t--){ int n; cin>>n;...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> #ifndef ONLINE_JUDGE #define debug(x) cout << #x << ": " << (x) << endl #else #define debug(x) #endif using namespace std; typedef long long ll; typedef vector<int> vi; const int maxn=1e6+7,inf=0x3f3f3f3f,mod=1e9+7; int main() { ios::sync_with_stdio(false); cin.tie(0); int kase; ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; #define INF 2000000000 typedef long long int ll; typedef pair<ll,ll> ii; typedef pair<ii,ll> iii; typedef vector<ll> vi; typedef vector<ii> vii; #define getbit(n,i) (((n)&(1LL<<(i)))!=0) #define setbit0(n,i) ((n)&(~(1LL<<(i)))) #define setbit1(n,i) ((n)|(1LL<<(i))) #define ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; #define int long long #define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++) #define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--) #define endl "\n" #define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define pii pair<int,int> #define pb push_back #define all(v) v.begin...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
for _ in range(int(input())): n = int(input()) a = list(range(1, n + 1)) ans = (n - 1)**2 for i in range(1, n - 1): ans += max(i, n - i - 1)**2 pos = list(range(n - 1)) pos.sort(key=lambda i: min(i, n - i - 1)) ops = [] for i in pos: if i * 2 < n: ops.append([i + 1, n]) a[i], a[n - 1] = a[n - 1], a[i]...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include<bits/stdc++.h> using namespace std; int T,n,p[100010],ls; long long ans; int main(){ scanf("%d",&T); while(T--){ scanf("%d",&n),ls=n,ans=0; for(int i=2;i<=(n>>1);++i)p[ls]=i,ans+=1ll*(n-i)*(n-i),ls=i; p[ls]=1,ls=1; for(int i=(n>>1)+1;i<=n;++i)p[ls]=i,ans+=1ll*(i-1)*(i-1),ls=i; printf("%lld\n",ans);...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n,T,cnt; char s[100005]; int a[100005]; pair<int,int> all[200005]; int main() { scanf("%d",&T); while(T--) { scanf("%d",&n); cnt=0; for(int i=1;i<=n;i++) a[i]=i; ll ans=1ll*(n-1)*(n-1); for(int i=n-2;i>=n/2;i--) ans+=2ll*i*i; if(n&1) ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
def ints(): return list(map(int, input().split())) def go(): n, = ints() if n <= 3: print(sum(i**2 for i in range(n))) print(' '.join(map(str, range(2, n+1))), 1) print(n-1) for i in range(1, n): print(i, n) else: print(sum(max(i-1, n-i)**2 for i in r...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; #define mod(a, b) ((((a)%(b))+(b))%(b)) #define pb push_back #define sz(c) int((c).size()) typedef long long ll; typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<vector<int> > vvi; typedef vector<ll> vll; typedef vector<vll> vvll; int main() { ios_b...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
/*input 1 5 */ //assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pii pair<ll int,ll int> #define vpii vector< pii > #define vi vector...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
/* Author: Wa-Automaton Time: 202101203 15:20:00 UTC+8 Website: codeforces Contest: Codeforces Round #696 (Div. 2) Problem: E. What Is It? Result: Solutions: */ #include<bits/stdc++.h> using namespace std; #define lson (root << 1) #define rson (root << 1 | 1) typedef long long LL; typedef pair<LL, L...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef priority_queue<pl, vector<pl>, greater<pl> > pq; template<class T, cla...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
from sys import stdin, stdout tc = input() inp = stdin.readlines() out = [] for line in inp: n = int(line.strip()) ans = 0 p = [i for i in xrange(n)] ops = [] for i in xrange(n): j = n - i - 1 if i > j: break if i < n - 1: # to handle the case n = 1 (not needed as n >= 2...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; if (n == 1) { cout << 0 << "\n"; cout << 1 << "\n"; cout << 0 << "\n"; return; } long long ans = 0; long long cnt = 1, st = n - 1, asz = 0; while (asz < n - 1) { ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
from sys import stdout def solve(): n = int(raw_input()) a = range(1, n + 1) ans = [] s = 0 for i in xrange(n - 1): x = n - 1 if i < n - 1 - i else 0 s += (x - i) * (x - i) ans.append((i + 1, x + 1)) a[x], a[i] = a[i], a[x] ans.reverse() stdout.write(str(s) + ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
import java.io.*; import java.util.*; public class CF1474E extends PrintWriter { CF1474E() { super(System.out); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1474E o = new CF1474E(); o.main(); o.flush(); } int[] ii, jj; int cnt; long ans; void add(int i, int j) { ii[cnt] = i...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include<bits/stdc++.h> #define fi first #define se second #define lo (o<<1) #define ro (o<<1|1) #define mid (l+r>>1) #define endl '\n' using namespace std; typedef long long ll; typedef vector<int>vi; typedef pair<int, int>pii; const int inf = 0x3f3f3f3f; const ll linf = 0x3f3f3f3f3f3f3f3f; const int N = 200 + 10; con...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include<bits/stdc++.h> using namespace std; #define f first #define s second using ll = long long; const int MX = 5e5+5; int main() { //ios_base::sync_with_stdio(false); //cin.tie(nullptr); int t; cin >> t; while(t--) { int n; cin >> n; vector<int> p(n); p[0] = n/2+1; for(int i=1;i<=n/2 - 1;i+...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
import sys input=sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) time = 0 integer = [i for i in range(1,n+1)] l = [] for i in range(n//2,n): time += i**2 integer[0],integer[i] = integer[i],integer[0] l.append((i+1,1)) for i in range(1,n...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e5+10; int n; void solve(){ cin>>n; ll ans=0; for(int i=n/2+1;i<n;++i)ans+=ll(i-1)*(i-1); for(int i=n/2;i>=1;--i)ans+=ll(n-i)*(n-i); cout<<ans<<endl; cerr<<"----------------------"<<endl; cout<<n/2+1<<' '; for(int i=1;i<n/2;+...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #define FASTER ios_base::sync_with_stdio(0);cin.tie(0) #define setPrecision(n) cout << std::setprecision(n) << std::fixed; #define rep(i,j,n) for(int i = j; i < n; i++)...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
/// I'm the President of the United States of America #include <bits/stdc++.h> using namespace std; #define int long long const int N = (int) 1e5 + 7; int n, a[N], cost; vector<pair<int, int>> history; void op(int i, int j) { cost += (i - j) * (i - j); history.push_back({i, j}); swap(a[i], a[j]); } signed ma...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> #define perr(a...) fprintf(stderr, a) #define dbg(a...) perr("\033[32;1m"), perr(a), perr("\033[0m") template <class T, class U> inline bool smin(T &x, const U &y) { return y < x ? x = y, 1 : 0; } template <class T, class U> inline bool smax(T &x, const U &y) { return x < y ? x = y, 1 : 0; ...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+10; typedef long long ll; ll s[maxn];int a[maxn]; int main() { s[2]=1;s[3]=5; for(int i=4;i<=1e5;i++) s[i]=s[i-1]+1LL*(i-1)*(i-1)-1LL*((i-1)/2)*((i-1)/2)+1LL*(i-2)*(i-2); int t;scanf("%d",&t); while(t--){ int n;scanf("%d",&n); printf("%lld\n",s[n])...
Problem: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way t...
#include <bits/stdc++.h> using namespace std; int main(){ int t; cin >> t; for (int i = 0; i < t; i++){ int n; cin >> n; vector<int> p(n); for (int j = 0; j < n; j++){ p[j] = j; } long long T = 0; vector<pair<int, int>> op; op.push_back(make_pair(0, n - 1)); swap(p[0], p[...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { int n, x, a, b; vector<int> v; vector<int> v2; cin >> n >> x; for (int i = 0; i < n; i++) { cin >> a >> b; if (a < b) { v.push_back(a); v2.push_back(b); } else { v.push_back(b); v2.push_back(a); } } sort(v.b...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#***************14B - Young Photographer***************# #author - @Divyesh Chhabra from math import * import os import random import re import sys from itertools import * n,a = map(int,input().split()) sp = [] xp = [] yp = [] f = 1 while n != 0: x,y = map(int,input().split()) if x>y: x,y = y,x xp...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
//package clipse; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Random; import java.util.StringTokenizer; imp...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n, x0 = map(int, input().split()) kiri = 0 kanan = 1000 for _ in range(n): a, b = map(int, input().split()) kiri = max(kiri, min(a, b)) kanan = min(kanan, max(a, b)) if kiri > kanan: print(-1) elif kiri <= x0 <= kanan: print(0) elif x0 < kiri: print(kiri - x0) else: print(x0 - kanan) ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, x0, left = INT_MIN, right = INT_MAX; cin >> n >> x0; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; left = max(left, min(a, b)); right = min(right, max(a, b));...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; public class Books { public static void main(String args[]) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int x=in.nextInt(); int left=0; int right=1000; for(int i=0;i<n;i++){ int a=in.nextInt(); i...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> template <typename T, typename U> std::istream& operator>>(std::istream& input, std::pair<T, U>& v) { return input >> v.first >> v.second; } template <typename T> std::istream& operator>>(std::istream& input, std::vector<T>& v) { for (T& a : v) input >> a; return input; } void answer(int ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") #pragma GCC optimize("Ofast") using namespace std; void fastio() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long dp[101][1001], ans1 = 1e9, dp1[1000001]; long long num[10]; long long a[1000000]; signed m...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import sys import math import bisect import re def solve(L, R, m): #print('L: %s, R: %s, m: %d' % (L, R, m)) l = max(L) r = min(R) if l > r: return -1 if m < l: return abs(m - l) if m > r: return abs(m - r) return 0 def main(): n, m = map(int, input().split()) ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
def s(): [n,x] = list(map(int,input().split())) a = 0 b = 1000 for _ in range(n): t = list(map(int,input().split())) t.sort() a = max(a,t[0]) b = min(b,t[1]) if b<a: print(-1) else: print(0 if x > a and x < b else min(abs(a-x),abs(b-x))) s()
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int x[1001]; void print() { cout << "\n"; for (int i = 0; i < 1001; i++) { cout << x[i] << ","; } cout << endl; } int main() { for (int i = 0; i < 1001; i++) x[i] = 0; int n, x0; cin >> n >> x0; for (int i = 0; i < n; i++) { int a, b; cin >> a >>...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; import java.io.*; public class Problem { static Pair[] pairs; public static void main(String[] args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); StringTokenizer s = new Str...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; bool isPrime(long long N) { for (long long i = 2; i * i <= N; ++i) { if (N % i == 0) return false; } return true; } bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return (a.first > b.first); } int gcd(int a, int b)...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n,x = map(int,input().split()) low = 0 high = 1000 for _ in range(n): a,b = map(int,input().split()) low = max(low,min(a,b)) high = min(high,max(a,b)) if low > high: print(-1) elif x>=low and x<=high: print(0) else: print(min(abs(x-low),abs(x-high)))
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n,xo=map(int,input().split()) L=[] c=0 M=0 m=10**18 for i in range(n): a,b=map(int,input().split()) a,b=min(a,b),max(a,b) while(a>xo): c+=1 xo=xo+1 while(b<xo): c+=1 xo=xo-1 M=max(M,a) m=min(m,b) if(M>xo or m<xo): c=-1 break print(c)
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n, x = map(int, input().split()) l = 0 r = 1000 for i in range(n): a, b = sorted(map(int, input().split())) l = max(l, a) r = min(r, b) #initial point of the common segmnet is l # and the end point ofthe segment is r if l > r: print(-1) exit(0) if l <= x <= r: print(0) else: print(min(ab...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { int n, x0; cin >> n >> x0; int p1 = INT_MAX; int p2 = INT_MIN; int i; for (i = 1; i <= n; i++) { int a, b; cin >> a >> b; if (b < a) swap(a, b); p1 = min(p1, b); p2 = max(p2, a); } if (p1 < p2) { cout << "-1" << endl; ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.HashSet; import java.util.Scanner; public class youngPhotographer { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for (int i =...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n, x = map(int, input().split()) a, b = 0, 10**4 for _ in range(n): a_i, b_i = sorted(map(int, input().split())) a, b = max([a, a_i]), min([b, b_i]) if a > b: print("-1") else: if a <= x and x <= b: print("0") else: print(min([abs(x-a), abs(x-b)]))
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.*; import java.util.*; public class YoungPhotographer { static final int MAX = 1000; public static void main(String[] args) { InputReader in = new InputReader(System.in); int n = in.nextInt(); int x0 = in.nextInt(); int[] count = new int[MAX + 1]; for (int i = 0; i < n; ++i) { ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import static java.lang.Math.*; import java.awt.Point; import java.util.Scanner; @SuppressWarnings("unused") public class round14B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int cur = sc.nextInt(); Point [] in = new Point [...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.Scanner; public class codeforces { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int x=sc.nextInt(); int CurrentMin=Integer.MIN_VALUE; int C...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; import java.io.*; public class B { private static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, mn = 1005; cin >> n >> k; int a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; for (int i = 0; i < 1001; i++) { bool f = 0; for (int j = 0; j < n; j++) { if (i < min(a[j], b[j]) || i > max(a[j], b[j])) f = 1; } ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } int isprime(int n) { if (n < 2) return 0; if (n < 4) return 1; if (n % 2 == 0 or n % 3 == 0) return 0; for (int i = 5; i * i <= n; i += 6) if (n % i == 0 or n % (i + 2) == 0) return 0; retu...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
a,d = map(int,input().split()) bb,cc =map(int,input().split()) mi=min(bb,cc) ma=max(bb,cc) boo=True for i in range(a-1): b,c =map(int,input().split()) if(min(b,c)>mi): mi = min(b,c) if(max(b,c)<ma): ma = max(b,c) if(min(b,c)>ma or max(b,c)<mi): boo=False break if(boo): ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.util.*; import java.io.*; import java.math.BigInteger; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub InputReader in = new InputReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); new Task().go(in, out); out.c...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top * @author nasko */ public class Main ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
'use strict' let lll = readline().split(' ') const N = lll[0] const X = lll[1] var spos = [] while (lll = readline()) spos.push(lll.split(' ').map(v => +v)) spos = spos.map(s => s[0] < s[1] ? s : [s[1], s[0]]) let p = spos.reduce((p, s) => [Math.max(p[0], s[0]), Math.min(p[1], s[1])]) if (p[0] > p[1]) { print(-...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n, x = map(int, input().split()) A = [] B = [] for i in range(n): a, b = map(int, input().split()) A.append(min(a, b)) B.append(max(a, b)) R = [] for i in range(min(A), max(B) + 1): res = abs(x - i) for j in range(n): if A[j] <= i <= B[j]: pass else: res = 100...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; struct iii { int a, b, c; iii() {} iii(int a, int b, int c) : a(a), b(b), c(c) {} bool operator<(const iii& e) const { return a < e.a || a == e.a && (b < e.b || b == e.b && c < e.c); } }; template <typename T> T sq(const T& x) { return x * x; } template <typ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; void solveQues() { long long int n, x; cin >> n >> x; vector<long long int> s(n); vector<long long int> e(n); for (int i = 0; i < n; i++) { long long int a, b; cin >> a >> b; if (a < b) { s[i] = a; e[i] = b; } else { s[i] = b; ...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n, x0 = map(int, raw_input().split()) x1, x2 = 0, 1000 for i in range(n): a, b = map(int, raw_input().split()) x1 = max(x1, min(a, b)) x2 = min(x2, max(a, b)) print max(0, x1 - x0, x0 - x2) if x2 >= x1 else -1
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
#include <bits/stdc++.h> using namespace std; int main() { int n; int x; int v[1001][2]; cin >> n >> x; for (int i = 0; i < n; i++) { cin >> v[i][0] >> v[i][1]; if (v[i][0] > v[i][1]) swap(v[i][0], v[i][1]); } int best = 1000000000; for (int i = 0; i <= 1000; i++) { if (abs(i - x) >= best) c...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
import java.io.*; import java.util.*; import java.util.HashSet; import java.util.*; import java.util.Scanner; import java.util.Set; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.text.DecimalFormat; import java.lang.Math; import java.util.Iterator;...
Problem: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, traini...
n, p = map(int, input().split()) x = [] for i in range(n): a, b= map(int, input().split()) n = [] if a<b: for i in range(a, b+1): n.append(i) else: for i in range(b,a+1): n.append(i) if x == []: x = n else: x = set(n)&set(x) if x == set(): print(-1) else: m = x.pop() while x.__len__()>1: x.pop...