akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <assert.h>
using namespace std;
const int MAXN = 15;
const int MAXCASE = 25;
vector<int> m[MAXN];
int n, p;
int sum;
int vis[MAXN];
int judge[MAXN][MAXN];
void dfs(int cot,int num)
{
    if(num == n)
    {
        sum++;
        return;
    }
    for(int i = 0;i < m[cot].size();i++)
    {
        if(vis[m[cot][i]] == 0)
        {
            vis[m[cot][i]] = 1;
            dfs(m[cot][i],num + 1);
            vis[m[cot][i]] = 0;
        }
    }
}
int main()
{
    int Test, numCase = 0;
    //cin >> Test;
    while(cin >> n >> p)
    {

        assert(2 <= n && n <= 8);
        assert(1 <= p && p <= n * (n - 1) / 2);

        memset(judge, 0, sizeof(judge));
        numCase++;
        for(int i=1;i<=p;i++)
        {
            int v,u;
            cin >> v >> u;
            m[v].push_back(u);
            m[u].push_back(v);

            assert(1 <= v && v <= n);
            assert(1 <= u && u <= n);
            assert(u != v && judge[u][v] == judge[v][u] && judge[u][v] == 0);
            judge[u][v] = judge[v][u] = 1;
        }

        sum = 0;
        vis[1] = 1;
        dfs(1, 1);
        cout << sum << endl;
    }
    //assert(numCase == MAXCASE);
    return 0;
}


Measured memory_bytes: 256
N,*target = map(int,(input().split()))
l = [int(input()) for i in range(N)]

cnt = 0
out = None
for i in range(4**N):
    j = [(i//(4**k) % 4) for k in range(N)]
    num = [j.count(i) for i in range(3)]
    if num[0]==0 or num[1]==0 or num[2]==0:
        continue
    score = sum([abs(target[k]-sum([l[tmp] for tmp in range(N) if j[tmp]==k])) for k in range(3)]) + (sum(num)-3)*10
    if out == None:
        out = score
    else:
        out = min(out,score)
print(out)

Measured memory_bytes: 3064
package main

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

func solve() {
	n, xOffset := getInt(), getInt()
	xs := make([]int, n)
	for i := range xs {
		xs[i] = abs(getInt() - xOffset)
	}

	ans := xs[0]
	for _, x := range xs {
		ans = gcd(ans, x)
	}
	fmt.Fprintln(wr, ans)
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

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

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 2944
s = str(input())
if len(set(s)) == 1:
    print('No')
elif (s[0] == s[1]) and (s[2] == s[3]):
    print('Yes')
elif (s[0] == s[2]) and (s[1] == s[3]):
    print('Yes')
elif (s[0] == s[3]) and (s[1] == s[2]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
total=0
an0=-1
for an in a:
    total+=b[an-1]
    if an-1==an0:
        total+=c[an0-1]
    an0=an

print(total)

Measured memory_bytes: 3064
n, m = map(int, input().split())
ss = []
for i in range(m):
    s = list(map(int, input().split()))
    x = 0
    for i in range(1, len(s)):
        x |= 1 << (s[i] - 1)
    ss.append(x)
pp = list(map(int, input().split()))

ans = 0
for x in range(2 ** n):
    non = 0
    for i in range(m):
        a = ss[i] & x
        nb = 0
        while a != 0:
            if a & 1 == 1:
                nb += 1
            a >>= 1
        if nb % 2 == pp[i]:
            non += 1
    if non == m:
        ans += 1
print(ans)

Measured memory_bytes: 3188
#include "bits/stdc++.h"

#define sai(j,n) for(sei j=0;j<sei(n);++j)
#define hsai(j,n) for(sei j=sei(n)-1;j>=0;--j)
#define kan(j,m,n) for(sei j=m;j<sei(n);++j)
#define hkan(j,m,n) for(sei j=sei(n)-1;j>=sei(m);--j)
#define zen(v) (v).begin(),(v).end()
#define yu(v) v.erase(unique(zen(v)), v.end());
#define syutu(v) si(a, (v).size()) {cout << v[a];if(a != v.size()-1)cout << " ";else cout << endl;}
#define mug 10000000111;
#define yo 10000000711;
#define kyo 1e-9;

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

using namespace std;
typedef long long sei;
typedef long double syo;
typedef vector<sei> vs;
typedef vector<syo> vy;
typedef vector<vs> vvs;
typedef vector<vy> vvy;
typedef pair<sei, sei> ks;
sei max(sei a, int b) {return max(a, sei(b));}
sei max(int a, sei b) {return max(sei(a), b);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    sei n;
    while(cin >> n,n){
        vector<sei> s(n);
        sai(j,n){
            cin >> s[j];
        }

        sort(s.begin(),s.end());
        sei m = 0;
        kan(j,1,n-1){
            m += s[j];
        }
        m /= n-2;
        cout << m << endl;
    }
    return 0;
}


Measured memory_bytes: 3140
'use strict'

function Main(input) {
  const N = Number(input.split("\n")[0])
  const H = input.split("\n")[1].split(" ").map(x => Number(x))
  let max = 0
  let count = 0
  
  for(let i=0; i<N-1; i++) {
    if(H[i] >= H[i+1]) {
      count++
      if(i === N-2) {
        max = Math.max(max, count)
      }
    } else {
      max = Math.max(max, count)
      count = 0
    }
  }

  console.log(max)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim())


Measured memory_bytes: 21580
#include <stdio.h>

int comb(int n);

int main(void)
{
	int n;
	int i, j, k, l;
	
	while (scanf("%d", &n) != EOF){
		printf("%d\n", comb(n));
	}
	
	return (0);
}

int comb(int n)
{
	int i, j, k, l;
	int cnt = 0;
	
	for (i = 0; i < 10; i++){
		for (j = 0; j < 10; j++){
			for (k = 0; k < 10; k++){
				for (l = 0; l < 10; l++){
					if (i + j + k + l == n){
						cnt++;
					}
				}
			}
		}
	}
	
	return (cnt);
}

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

#define ll long long int
#define ull unsigned long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {

	IO; 

	int n;
	cin >> n;
	vector<int> a(n);
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	sort(a.begin(), a.end());
	
	for (int i = 0; i < n-1; ++i) {
		cnt += a[i];
	}
	
	if (cnt > a[n-1]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
int head[maxn];
int counts = 1,maxx = -0x3f3f3f3f;
struct node{
	int to;
	int nxt;
	int color;
}edge[maxn];
void add(int a,int b){
	edge[counts].to = b;
	edge[counts].color = 0;
	edge[counts].nxt = head[a];
	head[a] = counts++;
}
void dfs(int u,int y){
	int t = 1;
	for(int i = head[u];i != 0;i = edge[i].nxt){
		int v = edge[i].to;
		if(t == y) t++;
		edge[i].color = t;	
		maxx = max(maxx,t);
		dfs(v,t);
		t++;
	}
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1;i < n;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		add(a,b);
	}
	dfs(1,0);
	printf("%d\n",maxx);
	for(int i = 1;i < counts;i++){
		printf("%d\n",edge[i].color);
	}
	return 0;
}

Measured memory_bytes: 3968
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long n = in.nextLong();
			long x = in.nextLong();

			out.println(f(x, n-x) + n);
		}

		long f(long s, long l) {
		long ret = 0;

		if (s > l) {
			long t = s;
			s = l;
			l = t;
		}

		if (s == l) {
			return s;
		}

		if (s == 0) {
			return l;
		}

		if (l % s == 0) {
			return (l/s-1)* 2*s + f(s, l%s);
		} else {
			ret += (l/s)* 2*s + f(s, l%s);
		}

		return ret;
	}

	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21588
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;

typedef pair<int,int> P;
typedef vector<pair<int,int> > VP;

int main ()
{
    int n;
    while (cin >> n) {
        if (n == 0) break;
        bool d[22][22];
        memset(d, false, sizeof(d));
        int c = n;
        while (c--) {
            int a, b;
            cin >> a >> b;
            d[a][b] = true;
        }
        int x = 10, y = 10;
        int t;
        cin >> t;
        for (int i = 0; i < t; i++) {
            int num;
            char str;
            cin >> str >> num;
            switch (str) {
            case 'N' :
                for (int i = 0; i < num; i++) {
                    ++y;
                    if (d[x][y]) {
                        d[x][y] = false, --n;
                    }
                }
                break;
            case 'E' :
                for (int i = 0; i < num; i++) {
                    ++x;
                    if (d[x][y]) {
                        d[x][y] = false, --n;
                    }
                }
                break;
            case 'S' :
                for (int i = 0; i < num; i++) {
                    --y;
                    if (d[x][y]) {
                        d[x][y] = false, --n;
                    }
                }
                break;
            case 'W' :
                for (int i = 0; i < num; i++) {
                    --x;
                    if (d[x][y]) {
                        d[x][y] = false, --n;
                    }
                }
                break;
            }
        }

        cout << (n == 0 ? "Yes" : "No" ) << endl;
    }

    return 0;
}

Measured memory_bytes: 1152
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk) {
    var x = chunk.toString().split(' ');
    var a = Number(x[0]);
    var b = Number(x[1]);
    var c = Number(x[2]);
    if (a < b && b < c){
        console.log("Yes");
    }else{
        console.log("No");
    }
});

Measured memory_bytes: 15520
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 1000000007;

int main() {
    Int H, W;
    cin >> H >> W;
    vector<vector<Int>> dp(H, vector<Int>(W));
    for (Int i = 0; i < H; i++) {
        for (Int j = 0; j < W; j++) {
            char a;
            cin >> a;
            if (i == 0 && j == 0) {
                dp[0][0] = 1;
                continue;
            }
            if (a == '#') {
                dp[i][j] = 0;
                continue;
            }
            dp[i][j] = 0;
            if (i > 0) dp[i][j] += dp[i - 1][j];
            if (j > 0) dp[i][j] += dp[i][j - 1];
            dp[i][j] %= MOD;
        }
    }
    cout << dp[H - 1][W - 1] << endl;
}


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

int main() {
  int a, b;
  cin >> a >> b;

  if (a < b) {
    cout << "a < b" << endl;
  }
  else if (a > b) {
    cout << "a > b" << endl;
  }
  else if (a == b) {
    cout << "a == b" << endl;
  }
}


Measured memory_bytes: 3092
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input! {s:String}
    let c = s.chars().filter(|&c| c == 'o').count();
    println! {"{}", 700 + c * 100}
}


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

vector<bool> dir(4, 0);
string s;

int main() {
  cin >> s;
  rep (i, s.size()) {
    if (s[i] == 'N') dir[0] = 1;
    if (s[i] == 'S') dir[1] = 1;
    if (s[i] == 'E') dir[2] = 1;
    if (s[i] == 'W') dir[3] = 1;
  }
  bool ans = ((!(dir[0] xor dir[1])) && (!(dir[2] xor dir[3])));
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3568
/*▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄█████████████  █▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐*/
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("fast-math")
#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
// #define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vector<ll> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<ll> > vvi;
typedef vector<char> vc;

const ll INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9 + 7;
// const ll MAXN = 3e5;
const ld eps = 1e-6;
const ld eps2 = 1e-9;
const ll MOD2 = 998244353;
const ll dosz = 5e5;
const ll SZ = (1<<18);
const ld PI = atan2l(0, -1);


void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
        // freopen("a.in", "r",stdin);
#else
       // freopen("tickets.in", "r", stdin);
       // freopen("tickets.out", "w", stdout);
#endif
}


void solve(){
    int n;
    cin >> n;
    vi nums(n);
    for(int &i:nums)
        cin >> i;
    map<int, int> kek;
    for(int i=0; i<n; i++){
        kek[i-nums[i]]++;
    }
    int ans = 0;
    for(int i=0; i<n; i++){
        ans += kek[i+nums[i]];
    }
    cout << ans << endl;
} 

signed main() {
    fast_io();
    ll q = 1;
    // cout << fixed;
    // cin >> q;
    while(q--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 27472
a, b, n = map(int, input().split())
def func(i, j, k):
    return (i*k)//j - i*(k//j)
m = min(n, b-1)
r = (a*min(n, b-1)) // b
while ((a*m) // b) == r:
    m -= 1
print(func(a, b, m+1))

Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <string>
 
using namespace std;
 
template <typename T>
class  PriorityQueue {
private:
    vector <T> d;
public:
    void push(T s) {
        int k = d.size();
        d.push_back(s);
        while (k&&d[(k - 1) / 2] < d[k]) {
            swap(d[(k - 1) / 2], d[k]);
            k = (k - 1) / 2;
        }
    }
    T top() {
        return d[0];
    }
    void pop() {
        d[0] = d.back();
        d.pop_back();
        maxHeapify(0);
    }
    void maxHeapify(int k) {
        int l = 2 * k + 1, r = 2 * k + 2;
        T leargest;
        if (l < d.size() && d[k] < d[l]) {
            leargest = l;
        }
        else {
            leargest = k;
        }
        if (r < d.size() && d[leargest] < d[r]) {
            leargest = r;
        }
        if (leargest != k) {
            swap(d[k], d[leargest]);
            maxHeapify(leargest);
        }
    }
};
int main() {
    PriorityQueue<int> pq;
    string a;
    int b;
    while (1) {
        cin >> a;
        if (a == "insert") {
            cin >> b;
            pq.push(b);
        }
        else if (a == "end")break;
        else {
            cout << pq.top() << endl;
            pq.pop();
        }
    }
    return 0;
}




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

int main(){
	int n,m,c;
	cin >> n >> m >> c;
	vector<int> b(m);
	rep(i,m) cin >> b[i];
	int cnt = 0;
	rep(i,n){
		int sum = c;
		rep(j,m){
			int a;
			cin >> a;
			sum += a*b[j];
		}
		if(sum > 0) cnt++;
	}
	cout << cnt << endl;
}

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

const int N=100005;

int n,s1,s0,s2;
int a[N];

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if (a[i]%4==0) s2++;
		else if (a[i]%2==0) s1++;
		else s0++;
	}
	if (s1){
		if (s2>=s0) printf("Yes\n");
		else printf("No\n");
		return 0;
	}
	if (s2>=s0-1) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int main(){
    int i,sum=0,n;
    int *a,*b;
    
    scanf("%d",&n);
    
    a = (int *)malloc(sizeof(int) * n);
    b = (int *)malloc(sizeof(int) * n);
    
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    
    for(i=0;i<n;i++){
        scanf("%d",&b[i]);
    }
    
    for(i=0;i<n;i++){
        if(a[i]-b[i]>0){
            sum=sum+(a[i]-b[i]);
        }
    }
    
    printf("%d\n",sum);
    
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,j,k;
	int n,m,g;
	int dist[114][114];
	int a,b;
	while(1) {
		cin>>n>>m>>g;
		if(!n&&!m) break;
		for(int i=0;i<m;i++) {
			for(int j=0;j<n;j++) {
				dist[i][j]=0;
			}
		}
		for(int i=0;i<g;i++) {
			cin>>a>>b;
			a--,b--;
			dist[b][a]=-1;
		}
		dist[0][0]=1;
		for(int i=0;i<m;i++) {
			for(int j=0;j<n;j++) {
				if(dist[i][j]!=-1&&dist[i][j]!=0) {
					if(dist[i+1][j]!=-1&&i<m) dist[i+1][j]+=dist[i][j];
					if(dist[i][j+1]!=-1&&j<n) dist[i][j+1]+=dist[i][j];
				}
			}
		}
		cout<<dist[m-1][n-1]<<endl;
	}
}

Measured memory_bytes: 3096
# encoding: utf-8
N, M = map(int, input().split())

diff = (N - M) if N > M else (M - N)

def bikkuri2(N, M):
    ans = 1
    for i in range(2, M + 1): ans = (ans * i) % (10 ** 9 + 7)
    ans0 = ans
    for i in range(M + 1, N + 1): ans = (ans * i) % (10 ** 9 + 7)
    ans1 = ans
    return (ans0, ans1)

N0, N1 = bikkuri2(N, M) if N > M else bikkuri2(M, N)
if diff < 1: print((2 * (N0 ** 2)) % (10 ** 9 + 7))
elif diff < 2: print((N0 * N1) % (10 ** 9 + 7))
else: print(0)


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

using namespace std;

const int N = 100;

int main() {
  int a, b;
  cin >> a >> b;
  vector<vector<char>> grid(N);
  for (int i = 0; i < N; ++i) {
    grid[i] = vector<char>(N, i < N / 2 ? '.' : '#');
  }
  for (int i = 1; i < b; ++i) {
    int x = i / 50 * 2;
    int y = i % 50 * 2;
    grid[x][y] = '#';
  }
  for (int i = 1; i < a; ++i) {
    int x = i / 50 * 2;
    int y = i % 50 * 2;
    grid[N - 1 - x][N - 1 - y] = '.';
  }
  cout << N << ' ' << N << '\n';
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      cout << grid[i][j];
    }
    cout << '\n';
  }
  return 0;
}

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

enum{UE,MAE,MIGI,HIDARI,USIRO,SITA};

int daice[6]={1,2,3,4,5,6};
int n,wa,tmp;
char sizi[100];

int main(void){

	while(1){
		wa=1;
		for(int i=0;i<6;i++) daice[i]=i+1;

		cin>>n;
		if(n==0) break;

		for(int i=0;i<n;i++){
			cin>>sizi;
			if(!strcmp(sizi,"North")){
				tmp=daice[UE];
				daice[UE]=daice[MAE];
				daice[MAE]=daice[SITA];
				daice[SITA]=daice[USIRO];
				daice[USIRO]=tmp;
				wa+=daice[UE];
			}
			else if(!strcmp(sizi,"South")){
				tmp=daice[UE];
				daice[UE]=daice[USIRO];
				daice[USIRO]=daice[SITA];
				daice[SITA]=daice[MAE];
				daice[MAE]=tmp;
				wa+=daice[UE];
			}
			else if(!strcmp(sizi,"West")){
				tmp=daice[UE];
				daice[UE]=daice[MIGI];
				daice[MIGI]=daice[SITA];
				daice[SITA]=daice[HIDARI];
				daice[HIDARI]=tmp;
				wa+=daice[UE];
			}
			else if(!strcmp(sizi,"East")){
				tmp=daice[UE];
				daice[UE]=daice[HIDARI];
				daice[HIDARI]=daice[SITA];
				daice[SITA]=daice[MIGI];
				daice[MIGI]=tmp;
				wa+=daice[UE];
			}
			else if(!strcmp(sizi,"Right")){
				tmp=daice[MAE];
				daice[MAE]=daice[MIGI];
				daice[MIGI]=daice[USIRO];
				daice[USIRO]=daice[HIDARI];
				daice[HIDARI]=tmp;
				wa+=daice[UE];
			}
			else if(!strcmp(sizi,"Left")){
				tmp=daice[MAE];
				daice[MAE]=daice[HIDARI];
				daice[HIDARI]=daice[USIRO];
				daice[USIRO]=daice[MIGI];
				daice[MIGI]=tmp;
				wa+=daice[UE];
			}
			/*for(int i=0;i<6;i++) cout<<daice[i]<<",";
			cout<<endl;*/
		}
		cout<<wa<<endl;
	}

	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n; cin>>n;
    //切り上げ処理
    ll x = (n+1000-1)/1000;
    
    ll ans= x*1000 - n;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
main(){
int i,j,k,l,n;
char s1[10000],s2[10000];
while(cin>>s1>>s2){
  k=strlen(s1);
  j=strlen(s2);
  for(i=0;i<j;i++){
  cout<<s1[i]<<s2[i];
  }
if(k>j) cout<<s1[k-1];
cout<<endl;
} return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int n;
long long c[100][100];
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> c[i][j];
        }
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            ans += min(c[i][j], c[j][i]);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3192
N = gets.to_i
W = N.times.map{gets.chomp}
hash = Hash.new(0)
pre = W[0][0]
N.times do |i|
  if hash[W[i]] == 0
    hash[W[i]] = 1
    if W[i][0] == pre
      pre = W[i][-1]
    else
      puts "No"
      exit
    end
  else
    puts "No"
    exit
  end
end
puts "Yes"


Measured memory_bytes: 14348
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
ll a[200009];
unordered_map<ll,ll> ma;

bool sol(ll n)
{
    for( ll i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            if(ma.find(i)!=ma.end() && i!=n)
            {
                return 0;
            }
            ll x  =n/i;
            if(x==n)
            {
                if(ma[x]>1)
                    return 0;
            }
            else
            {
                if(ma.find(x)!=ma.end())
                {
                    return 0;
                }
            }
        }
    }
    return 1;
}
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    ma.reserve(1048576);
    ma.max_load_factor(1.0);
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        ma[a[i]]++;
    }
    for(i=0;i<n;i++)
    {
        if(sol(a[i]))
            x++;
    }
    cout<<x<<endl;

    return 0;
}



Measured memory_bytes: 19280
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, a;
string str;

int main(){
	cin >> n;
	priority_queue<ll> p, m;
	for(ll i = 1; i <= n; i++){
		cin >> a;
		if(a >= 0){p.push(-a);}
		else{m.push(a);}
	}
	
	if(p.size() == 0){
		p.push(-m.top()); m.pop();
	}
	if(m.size() == 0){
		m.push(-p.top()); p.pop();
	}
	
	vector<ll> ansp, ansm;
	while(!(p.size() == 1 && m.size() == 1)){
		if(p.size() <= m.size()){
			ansp.push_back(-p.top());
			ansm.push_back(m.top());
			a = -p.top()-m.top();
			p.pop(); m.pop();
			p.push(-a);
		}
		else{
			ansp.push_back(m.top());
			ansm.push_back(-p.top());
			a = -p.top()-m.top();
			p.pop(); m.pop();
			m.push(-a);
		}
	}
	ansp.push_back(-p.top());
	ansm.push_back(m.top());
	
	cout << -p.top()-m.top() << endl;
	for(ll i = 0; i < ansp.size(); i++){
		cout << ansp[i] << " " << ansm[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4852
using System;

class test {
    static void Main() {
        string[] s = Console.ReadLine().Split(' ');
        int[] n = new int[3];
        int i;
        for (i = 0; i < 3; i++) {
            n[i] = int.Parse(s[i]);
        }
        int[] ans;
        int size = n[1] - n[0] + 1;
        if (size > n[2] * 2) {
            ans = new int[n[2] * 2];
            for (i = 0; i < n[2]; i++) {
                ans[i] = n[0] + i;
            }
            for (i = 0; i < n[2]; i++) {
                ans[n[2]*2-1-i] = n[1] - i;
            }
        } else {
            ans = new int[size];
            for (i = 0; i < size; i++) {
                ans[i] = n[0] + i;
            }
        }
        for (i = 0; i < ans.Length; i++) {
            Console.WriteLine(ans[i]);
        }
    }
}

Measured memory_bytes: 11092
#include<cstdio>
using namespace std;
long long n , h , w;
long long a , b , ans;
int main()
{
	scanf("%lld%lld%lld",&n,&h,&w);
	for(int i = 1 ; i <= n ; i = i + 1)
	{
		scanf("%lld%lld",&a,&b);
		if(a >= h && b >= w)
			ans++;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
import * as fs from 'fs'
const reader = (s: string) => s.split('\n')

function Main(input: string) {
  const [_, ...S] = reader(input)
  console.log(S.sort((a, b) => (a < b ? -1 : 1)).join(''))
}

Main(fs.readFileSync('/dev/stdin', 'utf8'))



Measured memory_bytes: 7500
n,m = map(int,input().split())
count = [0]*(m+1)
for _ in range(n):
    a = list(map(int,input().split()))
    for i in range(1,a[0]+1): count[a[i]] += 1
ans = 0
for i in range(1,m+1):
    if count[i] == n: ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N;
  cin >> N;
  vector <int> cnt(N + 1);
  for (int i = 2; i <= N; i++){
    int a;
    cin >> a;
    cnt[a] ++;
  }
  for (int i = 1; i <= N; i++){
    cout << cnt[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=1e9 + 7;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n<0)return 0;if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
#define all(x) x.begin(),x.end()
#define Return(x) {cout << x << endl; return 0;}

vvi a;
vvi dp;

void dfs(int x,int p) {
    int cur_white = 1;
    int cur_black = 1;

    for(int y:a[x]) {
        if(y == p) continue;
        dfs(y,x);
        cur_white = Mod(cur_white * (dp[y][0] + dp[y][1]));
        cur_black = Mod(cur_black * (dp[y][0]));
    }

    dp[x][0] = cur_white; 
    dp[x][1] = cur_black;
}

int__ main() {
    fast;
    int n; cin >> n ;
    a = vvi (n+1);
    dp = vvi(n+1,vi (2,0));

    for(int i=0;i<n-1;i++) {
        int u,v; cin >> u >> v;
        a[u].pb(v); a[v].pb(u);
    }

    dfs(1,1);

    cout << Mod(dp[1][0] + dp[1][1]) << endl;
}

Measured memory_bytes: 19584
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;


	   
int main() {
			fast
			// #ifndef ONLINE_JUDGE
			// freopen("input.txt","r",stdin);
			// freopen("output.txt","w",stdout);
			// #endif
			 
	     	 ll n,k;
			 cin>>n>>k;
			 ll arr[n+5];
			
			 for(ll i=1;i<=n;i++)
			 cin>>arr[i];
			
		
			
				 ll temp=arr[1];
				 ll cs=arr[1];
				 vector<ll>ans2;
				 ans2.pb(cs);
			
				 set<ll>s;
				 s.insert(cs);
				
				 for(ll i=2;i<=3*n;i++)
				 {

					temp=arr[cs];
				
					ll prev=s.size();
					s.insert(temp);
					ll next=s.size();

					if(prev==next)
					{
						break;
					}

					ans2.pb(temp);
					cs=temp;
					
					
				 }
				//  cout<<last<<endl;
				// for(ll i=0;i<ans2.size();i++)
				// cout<<ans2[i]<<" ";
				// cout<<endl;
				
				ll len=ans2.size();
				if(k<=len)
				cout<<ans2[k-1];
				else
				{
					ll id=0;
					for(ll i=0;i<len;i++)
					{
						if(ans2[i]==temp)
						{
							id=i;
							break;
						}
					}
					ll total=ans2.size()-id;
					// cout<<id<<" "<<total<<endl;
					k-=len;
					ll x=k%total;
					if(x==0)
					x=total;
					
					// cout<<x<<" "<<id<<endl;
					cout<<ans2[id+x-1];
				}
				
				
			 
			return 0;
		 }	
 

Measured memory_bytes: 15412
#include<cstdio>
#include<cstring>
#include<algorithm>
typedef unsigned long long LL;
using namespace std;
int n;
LL p;
LL gcd(LL x,LL y)
{
	if(y==0)return x;
	return gcd(y,x%y);
}
int main()
{
	scanf("%d",&n);LL now=1;
	for(int i=1;i<=n;i++){
		scanf("%lld",&p);
		LL fu=gcd(now,p);
		now=now/fu*p;
	}
	printf("%lld",now);
	return 0;
}

Measured memory_bytes: 128
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=1e5+19;

char s[N];
int n;

int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	if ((s[1]==s[n])==(n%2==0)) puts("First");else puts("Second");
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;

int main()
{
    string s;
    int sum;
    cin >> s;
    bitset<3> b;
    for(int i=0; i<8; ++i){
        // 0 -> +, 1 -> -
        b = static_cast<bitset<3>>(i);
        sum = s[0] - '0';
        for(int j=0; j<3; ++j){
            if(b[j] == 0){
                sum += s[j+1] - '0';
            }
            else {
                sum -= s[j+1] - '0';
            }
        }
        if(sum == 7){
            for(int j=0; j<=3; ++j){
                cout << s[j];
                if(j == 3){
                    cout << "=7" << endl;
                }
                else {
                    cout << ((b[j] == 0) ? '+' : '-');
                }
            }
            break;
        }
    }
}


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

using namespace std;

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


void solve() {
	//~ freopen("lca.out", "w", stdout);
	//~ freopen("lca.in", "r", stdin);
	ios_base::sync_with_stdio(false); 
	cin.tie(nullptr);
	
	int n, k;
	cin >> n >> k;
	vector<int> h(n + 1);
	for (int i = 1; i <= n; i++)
		cin >> h[i];
		
	int INF = 1e9;
		
	vector<int> dp(n + 1, INF);
		dp[1] = 0;
	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= k; j++) {
			if (i + j <= n)
				dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
		}
	}
	
	cout << dp[n];
}

int main() {
	solve();
	return 0;
}




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

#define ll long long
#define PB push_back
#define PII pair<int, int>
#define MP make_pair
#define all(x) x.begin(), x.end()
#define REP(x, y, z) for(int x = y; x <= z; x++)
#define REPP(x, y, z) for(int x = y; x >= z; x--)
#define F first
#define S second
#define MSET(x, y) memset(x, y, sizeof(x)) 
#define EB emplace_back
#define maxn 

//structure

//declaration
//functions

int main(void)
{
	#ifdef DBG
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
	#endif

	ll n, x, d;

	cin >> n >> x >> d;

	if(d == 0)
	{
		if(x == 0)
			printf("1\n");
		else
			cout << 1+n << '\n';
	}

	else
	{
		if(d < 0)
		{
			d = -d;
			x = -x;
		}

		unordered_map<ll, vector<pair<ll, ll> > > mp;

		for(ll k = 0; k <= n; k++)
		{
			ll modd = ((k*x)%d>=0 ? (k*x)%d : (-(k*x)%d)+d);
			ll kxmod=( x<0 ? (k*x)/d -1 : (k*x)/d );
			// cout << (k*x)/d << ' ' << (k*x)/d -1 << endl;

			mp[modd].EB(kxmod+(((k-1)*k)/2), kxmod+(((2*n-k-1)*k)/2));
		}

		ll ans = 0;

		for(auto i : mp)
		{
			auto j = i.S;

			sort(all(j));

			ll right = -1000000000000000037;
	        for(auto pe: j){
	            ll le=pe.first;
	            ll ri=pe.second;
	            if(ri<=right) 
	            	continue;
	            if(le>right)
	            {
	                ans+=ri-le+1;
	            }
	            else
	            {
	                ans+=ri-right;
	            }
	            right=ri;
	        }

		}
		cout << ans << '\n';
	}
		

	

	return 0;
}


Measured memory_bytes: 17864
/*


*/
#include <cstdio>
#include <cctype>
#include <algorithm>
#define MAXIN 500000
#define gc() (SS==TT&&(TT=(SS=IN)+fread(IN,1,MAXIN,stdin),SS==TT)?EOF:*SS++)
typedef long long LL;
const int N=2e5+5;

int A[N];
char IN[MAXIN],*SS=IN,*TT=IN;

inline int read()
{
	int now=0;register char c=gc();
	for(;!isdigit(c);c=gc());
	for(;isdigit(c);now=now*10+c-48,c=gc());
	return now;
}
LL Solve(const int n,const int L)
{
	static LL pre[N],suf[N];
	for(int i=1; i<=n; ++i) pre[i]=pre[i-1]+A[i];
	for(int i=n; i; --i) suf[i]=suf[i+1]+L-A[i];
	LL ans=A[n];
	for(int i=1,p; i<n; ++i)
		p=i+((n-i)>>1), (n-i)&1 ? ans=std::max(ans,(suf[p+2]+pre[p]-pre[i]+A[i])*2+L-A[p+1]) : ans=std::max(ans,(suf[p+1]+pre[p-1]-pre[i]+A[i])*2+A[p]);
	return ans;
}

int main()
{
	const int L=read(),n=read();
	for(int i=1; i<=n; ++i) A[i]=read();
	LL ans=Solve(n,L);
	std::reverse(A+1,A+1+n);
	for(int i=1; i<=n; ++i) A[i]=L-A[i];
	ans=std::max(ans,Solve(n,L));
	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  int a;
  cin >> a;
 
  cout << "ABC" << a << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

//aのb乗
int beki(int a,int b){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=mod(x*a);
		}
		a=mod(a*a);
		b>>=1;
	}
	return x;
}

//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}



int main(){
	
	int N;
	cin>>N;
	
	
	vector<int> A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	
	sort(A.rbegin(),A.rend());
	
	int ans = 0;
	
	for(int i=0;i<N;i++){
		int k = mod((i+2) * gyakugen(2));
		k = mod(k * beki(4,N-1));
		k = mod(k * A[i]);
		ans = mod(ans + k);
	}
	
	cout<<mod(ans*2)<<endl;
	
	//cout<<ans<<endl;
	
	
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>

int taxCalc(int x,int r){//x:?¨??????? r:?¨????
  return (double)(x*(100+r))/100.0;
}

int main(){
  int x,y,s;

  scanf("%d %d %d",&x,&y,&s);
  while(x+y+s > 0){
    int max = 0;

    for(int i=1;i<s;i++){
      for(int j=1;j<s;j++){
	if(taxCalc(i,x)+taxCalc(j,x) == s ){
	  int p = taxCalc(i,y)+taxCalc(j,y);
	  if(p > max)
	    max = p;
	}
      }
    }
    printf("%d\n",max);
    
    scanf("%d %d %d",&x,&y,&s);
  }
}

Measured memory_bytes: 1028
#define _CRT_SECURE_NO_WARNINGS
#include<utility>
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>

#define mp make_pair
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef long double ld;


mt19937 gen;


int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll N, H; cin >> N >> H;
    vector<ll>a(N),b(N);
    for(ll i =0;i<N;i++){
        cin >> a[i]>> b[i];
    }
    sort(a.rbegin(),a.rend());
    sort(b.rbegin(),b.rend());
    ll xx = a[0];
    ll ans = 0;
    ll j = 0;
    while(H > 0){
       if(j<N){
           if(b[j] > xx){
               H -= b[j];
               ans++;
               j++;
            }
           else{
               ans += H / xx + (H % xx ? 1 : 0);
               break;
            }
        }
        else{
            ans += H / xx + (H % xx ? 1 : 0);
            break;
        }
    }
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b, m; cin >> a >> b >> m;
    vector<int> A(a);
    vector<int> B(b);

    int mina = INF;
    int minb = INF;
    rep(i,a) {
        cin >> A[i];
        chmin(mina,A[i]);
    }
    rep(i,b) {
        cin >> B[i];
        chmin(minb,B[i]);
    }
    int ans = INF;
    rep(i,m) {
        int x, y, c; cin >> x >> y >> c;
        x--; y--;
        ans = min(ans,A[x]+B[y]-c);
    }
    cout << min(ans,mina+minb) << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int h = Integer.parseInt(sc.next());
		int n = Integer.parseInt(sc.next());
		
		int []a = new int [n];
		int []b = new int [n];
		
		for(int i = 0 ;i < n ;i++) {
			a[i] = Integer.parseInt(sc.next());
			b[i] = Integer.parseInt(sc.next());
		}

		int []dp = new int [h+1];
		
		for(int i = 1 ;i <= h ; i++) {
			dp[i] = 1000000007;
		}
		dp[0] = 0;
		
		for(int i = 0 ;i <= h ;i++) {
			for(int j = 0 ; j < n ; j++) {
				if(i+a[j] <= h) {
				dp[i+a[j]] = Math.min(dp[i+a[j]], dp[i] + b[j]);
			}
				else {
				dp[h] = Math.min(dp[h], dp[i] + b[j]);
				}
			}
		}
		
		System.out.println(dp[h]);
	}

}


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

int main()
{
	string s;
	getline(cin,s);
	for(int i=0;i<s.size();i++){
		if(s[i]>='a'&&s[i]<='z')
			cout<<'a';
		else
			cout<<'A'; 
	return 0; 
	}
}

Measured memory_bytes: 3592
i = list(map(int, input().split()))
if i[0]==i[1] and i[0]!=i[2]:
    print('Yes')
elif i[0]==i[2] and i[0]!=i[1]:
    print('Yes')
elif i[1]==i[2] and i[0]!=i[1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;



int main() {
	LL A, V, B, W, T;
	cin >> A >> V >> B >> W >> T;
	if (V <= W) {
		cout << "NO" << endl;
		return 0;
	}
	if (abs(A - B) <= T * (V - W)) {

		cout << "YES" << endl;
		return 0;
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 3624
from bisect import *
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# Aの累積和を保存しておく
# 各Aの要素について、Bが何冊読めるか二分探索する。
# 計算量: AlogB
A.insert(0, 0)

for i in range(1,len(A)):
  A[i] += A[i-1]
for i in range(1, len(B)):
  B[i] += B[i-1]

ans = 0
for i in range(len(A)):
  rest_time = k - A[i]
  if rest_time >= 0:
    numb = bisect_right(B, rest_time)
    anstmp = i + numb 
    ans = max(ans, anstmp)
print(ans)

Measured memory_bytes: 40432
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cstdio>
using namespace std;
#define NIN(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define NINJ(i,n) for((i)=1;(i)<=(int)(n);(i)++)
#define pb push_back
#define LL long long
#define ff first
#define ss second
#define pp pair<double,double>
#define pt pair<double,pair<int,int>>

int pr[200005];

int fnd(int r)
{
    return (pr[r]==r) ? r :  pr[r]=fnd(pr[r]);
}
int main()
{
    char c;
    cin>>c;
    if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u')
        cout<<"vowel"<<endl;
    else
        cout<<"consonant"<<endl;
    return 0;
}


Measured memory_bytes: 256
#Together

N = int(input())
a = list(map(int, input().split()))

b = []

for ai in a:
    b.append(ai-1)
    b.append(ai)
    b.append(ai+1)
#print(b)

import collections
cnt = collections.Counter(b)
#print(cnt)
print(max(cnt.values()))

Measured memory_bytes: 25848
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <bitset>
#include <tuple>
#include <stack>
#include <utility>

using namespace std;
typedef long long ll;

int main(){
    int A, B;
    cin >> A >> B;
    int ans = 0;
    ans = max(A+A-1, ans);
    ans = max(A+B, ans);
    ans = max(B+B-1, ans);

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

Measured memory_bytes: 256