akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,Q;
    cin >> N >> Q;
    vector<vector<int>> g(N);
    vector<ll> ans(N);
    vector<bool> v(N);
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i,Q){
        int p,x;
        cin >> p >> x;
        p--;
        ans[p]+=x;
    }
    queue<int> q;
    q.push(0);
    v[0] = 1;
    while(!q.empty()){
        int now = q.front();q.pop();
        for(int i=0;i<g[now].size();i++){
            int next = g[now][i];
            if(v[next])continue;
            v[next] = 1;
            q.push(next);
            ans[next] += ans[now];
        }
    }
    for(auto x:ans)cout << x << endl;
}

Measured memory_bytes: 16372
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (x,y) = get!(isize, isize);
    let res = if x == y {
        0
    } else if x == 0 {
        if y > 0 {
            y
        } else {
            -y + 1
        }
    } else if y == 0 {
        if x > 0 {
            x+1
        } else {
            -x
        }
    } else {
        if x > y {
            if y > 0 {
                x-y+2
            } else if x > 0 {
                (x.abs()-y.abs()).abs()+1
            } else {
                x-y+2
            }
        } else {
            if x > 0 {
                y-x
            } else if y > 0 {
                (x.abs()-y.abs()).abs()+1
            } else {
                y-x
            }
        }
    };
    println!("{}", res);
}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
#define ifor(i,n) for(i=0;i<n;i++)
#define ll long long
int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
      int i,n,t,p=INT_MAX,j=1,x,a=0,b,l=0,r=0,y;
     string s,m;
     cin>>a>>b;
     for(i=1;i<=10000;i++){
        x=i*.08;
        y=i*.1;
        if(x==a && y==b){
            cout<<i<<endl;
            return 0;
        }
     }
     cout<<-1<<endl;

     return EXIT_SUCCESS;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll n;
    cin>>n;
    ll arr1[n];
    for(ll i=0;i<n;i++)
    {
        cin>>arr1[i];
    }
    sort(arr1,arr1+n);
    ll val=n/2;
    ll ans=arr1[val]-arr1[val-1];
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cmath>
#include<stack>
#include<vector>
#include<numeric>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	int r = 0;
	while (true)
	{
		bool amari = false;
		sort(A.begin(), A.end());
		
		while (true)
		{
			if (A[r] == 0)
			{
				r++;
			}
			else
			{
				break;
			}
		}

		for (int i = r + 1; i < N; i++)
		{
			A[i] = A[i] % A[r];
			if (A[i])
			{
				amari = true;
			}
		}

		if (!amari)
		{
			break;
		}
	}
	
	cout << A[r] << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> 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); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

int N, T, A;
int H[1010];

void _main() {
    cin >> N >> T >> A;
    REP(i, N) cin >> H[i];
    int ans = 0;
    REP(i, N) {
        double t = T - H[i] * 0.006;
        if (abs(t - A) < abs(T - H[ans] * 0.006 - A)) {
            ans = i;
        }
    }
    cout << ans + 1 << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i'))
            freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o'))
            freopen("output.txt", "w", stdout);
    }
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    string S;
    int a, b;
    cin >> a >> S >> b;
    if(S=="+"){
        cout << a+b << endl;
    }else{
        cout << a-b << endl;
    }
    
    return 0;
}

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


int main() {
    int N; cin >> N;
    // A = [7, 1, 15] (= [111, 1, 1111])
    vector<long long int> A(N); for (int i = 0; i < N; i++) cin >> A[i];
    long long int ans = 0;

    for (int i = 0; i < 60; i++) {
        int s = 0;
        // for i = 0, s = 1 xor 1 xor 1 = 1
        for (int j = 0; j < N; j++) s ^= A[j] >> i & 1;
        if (s == 1) {
            ans += 1LL << i;
            // for i = 0, A -> [110, 0, 1110]
            for (int j = 0; j < N; j++) A[j] &= ~(1LL << i);
        }
    }

    vector<long long int> bases;
    // A -> [0110, 110, 0]
    sort(A.begin(), A.end(), greater<>());
    for (long long int x : A) {
        // min(110, 110 ^ 0110) = min(110, 0) = 0
        for (long long int y : bases) x = min(x, x ^ y);
        if (x != 0) bases.push_back(x);
    }
    long long s = 0;
    // max(0110, 0110 ^ 0) = 0110
    for (long long int x : bases) s = max(s, s ^ x);

    cout << ans + s * 2 << endl;

    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using static Input;
using static Util;
class Program
{
    static long A;
    static string B;
    static void INPUT()
    {
        A = NextLong();
        B = NextString();
    }

    static void OUT()
    {
        var b = int.Parse(B.Replace(".", ""));
        var ans = (long)(A * b) / 100;
        
        Console.WriteLine(ans);
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}


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

int cnt[100005];

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    int a;
    cin >> a;
    if (a > n) ++cnt[n+1];
    else ++cnt[a];
  }
  int ans = cnt[n+1];
  for (int i = 1; i <= n; ++i) {
    if (cnt[i] >= i) ans += cnt[i] - i;
    else ans += cnt[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
import itertools

H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

one_line = []
for i in range(N):
    s = str(i+1)
    one_line.append([s]*A[i])
li = list(itertools.chain.from_iterable(one_line))

for i in range(0, H):
    tmp = li[i*W:i*W+W]
    if i % 2 != 0:
        tmp = tmp[::-1]
    print(' '.join(list(tmp)))


Measured memory_bytes: 10532
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        solve();
    }
    static Scanner cin;
    static int N;
    static int[] a;

    static void input()
    {
        cin = new Scanner();
        N = cin.nextInt();
        a = cin.ArrayInt(N);
    }
    static void solve()
    {
        input();
        List<int> ans = new List<int>();
        for(int i = 0; i < N; i++)
        {
            if ((i + N) % 2 == 0)
                ans.Add(a[i]);
            else
                ans.Insert(0, a[i]);
        }
        WriteLine(string.Join(" ", ans));
    }
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }
        
        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for(int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }

        public double[] ArrayDounble(int N, int add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 43292
#include <iostream>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;


bool can_be_pair(int row, int col, int A, int B, vector<string> const &s){
    int N = s.size();
    for (int k = 0; k < N; k++){
        int idx1 = (k-B)%N;
        if (idx1 < 0) idx1 += N;
        int idx2 = (k-A)%N;
        if (idx2 < 0) idx2 += N;

        if (s[row][idx1] != s[idx2][col]){
            return false;
        }
    }
    return true;
}

int main(){
    int N;
    cin >> N;
    vector<string> s;
    for (int i = 0; i < N; i++){
        string buf;
        cin >> buf;
        s.push_back(buf);
    }

    int ret = 0;
    int  A = 0;
    for (int B = 0; B < N; B++){
        bool valid = true;
        for (int row = 0; row < N; row++){
            int col = (row + A - B)%N;
            if (col < 0) col += N;

            if (!can_be_pair(row, col, A, B, s)){
                valid = false;
                break;
            }
        }
        if (valid){
            ret += N;
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
bool comp(pair<string,int>&a,pair<string,int>&b){
  return a.first < b.first || a.first == b.first && a.second > b.second;
}
int main() {
    int n;
    cin >> n;
    vector<pair<string,int>>a;
    for (int i = 0; i < n; i++) {
        string in;
        int p;
        cin >> in >> p;
        a.push_back(make_pair(in,p));
    }
    vector<pair<string,int>>b = a;
    sort(b.begin(),b.end(),comp);
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            if(b[i] == a[j]){
                cout << j+1 << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
WHxy = list(map(int, input().split()))
W = WHxy[0]
H = WHxy[1]
x = WHxy[2]
y = WHxy[3]

sq = W*H /2

if x == W/2 and y == H/2:
    print("{} 1".format(sq))
else:
    print("{} 0".format(sq))


Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u64 = read();
    let x: u64 = read();
    let mut ans: u64 = 1;
    let mut sum: u64 = 0;
    for _ in 0..n {
        sum += read();
        if sum > x {
            println!("{}", ans);
            return;
        }
        ans += 1;
    }
            println!("{}", n + 1);
}


Measured memory_bytes: 4352
n = int(input())
A = list(map(int, input().split()))

not_important = 0
for a in A:
    not_important ^= a

for i in range(n):
    A[i] &= ~not_important

A.sort(reverse=True)
rank = 0
for digit in range(60, -1, -1):
    check_bit = 1 << digit

    for i in range(rank, n):
        if A[i] & check_bit:
            A[rank], A[i] = A[i], A[rank]
            break
    else:
        continue

    for i in range(n):
        if i == rank: continue
        if A[i] & check_bit:
            A[i] ^= A[rank]

    rank += 1

ans = 0
for i in range(rank):
    ans ^= A[i]

print(ans*2 + not_important)


Measured memory_bytes: 16116
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static Integer N;
	static int[][] dp;
	static Node[] v;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		N = Integer.parseInt(sc.next());
		Integer M = Integer.parseInt(sc.next());
		v = new Node[N];
		//Edge e[] = new Edge[M];
		for(int i=0;i<N;i++) {
			v[i] = new Node(i);
		}
		for(int i=0;i<M;i++) {
			int a = Integer.parseInt(sc.next())-1;
			int b = Integer.parseInt(sc.next())-1;
			//e[i] = new Edge(v[a-1],v[b-1],1);
			v[a].edges.add(new Edge(b,1));
			v[b].edges.add(new Edge(a,1));
		}
		dp = new int[1<<N][N];
		for(int i =0;i<(1<<N);i++) {
			for(int j=0;j<N;j++) {
				dp[i][j] = -1;
			}
		}
		int result = dp(1,v[0]);

		out.println(result);


		out.flush();
	}

	public static int dp(int i,Node j) {
		if(i==(1<<N)-1) {
			return dp[i][j.id] = 1;
		}
		if(dp[i][j.id] >= 0){
			return dp[i][j.id];
		}
		boolean b = false;
		dp[i][j.id]=0;
		for(Edge edge : j.edges) {
			Node j1 = v[edge.v];
			if((i & (1<<j1.id)) == 0) {
				dp[i][j.id]+= dp(i+(1<<j1.id),j1);
				b = true;
			}
		}
		if(!b) {
			return dp[i][j.id]; 
		}

		return dp[i][j.id];
	}
}

class Node{
	int id;
	ArrayList<Edge> edges = new ArrayList<>();

	public Node(int id) {
		this.id = id;
	}
}

class Edge{
	int v;
	int cost;
	public Edge(int id,int c) {
		this.v = id;
		this.cost = c;
		//non-directed graph
//		v1.Connect(this);
//		v2.Connect(this);
	}

//	public Node First_one() {
//		return this.v1;
//	}
//
//	public Node Second_one() {
//		return this.v2;
//	}
//
//	public Node Other_one(Node v) {
//		if(v.equals(this.v1)) {
//			return this.v2;
//		}
//		else {
//			return this.v1;
//		}
//	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
int main(){
    string s;
    int q;
    cin>>s>>q;
    bool flag=0;
    rep(i,q){
        int a;
        cin>>a;
        if(a==1){
            flag=!flag;
        }
        else if(a==2){
            int f;
            char c;
            cin>>f>>c;
            f--;
            if(flag){
                f=!f;
            }
            if(f==0){
                s.insert(s.begin(),c);
            }
            else{
                s+=c;
            }
        }
    }
    if(flag) reverse(s.begin(),s.end());
    cout<<s<<endl;
}


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


using namespace std;





int main(){
	int n;
	cin>>n;
	int ans = 0;
	vector<int> p(n);
	for(int i = 0 ; i < n ; i++){
		cin >>p.at(i);
	  }
	  sort(p.begin(),p.end());
	  for(int i = 0 ; i < n ; i ++){
		if(i==n-1){
			ans += p.at(i)/2;
		  }
		  else{
		ans +=p.at(i);
		  }
		}
		cout << ans <<endl;
}



Measured memory_bytes: 256
N = int(input())
S = input()

need_left = 0
pointer = 0
for i in range(len(S)):
    if S[i] == '(':
        pointer += 1
    else:
        if pointer == 0:
            need_left += 1
        else:
            pointer -= 1
need_right = pointer

res = "(" * need_left + S + ")" * need_right
print(res)

Measured memory_bytes: 38384
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;
const ll inf2 = 0x3f3f3f3f3f3f3f3f;

template<class T>void read(T &x){
    T s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    x = s*w;
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}

ll a,b,c,d;

void solve(){
	ll ans = -inf2;
	ans = max(ans,b*d);
	ans = max(ans,a*c);
	ans = max(ans,b*c);
	ans = max(ans,a*d);
	printf("%lld\n",ans);
}	
int main(){
	// debug;
	
	read(a,b,c,d);
	solve();

	
	return 0;
}


Measured memory_bytes: 3712
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


class Solution {
    public:
        vector<string> solve(vector<long long>& X, vector<long long>& Y, vector<long long>& A) {
            int n = X.size();
            for (int i = 0; i < n; ++i) {
                if ((abs(X[i]) + abs(Y[i])) % 2 != (abs(X[0]) + abs(Y[0])) % 2) {
                    return {};        
                }
            }

            int h = 32;
            A.clear();
            for (int i = h - 1; i >= 0; --i) {
                A.emplace_back(1LL << i);
            }
            if ((abs(X[0]) + abs(Y[0])) % 2 == 0) {
                A.emplace_back(1);
            }
            

            string dir = "LRUD";
            vector<int> DX{-1, 1, 0, 0};
            vector<int> DY{0, 0, 1, -1};

            vector<string> res;

            for (int i = 0; i < n; ++i) {
                long long x = X[i], y = Y[i];
                string s;
                for (int j = 0; j < A.size(); ++j) {
                    long long nx = 0, ny = 0;
                    long long dis = 1LL << 60;
                    int d = -1;

                    for (int k = 0; k < 4; ++k) {
                        long long dx = DX[k ^ 1];
                        long long dy = DY[k ^ 1];
                        long long tx = x + dx * A[j], ty = y + dy * A[j];
                        if (abs(tx) + abs(ty) < dis) {
                            dis = abs(tx) + abs(ty);
                            nx = tx, ny = ty;
                            d = k;
                        }
                    }

                    s += dir[d];
                    x = nx, y = ny;
                }
                assert(x == 0 && y == 0);
                res.emplace_back(s);
            }

            return res;
        }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);


    int n;
    cin >> n;
    vector<long long> X(n);
    vector<long long> Y(n);
    for (int i = 0; i < n; ++i) {
        cin >> X[i] >> Y[i];
    }


    vector<long long> A;
    Solution sol;
    auto res = sol.solve(X, Y, A);
    if (res.empty()) {
        cout << "-1\n";
    } else {
        cout << A.size() << "\n";
        for (int i = 0; i < A.size(); ++i) {
            cout << A[i] << (i + 1 == A.size() ? '\n' : ' ');
        }
        for (auto& s : res) {
            cout << s << "\n";
        }
    }

    return 0;
}

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

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

  ll N; cin >> N;
  ll K; cin >> K;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];

  if (K == 0) {
    ll ans = *max_element(A.begin(), A.end());
    cout << ans << '\n';
    return 0;
  }

  double l = 0.0000005, r = 1e9 + 1.0;
  while (r - l > 0.0000005) {
    double m = (r + l) / 2.0;
    ll cnt = 0;
    for (ll i = 0; i < N; i++) {
      cnt += A[i] / m;
    }
    if (cnt <= K) r = m;
    else l = m;
  }

  ll temp = max((ll) 1, (ll) ceil(l) - 10);
  ll ans = 1;
  for (ll i = temp; i < temp + 20; i++) {
    ll cnt = 0;
    for (ll j = 0; j < N; j++) {
      cnt += A[j] / i;
      if (A[j] % i == 0) cnt--;
    }
    if (cnt <= K) {
      ans = i;
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
#define MAXN 1000005
#define INF 1e18
#define LL long long

int n, m, cnt, head[MAXN], vis[MAXN];
LL l=1, r=INF, root=-1, f[MAXN][5];

LL min(LL x, LL y) {if(x>y) return y; return x;}
LL max(LL x, LL y) {if(x<y) return y; return x;}

struct Edge{int next, to; LL dis;} edge[MAXN];

std::queue<int> q;

void addedge(int from, int to, LL dis)
{
	edge[++cnt].next=head[from];
	edge[cnt].to=to;
	edge[cnt].dis=dis;
	head[from]=cnt;
} 

void bfs(int x)
{
	vis[x]=1; q.push(x);
	f[x][0]=1; f[x][1]=0;
	while(!q.empty())
	{
		int x=q.front(); q.pop();
		for(int i=head[x]; i; i=edge[i].next)
		{
			int to=edge[i].to;
			if(vis[to]) continue;
			f[to][0]=-f[x][0];
			f[to][1]=edge[i].dis-f[x][1];
			vis[to]=1; q.push(to);
		}
	}
}

int main()
{
	scanf("%d%d", &n, &m);
	for(int i=1; i<=m; i++)
	{
		int u, v, s;
		scanf("%d%d%d", &u, &v, &s);
		addedge(u, v, s);
		addedge(v, u, s);
	}
	bfs(1);
	for(int i=1; i<=n; i++)
	{
		if(f[i][0]==1) l=max(l, 1-f[i][1]);
		else r=min(r, f[i][1]-1);
		for(int j=head[i]; j; j=edge[j].next)
		{
			int to=edge[j].to;
			LL x=f[i][0]+f[to][0];
			LL y=f[i][1]+f[to][1];
			if(x==0 && y!=edge[j].dis) {printf("0\n"); return 0;}
			if(x!=0)
			{
				LL temp=edge[j].dis-y;
				if(temp%2) {printf("0\n"); return 0;}
				if(root==-1) root=temp/x;
				if(root!=temp/x) {printf("0\n"); return 0;}
			}
		}
	}
	if(root==-1) printf("%lld\n", max(0, r-l+1));
	else printf("%d", (root>=l && root<=r));
}


Measured memory_bytes: 14976
/*smile please!*/
#include<bits/stdc++.h>
using namespace std;
#define   int      long long
#define   fast()   ios_base::sync_with_stdio(0);cin.tie(0)
int32_t main()
{int l,i;
 string s;
 stack<char> stk;
 fast();
 cin>>s;
 l=s.length();
 for(i=0;i<l;++i)
 {if(!stk.empty() && stk.top()!=s[i])
  stk.pop();
  else
  stk.push(s[i]);
 }
 int c=0;
 while(!stk.empty())
 ++c,stk.pop();
 cout<<l-c;
 return 0;
}





Measured memory_bytes: 512
/*
Author: Hrujul Thumar
*/
#include <bits/stdc++.h>
#define int         long long
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define whilet()    int t; scanf("%d",&t); while(t--)
#define vp          vector<pair<int,int>,int>
#define pb          push_back
#define mii         map<int,int>
#define pii         pair<int,int>
#define msi         map<string,int>
#define psi         pair<string,int>
#define mpi         map<pair<int,int>,int>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define ef          else if
#define MOD         10^9+7
#define endl 	    '\n'
#define fastio       ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define pi          3.141592653589793238
using namespace std;
int gcd(int a, int b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int power(int x,  int y, int p){
    int res = 1;      // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
            y = y>>1; // y = y/2
            x = (x*x) % p;
    }
    return res;
}

int mod_inv(int a,int m){
    a=a%m;
    return power(a,m-2,m)%MOD;
}

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

bool mod(double a,double b) {
    return a/b - floor(a/b);}

int logb(int base, int x) {
    return (log(x) / log(base));
}
char ToLower(char c)
{
    if ((c >= 'A') && (c <= 'Z')) return (char)((int)c - 'A' + 'a');
    else return c;
}

int Vowel(char c)
{
    c = ToLower(c);
    return (c == 'a') || (c == 'o') || (c == 'i') || (c == 'y') || (c == 'u') || (c == 'e');
}
signed main()
{
   string s,t;
   cin>>s>>t;
   int ans=0;
   for(int i=0;i<s.length();i++)
   {
       if(s[i]!=t[i])
       {
           ans++;
       }
   }
   cout<<ans<<endl;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    int M = max(H, W);
    int ans = N / M;
    if (N % M) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
	ID: sixathofpain
	TASK: friday
	LANG: C++   

*/


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const int N = int(3e5) + 999;
#define int long long int

int32_t main(){
    IOS;
	
    // freopen("friday.in","r",stdin);
    // freopen("friday.out","w",stdout);

    int s;
    cin>>s;
    int dp[s+1]={0};
    dp[0]=1;
    for(int i=3;i<=s;i++){
        for(int j=i;j>=3;j--){
            dp[i]+=dp[i-j];
            dp[i]%=MOD;
        }
    }
    cout<<dp[s]<<endl;
    

    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
#include <functional>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];


ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long COM(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;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
        prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
}


int main() {
    ll H, W;
    cin >> H >> W;

    vector<vector<int>> a(H+1, vector<int>(W + 1, 0));
    for(int h = 1; h <= H; h++) {
        for(int w = 1; w <= W; w++) {
            cin >> a[h][w];
        }
    }

    int h = 0;
    int w = 0;

    int odd_h = 0;
    int odd_w = 0;

    vector<int> A, B, C, D;

    for(int i = 0; i < H*W; i++) {
        h = (i / W) + 1;
        w =  h % 2 == 1 ? (i % W) + 1 : W - (i%W);

        //cout << h << "<" << w << endl;

        if(a[h][w] % 2 == 1) {
            if(odd_h != 0) {
                A.push_back(odd_h);
                B.push_back(odd_w);
                C.push_back(h);
                D.push_back(w);
                
                //cout << odd_h << " " << odd_w << " " << h << " " << w << endl;
                odd_h = 0;
                odd_w = 0;
            } else {
                odd_h = h;
                odd_w = w;
            }
        } else {            
            if(odd_h != 0) {
                A.push_back(odd_h);
                B.push_back(odd_w);
                C.push_back(h);
                D.push_back(w);
                
                //cout << odd_h << " " << odd_w << " " << h << " " << w << endl;
                odd_h = h;
                odd_w = w;
            }
        }
    }

    cout << A.size() << endl;
    for(int i = 0; i < A.size(); i++) {
        cout << A[i] << " " << B[i] << " " << C[i] << " " << D[i] << endl;
    }

    return 0;    
}



Measured memory_bytes: 5220
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

const long long maxi = 1e18;

int main() {
	int n;
	cin >> n;

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

	vector<long long> capacity(n + 1, 0);
	for (int i = 0; i <= n; i++) {
		long long tmp = (i == 0 ? 1 : 2LL * capacity[i-1]);
		if (i < n) {
			tmp -= a[i];
		}

		tmp = min(tmp, maxi);

		if (tmp < 0) {
			cout << -1 << endl;
			return 0;
		}
		capacity[i] = tmp;
	}

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

	long long ans = 0;
	long long n_node = 0;
	for (int i = n; i >= 0; i--) {

		if (n_node > 2LL * capacity[i]) {
			ans = -1;
			break;
		}

		n_node = min(n_node, capacity[i]);
		n_node += a[i];

		ans += n_node;
	}

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


Measured memory_bytes: 4464
var n,a,b,i:Longint;
s:String;
begin
readln(n,a,b);
readln(s);
for i:=1 to n do begin
if s[i]='a'then begin
if a>0 then begin dec(a);writeln('Yes');end
else if b>0 then begin dec(b);writeln('Yes');end
else writeln('No');
end else if s[i]='b'then begin
if b>0 then begin dec(b);writeln('Yes');end
else writeln('No');
end else writeln('No');
end;
end.

Measured memory_bytes: 640
//ALDS1_3_A:Stack
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int top, stack[1000];

void push(int x)
{
    stack[++top] = x;
}
int pop()
{
    top--;
    return stack[top + 1];
}

int main()
{
    char s[100];
    top = 0;
    int a, b;
    while (scanf("%s", s) != EOF)
    {
        if (s[0] == '+')
        {
            a = pop();
            b = pop();
            push(a + b);
        }
        else if (s[0] == '-')
        {
            a = pop();
            b = pop();
            push(b - a);
        }
        else if (s[0] == '*')
        {
            a = pop();
            b = pop();
            push(a * b);
        }
        else
        {
            push(atoi(s));
        }
    }
    printf("%d\n", pop());
    return 0;
}


Measured memory_bytes: 2092
#include <cstdio>
#define LL long long
#define F(i, a, b) for (int i = a; i <= b; ++i)

const int MS = 2e5 + 5, mod = 1e9 + 7;
int n, a[MS];

int main()
{
	scanf("%d", &n);
	LL sum = 0, sq = 0;
	F(i, 1, n)
	{
		scanf("%d", &a[i]);
		sum = (sum + a[i]) % mod;
		sq = (sq + (LL)a[i] * a[i]) % mod;
	}
	printf("%lld", (sum * sum % mod - sq + mod) % mod * (mod + 1) / 2 % mod);
	return 0;
}


Measured memory_bytes: 2504
using System;
class program {
static void Main(string[] args){
  program p = new program();
  p.Run();
}
  void Run(){
  string[] inp = Console.ReadLine().Split();
  int ab = int.Parse(inp[0]);
   int bc = int.Parse(inp[1]);
  int ans = ab*bc/2;
  Console.WriteLine(ans.ToString());
   }
  }

Measured memory_bytes: 11092
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=100005;

int n,m,x,y;
int d[N];

int main(){
	int i;
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		d[x]++; d[y]++;
	}
	for (i=1;i<=n;i++)
		if (d[i]&1){
			printf("NO\n");
			return 0;
		}
	printf("YES\n");
	return 0;
} 

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数（ll）
ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

//素因数分解
vector<pair<ll, int>>factorize(ll n){
  vector<pair<ll, int>> res;
  for(ll i = 2; i * i <= n; ++i){
    if(n % i) continue;
    res.emplace_back(i, 0);
    while(n % i == 0){
      n /= i;
      res.back().second++;
    }
  }
if(n != 1) res.emplace_back(n, 1);
return res;
}




int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	REP(i, N) cin >> A[i];

	sort(all(A));
	int tmp = 0;
	ll tmp2 = A.at(0);
	int ans = N;
	REP(i, N - 1){
		tmp++;
		if(tmp2 * 2 < A.at(i + 1)){
			tmp2 += A.at(i + 1);
			ans = N - tmp;
		}else{
			tmp2 += A.at(i + 1);
		}
	}
	print(ans);
}


Measured memory_bytes: 640
N = int(input())
arms = []
for _ in range(N):
    x1, l1 = map(int, input().split())
    arms.append([x1+l1, x1-l1])
    
arms.sort()

last = -(10 ** 9)
ans = 0
for i in range(N):
    if last <= arms[i][1]:
        ans += 1
        last = arms[i][0]
    else:
        continue
    
print(ans)

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

int main(){
    string s;
    cin >> s;
    std::regex re1("^(dream|dreamer|erase|eraser)+$"); // 正規表現
    std::smatch match; // string型の文字列に対するマッチング結果を格納するのがstd::smatch型
    if(regex_match(s, match, re1)){
        cout << "YES";
    }else{
        cout << "NO";
    }
    return 0;
}

Measured memory_bytes: 39808
#include<stdio.h>
#include<math.h>

int main(){
    int i,j,k,n,count = 0,flag = 0;

    scanf("%d",&i);

    for(j = 0;j < i;j++){
        scanf("%d",&n);
        if((n%2) == 0){
            if(n == 2) {
              count++;
            }
            continue;
        }
        flag = 0;
        for(k = 1;(2*k+1) <= sqrt(n);k++){
            if((n%(2*k+1)) == 0){
              flag = 1;
              break;
            }
        } count++;
        if(flag == 1) count--;
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2144
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class CShoppingStreet {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            boolean[][] f = new boolean[10][n];
            for (int j = 0; j < n; j++) {
                for (int i = 0; i < 10; i++) {
                    f[i][j] = in.nextInt() == 1;
                }
            }
            int[][] p = new int[11][n];
            for (int j = 0; j < n; j++) {
                for (int i = 0; i <= 10; i++) {
                    p[i][j] = in.nextInt();
                }
            }

            int ans = Integer.MIN_VALUE;
            for (int i = 1; i < 0b1_00000_00000; i++) {
                int a = 0;
                for (int j = 0; j < n; j++) {
                    int d = 0;
                    for (int k = 0; k < 10; k++) {
                        if ((i & (1 << k)) > 0 && f[k][j]) {
                            d++;
                        }
                    }
                    a += p[d][j];
                }
                ans = Math.max(ans, a);
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 27876
#include <iostream>
#include <string>
#include <cmath>

int main() {
    std::string a, b;   std::cin>>a>>b;
    std::string c = a + b;
    int num = std::stoi(c);
    int sq = std::sqrt(num);
    if (sq * sq == num)
        std::cout<<"Yes";
    else
        std::cout<<"No";
    
    return 0;
}

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

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

template <class T>
vector<T> Vec(size_t l, T v) { return vector<T>(l, v); }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}

template <typename T, typename U>
T mpow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * b % MOD;
        n >>= 1;
        b = b * b % MOD;
    }
    return ret;
}

const ll inv2 = mpow(2LL, MOD - 2);

// 高速に2で割る
inline ll div2(ll n) {
    return (n & 1 ? n * inv2 % MOD : n / 2);
}

int main() {
    int N, Q;
    cin >> N >> Q;

    auto A = Vec<int>(N, 0);
    for (int& a : A) cin >> a;

    auto dp = Vec<ll>(N, N, 0LL);
    // i番目がj番目より大きい確率

    // 初期状態(比較するだけ)
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            dp[i][j] = (A[i] > A[j] ? 1 : 0);
        }
    }

    for (int q = 0; q < Q; ++q) {
        int x, y;
        cin >> x >> y;
        --x, --y;

        // xとyに関与するところだけ更新する
        // ただしdp[x][x]とdp[y][y]は更新してはいけない
        for (int k = 0; k < N; ++k) {
            if (k == x || k == y) continue;
            dp[k][x] = div2(dp[k][x] + dp[k][y]);
            dp[k][y] = dp[k][x];

            dp[x][k] = div2(dp[x][k] + dp[y][k]);
            dp[y][k] = dp[x][k];
        }

        // 互いに位置が入れ替わるdp[x][y]とdp[y][x]を更新
        dp[x][y] = div2(dp[x][y] + dp[y][x]);
        dp[y][x] = dp[x][y];
    }

    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            ans += dp[i][j];
        }
    }

    cout << ans % MOD * mpow(2LL, Q) % MOD << endl;
    return 0;
}


Measured memory_bytes: 70656
#include<stdio.h>
#include<math.h>

#define N 10000

int isPrime(int);

int main()
{
  int n,i,j=0,a,ret,array[N];

  scanf("%d",&n);

  for(i = 0; i < n; i++)
  {
    scanf("%d",&a);
    ret = isPrime(a);
    if(ret == 1)
    {
      array[j] = a;
      j++;
    }
  }

  printf("%d\n",j);

  return 0;
}

int isPrime(int x)
{
  int i;
  if(x == 2)return 1;

  if(x < 2 || x % 2 == 0)return 0;

  i = 3;
  while(i <= sqrt(x)){
    if(x % i == 0)return 0;
    i = i + 2;
  }

  return 1;
}



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

int main(void){
 long long n;
 long long t;
 cin>>n;
 t=0;
 for(long long i=1;i*i<=n;i++){
 		if(n%i==0){
 			t=i;
 		}
 	}
 	cout<<t+n/t-2;
}


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

char get_corresponding_base(char base)
{
    switch (base)
    {
        case 'A':
            return 'T';
        case 'C':
            return 'G';
        case 'G':
            return 'C';
        case 'T':
            return 'A';
        default:
            assert(false && "invalid base");
            break;
    }

    return '0';
}

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

    char base;
    cin >> base;
    cout << get_corresponding_base(base) << endl;

    // test code.
    // cout << get_corresponding_base('A') << endl;
    // cout << get_corresponding_base('C') << endl;
    // cout << get_corresponding_base('G') << endl;
    // cout << get_corresponding_base('T') << endl;
}

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

int main(){
  int x, y, z, t;
  cin >> x >> y >> z;
  if (x > y){
    t = x;
    x = y;
    y = t;
  }
  if (y > z){
    t = y;
    y = z;
    z = t;
  }
  if (x > y){
    t = x;
    x = y;
    y = t;
  }

  cout << x << " " << y << " " << z << "\n";

  return 0;
}

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

using namespace std;

int main()
{
	int N,T,A,H[1000];

	cin >> N >> T >> A;
	
	double ans = 1e18;
	
	for(int i=0; i<N; i++){
		cin >> H[i];
		ans = min(ans, abs(A - (T - H[i] * 0.006)));
	}

	for(int i=0; i<N; i++){
		if(ans == abs(A - (T - H[i] * 0.006))){
			cout << i+1 << endl;
		}
	}

	return 0;
}


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

using namespace std;

#define INF ( 1 << 15 )

int main(){
  int n, m, mas[501][501];
  while( cin >> n >> m , n){
    fill_n( *mas, 501 * 501, INF);
    for(int i = 0, a, b ; i < m ; i++ ){
      cin >> a >> b;
      mas[a][b] = mas[b][a] = 1;
    }
    for(int i = 1 ; i <= n ; i++ ){
      for(int j = 1 ; j <= n ; j++ ){
        for(int k = 1 ; k <= n ; k++ ){
          mas[j][k] = min( mas[j][k], mas[j][i] + mas[i][k]);
        }
      }
    }
    int ret = 0;
    for(int i = 2 ; i <= n ; i++ ){
      if( !~(mas[1][i]-2) | !(mas[1][i]-2)) ret++;
    }
    cout << ret << endl;
  }
}

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

typedef unsigned long long ull;
typedef long long ll;

const int max_n = 100005;
int h[max_n];



int main() {	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	
	for (int i = 1; i <= n; ++i) {
		cin >> h[i];
	}
	
	vector<vector<int>> g(n + 1, vector<int>());
	
	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		bool good = true;;
		
		for (int u: g[i]) {
			if (h[u] >= h[i]) {
				good = false;
				break;
			}
		}
		
		if (good) ++ans;
		
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 8744
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

#define int long long int

constexpr int INF = std::numeric_limits<int>::max();

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

    int N; cin >> N;
    int m = 0;
    int ans = 0;

    while (N--) {
        int p; cin >> p;
        ans += p;
        m = max(m, p);
    }

    ans -= m/2;
    cout << ans << endl;
}

Measured memory_bytes: 256