prompt
string
response
string
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 10; int x[MAXN], y[MAXN]; int main() { int n, a, b, c, d; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d%d%d", &a, &b, &c, &d); x[i] = abs(a); y[i] = abs(b); } puts("YES"); for (int i = 0; i < n; i++) { if ((x[i...
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class D { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); System.out.println...
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
#include <bits/stdc++.h> using namespace std; int n; int main() { printf("YES\n"); scanf("%d", &n); while (n--) { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); if ((a & 1) && (b & 1)) printf("1\n"); else if (!(a & 1) && (b & 1)) printf("2\n"); else if ((a & 1) && !(b & 1)) ...
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n, a1, b1, a2, b2; cin >> n; cout << "YES" << '\n'; for (long long i = 0; i < n; i++) { cin >> a1 >> b1 >> a2 >> b2; long long x = (a1 & 1) * 2 + (b1 & 1) + 1; cout << x << '\n'; } }
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
import java.io.*; import java.util.*; public class Main { static FastScanner in; static int n; public static void main(String[] args) throws IOException { // Scanner in = new Scanner(new File("input.txt")); // Scanner in = new Scanner(System.in); in = new FastSc...
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
#include <bits/stdc++.h> using namespace std; int color[500005]; int main() { int n; scanf("%d", &n); int i; int x1, y1, x2, y2; for (i = 0; i < n; i++) { scanf("%d %d %d %d", &x1, &y1, &x2, &y2); if (x1 % 2) { if (y1 % 2) { color[i] = 1; } else { color[i] = 2; } ...
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; cout << "YES" << endl; for (int i = 0; i < n; i++) { int x, y, x1, y1; cin >> x >> y >> x1 >> y1; if (abs(x) % 2 == 0 && abs(y) % 2 == 0) { cout << 1 << endl; } ...
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); printf("YES\n"); for (int i = 1; i <= n; i++) { int x, y; int a, b; scanf("%d%d%d%d", &x, &y, &a, &b); if ((x & 1) && (y & 1)) cout << 1 << endl; if ((x & 1) && !(y & 1)) cout << 2 << endl; if (!(x & 1) &&...
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
n = int(input()) print("YES") for i in range(n): a, b, c, d = map(int, input().split()) print(1 + (a % 2) + 2*(b % 2))
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Random; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; import ja...
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << "YES\n"; while (n--) { int a, b, c, d; cin >> a >> b >> c >> d; cout << 2 * (a & 1) + (b & 1) + 1 << endl; } }
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
#include <bits/stdc++.h> using namespace std; int x[500010], y[500010]; int main() { int n, a, b; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d %d %d %d", &x[i], &y[i], &a, &b); x[i] = abs(x[i]); y[i] = abs(y[i]); } printf("YES\n"); for (int i = 0; i < n; ++i) { if (x[i] % 2 == 0 ...
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 10; long long x1[MAXN], x2[MAXN], yy[MAXN], y2[MAXN]; int32_t main() { long long n; cin >> n; long long mn = 0; for (long long i = 0; i < n; i++) { cin >> x1[i] >> yy[i] >> x2[i] >> y2[i]; mn = min(mn, x1[i]); mn = min(mn, x2[i]); ...
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
n = int(input()) ans = 'YES\n' for i in range(n): x1, y1, x2, y2 = map(int, input().split()) res = (x1 & 1) * 2 + (y1 & 1) + 1 ans += str(res) + '\n' print(ans)
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, n; cin >> n; cout << "YES" << endl; for (int i = 0; i < n; i++) { cin >> a >> b >> c >> d; if (a < 0) a *= -1; if (b < 0) b *= -1; cout << 1 + 2 * (a % 2) + (b % 2) << ' ' << endl; } return 0; }
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int INF = 1e9; const double EPS = 1e-8; int main() { int n; scanf("%d", &(n)); int a, b, c, d; puts("YES"); for (int i = 1; i <= n; i++) { scanf("%d", &(a)), scanf("%d", &(b)); scanf("%d", &(c)), scanf("%d", &(d)); if (a ...
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
#include <bits/stdc++.h> using namespace std; class rectangle { public: int x1; int x2; int y1; int y2; int color; void handle() { if ((x1 % 2 == 0) && (y1 % 2 == 0)) color = 1; else if ((abs(x1 % 2) == 1) && (y1 % 2 == 0)) color = 2; else if ((x1 % 2 == 0) && (abs(y1 % 2) == 1)) ...
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /** * @author Don Li */ public class TimofeyRectangles { void solve() { int n = in.nextInt(); out.println("YES"); for (i...
Problem: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << "YES\n"; for (int i = 1; i <= n; i++) { int x, y, x2, y2; cin >> x >> y >> x2 >> y2; cout << 1 + 2 * (abs(x) % 2) + (abs(y) % 2) << '\n'; } return 0; }
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class App { public static PrintWriter out; static int s = Integer.MIN_VALUE; public static void main(String[] args) {...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n=int(input()) l=list(map(int,input().split())) ma=0 p1=0 p2=0 for i in range(n-1) : if (i+1)%2!=0 : p1=p1+abs(l[i]-l[i+1]) p2=p2-abs(l[i]-l[i+1]) if p2<0 : p2=0 ma=max(p1,ma) else : p2=p2+abs(l[i]-l[i+1]) p1=p1-abs(l[i]-l[i+1]) if p1<0 : ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long arr[] = new long[n+1]; arr[0] = 0; for(int i=1;i<n+1;i++){ arr[i] = sc.nextInt...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.*; public final class B{ public static void main(String[] args) { Scanner scan= new Scanner(System.in); int n=scan.nextInt(); long a=scan.nextInt(); long sum=0,min=0,max=0; long b=0; for (int i=1;i<n ;i++ ) { b=scan.nextInt(); if (i%2==0) { sum+=Math.abs(a-b)*(-1); } else{...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author Madi Sovetbekov */ public class snova { public static void main(String[]args){ ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; /** * Created by Lenovo on 21-12-2016. */ public class z { public static ArrayList<ArrayList<String>> ss; public static int visit[]; public static void main(String...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.*; import java.util.*; import java.util.logging.Logger; import static java.lang.System.*; public class o{ static BufferedReader br; static long mod = 998244353; static HashSet<Integer> p = new HashSet<>(); public static void main(String[] args) throws Exception { br = new Buf...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int n, a[100005]; long long b[100005], dpMax[100005], dpMin[100005], ans = (1ll << 63); void setup() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n - 1; i++) b[i] = abs(a[i] - a[i + 1]); n--; } void xuly() { for (int i = n; i >= 1; i-...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long int n, arr[5000005], arrabs[5000005], arr1[5000005], arr2[5000005], pre1[5000005], pre2[5000005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int i, j; cin >> n; for (i = 0; i < n; i++) cin >> arr[i]; n--; for ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int* arr = new int[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int* dp1 = new int[n]; for (int i = 1; i < n; i++) dp1[i] = abs(arr[i - 1] - arr[i]); long long* dp2 = new long long[n]; dp2[0] = 0; for (int i = 1; i < n; i++)...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = int(raw_input()) xs = map(int, raw_input().split(' ')) fs = map(lambda (x, y): abs(x - y), zip(xs, xs[1:])) fs_start_even = [fs[i] * (-1) ** i for i in xrange(n - 1)] fs_start_odd = [fs[i] * (-1) ** (i + 1) for i in xrange(n - 1)] ''' Returns the maximum sum of a subarray of the `fs` array that starts at an od...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long mod1 = 998244353; const long long inf = 1e18; const long long nax = 100005; long long n, a[nax], b[nax], c[nax]; void solve() { cin >> n; for (long long i = (1); i < (n + 1); i++) cin >> a[i]; for (long long i = (1); i < ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import sys input = sys.stdin.readline n = int(input()) a = list(map(int,input().split())) d = [0]*n c = [0]*n e = [0]*n x = 1 mx = 0 for i in range(1,n): d[i] = abs(a[i] - a[i-1]) for i in range(1,n): c[i] = max(0,c[i-1] + d[i]*x) e[i] = max(0,e[i-1] + d[i]*(-x)) mx = max(mx,max(c[i],e[i])) x = -...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 9; long long arr[maxn]; long long dp[maxn]; int main() { long long a, b, c, d, e, f, g, h; ios::sync_with_stdio(0); while (cin >> a) { long long ans = -1e16; for (int i = 1; i <= a; i++) { cin >> arr[i]; } g = 0; e = 1;...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().spl...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; void display(vector<int> &a) { for (int z : a) cout << z << " "; cout << endl; } int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; const int mod = (int)1e9 + 7; const long long INF64 = 3e18; void smxl(long long &a, long long b) { if (a < b) a = b; } void smnl(long...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const long long infl = 1e15 + 5; long long int m, n, p, q, x, y, k, mx = 0, mn = 0, f, val, sz, sm, cnt, ans, t = 1, i, j, ind = -1; long long int a[300004], cur; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); if (fope...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = int(input()) a = list(map(int, input().split())) a = [abs(a[i] - a[i + 1]) for i in range(n - 1)] ans = t1 = t2 = 0 for i in a: t1, t2 = max(t2 + i, 0), max(t1 - i, 0) ans = max(ans,t1,t2) print(ans)
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) { cin >> a[i]; } vector<long long> prefix(n); prefix[0] = -1; prefix[1] = abs(a[0] - a[1]); for (...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.*; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; import java.util.TreeSet; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out);...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long aa[100005]; int main() { int n; long long m1, a, m2; cin >> n; for (int i = 0; i < n; i++) cin >> aa[i]; for (int i = 0; i < n - 1; i++) aa[i] = abs(aa[i] - aa[i + 1]); m1 = m2 = a = 0; for (int i = 0; i < n - 1; i++) { if (i % 2) a -= aa[i...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; vector<long long> v(n), pr1(n), pr2(n); for (long long i = 0; i < n; i++) { cin >> v[i]; } for (long long i = 1; i < n; i++) { if (i & 1) { pr2[i] = -1 * abs(v[i...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
def main(): n = int(input()) a = list(map(int, input().split())) b = [abs(a[i] - a[i + 1]) for i in range(len(a) - 1)] ansmx = [0] * len(b) ansmn = [0] * len(b) ansmx[-1] = b[-1] ansmn[-1] = 0 for i in range(1, len(b)): j = i - 1 ansmx[-1 - i] = b[-1 - i] - ansmn[-i] ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.Queue;...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import os import sys from io import BytesIO, IOBase import heapq as h from bisect import bisect_left from types import GeneratorType BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): import os self.os = os self._fd = file.fileno() self.buffer = Bytes...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.*; import java.io.*; public class Solution { static FastScanner scr=new FastScanner(); // static Scanner scr=new Scanner(System.in); static PrintStream out=new PrintStream(System.out); static StringBuilder sb=new StringBuilder(); static class pair{ int x;int y; pair(int x...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
def mp(): return map(int,input().split()) def lt(): return list(map(int,input().split())) def pt(x): print(x) def ip(): return input() def it(): return int(input()) def sl(x): return [t for t in x] def spl(x): return x.split() def aj(liste, item): liste.append(item) def bin(x): return "{0:b}".format(x) def list...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; cin >> n; int a[100002] = {}; for (int i = 0; i < n; i++) { cin >> a[i]; } long long ans1 = 0, ans2 = 0; long long ans; for (int i = 1; i < n; i++) { long long v = abs(a[i] - a[i - 1]); if (i % 2 ==...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n=int(input()) a=list(map(int,input().split())) l=[abs(a[i+1]-a[i]) for i in range(n-1)] dp=[[0,0] for i in range(n-1)] dp[0][0]=l[0] ans=max(dp[0]) for i in range(1,n-1): dp[i]=[max(dp[i-1][1]+l[i],l[i]),max(dp[i-1][0]-l[i],-l[i])] ans=max(ans,max(dp[i])) print(ans)
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = int(raw_input()) a = map(int, raw_input().split()) b = [] for i in xrange(len(a) - 1): b.append(abs(a[i] - a[i+1])) b1 = [] p1 = [0] for i in xrange(len(b)): b1.append(b[i] if i % 2 == 0 else -b[i]) p1.append(p1[i] + b1[i]) b2 = [-r for r in b1] p2 = [-p for p in p1] mp1 = [p for p in p1] mp2 = [p for ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.*; import java.lang.*; import java.io.*; public class Main { void run() throws Exception { int n = nextInt(); int[] vals = new int[n]; for(int i = 0; i < n; i++) vals[i] = nextInt(); long[] diff = new long[n-1]; for(int i = 0; i < n-1; i++) diff[i] = Ma...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
N = int(input()) L = list(map(int, input().split())) if N == 2: print(abs(L[0] - L[1])) exit() M = [] for i in range(N - 1): M.append(abs(L[i] - L[i + 1])) M1 = [0] flg = True for i in range(N - 1): if flg: M1.append(M1[-1] + M[i]) else: M1.append(M1[-1] - M[i]) flg = not flg...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.PrintStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHel...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const int mx = 1e5 + 7; int a[mx]; long long dp[mx][2]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i < n; i++) a[i] = abs(a[i] - a[i + 1]); long long ans = 0; for (int i = 1; i < n; i++) { dp[i][0] =...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using vi = vector<ll>; using vs = vector<string>; using ii = pair<ll, ll>; using ss = pair<string, string>; using ldld = pair<ld, ld>; template <typename X> istream& operator>>(istream& stream, ve...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 8; long long a[MAXN], b[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0); long long n, x, y, i; cin >> n; for (i = 1; i <= n; i++) { cin >> x; if (i > 1) { if (i % 2 == 0) { a[i - 1] = abs(x - y); b[i...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int b[n]; b[0] = 0; for (int i = 1; i < n; i++) b[i] = abs(a[i] - a[i - 1]); long long int dp[n], dd[n]; dp[0] = 0; dd[0] = 0; for (int i = 1; i < n; i++) { if (i % 2 ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const long long maxn = 5e5; long long n, a[maxn], b[maxn], res = 0, Maxn = 0; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i < n; i++) { b[i] = abs(a[i] - a[i + 1]); } for (int i = 1; i < n; i++) { if (i % 2 ==...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.util.StringTokenizer; public class cfs407C { public static void main(String[] args) { FastScanner sc = new FastScanner(); int N = sc.nextInt(); long[] arr = new long[N]; for (int n ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = int(raw_input()) a = map(int,raw_input().split()) for i in range(n-1): a[i] = abs(a[i]-a[i+1]) dpplus = [0]*(n-1) dppminus = [0]*(n-1) dpplus[0],dppminus[0] = a[0],-a[0] for i in range(1,n-1): dpplus[i]=max(a[i],dppminus[i-1]+a[i]) dppminus[i] = max(-a[i],dpplus[i-1]-a[i]) print max(max(dpplus),max(dppm...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; int n; long long dp[MAXN]; long long a[MAXN]; long long Cal(int i) { return abs(a[i] - a[i + 1]); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]); dp[n - 1] = Cal(n - 1); long long ans = dp[n - 1]; for (i...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int a[100100]; int b[100100]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", a + i); } for (int i = 1; i < n; i++) { b[i] = abs(a[i] - a[i + 1]); } long long sum = 0, summ = 0; long long ans = -1; for (int i = 1; i ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
from sys import stdin, stdout n = int(stdin.readline().rstrip()) a = [int(q) for q in stdin.readline().rstrip().split()] fOdd = [] fEven = [] for i in range(n-1): fOdd.append(abs(a[i]-a[i+1])*(-1)**(i)) fEven.append(abs(a[i]-a[i+1])*(-1)**(i-1)) index=0 fOddCurrent=0 fEvenCurrent=0 fMax=0 while index<n...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int a[N], s[N]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n - 1; i++) s[i] = abs(a[i] - a[i + 1]); long long maxs = 0; long long sum = 0; for (int i = 0; i < n - 1; i++) { ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
# helper methods for input def ri(): return raw_input() def ii(type): x = ri() if type == 'i': return int(x) if type == 'l': return long(x) if type == 'f': return float(x) if type == 's': return str(x) return def i2(type): x = ri().split() if type ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Code { public static void main(String[] args) throws IOException{ Scanner sc = new Scanner(System.in); Pr...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.*; public class functions{ public static void main(String [] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n+1]; long ans = 0; for (int i = 1;i<=n ;i++ ) { a[i] = sc.nextInt(); } long[] b = new long[n+1]; long odd = 0; long even = 0; long ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int n, a[200005]; long long ans; long long solve() { long long Max = -99999999, Min = 0, sum[200005]; sum[0] = 0; for (int i = 1; i < n; i++) { sum[i] = sum[i - 1] + a[i]; Min = min(Min, sum[i]); Max = max(Max, sum[i] - Min); } return Max; } int main()...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = int(raw_input()) A = map(int, raw_input().split()) def f(A): B = [] lenA = len(A) for i in range(lenA - 1): B += [abs(A[i] - A[i + 1]) * (-1) ** i] ll = len(B) #print B if ll < 1: return 0 l = 0 r = 0 curSum = B[0] maxSum = B[0] while...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long kadane(long long a[], long long s) { long long int maxx = 0, maxend = 0; for (long long int i = 0; i < s; i++) { maxend = maxend + a[i]; if (maxx < maxend) maxx = maxend; if (maxend < 0) maxend = 0; } return maxx; } int main() { long long int...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int a[100005]; long long s[100005], d[100005], d2[100005]; long long max(long long a, long long b) { if (a < b) return b; return a; } int abs(int x) { if (x > 0) return x; return -x; } int main() { int n, i; long long S, res = -1e9; scanf("%d", &n); for (i =...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.*; import java.math.BigInteger; import java.util.*; public class main { private static InputStream stream; private static byte[] buf = new byte[1024]; private static int curChar; private static int numChars; private static SpaceCharFilter filter; private static PrintWriter pw; private static long...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.*; public class TestClass { static long f(long dp[],int n){ long fm=dp[0],tm=dp[0]; for(int i=1;i<n;i++){ tm=Math.max(tm+dp[i],dp[i]); fm=Math.max(fm,tm); } return fm; } public static int gcd(int a, int b) { if (a == 0) ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.*; import java.io.*; public class Hello { public static void main(String[] args) { FastReader s=new FastReader(); PrintWriter pr=new PrintWriter(System.out,true); int n=s.nextInt(); int a[]=new int[n+1]; for(int i=1;i<=n;i++) a[i]=s.nextInt(); long max=Long.MIN_VALUE; boolean tog...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long st[100005]; bool binSearch(long long beg, long long end, long long num) { if (beg == end) { if (st[beg] == num) return true; else return false; } if (binSearch(beg, (beg + end) / 2, num)) return true; else if (binSearch((beg + end) ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.util.*; public class Main { static long mod = 998244353; static int size = 200000; static long[] fac = new long[size]; static long[] finv = new long[size]; static long[] inv = new long[size]; static int INF = Integer.MAX_VALUE; public static void main(String[] args){ Scanner scanner = new Scann...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long A[1000005]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) scanf("%I64d", &A[i]); long long ma = abs(A[n - 1] - A[n]); long long mi = ma; long long lma = ma; long long lmi = mi; for (int i = n - 2; i > 0; --i) { long long temp1 = ab...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.*; import java.util.*; import java.text.*; public class Main { private static long kadane(long input[]){ long curMax=input[0]; long max=input[0]; for(int i=1;i<input.length;i++){ curMax=Math.max(input[i],curMax+input[i]); max=Math.max(max,curMax); } return max; } public static void...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.*; import java.util.StringTokenizer; /** * Created by Julia on 01.04.2017. */ public class SolverC { public static void main(String[] args) throws IOException { new SolverC().run(); } StringTokenizer stok; BufferedReader br; PrintWriter pw; String nextToken() throws ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import sys from io import BytesIO, IOBase import os BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = int(input()) arr = list(map(int, input().split())) diff = [abs(arr[i] - arr[i-1]) for i in range(1, n)] res0, res1, res, curr_sum = -2e9, 0, -2e9, 0 for i in range(n-1): curr_sum += diff[i] * (1 if i % 2 == 0 else -1) res = max(res, curr_sum - res1, res0 - curr_sum) if i % 2 == 0: res0 = max(res...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.*; import java.lang.reflect.Array; import java.util.*; /** * Created by Alexander on 18.03.2017. */ public class Stress { BufferedReader br; StringTokenizer sc; PrintWriter out; public static void main(String[] args) throws IOException { Locale.setDefault(Locale.US); ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const int MX = 1e5 + 5; long long a[MX], dp[MX][2]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { a[i] = abs(a[i] - a[i + 1]); } dp[1][1] = a[1]; dp[1][0] = 0; long long ans = a[1]; for (int i = 2...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long int dp[100005]; int n; long long int findmax() { long long int max_sum = 0; long long int mini = INT_MIN; for (int i = 0; i < n - 1; i++) { max_sum += dp[i]; if (max_sum > mini) mini = max_sum; if (max_sum < 0) max_sum = 0; } return mini; } i...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO,IOBase def kadane(lst): su,ans = 0,0 for i in lst: su = max(0,su+i) ans = max(ans,su) return ans def main(): n = int(input()) a = list(map(int,input().split())) ls = [pow(-1,i)*ab...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
//package a2oj_dp; import java.io.*; import java.util.Arrays; public class Functions_again { public static void main(String[] args) throws IOException{ InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); int n = Integer.parseInt(br.readLine()); int[] arr = n...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
def max_subarray(numbers,k): best_sum = 0 current_sum = 0 for x in range(len(numbers)): if(k%2==k): current_sum = max(0, current_sum + numbers[x]) else: current_sum = current_sum + numbers[x] best_sum = max(best_sum, current_sum) return best_sum n = int(in...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
n = int(raw_input()) a = map(int, raw_input().split()) b = [] c = [] for i in range(n-1): val = abs(a[i+1]-a[i]) if(i%2==1): val*=-1 b.append(val) for i in range(n-1): val = abs(a[i+1]-a[i]) if((i+1)%2==1): val*=-1 c.append(val) c_pref = [c[0]] b_pref = [b[0]] for i in range(1,n-1): c_pref.append(max(c...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; long long dp[100010], arr[100010]; int main() { long long n, x, i, mx, y; cin >> n; cin >> x; for (i = 2; i <= n; i++) { cin >> y; arr[i - 1] = abs(x - y); x = y; } n--; if (n == 1) { cout << arr[1] << endl; return 0; } dp[1] = arr[1]; ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
def maxSubArraySum(a, size): max_so_far = -9999999999999 - 1 max_ending_here = 0 for i in range(0, size): max_ending_here = max_ending_here + a[i] if (max_so_far < max_ending_here): max_so_far = max_ending_here if max_ending_here < 0: max_ending_here = 0 ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import sys input=sys.stdin.readline n=int(input()) l=input().split() li=[int(i) for i in l] l=[] for i in range(1,n): l.append(abs(li[i]-li[i-1])*pow(-1,i)) dp=[0 for i in range(n-1)] dp[0]=l[0] for i in range(1,n-1): dp[i]=max(l[i],l[i]+dp[i-1]) maxa=0 for i in dp: maxa=max(maxa,i) for i in range(n-1): ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.awt.List; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const long long LINF = (long long)1e18; const long double PI = acos((long double)-1); const long double EPS = 1e-9; inline long long gcd(long long a, long long b) { long long r; while (b) { r = a % b; a = b...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<long long> a(n); for (auto &s : a) scanf("%lld", &s); vector<long long> b(n - 1); for (int i = 0; i < n - 1; i++) { b[i] = abs(a[i] - a[i + 1]); } long long ans = 0, sum = 0; for (int i = 0; i < n - 1; i++) { ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; const int N = 100000; int a[N]; void solve() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1; i++) { a[i] = abs(a[i] - a[i + 1]); } n--; long long mx = INT_MIN; long long sm = 0; for (int i = 0; i < n; i+...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int a[100000]; int b[100000]; int c[100000]; long long ayuda1; long long n; void entrarDatos() { for (int i = 0; i < n; i++) { cin >> a[i]; if (i > 0) { b[i - 1] = (a[i - 1] - a[i]); b[i - 1] = abs(b[i - 1]); ayuda1 = (i - 1) % 2; b[i - 1] ...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Scanner; // author : iam_ss public class A { static int[][][] dp; static int[][][] store; static int[] arr; public static void main (String[] args) throws java.lang.Exception { //BufferedRea...
Problem: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is d...
#include <bits/stdc++.h> using namespace std; int store[100005]; long long ubound[100005], lbound[100005]; int cmp(const void* v1, const void* v2) { return *(int*)v1 - *(int*)v2; } int main(void) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &store[i]); ubound[n - 1] = abs(store[n - 1] - st...