akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int b=scanner.nextInt();
		int t=scanner.nextInt();
		System.out.println(t/n*b);
	}	
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int d = 0;
    bool update = true;
    while (update) {
        rep(i, n) {
            if (a[i]%2 != 0) { update = false; break; }
            a[i] /= 2;
        }
        d += update;
    }
    cout << d << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int a,b;
    cin>>a>>b;
    if(a>b){
        swap(a,b);
    }
    FOR(i,0,b){
        cout<<a;
    }
}


Measured memory_bytes: 256
#ifdef __cplusplus
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#endif

#define rep(i,n) for(int i = 0; i < (n); ++i)
 
#define BIG_PRIME 1000000007
#define BP_remainder(x) ((x) % BIG_PRIME)

#define INF (1 << 30)
#define INF_NEG (INF * -1)
#define INF_LONG (1LL << 62)
#define INF_LONG_NEG (INF_LONG * -1L)

typedef long long ll;
typedef char str255[256];
int StrLen(char *s) { for(int ptr = 0;; ++ptr) if(!s[ptr]) return ptr; } 
// char * の後ろから n 文字削除, 削除後の文字数を返す
int StrDel(char *s, int n) { int l = StrLen(s); s[l - n + 1] = '\0'; return l - n; }

int NumDigits(int i){ char s[20]; return sprintf(s, "%d", i); }
int NumDigitsLL(long long l){ char s[30]; sprintf(s, "%lld", l); return strlen(s); }

int is1stAns = 1;
#ifdef __cplusplus
template <class T> 
void print(T t) { if (is1stAns) cout << t, is1stAns = 0; else cout << " " << t; }
#else
void printI(int    i) { if (is1stAns) printf(  "%d", i), is1stAns = 0; else printf(  " %d", i); }
void printL(ll     l) { if (is1stAns) printf("%lld", l), is1stAns = 0; else printf(" %lld", l); }
void printD(double d) { if (is1stAns) printf("%.9f", d), is1stAns = 0; else printf(" %.9f", d); }
void printC(char   c) { if (is1stAns) printf(  "%c", c), is1stAns = 0; else printf(  " %c", c); }
void printS(char  *s) { if (is1stAns) printf(  "%s", s), is1stAns = 0; else printf(  " %s", s); }
#endif

signed main()
{
#ifdef __cplusplus
    cout << fixed << setprecision(9);
#endif

    int N; scanf("%d", &N);
    ll *A = (ll *)malloc(sizeof(ll) * (N + 9));
    ll *B = (ll *)malloc(sizeof(ll) * (N + 9));

    rep(i, N + 1) scanf("%lld", &A[i]);
    rep(i, N) scanf("%lld", &B[i]);

    ll ans = 0;
/*    rep(i, N){
        if (A[i] >= B[i]){
            ans += B[i];
        } else {
            ans += A[i];
            B[i] -= A[i];
            if (A[i + 1] >= B[i]){
                ans += B[i];
                A[i + 1] -= B[i];
            } else {
                ans += A[i + 1];
                A[i + 1] = 0;
            }
        }
    }
*/

    // 前からだとWAになったので、後ろから倒してみる

    for (int i = N - 1; i >= 0; --i){
        if (A[i + 1] >= B[i]){
            ans += B[i];
        } else {
            ans += A[i + 1]; B[i] -= A[i + 1];
            if (A[i] >= B[i]){
                ans += B[i]; A[i] -= B[i];
            } else {
                ans += A[i]; A[i] = 0;
            }
        }
    }


    printf("%lld\n", ans);

    free(A);
    free(B);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

#define MAX_V 310
ll d[MAX_V][MAX_V];    //d[u][v] is cost of e(u, v)
int N;      //num of v

void warshall_floyd(){
    for(int k = 0; k < N; k++)
        for(int i = 0; i < N; i++)
            for(int j = 0; j < N; j++)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

ll od[MAX_V][MAX_V];
bool eneed[MAX_V][MAX_V];

int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            ll a;
            cin >> a;
            d[i][j] = a;
            od[i][j] = a;
        }
    }

    warshall_floyd();
    ll fail = false;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(od[i][j] > d[i][j]) fail = true;
        }
    }

    if(fail){
        cout << -1 << endl;
        return 0;
    }

    REP(i,N) REP(j,N) eneed[i][j] = true;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            ll dist = d[i][j];
            for(int k = 0; k < N; k++){
                if(k == i || k == j) continue;
                ll dd = d[i][k] + d[k][j];
                if(dist == dd){
                    eneed[i][j] = false;
                }
            }
        }
    }

    ll ans = 0;
    REP(i,N){
        for(int j = i+1; j < N; j++){
            if(eneed[i][j])
                ans += d[i][j];
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
type exp = Int of int | Add of exp * exp | Sub of exp * exp

let rec str_of_exp = function
  | Int i -> string_of_int i
  | Add (e1, e2) -> Printf.sprintf "%s+%s" (str_of_exp e1) (str_of_exp e2)
  | Sub (e1, e2) -> Printf.sprintf "%s-%s" (str_of_exp e1) (str_of_exp e2)

let rec calc = function
  | Int i -> i | Add (e1, e2) -> calc e1 + calc e2
  | Sub (e1, e2) -> calc e1 - calc e2

let solve inputs =
  let rec inner tmp = function
    | [] -> if calc tmp = 7 then Some tmp else None
    | l::ls ->
       match inner (Add (tmp, Int l)) ls with
       | Some tmp -> Some tmp
       | None ->
          match inner (Sub (tmp, Int l)) ls with
          | Some tmp -> Some tmp
          | None -> None
  in inner (Int (List.hd inputs)) (List.tl inputs)

let c_to_d c = Char.code c - Char.code '0'
let _ =
  let inputs = Scanf.scanf "%c%c%c%c\n" 
                 (fun a b c d -> 
                   (c_to_d a)::(c_to_d b)::(c_to_d c)::(c_to_d d)::[]) in
  match solve inputs with
  | None -> assert false
  | Some tmp -> (str_of_exp tmp) ^ "=7" |> print_string


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int h, a;
int main() {
    DAU
    cin >> h >> a;
    cout << h / a + (h % a != 0);
    PLEC
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N+1);
  for(int i=0; i<N; i++){
    cin >> a.at(i);
  }
  a.at(N)=0;
  
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int count=0;
  for(int i=0; i<N; i++){
    if(a.at(i) != a.at(i+1)){
      count++;
    }
  }
  cout << count << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int result = 0;
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			if (x <= k - x) {
				result += x * 2;
			} else {
				result += (k - x) * 2;
			}
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
 
using namespace std;
 
const int N=1000000;
const int INF=1<<30;
 
int main(){
  static int dp[N];
  static int dpo[N];
  fill(begin(dp),end(dp),INF);
  fill(begin(dpo),end(dpo),INF);
  dp[0]=dpo[0]=0;
  for(int i=0;;i++){
    int q=i*(i+1)*(i+2)/6;
    if(q>N)break;
    for(int j=q;j<N;j++){
      dp[j]=min(dp[j],dp[j-q]+1);
      if(q%2){
    dpo[j]=min(dpo[j],dpo[j-q]+1);
      }
    }
  }
  for(int n;cin>>n,n;){
    cout<<dp[n]<<' '<<dpo[n]<<endl;
  }
}

Measured memory_bytes: 10880
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)


int main() {
	int a, b;
	cin >> a >> b;
	int sum = a + b;
	if (sum == 3)cout << 3 << endl;
	else if (sum == 4)cout << 2 << endl;
	else cout << 1 << endl;




	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        String ret = "";
        for (int i = 0;i < 3;++i){
            ret += scanner.next().charAt(0);
        }
        System.out.println(ret.toUpperCase());
    }
}

Measured memory_bytes: 23764
n, k = map(int, input().split())
nums = list(map(int, input().split()))

neg_nums = []
pos_nums = []
nums.sort()
for num in nums:
    if num < 0:
        neg_nums.append(num)
    else:
        pos_nums.append(num)
l = -1231232132131232112213
r = 12312321321312312312


def cost_k(m):
    cur_k = 0
    l_pos, r_pos = 0, len(pos_nums) - 1
    while l_pos < r_pos:
        if pos_nums[l_pos] * pos_nums[r_pos] <= m:
            cur_k += r_pos - l_pos
            l_pos += 1
        else:
            r_pos -= 1
    l_neg, r_neg = 0, len(neg_nums) - 1
    while l_neg < r_neg:
        if neg_nums[l_neg] * neg_nums[r_neg] <= m:
            cur_k += r_neg - l_neg
            r_neg -= 1
        else:
            l_neg += 1
    l_pos, l_neg = 0, 0
    while l_pos < len(pos_nums) and l_neg < len(neg_nums):
        if neg_nums[l_neg] * pos_nums[l_pos] <= m:
            cur_k += len(pos_nums) - l_pos
            l_neg += 1
        else:
            l_pos += 1
    return cur_k


while r - l > 1:
    m = (r + l) // 2
    # pos pos
    # neg neg
    # neg pos
    cur_k = cost_k(m)
    if cur_k < k:
        l = m
    else:
        r = m
print(r)


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

int main(){
    int n;
    double a = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        double x;
        cin >> x;
        a += (1 / x);
    }

    printf("%.5f\n", (double)1 / a);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, n) for (int i = (n)-1; i >= 0; i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase(unique(ALL(v)), v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

ll gcd(ll x, ll y)
{
    ll r = 0;
    if (x < y)
        swap(x, y);
    while (y > 0)
    {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    //cout << gcd(A,B) << endl;
    int ans = 1;
    for(ll i = 2; i < 1e6 + 2; i++)
    {
            if (A % i == 0 && B % i == 0)
            {
                ans++;
                while (A % i == 0)A /= i;
                while (B % i == 0)B /= i;
            }
    }
    if (gcd(A,B)!= 1)
        if(A != 1 && B != 1)ans++;
    cout << ans << endl;
    return 0;
}

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

typedef long long LL;
typedef pair<int, int> II;

const int N = (int) 1e5 + 10;
int n, deg[N], cnt[N];
vector<int> adj[N];

int main() {
#ifdef LOCAL
    freopen("inp", "r", stdin);
    freopen("out", "w", stdout);
#endif
    vector<int> a(3); cin >> a[0] >> a[1] >> a[2]; sort(a.begin(), a.end());
    set< vector<int> > S; S.insert(a); int ans = 0;
    while (1) {
        if (a[0] % 2 || a[1] % 2 || a[2] % 2) break;
        vector<int> b(3);
        b[0] = (a[1] + a[2]) / 2;
        b[1] = (a[0] + a[2]) / 2;
        b[2] = (a[0] + a[1]) / 2;
        sort(b.begin(), b.end());
        if (S.count(b)) {
            puts("-1");
            return 0;
        }
        ans++; a = b;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int x(int n,int s,int k[]){
    int kcpy[10];
    int i,j;
    int cnt = 0;
    if(n*(n+1)*(31-n)>=6*s&&6*s>=n*n*n-n){
    if(n-1){
        for(i=0;i<10;i++){
            kcpy[i] = k[i];
        }
        for(j=0;j<10&&j*n<=s;j++){
            if(kcpy[j]){
                kcpy[j] = 0;
                cnt += x(n-1,s-j*n,kcpy);
                kcpy[j] = 1;
            }
        }
    }else if(s<10){
        cnt = k[s];
    }
    }
    return cnt;
}

int main(){
    int y=0,n,s;
    int k[]={1,1,1,1,1,1,1,1,1,1};
    while(scanf("%d %d",&n,&s)!=EOF){
        y = x(n,s,k);
        printf("%d\n",y);
    }
}

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

int main(){
  int x[10000];
  int i;
 
  for(i = 0;;i++){
      cin >> x[i];
      if(x[i] == 0)break;
  }
  
  for(int j = 0;j < i;j++){
      cout <<"Case "<< j + 1 <<": " << x[j] <<endl;
  }
  return 0;
}








Measured memory_bytes: 3024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool OK(int num, int prev) {
  if (num == 0) {
    return true;
  }
  if (num % 10 != prev - 1) {
    return false;
  }
  return OK(num / 10, num % 10);
}

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  
  int maxnum = -1;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int num = a[i] * a[j];
      if (!OK(num / 10, num % 10)) {
        continue;
      }
      maxnum = max(maxnum, num);
    }
  }

  cout << maxnum << endl;

  return 0;
}

Measured memory_bytes: 3100
a,b,c = gets.split.map(&:to_i)
if (a == 5 && b == 7 && c == 5) || (a == 5 && b == 5 && c == 7) || (a == 7 && b == 5 && c == 5)
  puts "YES"
else
  puts "NO"
end


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

long n, m, ans;
long a;

int main(){
	cin >> n;
	m = n+1;
	for (int i = 0; i < 5; ++i) {
		cin >> a;
		if (a < m) m = a;
	}
	ans = (n / m) + (n % m > 0) + 4;
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cstdio>
#define reep(num1,num2,num3) for(int num1=num3;num1<num2;num1++)
#define rep(num1,num2) reep(num1,num2,0)
#define INF 1e9
using namespace std;
class edge{
public:
    int to,c;
    edge(int to,int c):to(to),c(c){}
    edge(){}
    bool operator<(const edge &a)const{
        if(c!=a.c)return c>a.c;
        return to<a.to;
    }
};
int main()
{
    int n;
    while(cin>>n,n)
    {
        bool vis[111]={false};
        vector<edge> G[111];
        int d[111];
        int m,res=0;
        cin>>m;
        rep(i,m){
            int a,b,c;
            scanf("%d,%d,%d",&a,&b,&c);
            G[a].push_back(edge(b,c));
            G[b].push_back(edge(a,c));
        }
        priority_queue<edge> PQ;
        PQ.push(edge(0,0));
        while(!PQ.empty())
        {
            edge e=PQ.top();PQ.pop();
            if(vis[e.to])continue;
            vis[e.to]=true;
            res+=e.c;
            rep(i,G[e.to].size()){
                PQ.push(edge(G[e.to][i].to,G[e.to][i].c));
            }
        }
        cout<<res/100-n+1<<endl;
    }
}

Measured memory_bytes: 1540
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define mn 55
#define inf 4444444444444444444
#define mod (ll) 1000000007
#define base 31
#define fu(i, a, b) for (int i=a; i<=b; i++)
#define fd(i, a, b) for (int i=a; i>=b; i--)
#define fi first
#define se second
#define pii pair <int, int>
#define pb push_back
#define mp make_pair

//int t, ntest;
int n, m, s, c[mn], d[mn], f[mn][2505], passed[mn][2505], ans[mn];
vector <pair <int, pii> > dsk[mn];

void input(){
	cin>>n>>m>>s;
	fu (i, 1, m) {
		int x, y, a, b;
		cin>>x>>y>>a>>b;
		dsk[x].pb(mp(y, mp(a, b)));
		dsk[y].pb(mp(x, mp(a, b)));
	}
	fu (i, 1, n) cin>>c[i]>>d[i];
}

void solve(){
	s=min(s, (ll)2500);
	fu (i, 1, n) fu (j, 0, 2500){
		f[i][j]=-inf;
	}
	f[1][s]=0;
	priority_queue <pair <int, pii> > PQ;
	PQ.push(mp(0, mp(1, s)));
	while (!PQ.empty()){
		int u=PQ.top().se.fi, s1=PQ.top().se.se;
		PQ.pop();
		if (passed[u][s1]) continue;
		passed[u][s1]=1;
		fu(i, 0, dsk[u].size()-1){
			int v=dsk[u][i].fi, a=dsk[u][i].se.fi, b=dsk[u][i].se.se;
			if (s1>=a){
				if (passed[v][s1-a]) continue;
				if (f[v][s1-a]<f[u][s1]-b){
					f[v][s1-a]=f[u][s1]-b;
					PQ.push(mp(f[v][s1-a], mp(v, s1-a)));
				}
			}
		}
		if (f[u][min(s1+c[u], (ll)2500)]<f[u][s1]-d[u]){
			f[u][min(s1+c[u], (ll)2500)]=f[u][s1]-d[u];
			PQ.push(mp(f[u][min(s1+c[u], (ll)2500)], mp(u, min(s1+c[u], (ll)2500))));
		} 
	} 
	fu (i, 2, n) {
		ans[i]=inf;
		fu(j, 0, 2500) ans[i]=min(ans[i], -f[i][j]);
		cout<<ans[i]<<"\n";
	} 
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//	freopen("test.inp", "r", stdin);
//	freopen("test.out", "w", stdout);
//	cin>>t;
//	for (ntest=1; ntest<=t; ntest++){
		input();
		solve();
//	}
}

//By: 646487264





Measured memory_bytes: 8084
#include <stdio.h>
int main(int argc, char const *argv[])
{
  char s[101];
  int i,n;
  int c=0;
  n=100;
  for(i=0;i<101;i++) s[i]='A';
  scanf("%s",s);
  for(i=0;i<101;i++){
    if(s[i]=='A'){
      n=i-1;
      break;
    }
  }
  for(i=0;i<n/2;i++){
    if(s[i]!=s[n-i-1]) c++;
  }
  printf("%d",c);
  return 0;
}

Measured memory_bytes: 128
H, W = map(int,input().split(' '))
ofs = 1

A =[]
for i in range(H):
    atmp=list(map(int,input().split(' ')))
    A.append(atmp)

def evenChk(nn):
    if nn % 2 == 0:
        return True
    else:
        return False

# 行単位で持っていく
msg=[]
for i in range(H):
    for j in range(W-1):
        if evenChk(A[i][j]):
                continue
        else:
            A[i][j+1]+=1
            msg.append([i+ofs,j+ofs,i+ofs,j+ofs+1])

for i in range(H-1):
    if evenChk(A[i][W-1]):
        continue
    else:
        A[i+1][W-1]+=1
        msg.append([i+ofs,W+ofs-1,i+ofs+1,W+ofs-1])

print(len(msg))
for i in range(len(msg)):
    print(' '.join(map(str,msg[i])) )


Measured memory_bytes: 30040
O=input()
E=input()

L=[]

if len(O)>len(E):
    for i in range(len(E)): 
        L.append(O[i])
        L.append(E[i])
        
    L.append(O[i+1])
        
else:
    for i in range(len(E)): 
        L.append(O[i])
        L.append(E[i])

print("".join(L))

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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

int main() {
  int N;
  ll A,B,cost = 0;
  cin >> N >> A >> B;
  vector<ll> X(N);
  rep(i,N) cin >> X[i];
  rep(i,N-1) {
    if ((X[i+1]-X[i])*A>B) cost+=B;
    else cost += (X[i+1]-X[i])*A;
  }
  cout << cost << endl;
} 

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

using namespace std;

namespace mylib {
template<int mod>
struct ModInt {
	using ll = long long;
	int x;
	const static int M = mod;
	ModInt(ll x_) {
		x = x_ % mod;
		if (x < 0) x += mod;
	}
	ModInt() : ModInt(0) {}
	inline ModInt& operator+=(const ModInt rhs) {
		x += rhs.x;
		x %= mod;
		return (*this);
	}
	inline ModInt& operator-=(const ModInt rhs) {
		x += -rhs;
		return *this;
	}
	inline ModInt& operator*=(const ModInt rhs) {
		x = ((ll) x * rhs.x) % mod;
		return *this;
	}
	inline ModInt& operator/=(ModInt rhs) {
		return *this *= rhs.power(mod - 2);
	}
	inline ModInt power(ll p) {
		if (p == 0) return 1;
		if (p % 2 == 1) return (*this) * power(p - 1);
		ModInt t = power(p / 2);
		return t * t;
	}
	inline ModInt& operator=(const ModInt& rhs) {
		this->x = rhs.x;
		return *this;
	}
	inline int operator==(const ModInt& rhs) const {
		return this->x == rhs.x;
	}
	inline int operator!=(const ModInt& rhs) const {
		return !(*this != rhs);
	}
	inline ModInt operator++(signed unused) {
		ModInt res(*this);
		++(*this);
		return res;
	}
	inline ModInt& operator++() {
		(*this) += 1;
		return (*this);
	}
	inline ModInt operator--(signed unused) {
		ModInt res(*this);
		--(*this);
		return res;
	}
	inline ModInt& operator--() {
		(*this) -= 1;
		return (*this);
	}
	inline ModInt operator+() const {
		return (*this);
	}
	inline ModInt operator-() const {
		return (*this).x ? ModInt(mod - (*this).x) : ModInt(0);
	}
	friend const ModInt operator+(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) += rhs;}
	friend const ModInt operator-(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) -= rhs;}
	friend const ModInt operator*(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) *= rhs;}
	friend const ModInt operator/(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) /= rhs;}
	explicit operator int() const {return x;}
	friend ostream& operator<<(ostream& lhs, const ModInt& rhs) {
		lhs << rhs.x;
		return lhs;
	}
	friend istream& operator>>(istream& lhs, ModInt& rhs) {
		long long t;
		lhs >> t;
		rhs = ModInt(t);
		return lhs;
	}
};
using modint = ModInt<1000000007>;
//using modint = ModInt<998244353>;
modint operator"" _mi(unsigned long long lit) {
	return modint(lit % modint::M);
}
}; // mylib
using namespace mylib;

modint solve() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	if (N % 2) {
		for (int i = 0; i < N; i++) {
			if (A[i] != (i + 1) / 2 * 2) return 0;
		}
	} else {
		for (int i = 0; i < N; i++) {
			if (A[i] != i / 2 * 2 + 1) return 0;
		}
	}
	modint res = 1;
	modint d = 1_mi / 2;
	for (int i = 0; i < N / 2; i++) {
		res /= d;
	}
	return res;
}

int main() {
	cout << solve() << endl;
}



Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int K, S;
  cin >> K >> S;
  int cnt = 0;
  rep(i, K+1){
    rep(j, K+1){
      if(S-i-j >= 0 && S-i-j <= K){
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

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

struct edge {
    int from, to;
};

using edges = std::vector<edge>;
using graph = std::vector<edges>;


class lowlink {
public:
    lowlink(graph const& g, int root)
        : ord(g.size()),
          low(g.size())
    {
        const int N = g.size();
        std::vector<bool> visited(N);
        int cnt = 0;
        for(int i=0; i<N; ++i) {
            if(!visited[i]) {
                dfs(i, -1, cnt, g, visited);
            }
        }
    }

    std::vector<int> get_articulation_points() const {
        return articulation_points;
    }

    std::vector<edge> get_bridges() const {
        return bridges;
    }

private:
    void dfs(int v, int prev, int& cnt, graph const& g, std::vector<bool>& visited) {
        visited[v] = true;
        ord[v] = cnt++;
        low[v] = ord[v];
        bool is_articulation = false;
        int cnt2 = 0;

        for(auto& e : g[v]) {
            if(e.to != prev && visited[e.to]) {
                low[v] = min(low[v], ord[e.to]);
            } else if(!visited[e.to]) {
                cnt2++;
                dfs(e.to, v, cnt, g, visited);
                low[v] = min(low[v], low[e.to]);
                if(prev != -1 && ord[v] <= low[e.to]) {
                    is_articulation = true;
                }
                if(ord[v] < low[e.to]) {
                    bridges.push_back(edge{min(v, e.to), max(v, e.to)});
                }
            }
        }

        if(prev == -1 && cnt2 > 1) {
            is_articulation = true;
        }
        if(is_articulation) {
            articulation_points.push_back(v);
        }
    }

private:
    std::vector<int> articulation_points;
    std::vector<edge> bridges;
    std::vector<int> ord;
    std::vector<int> low;
};

int main() {
    int V, E;
    cin >> V >> E;
    graph g(V);
    for(int i=0; i<E; ++i) {
        int s, t;
        cin >> s >> t;
        g[s].push_back(edge{s, t});
        g[t].push_back(edge{t, s});
    }
    lowlink ans(g, 0);
    auto es = ans.get_bridges();
    sort(es.begin(), es.end(), [](auto const& e1, auto const& e2) {
        if(e1.from == e2.from) {
            return e1.to < e2.to;
        }
        return e1.from < e2.from;
    });
    for(auto e : es) {
        cout << e.from << ' ' << e.to << endl;
    }
}


Measured memory_bytes: 5248
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    st = [list(map(str, readline().rstrip().decode('utf-8').split())) for _ in range(n)]
    x = str(readline().rstrip().decode('utf-8'))
    b = True
    cnt = 0
    for s, t in st:
        if not b:
            cnt += int(t)
        if s == x:
            b = False
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main()
{
    int N;
    cin >> N;
    int A[N+10];
    rep(i,N) cin >> A[i];

    double ans = 0;
    rep(i,N)
    {
        ans += 1.0/A[i];
    }
    cout<< setprecision(10)<< fixed << 1.0/ans << endl;
}

Measured memory_bytes: 256
import numpy as np
n,m = input().split()
n = int(n)
m = int(m)
count = np.zeros(n)
for i in range(m):
    a, b = input().split()
    count[int(a)-1] += 1
    count[int(b)-1] += 1

for i in count:
    print(int(i))

Measured memory_bytes: 21512
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;
constexpr ll inf = 2e18;

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

  size_t n;
  cin >> n;
  string s;
  cin >> s;
  for (auto && elem : s)
  {
    auto c = elem - 'A';
    c += n;
    c %= 26;
    elem = c + 'A';
  }
  cout << s << endl;
}


Measured memory_bytes: 256
read n
a=(`dd`)
c=${a[0]: -1}
for((;++i<n;))do
	d=${a[i]:0:1}
	if [ $c != $d ];then
		echo No
		exit
	fi
	c=${a[i]: -1}
done
if [ $n -gt `echo ${a[*]}|xargs -n1|sort -u|wc -l` ];then
	echo No
else
	echo Yes
fi


Measured memory_bytes: 1432
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, x;
  cin >> n >> x;
  vector<int> in(n);
  for (int i = 0; i < n; i++) {
    cin >> in[i];
  }
  sort(in.begin(), in.end());
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += in[i];
    if (sum > x) {
      cout << i << endl;
      return 0;
    }
  }
  cout << (sum == x ? n : n - 1) << endl;
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1e9; //1(1倍)e(指数)9(10^9)
//const ll MX = 1e18; //1(1倍)e(指数)18(10^18)
//const ll MOD = 1e9 + 7; //1000000007で割った余りを聞かれたら使う
//加算代入演算子は+=
//int 2^31 10^9まで
//intは10桁、long longは18桁、doubleは308桁、long double は4932桁
//10^10くらいまででdoubleは誤差が発生しちゃう。なるべく整数にすること
//doubleからlong longにキャストするときは、+0.5で切り捨ての誤差を調整
//__int128()で128bit対応の整数（多倍長整数）
//||は片方が成り立つとき
int main()
{
    string str;
    cin >> str;
    int n = str.size();
    string tmp = str.substr(0, n - 1);
    while (tmp.size() >= 2)
    {
        if (tmp.size() % 2 == 0)
        {
            string prev = tmp.substr(0, tmp.size() / 2);
            string post = tmp.substr(tmp.size() / 2, tmp.size() / 2);
            if (prev == post)
            {
                int ans = tmp.size();
                printf("%d\n", ans);
                return 0;
            }
        }
        tmp = tmp.substr(0, tmp.size() - 1);
    }
    return 0;
}

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

int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	vector<int> b(n);
	
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>b[i];
	
	vector<int> rui(n+1);
	rui[0]=a[0];
	for(int i=1;i<n+1;i++)rui[i]=rui[i-1]+a[i];
	
	vector<int> rui2(n+1);
	rui2[0]=b[0];
	for(int i=1;i<n+1;i++)rui2[i]=rui2[i-1]+b[i];
	
	
	
	int ans=max(a[0]+rui2[n-1],rui[n-1]+b[n-1]);
	
	for(int i=1;i<n;i++){
		int tmp=0;
		tmp+=rui[i]+rui2[n-1]-rui2[i-1];
		ans=max(ans,tmp);
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n;
vector<int> Tree[101010];
LL dp[101010][2];
bool vis[101010][2];
const LL mod = 1e9 + 7;

LL calc(int cur, int par, bool flg){
    auto& res = dp[cur][flg];
    if(vis[cur][flg])return res;
    vis[cur][flg] = true;

    res = 1;

    for(auto to : Tree[cur]){
        if(to == par)continue;
        if(!flg)(res *= (calc(to, cur, true) + calc(to, cur, false))) %= mod;
        else    (res *= calc(to, cur, false)) %= mod;
    }
    return res;
}

int main(){
    cin >> n;
    REP(i, n - 1){
        int x, y;
        cin >> x >> y;
        x--, y--;
        Tree[x].emplace_back(y);
        Tree[y].emplace_back(x);
    }
    cout << (calc(0, -1, false) + calc(0, -1, true)) % mod << endl;
}

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

int main()
{
    char s[200001];
    scanf("%s", s);
    int i, a, z;
    for (i=0; i<strlen(s); i++)
    {
        if (s[i] == 'A') {
            a = i;
            break;
        }
    }
    for (i=strlen(s)-1; i>=0; i--)
    {
        if (s[i] == 'Z') {
            z = i;
            break;
        }
    }
    printf("%d\n", z - a + 1);
    return 0;

}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

const double pi = 2 * asin(1.0);

struct Point {
  ll x, y;

  Point()
  {
  }

  Point(ll x, ll y):
    x(x),
    y(y)
  {
  }

  void Load() {
    cin >> x >> y;
  }

  Point operator -(const Point& other) const {
    return Point(x - other.x, y - other.y);
  }

  ll operator *(const Point& other) const {
    return x * other.y - y * other.x;
  }

  ll operator ^(const Point& other) const {
    return x * other.x + y * other.y;
  }

  ll Length2() {
    return x * x + y * y;
  }
};

int main()
{
  int n;
  cin >> n;
  vector<Point> p(n);
  for (int i = 0; i < n; ++i) {
    p[i].Load();
  }

  for (int i = 0; i < n; ++i) {
    vector<Point> points;
    for (int j = 0; j < n; ++j) {
      if (j == i) continue;
      Point q = p[j] - p[i];
      bool found = false;
      for (Point a : points) {
        if (a * q == 0 && (a ^ q) > 0) {
          found = true;
          break;
        }
      }
      if (found) continue;
      points.push_back(q);
    }
    sort(points.begin(), points.end(), [](Point a, Point b) { return atan2(a.y, a.x) < atan2(b.y, b.x); });
    double ma = 0.0;
    for (int j = 0; j < points.size(); ++j) {
      int jj = (j + 1) % points.size();
      double angle = atan2(points[jj].y, points[jj].x) - atan2(points[j].y, points[j].x);
      if (angle < 1e-9) {
        angle += 2 * pi;
      }
      ma = max(ma, angle);
    }
    printf("%.10lf\n", ma < pi ? 0.0 : (ma - pi) / 2 / pi);
  }

  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		//青いカード
		int N = scanner.nextInt();
		String[] array1 = new String[N];
		for (int i = 0; i < N; i++) {
			array1[i] = scanner.next();
		}

		//赤いカード
		int M = scanner.nextInt();
		String[] array2 = new String[M];
		for (int i = 0; i < M; i++) {
			array2[i] = scanner.next();
		}

		//最大で、差し引き何円貰うことができるか

		/*
		for (String s : array1) {
			System.out.println("青いカード：" + s);
		}
		for (String s : array2) {
			System.out.println("赤いカード：" + s);
		}
		*/

		int max = 0;
		for (int i = 0; i < N; i++) {
			String str = array1[i];
			//System.out.println("array1[" + i + "]：" + array1[i]);
			int count = 0;
			for (int j = 0; j < N; j++) {
				if (array1[j].equals(str)) {
					count++;
				}
			}

			for (int j = 0; j < M; j++) {
				if (array2[j].equals(str)) {
					count--;
				}
			}
			//System.out.println("count：" + count);
			if (max <= count) {
				max = count;
			}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long

typedef tree< pair<int,int>, null_type, less< pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update>Order_Set;

Order_Set X;

const int mxn = 2e5+100;
const int Mod = 1e9+7;

int arr[mxn], qs[mxn];
int bitOn[55];
map<int,int>Mp, cnt, op;
vector< pair<int, pair<int,int> > >Pi, Ans;
vector<int>G[mxn];
set<int>seet[mxn];
bool visit[mxn];

int main()
{
      ios::sync_with_stdio(false);

      int n;
      cin>>n;
      long long arr[n+5];
      long long Ans = 0;
      for(int i=0 ; i<n ; i++) cin>>arr[i];
      long long one, zero;
      for(int i=0 ; i<60 ; i++){
        one = 0, zero = 0;
        for(int j=0 ; j<n ; j++){
          if((1LL<<i)&arr[j]) one++;
          else zero++;
        }
        Ans += (((1LL<<i)%Mod) *1LL* ((one*zero)%Mod));
        Ans%=Mod;
      }

    cout<<Ans<<endl;

    return 0;
}


Measured memory_bytes: 16768
import sys
input = sys.stdin.readline
N, M, Q = map(int, input().split())

ans_array = [[0] * N for _ in range(N)]

LR_array = [list(map(int, input().split())) for _ in range(M)]
PQ_array = [list(map(int, input().split())) for _ in range(Q)]

for lr in LR_array:
    l, r = lr
    ans_array[l - 1][r - 1] += 1

if N > 1:
    for i in range(1, N):
        for j in range(N - i):
            ans_array[j][j + i] += (
                ans_array[j][j + i - 1] + ans_array[j + 1][j + i] -
                ans_array[j + 1][j + i - 1])


for pq in PQ_array:
    p, q = pq
    print(ans_array[p-1][q-1])


Measured memory_bytes: 97500
#include <iostream> 
#include <algorithm>

using namespace std;


using ll = long long;


int main() {
	int n;

	cin >> n;
	int a[n];

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

	ll prev_plus = a[0] + a[1];
	ll prev_minus = - a[0] - a[1];

	for (int i = 2; i < n ; i++) {

		ll cur_plus = prev_plus + a[i];
		cur_plus = max(cur_plus, prev_minus + a[i]);

		ll cur_minus = prev_plus - a[i - 1] * 2 - a[i]; 
		cur_minus = max(cur_minus, prev_minus + a[i - 1] * 2 - a[i]);
	
		prev_plus =  cur_plus;
		prev_minus = cur_minus;
	}
	cout << max(prev_plus, prev_minus) << endl;

	return 0;

}

Measured memory_bytes: 640
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.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CSwitches solver = new CSwitches();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSwitches {
        long ans = 0;
        int n;
        int m;
        int p[];
        ArrayList<Integer> a[];

        public void cases(StringBuilder b, int n) {
            if (n == 0) {
                int count = 0;
                for (int i = 0; i < m; i++) {
                    count = 0;
                    for (int j = 0; j < a[i].size(); j++) {
                        if (b.charAt(a[i].get(j)) == '1') count++;
                    }
                    if (count % 2 != p[i]) {
                        return;
                    }
                }
                ans++;
                return;
            } else {
                cases(new StringBuilder(b.toString() + "0"), n - 1);
                cases(new StringBuilder(b.toString() + "1"), n - 1);
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();
            a = new ArrayList[m];
            for (int i = 0; i < m; i++) a[i] = new ArrayList<Integer>();
            p = new int[m];
            for (int i = 0; i < m; i++) {
                int k = in.nextInt();
                for (int j = 0; j < k; j++) a[i].add(in.nextInt() - 1);
            }
            for (int i = 0; i < m; i++) p[i] = in.nextInt();
            cases(new StringBuilder(""), n);
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



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

int main() {
    int W,H,N,x,y,a,o = 0;
    cin >> W >> H >> N;
    int table[H][W] = {0,0,0,0,0};
    for(int i = 0;i < N;i++) {
        cin >> x >> y >> a;
        switch(a) {
            case 1:
                for(int i = 0;i < x;i++) {
                    for(int t = 0;t < H;t++) {
                        table[t][i] = 1;
                    }
                }
                break;
            case 2:
                for(int i = x;i < W;i++) {
                    for(int t = 0;t < H;t++) {
                        table[t][i] = 1;
                    }
                }
                break;
            case 3:
                for(int i = 0;i < W;i++) {
                    for(int t = 0;t < y;t++) {
                        table[t][i] = 1;
                    }
                }
                break;
            case 4:
                for(int i = 0;i < W;i++) {
                    for(int t = y;t < H;t++) {
                       table[t][i] = 1;
                    }
                }
                break;
        }
    }
    for(int i = H;i > 0;i--) {
        for(int t = 0;t < W;t++) {
            if(table[i-1][t] == 0) o++;
        }
    }
    cout << o << endl;
}

Measured memory_bytes: 256
#include <iostream> 
#include <vector> 
#include <stack>
#define MAX 100000
using namespace std;

vector<int> Graph[MAX+1];
int color[MAX+1], col(0);

void AssignColor(int node, int col) 
{
    stack<int> S;
    color[node] = col;
    S.push(node);

    while(! S.empty())
    {
        int current_node = S.top(); S.pop();
        for (int i = 0; i < Graph[current_node].size(); ++i) 
        {
            int next = Graph[current_node][i];
            if (color[next] == -1) 
            {
                color[next] = col;
                S.push(next);
            } 
        }
    }
}


int main() 
{
    int node_num, edge_num, node1, node2;
    int q;
    cin >> node_num >> edge_num;
    for (int i = 0; i < node_num+1; ++i) 
    {
        color[i] = -1;
    }

    for (int i = 0; i < edge_num; ++i) 
    {
        cin >> node1 >> node2;
        Graph[node1].push_back(node2);
        Graph[node2].push_back(node1);
    }

    for (int i = 0; i < node_num; ++i)
    {
        if (color[i] < 0) 
        {
            AssignColor(i, col++);
        }
    }
    
    cin >>  q;
    for (int i = 0; i < q; ++i) 
    {
        cin >> node1 >> node2;
        if (color[node1] == color[node2]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


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

using namespace std;
typedef long long ll;
int f[200050];
int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int cnt=0;
    int p=0,a=1;
    for(int i=0;i<n;i++){
        cin >> f[i];
        if(f[i]==a){
            a++;
        }
        else
            cnt++;
    }
    if(a!=1)
        cout << cnt <<endl;
    else
        cout << -1<<endl;
    return 0;
}


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

int main(){
    int N, A[100000], B[100000];
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i] >> B[i];

    vector<int> order;
    for(int i=0; i<N; i++) order.push_back(i);
    sort(order.begin(), order.end(), [&](int a, int b){ return A[a]+B[a] > A[b]+B[b];});

    int64_t ans = 0;
    for(int i=0; i<N; i++){
        if(i%2 == 0){
            ans += A[order[i]];
        }else{
            ans -= B[order[i]];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1660
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;


	public class Main {
		
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
	        
			int n = sc.nextInt();
			Map<Character,Long> m = new HashMap<Character,Long>();
			long one = 1;
			
			for(int i=0;i<n;i++) {
				char[] s = sc.next().toCharArray();
				m.merge(s[0], one, Long::sum);
			}
			
			long[] num = new long[5];
			char[] march = "MARCH".toCharArray();
			long sum =0;
			long kind =0;
			long subst =0;
			
			if(n<3) {
				System.out.println(0);
				return;
			}
			
			for(int i=0;i<5;i++) {
				if(m.containsKey(march[i])) {
					num[i] = m.get(march[i]);
				}
				if(num[i]>0) {
					kind++;
				}
				sum += num[i];
			}
			long ret = 0;
			
			for(int i=0;i<5;i++) {
				for(int j=i+1;j<5;j++) {
					for(int k=j+1;k<5;k++) {
						ret += num[i]*num[j]*num[k];
					}
				}
			}
			
			System.out.println(ret);
		}
		
	}


Measured memory_bytes: 48740