akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

#define clr(a) (a.clear())
#define sz(x) (int)x.size()
#define mem(a,b) memset(a, b, sizeof(a))
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define pb push_back
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);

#define X first
#define Y second

using pii = pair <int, int>;
using pll = pair <ll, ll>;

const ll inf = 1;
const ll mod = 1E9;


#define SZ 100010



int main() {
#if defined JESI
//        freopen("1.txt", "r", stdin);
//        freopen("2.txt", "w", stdout);
#endif

    ios::sync_with_stdio(false);

    int n;
    string s;
    cin >> n >> s;

    vector < vector <int> > v(n, vector <int> (2, 0));

    stack <int> stk;
    int first = 0, last = 0;

    for (int i = 0; i < n; i++) {
        if (s[i] == '(') stk.push(i);
        else {
            if (!stk.empty()) stk.pop();
            else v[0][0]++, first++;
        }
    }

    while (!stk.empty()) {
        int u = stk.top(); stk.pop();
        v[u][1]++;
        last++;
    }

    while (first) cout << "(", first--;
    for (int i = 0; i < n; i++) {
//        while (v[i][0]) cout << "(", v[i][0]--;
        cout << s[i];
//        while (v[i][1]) cout << ")", v[i][1]--;
    }
    while (last) cout << ")", last--;
    cout << endl;

    return 0;
}






Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1,n-1):
    if p[i-1] < p[i] and p[i] < p[i+1]:
        ans += 1
    elif p[i+1] < p[i] and p[i] < p[i-1]:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n;
	cin >> n;
	string c;
	cin >> c;
	int r=0,w=0;
	for(int i=0;i<n;i++)
	{
		if(c[i]=='R')
			r++;
		else
			w++;
	}

	int cntw=0,cntr=0;
	for(int i=0;i<n;i++)
	{
		if(i<r)
		{
			if(c[i]=='W')
				cntw++;
		}
		else
		{
			if(c[i]=='R')
				cntr++;
		}
	}

	cout << max(cntw,cntr) << endl;




}

Measured memory_bytes: 3724
import java.util.Scanner;

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

		String s = sc.next();
		String t = sc.next();

		int count = 0;

		for (int i = 0; i < 3; i++) {
			if (s.charAt(i) == t.charAt(i)) {
				count++;
			}
		}
		System.out.println(count);

	}
}


Measured memory_bytes: 21844
/*
  A - HonestOrDishonest
  Contest 056
  Rakesh Kumar --> 18/08/2020
 */

#include <bits/stdc++.h>

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

    char a, b;
    std::cin >> a >> b;
    if (a == 'H')
        std::cout << b << std::endl;
    else
        if (b == 'H')
            std::cout << 'D' << std::endl;
        else
            std::cout << 'H' << std::endl;

    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D)
    cout<<"Left"<<endl;
  else if(A+B<C+D)
    cout<<"Right"<<endl;
  else if(A+B==C+D)
    cout<<"Balanced"<<endl;
}

Measured memory_bytes: 256
program green_bin
    implicit none
    integer(4):: n,i,j,k
    integer(4),allocatable:: a(:,:)
    integer(8) :: count=0
    character(10):: c
    character(10),allocatable:: ca(:)
    character(26),parameter:: alpha='abcdefghijklmnopqrstuvwxyz'
    
    read*, n
    allocate(a(10,n), ca(n))

    do i=1,n
        read*,c(:)
        do j=1,10
            a(j,i) = ichar(c(j:j))
        end do
        call merge_sort(a(:,i),1,10)
        do j=1,10
            ca(i)(j:j) = char(a(j,i))
        end do
        
    end do

    call smerge_sort(ca(:), 1, n)

    block; integer(4):: fst, scd
        fst=1; scd=2
        do while (scd <= n)
            if (ca(fst)==ca(scd)) then
                count = count + scd-fst
                scd=scd+1
            else
                fst=scd
                scd=scd+1
            end if
        end do
    end block

    print*, count



contains
recursive subroutine merge_sort(ar,fst,lst)
    integer(4):: ar(:), fst, lst, mid, tmp

    if (lst-fst < 2)then
        if (ar(lst) < ar(fst)) then
            tmp = ar(fst)
            ar(fst) = ar(lst)
            ar(lst) = tmp
        end if
        return
    end if

    mid = (fst+lst)/2
    call merge_sort(ar,fst,mid)
    call merge_sort(ar,mid+1,lst)
    call merge(ar,fst,mid,lst)
end subroutine

subroutine merge(ar, fst, mid, lst)
    integer(4):: ar(:), fst, mid, lst
    integer(4),pointer:: tmp(:)
    integer(4):: it, il, ir
    
    allocate(tmp(lst-fst+1))
    it=1
    il=fst
    ir=mid+1

    do while(il <= mid .and. ir <= lst)
        if (ar(il) <= ar(ir)) then
            tmp(it)=ar(il)
            il=il+1
        else
            tmp(it)=ar(ir)        
            ir=ir+1
        end if
        it=it+1
    end do

    if(ir > lst) then
        tmp(it:) = ar(il:mid)
    else
        tmp(it:) = ar(ir:lst)
    end if

    ar(fst:lst) = tmp(:)
    deallocate(tmp)
    
end subroutine

recursive subroutine smerge_sort(ar, fst, lst)
    character(10):: ar(:), tmp
    integer(4):: fst, lst, mid

    if (lst-fst < 2) then
        if (ar(lst) < ar(fst)) then
            tmp = ar(fst)
            ar(fst) = ar(lst)
            ar(lst) = tmp
        end if
        return
    end if

    mid = (fst+lst)/2
    call smerge_sort(ar, fst, mid)
    call smerge_sort(ar, mid+1, lst)
    call smerge(ar, fst, mid, lst)
end subroutine

subroutine smerge(ar, fst, mid, lst)
    character(10):: ar(:)
    character(10),pointer:: tmp(:)
    integer(4):: fst, mid, lst
    integer(4):: it, il, ir

    allocate(tmp(lst-fst+1))
    it=1
    il=fst
    ir=mid+1

    do while(il <= mid .and. ir<=lst)
        if (ar(il) <= ar(ir)) then
            tmp(it) = ar(il)
            il=il+1        
        else
            tmp(it) = ar(ir)
            ir=ir+1
        end if
        it=it+1
    end do

    if (ir > lst) then
        tmp(it:) = ar(il:mid)
    else
        tmp(it:) = ar(ir:lst)
    end if
    ar(fst:lst) = tmp(:)
end subroutine


    
end program green_bin

Measured memory_bytes: 21888
#include <iostream>
#include <math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <map>
using namespace std;
#define rep(i, n) for (int i =0; i < (int)(n); i++)
typedef pair<int, string> P;


int main() {
    int n;
    cin >> n;
    vector<int> x(10), y(10);
    rep(i, n)cin >> x[i] >> y[i];
    vector<int> a(n);
    rep(i, n)a[i] = i;

    double l;
    double total=0;
    do {
       
        rep(i, n - 1) {
            double dx = x[a[i]] - x[a[i + 1]];
            double dy = y[a[i]] - y[a[i + 1]];

            l = pow(dx * dx + dy * dy, 0.5);
            total += l;
        }

    } while (next_permutation(a.begin(), a.end()));
    int beki = 1;
    for (int i = 1; i <= n; i++)beki = beki * i;
        cout << setprecision(20)<< total / beki << endl;
}


Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	ps := scanInts(n)

	bit := make(BIT, n+2)
	idx := make([]int, n+1)
	for i := 0; i < n; i++ {
		idx[ps[i]] = i+1
	}

	ans := 0
	for i := 0; i < n; i++ {
		r1 := sort.Search(n+1-idx[n-i], func(idr int) bool {
			return 1 <= bit.Sum(idx[n-i]+idr)-bit.Sum(idx[n-i])
		})+idx[n-i]
		r2 := sort.Search(n+1-idx[n-i], func(idr int) bool {
			return 2 <= bit.Sum(idx[n-i]+idr)-bit.Sum(idx[n-i])
		})+idx[n-i]

		l1 := sort.Search(idx[n-i], func(idl int) bool {
			return -1 < -(bit.Sum(idx[n-i])-bit.Sum(idl))
		})
		l2 := sort.Search(idx[n-i], func(idl int) bool {
			return -2 < -(bit.Sum(idx[n-i])-bit.Sum(idl))
		})

		bit.Add(idx[n-i], 1)

		ans += ((r1-idx[n-i])*(l1-l2)+(r2-r1)*(idx[n-i]-l1))*(n-i)
		// debug(n-i,ans)

		// debug(idx[n-i], l2, l1, r1, r2)
	}

	fmt.Fprintln(wr, ans)

}

// BIT type
type BIT []int

// Sum function calculates a sum to i
func (t BIT) Sum(i int) int {
	s := 0
	for i++; i > 0; i -= i & -i {
		s += t[i]
	}
	return s
}

// Add function add x to i
func (t BIT) Add(i, x int) {
	for i++; i < len(t); i += i & -i {
		t[i] += x
	}
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

void make_prime_table(void);

int prime_table[SIZE];
vector< int > prime;

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

    LL n, m;
    cin >> n >> m;

    combInit();
    LL res = 1;
    for( int i = 2; i * i <= m; ++i ) {
        if( m % i == 0 ) {
            int cnt = 0;
            while( m % i == 0 ) {
                ++cnt;
                m /= i;

            }
            res = res * comb(cnt + n - 1, cnt) % MOD;

        }
    }
    if( m > 1 ) {
        res = res * comb(n, 1) % MOD;

    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4992
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

H,W = map(int,input().split())
INF = 10**18
q = []

visited = [[True]*(W+2)]
visited += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)]
visited.append([True]*(W+2))
  
for i in range(1,H+1):
  for j in range(1,W+1):
    if visited[i][j]:
      q.append((i,j))

moves = [(0,1),(0,-1),(1,0),(-1,0)]

ans = -1
while q:
  qq = []
  ans += 1
  for x,y in q:
    if not visited[x-1][y]:
      visited[x-1][y] = True
      qq.append((x-1,y))
    if not visited[x+1][y]:
      visited[x+1][y] = True
      qq.append((x+1,y))
    if not visited[x][y-1]:
      visited[x][y-1] = True
      qq.append((x,y-1))
    if not visited[x][y+1]:
      visited[x][y+1] = True
      qq.append((x,y+1))
  q = qq
  
print(ans)

Measured memory_bytes: 105976
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <vector>

using namespace std;

typedef pair<int, int> P;

int main() {
    int n;
    cin >> n;
    map<string, priority_queue<P> > m;
    for (int i = 1; i <= n; i++) {
        string s;
        int p;
        cin >> s >> p;
        m[s].push({p, i});
    }
    for (auto &mi:m) {
        while (!mi.second.empty()) {
            P now = mi.second.top(); mi.second.pop();
            cout << now.second << '\n';
        }
    }
    return 0;
}


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

#define MOD 1000000007

string S;
long long dp[100005][13];

int main() {
    
    cin >> S;

    dp[0][0] = 1;

    for(int i=1; i<=S.size(); i++)
    {
        int curr = (S[i-1] == '?' ? -1 : S[i-1] - '0');

        for(int j=0; j<13; j++)
        {
            if(curr != -1)
                dp[i][(j * 10 + curr) % 13] += dp[i-1][j];
            else
            {
                for(int k=0; k<=9; k++)
                    dp[i][(j * 10 + k) % 13] += dp[i-1][j];
            }
        }

        for(int j=0; j<13; j++)
            dp[i][j] %= MOD;
    }

    cout << dp[S.size()][5] << "\n";
    return 0;
}


Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[5];
  for(int i = 0;i < 5;i++) cin >> a[i];
  sort(a,a+5);
  for(int i = 4;i >= 0;i--){
    cout << a[i];
    if(i == 0) cout << endl;
    else cout << " ";
  }
  return 0;
}

Measured memory_bytes: 3164
#include<iostream>
#include<string>
int main(){
    int n;
    std::string s1;
    std::cin >> n;
    std::cin >> s1;
    for(int i=0; i<n && i<s1.length(); i++){
        printf("%c", s1[i]);
        //printf("%d",i);
    }
    if(s1.length() > n)printf("...");
    printf("\n");
    return 0;
}

Measured memory_bytes: 3224
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdio>
#include <cmath>
#include <utility>
#include <vector>
using namespace std;
using W = double;
using P = complex<W>;
using L = pair<P,P>;
using C = pair<P,W>;
using Poly = vector<P>;
#define X real()
#define Y imag()
const W EPS = (1e-10), pi = acos(-1);

double dot(P a, P b){ return a.X * b.X + a.Y * b.Y;}
W cross(P a, P b){ return a.X * b.Y - a.Y * b.X;}

//直線aと直線bの交点
P intersection(L a, L b){
  P af = a.first, as = a.second, bf = b.first, bs = b.second;
  return af + cross(bs-bf,af-bf)/(-cross(bs-bf,as-bf)+cross(bs-bf,af-bf))*(as-af);
}

int main(){
  int n;
  while(cin >> n, n){
    vector<L> l;
    l.emplace_back(P(-100,-100),P(-100,100));
    l.emplace_back(P(-100,-100),P(100,-100));
    l.emplace_back(P(100,100),P(-100,100));
    l.emplace_back(P(100,100),P(100,-100));
    for(int i = 0; i < n; ++i){
      double x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      l.emplace_back(P(x1,y1),P(x2,y2));
    }
    int ans = 1;
    for(int i = 4; i < n+4; ++i){
      vector<P> cps;
      for(int j = 0; j < i; ++j){
        if(abs(cross(l[i].first-l[i].second,l[j].first-l[j].second)) < EPS)
          continue;
        P cp = intersection(l[i],l[j]);
        if(cp.X < -100-EPS or cp.X > 100+EPS or
           cp.Y < -100-EPS or cp.Y > 100+EPS)
          continue;
        bool f = true;
        for(auto p : cps){
          if(abs(p-cp) < EPS){
            f = false;
            break;
          }
        }
        if(f) cps.emplace_back(cp);
      }
      if(cps.empty()) continue;
      ans += cps.size()-1;
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3260
n,k=map(int,input().split())

l=[]
for i in range(n):
    l.append(0)

for i in range(k):
    d=int(input())
    for i in input().split():
        l[int(i)-1]+=1

s=0
for i in range (n):
    if l[i]==0:
        s+=1

print(s)

Measured memory_bytes: 67644
n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = [1] * n

for i in range(m):
    a, b = map(int, input().split())
    if h[a - 1] < h[b - 1]:
        ans[a - 1] = 0
    elif h[a - 1] > h[b - 1]:
        ans[b - 1] = 0
    else:
        ans[a - 1] = 0
        ans[b - 1] = 0
print(ans.count(1))


Measured memory_bytes: 20116
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>
#include <set>
#include <queue>
#include <bitset>
#include <cassert>

using namespace std;

struct Edge {
    int to;
    int weight;

    Edge(int to, int weight) : to(to), weight(weight) {}
};

using Graph = vector<vector<Edge>>;
vector<int> colors;
vector<bool> seen;

Graph graph;

void dfs(int v, int c) {
    seen[v] = true;
    colors[v] = c;
    for (auto e : graph[v]) {
        if (seen[e.to]) continue;
        if (e.weight % 2 != 0) {
            int t = 1- c;
            dfs(e.to, t);
        }
        else {
            dfs(e.to, c);
        }
    }
}

int main() {

    int N;
    cin >> N;

    graph.assign(N, vector<Edge>());
    seen.assign(N,false);
    colors.assign(N, 0);

    for (int i = 0; i < N - 1; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        u -= 1;
        v -= 1;
        graph[u].push_back(Edge(v, w));
        graph[v].push_back(Edge(u, w));
    }

    dfs(0, 1);

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

}

Measured memory_bytes: 11028
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define mex 1000005
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
vector<int> adj[mex];
//a+b=a^b+2*(a&b)

long long recur(long long int a[], long long **dp, int i1, int i2){
	if(i1>i2)
	 return 0;
	if(dp[i1][i2]!=-1)
	 return dp[i1][i2];
	else{
		dp[i1][i2]=max((a[i1]-recur(a,dp,i1+1,i2)),(a[i2]-recur(a,dp,i1,i2-1)));
		return dp[i1][i2];
	}
}  
int main(){
	fast
	int n;
	cin>>n;
	long long int a[n];
	for(int i=0;i<n;i++)
	 cin>>a[i];
	long long ** dp;
	dp=new long long*[n+1];
	for(int i=0;i<=n;i++)
	 dp[i]=new long long[n+1];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++)
		 dp[i][j]=-1;
	} 
	cout<<recur(a,dp,0,n-1)<<endl;
}


Measured memory_bytes: 94464
#include <iostream>

using namespace std;

int main(){
  long long n, a;
  long long c = 0;
  long long count = 0;
  cin >> n;
  for (int i=0;i<n;i++) {
    int tmp;
    cin >> tmp;
    if (tmp > c) {
      cout << -1 << endl;
      return(0);
    }
    //    cout << c << "\t" << count<< endl;
    if (tmp < c) {
      count += tmp;
      c = tmp;
    } else {
      if (i!=0)
	count++;
    }
    c++;
  }
  cout << count << endl;
  return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
int n,k;
int ans=0;
int tri(int n){
    return n*(n+1)/2;
}
signed main(){
    string n;
    cin>>n;
    bool seven=false;
    rep(i,3){
        if(n[i]=='7')seven=true;
    }
    if(seven)puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int sum[15][1005];
int main(){
	int n,m,o,ans=1e9;
	cin>>n>>m>>o;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			char c;cin>>c;
			sum[i][j]=c-'0';
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
		}
	}
	for(int i=0;i<(1<<(n-1));i++){
		int val=0,last=0;
		vector<int> p;
		p.push_back(0);
		for(int j=0;j<n-1;j++){
			if((i>>j)&1==1) p.push_back(j+1);
		}
		p.push_back(n);
		for(int j=1;j<=m;j++){
			for(int k=1;k<p.size();k++){
				int x=p[k],t=p[k-1];
				if(((sum[x][j]-sum[t][j])-(sum[x][last]-sum[t][last]))>o){
					if(((sum[x][j-1]-sum[t][j-1])-(sum[x][last]-sum[t][last]))>o) val=1e9;
					else val++;last=j-1;
					break;
				}
			}
		}
		if(val>=m) val=1e9;
		val+=p.size()-2;
		ans=min(ans,val);
	}
	cout<<ans<<endl;

}

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

typedef long long int ll;


using namespace std;

int main() {

    ll N,a;
    vector<ll> A;
    cin >> N;

    ll sum = 0, nega_cnt, abs_min = 1000000000;

    for(ll i=0; i<N; i++){
        cin >> a;
        A.push_back(a);
        if (a < 0) {
            nega_cnt ++;
        }
        sum += abs(a);
        if (abs(a) < abs_min){
            abs_min = abs(a);
        }
    }

    if (nega_cnt %2 ==0){
        cout << sum << endl;
    }else{
        // cout << "aaaa" << endl;
        // cout << sum << endl;
        // cout << abs_min << endl;
        cout << sum - 2 * abs_min << endl;;
    }

    return 0;
}


Measured memory_bytes: 1400
import itertools
import math
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
L = list(map(list,list(itertools.permutations(list(i for i in range(1,N+1)),N))))
a = L.index(P)
b = L.index(Q)
print(abs(a-b))

Measured memory_bytes: 15140
import javax.swing.*;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        int[] arr = new int[count];
        int[] values = new int[count];
        for (int i = 0; i < count; i++) {
            arr[i] = sc.nextInt();
            values[i] = -1;
        }
        values[0] = 0;
        values[1] = Math.abs(arr[1] - arr[0]);
        for (int i = 2; i < count; i++) {
            int first = values[i - 1] + Math.abs(arr[i] - arr[i - 1]);
            int second = values[i - 2] + Math.abs(arr[i] - arr[i - 2]);
            values[i] = Math.min(first, second);
        }
        System.out.println(values[count - 1]);
    }
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(n); for(auto&i:a)cin>>i;
	sort(a.begin(),a.end());
	int ai=a.back(),aj=a.front();
	for(auto&taj:a){
		if(aj>=min(taj,ai-taj))continue;
		aj=taj;
	}
	cout<<ai<<" "s<<aj<<"\n"s;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <cctype>
#include <cstdio>
#include <iomanip>
#define PI 3.1415926535
 
using namespace std;
 
int n, a = 0, b = 0;
string s, t;
 
int main(){
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> s >> t;
        if (s>t)a += 3;
        else if (s < t) b += 3;
        else {
            a++;
            b++;
        }
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    ll a, b, c, x, y;

    cin >> a >> b >> c >> x >> y;

    if (c*2 < a+b) {
        ll tmp = min(x, y);

        ll got = tmp * 2 * c;

        ll tmpnxt, prc;
        if (x > y) tmpnxt = x, prc = a;
        else tmpnxt = y, prc = b;

        ll got1st = got + ((tmpnxt - tmp) * prc);


        tmp = max(x, y);
        ll got2nd = tmp * 2 * c;

        cout << min(got1st, got2nd) << endl;
    }

    else {
        cout << (a * x) + (b * y) << endl;
    }
}


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

typedef long long ll;

ll n,h,mx,ans;

int main()
{
	cin>>n>>h;
	
	vector<ll> v(n);
	for(int i=0;i<n;i++)
	{
		ll a;
		cin>>a>>v[i];
		mx=max(mx,a);
	}
	
	sort(v.begin(),v.end());
	while(h>0&&!v.empty())
	{
		ll t=v.back();
		if(t<=mx) break;
		ans++;
		h-=t;
		v.pop_back();
	}
	
	if(h>0) ans+=(h+mx-1)/mx;
	
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;

int main(){
      int n;
      cin>>n;
      double v[n];
      rep0(i,n){
            cin>>v[i];
      }
      sort(v,v+n);
      double ans=v[0];
      rep0(i,n){
            ans=((ans+v[i])/2);
      }
      cout<<setprecision(10)<<ans<<endl;
      
      return 0;
}

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

string S;

int main() {
    cin >> S;

    int S_cnt = 0;
    int p = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] == 'S') {
            S_cnt++;
        }
        else {
            if (S_cnt > 0) {
                p++;
                S_cnt--;
            }
        }
    }

    cout << S.length() - 2*p << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/

int n, ma1, ma2;
int a[214514];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		if (ma1 < a[i]) {
			ma2 = ma1;
			ma1 = a[i];
		}
		else if (ma2 < a[i]) {
			ma2 = a[i];
		}
	}
	rep(i, n) {
		if (a[i] == ma1)cout << ma2 << endl;
		else cout << ma1 << endl;
	}
}

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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

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

  if (a[0] > 0) {
    cout << -1 << endl;
    return 0;
  }

  ll ans = 0;
  for (int i=1; i<n; i++) {
    ll t = a[i]-a[i-1];
    switch(t) {
      case 2:
        cout << -1 << endl;
        return 0;
      case 1:
        ans++; break;
      default:
        ans += a[i]; break;
    }
  }
  cout << ans << endl;

  return 0;
}


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

template <int64_t N>
class modint {
    int64_t x;

public:
    modint(int64_t x = 0) : x((x % N + N) % N) {}
    modint operator-() const { return modint(-x); }
    modint& operator+=(const modint& a) {
        if ((x += a.x) >= N) x -= N;
        return *this;
    }
    modint& operator-=(const modint& a) {
        if ((x += N - a.x) >= N) x -= N;
        return *this;
    }
    modint& operator*=(const modint& a) {
        (x *= a.x) %= N;
        return *this;
    }
    modint operator+(const modint& a) const {
        return modint(*this) += a;
    }
    modint operator-(const modint& a) const {
        return modint(*this) -= a;
    }
    modint operator*(const modint& a) const {
        return modint(*this) *= a;
    }
    modint pow(int64_t t) const {
        if (not t) return 1;
        modint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime mod
    modint inv() const { return pow(N - 2); }
    modint& operator/=(const modint& a) {
        return (*this) *= a.inv();
    }
    modint operator/(const modint& a) const {
        return modint(*this) /= a;
    }
    friend ostream& operator<<(ostream& os,
                               const modint& m) {
        os << m.x;
        return os;
    }
};

const int64_t mod = 998244353;
using mint = modint<mod>;
int main() {
    int64_t n, k;
    cin >> n >> k;
    vector<pair<int64_t, int64_t>> s(k);
    for (auto i = 0; i < k; i++) {
        cin >> s[i].first >> s[i].second;
    }
    vector<mint> m(n + 1, 0);
    m[0] = 1;
    for (auto i = 0; i < n - 1; i++) {
        if (i > 0) m[i] += m[i - 1];
        for (auto j = 0; j < k; j++) {
            m[min(i + s[j].first, n)] += m[i];
            m[min(i + s[j].second + 1, n)] -= m[i];
        }
    }
    cout << m[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 4772
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];

int main(){
  int A,B,C,X,Y ;
  cin >> A >> B >> C >> X >> Y ;
  if(A+B <= 2*C)
    cout << A*X+B*Y << endl;
  else{
    if(X >= Y && (X-Y)*A <= 2*C*(X-Y))
      cout << 2*C*Y + (X-Y)*A << endl;
    else if(X >= Y && (X-Y)*A > 2*C*(X-Y))
      cout << 2*C*X << endl;
    else if (X < Y && (Y-X)*B <= 2*C*(Y-X))
      cout << 2*C*X + (Y-X)*B << endl;
    else if (X < Y && (Y-X)*B > 2*C*(Y-X))
      cout << 2*C*Y << endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

bool check(const string &s, const vector<pair<char, char>> &v, int x) {
    for (const auto &p : v) {
        if (s[x] == p.first) {
            x += (p.second == 'R' ? 1 : -1);
            if (x == -1)
                return true;
            if (x == s.size())
                return false;
        }
    }
    return false;
}

int get_rightmost(const string &s, const vector<pair<char, char>> &v) {
    int l = -1, r = s.size();
    while (r - l > 1) {
        int p = (l + r) >> 1;
        if (check(s, v, p))
            l = p;
        else
            r = p;
    }
    return l;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    int n, m;
    cin >> n >> m >> s;

    vector<pair<char, char>> v;

    for (int i = 0; i < m; i++) {
        char a, b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }

    int x = get_rightmost(s, v);

    reverse(all(s));
    for (auto &p : v) {
        p.second = (p.second == 'R' ? 'L' : 'R');
    }

    int y = n - 1 - get_rightmost(s, v);

    cout << y - x - 1 << "\n";

    return 0;
}

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

int main(){
	int n,piza,topping,piza_k;
	
	cin>>n;
	cin>>piza;
	cin>>topping;
	cin>>piza_k;
	
	int topping_k[n];
	
	for(int i=0;i<n;i++) cin>>topping_k[i];
	sort(topping_k,topping_k + n);
	
	int max=piza_k/piza;
	int sum_d=piza,sum_k=piza_k;
	for(int i=n-1;i>=0;i--){
		sum_d+=topping;
		sum_k+=topping_k[i];
		if(max<=sum_k/sum_d) max=sum_k/sum_d;
		else break;
	}
	cout<<max<<endl;
return 0;
}

Measured memory_bytes: 1176
import sys
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [long(input_raw[0]), long(input_raw[1])]
    if N == 1 and M == 1:
        print 1
    elif N == 1:
        print M - 2
    elif M == 1:
        print N - 2
    else:
        print N * M - ((((M - 1) + (N - 1)) * 2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2568
/* AOJ 0059 Intersection of Rectangles */

#include <iostream>
#include <algorithm>

using namespace std;

typedef pair<double, double> pdd;

pdd make_sorted_pair(double x, double y);
bool is_overlapped(pdd p1, pdd p2);

int
main()
{
    double xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;
    pdd xa, ya, xb, yb;

    for (;;) {
        cin >> xa1 >> ya1 >> xa2 >> ya2 >> xb1 >> yb1 >> xb2 >> yb2;
        if (cin.eof()) break;

        xa = make_sorted_pair(xa1, xa2);
        ya = make_sorted_pair(ya1, ya2);
        xb = make_sorted_pair(xb1, xb2);
        yb = make_sorted_pair(yb1, yb2);

        if (is_overlapped(xa, xb) && is_overlapped(ya, yb))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

pdd
make_sorted_pair(double a, double b)
{
    if (a > b) swap(a, b);
    return pdd(a, b);
}

bool
is_overlapped(pdd p1, pdd p2)
{
    if (p1 > p2) swap(p1, p2);
    return p1.second >= p2.first;
}

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

using namespace std;

class Solution {
public:
	int n, m, q;
	vector<int> a, b, c, d;
	int calc(vector<int>& cur, int depth = 1) {
		int ret = 0;
		if (depth == n) {
			for (int i = 0; i < q; i++)
				if (cur[b[i]] - cur[a[i]] == c[i]) ret += d[i];
			return ret;
		}
		for (int i = cur[depth - 1]; i <= m; i++) {
			cur[depth] = i;
			ret = max(ret, calc(cur, depth + 1));
		}
		return ret;
	}
	void solve() {
		cin >> n >> m >> q;
		a = vector<int>(q);
		b = vector<int>(q);
		c = vector<int>(q);
		d = vector<int>(q);
		for (int i = 0; i < q; i++) {
			cin >> a[i] >> b[i] >> c[i] >> d[i];
			a[i]--;
			b[i]--;
		}
		vector<int> cur(n);
		cur[0] = 1;
		cout << calc(cur) << endl;
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 3668
N = int(input())
H = [int(zz) for zz in input().split()]

ans = 0
p = 0
tmp = H[0]
for i in range(1,N):
    if tmp < H[i]:
        p = 0
    else:
        p += 1
    ans = max(ans,p)
    tmp = H[i]

print(ans)


Measured memory_bytes: 14252
import java.io.*;

public class Main{
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try{
            String line = reader.readLine();
            int x = Integer.parseInt(line);
            System.out.println(x*x*x);
        }catch(IOException e){
            System.out.println(e);
        } 
    }
}


Measured memory_bytes: 24192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=200005;
int mx[N],f[N],fa[N],sz[N],ans[N];
vector<int> v[N],F[N],G[N];
inline int gf(int x){
	return fa[x]==x?x:fa[x]=gf(fa[x]);
}
void mer(int a,int b){
	a=gf(a); b=gf(b);
	fa[a]=b;
	sz[b]+=sz[a];
}
void dfs(int p){
	mx[p]=max(p,mx[f[p]]);
	if(p>1){
		if(mx[p]==p){
			F[mx[f[p]]].pb(p);
		}else if(mx[f[p]]==f[p]){
			F[f[p]].pb(p);
			if(p<mx[f[f[p]]]){G[mx[f[f[p]]]].pb(p);}
		}
	}
	for(auto i:v[p])if(i!=f[p]){f[i]=p; dfs(i);}
}
void bao(int p){
	ans[p]+=ans[f[p]];
	for(auto i:v[p])if(i!=f[p])bao(i);
}
int main(){
	int n=read();
	For(i,1,n){fa[i]=i; sz[i]=1;}
	For(i,1,n-1){
		int s=read(),t=read();
		v[s].pb(t); v[t].pb(s);
	}
	dfs(1);
	//For(i,1,n)for(auto j:F[i])cout<<i<<" F "<<j<<endl;
	For(i,1,n){
		for(auto j:F[i]){
			if(j<i)ans[j]+=sz[j];
			else{
				ans[j]++;
				for(auto k:v[j])if(k!=f[j]&&k<i)ans[j]+=sz[k];
			}
		}
		for(auto j:G[i]){
			if(j<i)ans[j]-=sz[j];
			else{
				ans[j]--;
				for(auto k:v[j])if(k!=f[j]&&k<i)ans[j]-=sz[k];
			}
		}
		if(f[i]&&f[i]<=i){
			mer(i,f[i]);
		}
		for(auto j:v[i])if(j!=f[i]&&j<=i)mer(j,i);
	}
	bao(1);
	For(i,2,n)wri(ans[i]);
}

Measured memory_bytes: 35328
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
//typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v);
#define debug(a) cerr<<#a<<" --> "<<(a)<<"\n";
#define debug2(a) #a<<" --> "<<(a)<<" , "
#define HERE cerr<<"here - "<<__LINE__<<"\n";
const ll mod = 1e9+7 ;
const int N = 2e5 +5;
ll n,a,b,c,d;
map<ll,ll>mp;

ll solve(ll now)
{
    if(now==0)
    {
        return 0;
    }
    if(now==1)
    {
        return d;
    }
    if(mp.count(now))
        return mp[now];
    ll ans = 3e18;
    if(d*now>0)
    {
        ans = min(ans , d*now);
    }
    if(now%2==0)
    {
        ans = min(ans , a + solve(now/2));
    }
    else{
        ll md = now%2;
        ans = min(ans , a+ d*md + solve((now-md)/2));
        md = 2- md;
        ans = min(ans , a+ d*md + solve((now+md)/2));
    }
    if(now%3==0)
    {
        ans = min(ans , b + solve(now/3));
    }
    else{
        ll md = now%3;
        ans = min(ans , b+ d*md + solve((now-md)/3));
        md = 3- md;
        ans = min(ans , b+ d*md + solve((now+md)/3));
    }
    if(now%5==0)
    {
        ans = min(ans , c + solve(now/5));
    }
    else{
        ll md = now%5;
        ans = min(ans , c+ d*md + solve((now-md)/5));
        md = 5- md;
        ans = min(ans , c+ d*md + solve((now+md)/5));
    }
    return mp[now]= ans;
}

void TEST_CASES(int cas)
{
    mp.clear();
    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&c,&d);
    printf("%lld\n",solve(n));

}


/*

*/

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1,cas=0;
    scanf("%d",&t);
    while(t--)
    {
        TEST_CASES(++cas);
    }

    return 0;
}



//os.order_of_key(v): returns how many elements strictly less than v
//os.find_by_order()

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v)
{
    for(auto i:v)
    {
        os<<"Key : "<<i.first<<" , Value : "<<i.second<<endl;
    }
    return os;
}


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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int F[109][10];
int P[109][11];

int main() {
   int n;
   cin >> n;
   for (int i = 0; i < n; i++) {
      for (int j = 0; j < 10; j++) {
         cin >> F[i][j];
      }
   }
   for (int i = 0; i < n; i++) {
      for (int j = 0; j < 11; j++) {
         cin >> P[i][j];
      }
   }

   int ans = -2e9+7;
   for (int mask = 1; mask < (1<<10); mask++) { // mask生成
      int sum = 0;
      for (int i = 0; i < n; i++) {
         int cnt = 0;
         for (int j = 0; j < 10; j++) {
            if ( (mask>>j) & F[i][9-j] ) {
               cnt++;
            }
         }
         sum += P[i][cnt];
      }
      ans = max(ans, sum);
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
from heapq import heapify, heappush, heappop

n = int(input())
x_loc, y_loc = [], []
for i in range(n):
    x, y = map(int, input().split())
    x_loc.append((x, i))
    y_loc.append((y, i))
x_loc.sort()
y_loc.sort()
links = [set() for _ in range(n)]
for (x1, i1), (x2, i2) in zip(x_loc, x_loc[1:]):
    dist = abs(x1 - x2)
    links[i1].add((dist, i2))
    links[i2].add((dist, i1))
for (y1, i1), (y2, i2) in zip(y_loc, y_loc[1:]):
    dist = abs(y1 - y2)
    links[i1].add((dist, i2))
    links[i2].add((dist, i1))

visited = {0}
queue = list(links[0])
heapify(queue)
total = 0
while True:
    cost, i = heappop(queue)
    if i in visited:
        continue
    visited.add(i)
    total += cost
    if len(visited) == n:
        break
    for cost2, j in links[i]:
        if j in visited:
            continue
        heappush(queue, (cost2, j))
print(total)


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    g[a - 1].push_back(b - 1);
    g[b - 1].push_back(a - 1);
  }

  queue<int> que;
  vector<int> pvs(n, -1);
  int num_visits = 0;

  que.push(0);
  while (!que.empty()) {
    int cv = que.front();
    que.pop();
    num_visits++;

    for (auto nv : g[cv]) {
      if (pvs[nv] >= 0) continue;
      que.push(nv);
      pvs[nv] = cv;
    }
  }

  if(num_visits < n) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    rep2(i, 1, n) {
      cout << pvs[i] + 1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 10176
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int n;

int main(){
	
	cin >> n;
	cout << n * n * n << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(a) for(int k=head[a];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=1e6+5,M=5e3+5,INF=1e9,mod=998244353;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
int n,m,a[N];
int main(){
	read(n,m);vector<int>pos;
	rep(i,1,m){
		read(a[i]);
		if(a[i]&1)pos.pb(i);
	}
	if(pos.size()>2)return puts("Impossible"),0;
	if(n==1)return printf("1\n1\n1"),0;
	if(m==1)return printf("%d\n2\n%d 1",n,n-1),0;
	if(pos.size()==2)swap(a[pos[0]],a[1]),swap(a[pos[1]],a[m]);
		else if(pos.size()==1)swap(a[pos[0]],a[1]);
	rep(i,1,m)printf("%d ",a[i]);puts("");
	a[1]++;a[m]--;
	if(a[m]==0)m--;
	cout<<m<<endl;
	rep(i,1,m)printf("%d ",a[i]);
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>

using namespace std;

int main(void){
    int A,B;
    cin >> A >> B;

    if(A % 3==0 or B % 3 == 0 or (A+B) % 3 == 0){
        cout << "Possible" << endl;
    }
    else{
        cout << "Impossible" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

const int INF = 1 << 25;

int main() {
    int N, K;
    std::cin >> N >> K;
    std::vector<int> A(N);
    for (auto& a : A) {
        std::cin >> a;
        --a;
    }

    std::vector<int> cnt(K, 0);
    int unfill = K, r = 0;
    int ans = INF;
    for (int l = 0; l < N; ++l) {
        while (r < N && unfill > 0) {
            if (A[r] < K) {
                if (cnt[A[r]] == 0) --unfill;
                ++cnt[A[r]];
            }
            ++r;
        }

        if (unfill == 0) ans = std::min(ans, r - l);

        if (A[l] < K) {
            --cnt[A[l]];
            if (cnt[A[l]] == 0) ++unfill;
        }
    }

    std::cout << (ans == INF ? 0 : ans) << std::endl;
    return 0;
}



Measured memory_bytes: 3616
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String t = sc.next();
        char[] ch = t.toCharArray();
        for(int i = 0;i < ch.length;i++){
            if(ch[i] == '?')
                ch[i] = 'D';
        }
        for(char ans:ch){
            System.out.print(ans);
        }    
    }
}

Measured memory_bytes: 58552
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define uu first
#define vv second

using namespace std;

typedef long long ll;

int main() {
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    int a, b;
    cin >> a >> b;
    int res =  (b * 2) >= a ? 0 : (a - b * 2);
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [1]+a
flg = [0] * (n + 1)
 
now = 0
i = 1
flg2 = 1
loop = 0
while (i < k+1):
    if (flg2 and flg[a[now]] != 0):
        flg2 = 0
        loop = i-flg[a[now]]
        i += ((k - i) // loop - 1) * loop
    now = a[now]
    flg[now] = i
    i += 1
print(a[now])

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

string b[1000000];

bool cmp(string a,string b)
{
    return a<b;
}

int main()
{
    int n,l;
    cin>>n>>l;
    for(int i=1;i<=n;++i)
        cin>>b[i];
    sort(b+1,b+1+n,cmp);
    for(int i=1;i<=n;++i)
        cout<<b[i];
    return 0;
}

Measured memory_bytes: 8192