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

using namespace std;

const int INF = 1e9;

int n,i,j,a[200005],odd[100005],even[100005];
pair <int, int> oddt[400005],event[400005];

struct dat{
	pair<int, int> val;
	int l, r;
	
	bool operator < (const dat& T) const{
		return a[val.first] < a[T.val.first];
	}
};

set <dat> s;

void build_odd(int l, int r, int ind){
	if(l == r){
		oddt[ind] = {odd[l], l};
		return;
	}
	int mid = (l + r) / 2;
	build_odd(l, mid, ind * 2);
	build_odd(mid + 1, r, ind * 2 + 1);
	oddt[ind] = min(oddt[ind * 2], oddt[ind * 2 + 1]);
}

void build_even(int l, int r, int ind){
	if(l == r){
		event[ind] = {even[l], l};
		return;
	}
	int mid = (l + r) / 2;
	build_even(l, mid, ind * 2);
	build_even(mid + 1, r, ind * 2 + 1);
	event[ind] = min(event[ind * 2], event[ind * 2 + 1]);
}

pair<int, int> query(int l, int r, int ind, int lx, int ly, pair<int, int>* tree){
	//printf("QUERY %d %d %d %d\n", l, r, lx, ly);
	if(lx > r || ly < l) return {INF, INF};
	if(lx <= l && r <= ly){
		//printf("ANS %d %d %d\n", l, r, tree[ind].second);
		return tree[ind];
	}
	
	int mid = (l + r) / 2;
	
	return min(query(l, mid, ind * 2, lx, ly, tree), query(mid + 1, r, ind * 2 + 1, lx, ly, tree));
}

pair <int, int> solve(int l, int r){
	int mn, mn2;
	//printf("%d %d\n", l ,r);
	if(l & 1){
		//odd - even
		mn = query(1, n / 2, 1, (l + 1) / 2, r / 2, oddt).second;
		//printf("MN %d\n", mn);
		mn2 = query(1, n / 2, 1, mn, r / 2, event).second;
		//printf("ODD %d %d\n", mn, mn2);
		mn = mn * 2 - 1;
		mn2 = mn2 * 2;
	}
	else{
		//even - odd
		mn = query(1, n / 2, 1, l / 2, (r - 1) / 2, event).second;
		mn2 = query(1, n / 2, 1, mn + 1, (r + 1) / 2, oddt).second;
		
		mn = mn * 2;
		mn2 = mn2 * 2 - 1;
	}
	
	return {mn, mn2};
}

int main(){
	scanf("%d", &n);
	
	for(i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		if(i & 1)
		odd[(i + 1) / 2] = a[i];
		else
		even[i / 2] = a[i];
	}
	
	build_odd(1, n / 2, 1);
	build_even(1, n / 2, 1);
	
	set <dat> s;
	s.insert({solve(1, n), 1, n});
	
	bool flag = 0;
	
	while(s.size()){
		dat now = *s.begin();
		s.erase(now);
		
		if(flag)
		printf(" %d %d", a[now.val.first], a[now.val.second]);
		else
		printf("%d %d", a[now.val.first], a[now.val.second]);
		
		flag = 1;
		
		if(now.l < now.val.first - 1)
		s.insert({solve(now.l, now.val.first - 1), now.l, now.val.first - 1});
		if(now.val.first + 1 < now.val.second - 1)
		s.insert({solve(now.val.first + 1, now.val.second - 1), now.val.first + 1, now.val.second - 1});
		if(now.val.second + 1 < now.r)
		s.insert({solve(now.val.second + 1, now.r), now.val.second + 1, now.r});
	}
	
	printf("\n");
}


Measured memory_bytes: 11776
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    
    int n; cin >> n;
    vector<int> x(n);   
    vector<int> y(n);   
    map<pair<int, int>, int> mp;
    for(int i = 0; i < n; i++){
        int w;
        cin >> x[i] >> y[i] >> w;
        mp[{x[i], y[i]}] += w;
    }
    
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int di = -1; di < 2; di += 2){
            for(int dj = -1; dj < 2; dj += 2){
                int t = 0;
                for(int j = 0; j < 2; j++){
                    for(int k = 0; k < 2; k++){
                        
                        int nx = x[i] + j * di;
                        int ny = y[i] + k * dj;
                        t += mp[{nx, ny}];
                    }
                }
                ans = max(ans, t);
            }
        }
    }

    cout << ans << " / " << 1 <<  endl;
    
    return 0;
}



Measured memory_bytes: 60648
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
s = 0
for x in B:
    s += x
for i in range(n-1):
    if A[i+1]-A[i]==1:
        s += C[A[i]-1]
print(s)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
int main(){
    ll n,m;cin >> n >> m;
    vl f,s;
    rep(i,m){
        int a,b;cin >> a >> b;
        if(a==1)f.push_back(b);
        if(b==n)s.push_back(a);
    }
    sort(all(s));
    sort(all(f));
    rep(i,f.size()){
        ll key=f[i];
        auto iter = lower_bound(all(s),key);
        if(iter != s.end()&&*iter==key){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 1984
#include<bits/stdc++.h>
int A,B,K;std::set<int> S;
int main(){
    std::cin>>A>>B>>K;
    for(int i=0;i<K;i++)if(B-A>=i){S.insert(A+i);S.insert(B-i);}
    for(auto x:S)std::cout<<x<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
#define ld long double
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
ll mod2=998244353;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 300005
// Comment this out for interactive problem
#define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
ll n,k;
ll a[MAXN];
ll tree[4*MAXN];
ll dp[MAXN];

void build(ll node, ll l, ll r){
    if(l>r){
        return;
    }
    if(l==r){
        tree[node] = 0;
        return;
    }
    ll mid = (l+r)/2;
    build(2*node+1, l, mid);
    build(2*node+2, mid+1, r);
    tree[node] = max(tree[2*node+1], tree[2*node+2]);
}

void update(ll node, ll l, ll r, ll pos, ll val){
    if(l>r || l>pos || r<pos){
        return;
    }
    if(l==r && l==pos){
        tree[node] = val;
        return;
    }
    ll mid = (l+r)/2;
    update(2*node+1, l, mid, pos, val);
    update(2*node+2, mid+1, r, pos, val);
    tree[node] = max(tree[2*node+1], tree[2*node+2]);
}

ll query(ll node, ll l, ll r, ll start, ll end){
    if(l>r || l>end || r<start){
        return 0;
    }
    if(l>=start && r<=end){
        return tree[node];
    }
    ll mid = (l+r)/2;
    ll z1 = query(2*node+1, l, mid, start, end);
    ll z2 = query(2*node+2, mid+1, r, start, end);
    return max(z1, z2);
}


int main(){ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    cin>>n>>k;
    ll max1=0;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        max1 = max(max1, a[i]);
    }

    for (int i = 0; i < n; ++i)
    {
        dp[i]=1;        
    }

    build(0, 0, max1);

    for (int i = 0; i < n; ++i)
    {
        ll st = max(0, a[i]-k);
        ll en = min(max1, a[i]+k);
        ll x1 = query(0, 0, max1, st, en);
        dp[i] = max(dp[i], x1+1);
        update(0, 0, max1, a[i], dp[i]);
    }

    ll ans=0;
    for (int i = 0; i < n; ++i)
    {
        ans=max(ans, dp[i]);
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 16508
N=int(input())
a=list(map(int,input().split()))
M=int(input())
p=[]
x=[]
for i in range(M):
    p1,x1=[int(i) for i in input().split()]
    p.append(p1)
    x.append(x1)
sum=0
for i in range(N):
    sum+=a[i]
for i in range(M):
    print(sum-a[p[i]-1]+x[i])

Measured memory_bytes: 3064
import java.util.Scanner;
import java.util.ArrayList;
import java.lang.Integer;
import java.lang.StringBuilder;
import java.lang.Math;

public class Main {
  private static int[] S;

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    S = new int[3];
    for (int i = 0; i < 3; i++) {
      S[i] = in.nextInt();
    }

    if (S[0] + S[1] == S[2] ||
        S[0] == S[1] + S[2] ||
        S[0] + S[2] == S[1]) {
      System.out.println("Yes");
     } else {
      System.out.println("No");
     }
  }
}

Measured memory_bytes: 10196
import java.util.*;

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

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int ans = 0;

    for(int i = a; i <= b; i++){
      if(c % i == 0){
        ans += 1;
      }
    }

    System.out.println(ans);
  }
}



Measured memory_bytes: 26408
/*
  AtCoder Beginner Contest 091
  C - 2D Plane 2N Points
*/

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int N;
vector<pair<int,int>> red, blue;

int main() {
  scanf("%d", &N);
  int x, y;
  for (int i = 0; i < N; ++i) {
    scanf("%d%d", &x, &y);
    red.push_back(make_pair(x,y));
  }
  for (int i = 0; i < N; ++i) {
    scanf("%d%d", &x, &y);
    blue.push_back(make_pair(x,y));
  }

  sort(red.begin(), red.end());
  sort(blue.begin(), blue.end());

  int count = 0;
  vector<bool> unused(N, true);
  for (int b = 0; b < N; ++b) {
    int pos = -1;
    int max_y = -1;
    for (int r = 0; r < N; ++r) {
      if (red[r].first >= blue[b].first) break;
      if (!unused[r]) continue;

      if (red[r].second < blue[b].second && red[r].second > max_y) {
        pos = r;
        max_y = red[r].second;
      }
    }

    if (pos != -1) {
      ++count;
      unused[pos] = false;
    }
  }

  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
int n, arr[25], ans=0;

int main(){
	IOS
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> arr[i];
	}
	for(int i=2;i<=n-1;i++){
		if(arr[i]<arr[i-1]&&arr[i]>arr[i+1]){
			ans++;
		}
		else if(arr[i]>arr[i-1]&&arr[i]<arr[i+1]){
			ans++;
		}
	}
	printf("%d", ans);
}


Measured memory_bytes: 3736
// 169

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <climits>
#include <string>
#include <cmath>

using namespace std;
using ll = long long;


int main(){
    ll n, ans=1, buf;
    cin >> n;
    bool c = false;
    for(ll i=0; i<n; i++){
        cin >> buf;
        if(buf == 0){
            cout << 0 << endl;
            return 0;
        }
        if(c || ans*buf > 1000000000000000000 || 1000000000000000001/ans < buf){
            c = true;
        }
        ans *= buf;
    }

    if(c){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}


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

int main()
{
    int n, i;
    string str;
    cin >> n;

    for(i = 0; i < n; i++)
    {
        cin >> str;
        if(str == "Y") break;
    }

    if(i == n) cout << "Three" << endl;
    else cout << "Four" << endl;
    return 0;
}

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

// 文字から数値に変換
int getChar(char ch) {
    if ( ch == 'A' ) return 1;
    else if ( ch == 'C' ) return 2;
    else if ( ch == 'G' ) return 3;
    else if ( ch == 'T' ) return 4;
    else return 0;
}

// 文字列から数値へ変換して key を生成する
long long getKey(char str[]) {
    long long sum = 0, p = 1, i;
    for ( i = 0; i < strlen(str); i++ ) {
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[]){
    long long key, i, h;
    key = getKey(str); // 文字列を数値に変換
    for ( i = 0;; i++ ) {
        h = (h1(key) + i * h2(key)) % M;
        if ( strcmp(H[h], str) == 0 ) return 1;
        else if ( strlen(H[h]) == 0 ) return 0;
    }
    return 0;
}

int insert(char str[]) {
    long long key, i, h;
    key = getKey(str); //文字列を数値に変換
    for ( i = 0; ; i++ ) {
        h = (h1(key) + i * h2(key)) % M;
        if ( strcmp(H[h], str) == 0) return 1;
        else if ( strlen(H[h]) == 0 ) {
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main() {
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    scanf("%d", &n);
    for ( i = 0; i < n; i++ ) {
        scanf("%s %s", com, str); // より高速な入力 scanf を使用

        if ( com[0] == 'i' ) {
            insert(str);
        } else {
            if ( find(str) ) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 16100
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>

using namespace std;

int main()
{
    int K;
    cin >> K;
    long long runrun;
    queue<long long> Q;
    for(int i=1;i<10;i++){
        Q.push(i);
    }
    for(int i=0;i<K;i++){
        runrun = Q.front();
        Q.pop();
        if(runrun % 10 != 0){
            Q.push(runrun*10+runrun%10-1);
        }
        Q.push(runrun*10+runrun%10);
        if(runrun % 10 != 9){
            Q.push(runrun*10 + runrun%10+1);
        }
    }
    cout << runrun;
    
    
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005, MOD = 1000000007;
typedef long long ll;

ll N, arr[MAXN];

ll pkt(ll a, ll b) {
	if (b == 0) return 1;
	else if (b&1) return pkt(a, b-1)*a%MOD;
	else {
		ll tmp = pkt(a, b/2);
		return tmp*tmp%MOD;
	}
}

ll inv(ll x) {
	return pkt(x, MOD-2);
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	cin >> N;
	for (int i = 0; i < N; i++) cin >> arr[i];
	
	ll fact = 1;
	for (int i = 1; i <= N; i++) fact = fact*i%MOD;
	
	ll cur = 0;
	for (int i = 0; i < N; i++) {
		cur = (cur + inv(i+1))%MOD;
	}
	
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ans = (ans + cur*arr[i])%MOD;
		cur = (cur - inv(N-i) + inv(i+2) + MOD)%MOD;
	}
	ans = ans*fact%MOD;
	cout << ans << "\n";
	
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pb  					push_back
#define mp 						make_pair
#define all(v) 					((v).begin()) ,((v).end())
#define let(o,v)				memset(o,v,sizeof (o))
typedef long long 				ll;
typedef vector<int>				vi;
typedef vector<vi>				vvi;
typedef vector<string>			vs;

const int MOD = 998244353;
const int oo = (int)1e9;
const ll OO = (ll)1e18;
const double PI = acos(-1.0);
const int N = (int)1e5 + 9;

bool isprime(ll n) {
	if (n <= 1)
		return 0;
	for (ll i = 2; i*i <= n; i++)
		if (n%i == 0)
			return false;
	return 1;
}
ll intlog(ll base, ll x) {
	return (log(x) / log(base));
}
bool prime[N];
void primee()
{

	for (int p = 2; p*p <= N; p++)
	{

		if (prime[p] == true)
		{
			for (int i = p * 2; i < N; i += p)
				prime[i] = false;
		}
	}

}
string decToBinary(ll n)
{
	string z = "";
	int i = 0;
	while (n > 0) {

		z += (n % 2) + 48;
		n = n / 2;
		i++;
	}
	reverse(all(z));
	return z;
}
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}
ll power(ll x, int y)
{
	ll temp;
	if (y == 0)
		return 1;
	temp = power(x, y / 2);
	if (y % 2 == 0)
		return temp * temp;
	else
		return x * temp*temp;
}
int n,w;
ll dp[105][100005],ar[105][2];
ll calc(int idx, int ww) {
	if (idx == n) return 0;
	ll &ret = dp[idx][ww];
	if (ret != -1) return ret;
	ret = 0;
	if (ww + ar[idx][0] <= w) ret=calc(idx+1,ww+ar[idx][0])+ar[idx][1];
	ret = max(ret, calc(idx + 1, ww));
	return ret;
}
int main()
{
	let(dp, -1);
	scanf("%d %d", &n, &w);
	for (int i = 0; i < n; i++)
	{
		scanf("%lld %lld", &ar[i][0], &ar[i][1]);
	}
	printf("%lld\n", calc(0, 0));
	return 0;
}

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

ll ct[101010];
int main()
{
    ll n, k;
    scanf("%lld %lld",&n,&k);
    for (int i = 0; i<n; i++)
    {
        ll a,b;
        scanf("%lld %lld",&a,&b);
        ct[a] += b;
    }
    for (int i = 1; i<=101010; i++)
    {
        if (k > ct[i])
            k -= ct[i];
        else
        {
            printf("%d\n",i);
            return 0;
        }
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main(){
	int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n){
    cin >> vec.at(i);
  }
  cout << vec.at(n-1);
  if (n>1){
    for (int i=(n-2);i>=0;i--){
      cout << " " << vec.at(i);
    }
  }
  cout << endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define repr1(i, n) for (int i = n; i >= 1; i--)
#define all(v) v.begin(), v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  string s;
  cin >> s;
  bool ok = false;
  rep(i, 3) {
    if (s[i] == '7')
      ok = true;
  }
  cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3620
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    h, w, K = i_map()
    str_list = s_row_list(h)

    count = 0

    for h_bit in list(product([0,1], repeat=h)):
        for w_bit in list(product([0,1], repeat=w)):
            copy_list = deepcopy(str_list)

            for i in range(h):
                if h_bit[i] == 0:
                    continue
                copy_list[i][0] = '.' * w

            for i in range(w):
                if w_bit[i] == 0:
                    continue
                for k in range(h):
                    tmp = ''
                    for l in range(w):
                        if l == i:
                            tmp += '.'
                        else:
                            tmp += copy_list[k][0][l]
                    copy_list[k][0] = tmp
            tmp_count = 0
            for aaa in range(h):
                for bbb in range(w):
                    if copy_list[aaa][0][bbb] == '.':
                        continue
                    tmp_count += 1
            if tmp_count == K:
                count += 1

    print(count)
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 76972
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

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

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

// vars
int k, s;

void input(){
    cin >> k >> s;
    return;
}

void solve(){
    int ans = 0;
    for (int x=0; x<=k; ++x){
        for (int y=0; y<=k; ++y){
            int z = s - x - y;
            if(0 <= z && z <= k && x + y + z == s){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        BigInteger a = scanner.nextBigInteger();
        BigInteger b = scanner.nextBigInteger();
        if (a.equals(b)) {
            System.out.println("EQUAL");
        } else if (a.compareTo(b) > 0) {
            System.out.println("GREATER");
        } else {
            System.out.println("LESS");
        }
    }
}


Measured memory_bytes: 23892
#include <stdio.h>

int main(){
  char n1[30];
  char n2[30];
  char n3[30];

  scanf("%s %s %s", n1, n2, n3);
  printf("%c%c%c\n", n1[0]-32, n2[0]-32, n3[0]-32);
  return 0;
}


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

#define endl             '\n' 
#define pii              pair <int,int>
#define pll              pair <long long,long long>
#define sc               scanf
#define pf               printf
#define Pi               2*acos(0.0)
#define ms(a,b)          memset(a, b, sizeof(a))
#define pb(a)            push_back(a)
#define MP               make_pair
#define db               double
#define ll               long long
#define EPS              1E-5
#define ff               first
#define ss               second
#define sqr(x)           (x)*(x)
#define D(x)             cout<<#x " = "<<(x)<<endl
#define VI               vector <int>
#define DBG              pf("Hi\n")
#define MOD              1000000007
#define CIN              ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define SZ(a)            (int)a.size()
#define loop(i,n)        for(int i=0;i<n;i++)
#define loop1(i,n)       for(int i=1;i<=n;i++)
#define REP(i,a,b)       for(int i=a;i<b;i++)
#define TEST_CASE(t)     for(int z=1;z<=t;z++)
#define all(a)           a.begin(),a.end()
#define intlim           2147483648
#define infinity         (1<<28)
#define ull              unsigned long long
#define gcd(a, b)        __gcd(a, b)
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))
 
using namespace std;
 
 
const int fx[]= {+1,-1,+0,+0};
const int fy[]= {+0,+0,+1,-1};
// const int N = 1e5 + 5;
#define piii pair<int, pair<int,int> >

const int N = 2e5 + 5;
int arr[N],frec[N],vis[N];
int main(){
  CIN;
  int n,m;
  while(cin >> n >> m)
  {
    cout << (n/m) + ((n%m)?1:0) << endl;
  }
}

Measured memory_bytes: 256
import collections

N, M = map(int,input().split())
A = list(map(int,input().split()))
p = [list(map(int,input().split())) for i in range(M)]

c = collections.Counter(A)
ap = [[c[k],k] for k in c]
p = p + ap
p.sort(key=lambda x:x[1],reverse=True)
ans = 0
cnt = 0
index = 0
while cnt != N:
    if cnt + p[index][0] <= N:
        ans += p[index][0]*p[index][1]
        cnt += p[index][0]
    else:
        ans += (N-cnt)*p[index][1]
        cnt = N
    index += 1
print(ans)

Measured memory_bytes: 49712
#include <bits/stdc++.h>
using namespace std;
int main() {
	int ans = 0, N,tmp; 
	cin >> N;
	for (size_t i = 1; i <= N; i+=2)
	{
		tmp = 0;
		for (size_t j = 1; j <= i; j++)
		{
			if (i % j == 0)tmp++;
		}
		if (tmp == 8)ans++;
	}
	cout << ans;
}

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

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
	int N, M, X;
	cin >> N >> M >> X;

	vector<int> v( N, 0 );
	rep( i, M )
	{
		int tmp;
		cin >> tmp;
		v[tmp] = 1;
	}

	vector<int> vv( N + 1 );
	rep( i, N )
	{
		vv[i + 1] = vv[i] + v[i];
	}

	int result = min( vv[N] - vv[X], vv[X] - vv[0] );
	cout << result << endl;

	return ( 0 );
}


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

int main() {
  int N;
  cin >> N;
  int t = N, c = 0;
  while (t > 0) {
    c += t % 10;
    t /= 10;
  }
  
  if (N % c == 0) {cout << "Yes" << endl;}
  else {cout << "No" << endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;cin>>s;
    map<char,int>mpp;
    for(int i=0;i<s.size();++i){
        mpp[s[i]]=1;
    }
    if(mpp['N']==mpp['S'] && mpp['E']==mpp['W']){
        puts("Yes");   
    }else puts("No");
    return 0;
}


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

using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N ; i++)
    {
        cin >> A[i] ;
    }
    int Q;
    cin >> Q;
    vector<int> B(Q);
    vector<int> C(Q);
    for(int i = 0 ; i < Q; i++)
    {
        cin >> B[i] >> C[i];
    }
    vector<long long> sum(Q+1);
    vector<int> math(100010);
    for(int i = 0; i < N ; i++)
    {
        sum[0] = sum[0] + A[i];
        math[A[i]]++;
    }
    for(int i = 0; i < Q;i++)
    {
        sum[i+1] = sum[i] + (C[i]-B[i])*math[B[i]];
        math[C[i]] = math[C[i]]+math[B[i]];
        math[B[i]] = 0;
    }
    for(int i = 1; i <= Q;i++)
    {
        printf("%lld\n",sum[i]);
    }

}

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

#define int long long
#define double long double
#define incin(n) int (n); cin >> (n)

//main.cpp-Sample


namespace math
{
	double PI = 3.14159265359;
	int step(int n);
	int ncr(int n,int r);

	int step(int n){
		if(n<=1){
			return 1;
		}else{
			return n * step(n-1);
		}
	}
	int ncr(int n,int r){
		for(int i=1;i<r;i++){
			n *= n-i;
		}
		for(int i=1;i<r;i++){
			r *= r-1;
		}
		return n/r;
	}
}


using namespace std;
signed main (){
	string o,n;
	cin >> o >> n;
	for (int i = 0; i < o.size()+n.size(); ++i)
	{
		if((i & 0b1) == 0){
			cout<<o[i/2];
		}else{
			cout<<n[i/2];
		}
	}
	cout<<'\n';
	return 0;
}




Measured memory_bytes: 256
fn main() {
    let stdin = std::io::stdin();
    let mut rd = ProconReader::new(stdin.lock());

    let s: String = rd.get();
    let t: Vec<char> = s.chars().collect();
    if t.last().unwrap() != &'s' {
        println!("{}s", s);
    } else {
        println!("{}es", s);
    }
}

pub struct ProconReader<R: std::io::Read> {
    reader: R,
}

impl<R: std::io::Read> ProconReader<R> {
    pub fn new(reader: R) -> Self {
        Self { reader }
    }
    pub fn get<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&byte| byte == b' ' || byte == b'\n' || byte == b'\r')
            .take_while(|&byte| byte != b' ' && byte != b'\n' && byte != b'\r')
            .collect::<Vec<_>>();
        std::str::from_utf8(&buf)
            .unwrap()
            .parse()
            .ok()
            .expect("Parse Error.")
    }
}

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

bool IsPrime(int m){
  if(m==1)return false;
  for(int i=2;i*i<=m;i++){
    if(m%i==0)return false;
  }
  return true;
}

int main(){
  int n;
  cin >> n;
  ll ans=1;
  for(int i=1;i<=n;i++){
    if(IsPrime(i)){
      ll temp=i;
      ll sum=0;
      while(n/temp>0){
        sum+=n/temp;
        temp*=i;
      }
      ans*=sum+1;
      ans%=mod;
    }
  }
  cout << ans << endl;
return 0;}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = [int(x) for x in input().split()]
A = [0] * M
B = [0] * M
F = [0] * N
for i in range(M):
    A[i], B[i] = map(int, input().split())
    F[A[i] - 1] = max(F[A[i] - 1], H[B[i] - 1])
    F[B[i] - 1] = max(F[B[i] - 1], H[A[i] - 1])

ans = 0
for i in range(N):
    if F[i] < H[i]:
        ans += 1

print(ans)


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

using namespace std;

string s;
int ans[111111];

int main() {
    cin >> s;
    
    int i = 0;
    while(i < s.size()) {
        int r = 0;
        while(s[i] != 'L') {
            i++;
            r++;    
        }
        int x = i-1;
        int l = 0;
        while(s[i] == 'L' && i < s.size()) {
            i++;
            l++;
        }
        int a = (l + r) / 2;
        int b = l + r - a;
        if(l % 2 != 0) {
            ans[x] = a;
            ans[x+1] = b;
        }else{
            ans[x] = b;
            ans[x+1] = a;
        }
    }

    for(int i = 0; i < s.size(); i++) cout << ans[i] << " ";
    return 0;


}



Measured memory_bytes: 1024
solve :: Integral a => a -> a -> a -> a
solve w a b
    | a + w < b = b - a - w
    | b + w < a = a - b - w
    | otherwise = 0

main :: IO ()
main = do
    [w, a, b] <- fmap read . words <$> getLine :: IO [Int]
    print $ solve w a b


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

using namespace std;

#define nil -1
vector<vector<int>> makelist(int n, int m) {
	vector<vector<int>> Adjlist(n);
	int a, b;

	for(int i = 0; i < m; i++) {
		cin >> a >> b;
		Adjlist[a].push_back(b);
		Adjlist[b].push_back(a);
	}

	return Adjlist;
}

void dfs_run(int start, int id, vector<vector<int>>& adj, vector<int>& color) {
	//cout << start << endl;
	while(!adj[start].empty()) {
		int tmp;
		tmp = adj[start].back();
		adj[start].pop_back();	
		if(color[tmp] != nil) {
			continue;
		}
		color[tmp] = id;
		dfs_run(tmp, id, adj, color);
	}
}

void dfs(int n, vector<vector<int>>& adj, vector<int>& color) {
	int id = 0;
	for(int i = 0; i < n; i++) {
		if(color[i] == nil) {
			color[i] = i;
			dfs_run(i, id, adj, color);
		}
		id++;
	}
	/*for(int i = 0; i < n; i++) {
		cout << color[i] << endl;
	}*/
	
}

int main(void)
{
	int n, m, q;

	cin >> n >> m;
	vector<vector<int>> Adjlist = makelist(n, m);
	vector<int> color(n, nil);

	dfs(n, Adjlist, color);
	cin >> q;
	for(int i = 0; i < q; i++) {
		int a, b;
		cin >> a >> b;

		if(color[a] == color[b]) {
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}

	return 0;
}
		

Measured memory_bytes: 13420
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int r,g,b,n;
    cin>>r>>g>>b>>n;
    int count=0;
    for (int i=0;r*i<=n;i++) {
        for (int j=0;j*g<=n;j++) {
            if (n-(r*i+j*g)>=0&&(n-(r*i+j*g))%b==0) {
                count++;
                //cout<<i<<" "<<j<<endl;
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
// #define ll int
using namespace std;
const ll INF = 1 << 29;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const int MAX_V = 500;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }




ll H,W,m;
ll cnt_h[300050],cnt_w[300050];
ll h[300050],w[300050];


void solve() {
    cin>>H>>W>>m;
    rep(i,m){
        cin>>h[i]>>w[i];
        h[i]--,w[i]--;
        cnt_h[h[i]]++;
        cnt_w[w[i]]++;
    }
    ll sum_h = 0, sum_w = 0;
    rep(i,H){
        chmax(sum_h, cnt_h[i]);
    }
    rep(i,W){
        chmax(sum_w, cnt_w[i]);
    }
    vll v,t;
    rep(i,H){
        if(cnt_h[i] == sum_h) v.pb(i);
    }
    rep(i,W){
        if(cnt_w[i] == sum_w) t.pb(i);
    }
    ll ans = sum_h + sum_w, cnt = 0;
    rep(i,m){
        if(cnt_h[h[i]] == sum_h && cnt_w[w[i]] == sum_w){
            cnt++;
        }
    }
    if((ll)v.size() * (ll)t.size() == cnt) ans--;

    cout<<ans<<endl;

}






signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);


    ll t=1;
    rep(i,t){
        solve(); 
    }


    return 0;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int L, N;
    cin >> L >> N;

    vi x(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }

    vll pref(N + 1);
    for (int i = 1; i <= N; i++) {
        pref[i] = pref[i-1] + x[i-1];
    }

    ll ans = 0;
    for (int l = 0; l < N; l++) {
        int bef = l, aft = N - l - 1;
        int add = min(bef, aft);

        ll tot_bef = 2ll * (pref[l] - pref[l - add]);
        ll tot_aft = 2ll * add * L - 2ll * (pref[l + add + 1] - pref[l + 1]);
        ll tot = tot_bef + tot_aft;
        {
            // case 1: finish at l clockwise
            ll cand = tot + x[l];
            if (aft > add) cand += 2ll * (L - x[l + add + 1]);
            ans = max(ans, cand);
        }
        {
            // case 2: finish at l counter-clockwise
            ll cand = tot + L - x[l];
            if (bef > add) cand += 2ll * x[l - add - 1];
            ans = max(ans, cand);
        }
    }

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



Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define MAX 50

int main() {
	int i, n, f[MAX];
	f[0] = 1;
	f[1] = 1;
	scanf("%d",&n);
	for (i = 2; i <= n; i++) {
		f[i] = f[i - 1] + f[i - 2];
	}
	printf("%d\n",f[n]);
    
    return 0;
}


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

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
#define bs(a,x) binary_search(a.begin(),a.end(),x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define fill(a,p) memset(a,p,sizeof(a))
#define pb push_back
#define mod 1000000007
#define N 200005
#define all(a) a.begin(),a.end()
#define point pair<ll,ll>
#define endl "\n"

const int inf = 1000000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM =2005;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll minim(ll a, ll b){return a<b?a:b;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

ll power(ll x, ll y,ll p) 
{ 
    ll res = 1;      
     x = x % p;    
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
            y = y>>1;  
            x = (x*x) % p;   
    } 
    return res; 
}

ll modInverse(ll n,ll p) 
{ 
    return power(n, p-2, p); 
} 


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

bool comp(const point &p1,const point &p2){
	if(p1.first!=p2.first)return p1.first<p2.first;
	else return p1.second<p2.second;
}

string to(char x){
	string s(1,x);
	return s;
}

int main()
{
	fio;
	string a,b;
	cin>>a>>b;
	ll n=a.length(),m=b.length();
	ll dp[n+1][m+1];
	fill(dp,0);
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=m;j++){
			if(a[i-1]==b[j-1]){
				dp[i][j]=max(dp[i][j],1+dp[i-1][j-1]);
			}
			dp[i][j]=max({dp[i][j],dp[i-1][j],dp[i][j-1]});
		}
	}
	string ans="";
	ll i=n,j=m;
	while(i>0 && j>0){
		if(a[i-1]==b[j-1]){
			ans.append(to(a[i-1]));
			i=i-1,j=j-1;
			continue;
		}
		ll m=max({dp[i-1][j],dp[i][j-1]});
		if(m==dp[i-1][j]){
			i=i-1;
		}else{
			j=j-1;
		}
	}
	reverse(all(ans));
	cout<<ans<<endl;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
#define vecmin(A) *min_element(A.begin(),A.end())
#define vecmax(A) *max_element(A.begin(),A.end())
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n),c(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];
  sort(a);
  sort(b);
  sort(c);
  ll ans = 0;
  rep(i,n){
    int apart = upper_bound(a.begin(),a.end(),b[i]-1)-a.begin();
    int cpart = c.end() - lower_bound(c.begin(),c.end(),b[i]+1);
    ans += (ll)apart*cpart;
  }
 cout << ans << endl; 
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

 int gcd(int a,int b){

   if(a%b == 0)
    return b;
   else
    return gcd(b,a%b);

 }

 long long numbers[500005];

 int main(){

 string s;
 cin>>s;

  int n = s.length();

   numbers[0] = 0;

   long long sum=0;
   for(int i=0;i<n;i++)
   {
          if(s[i] == '<')
          numbers[i+1] = numbers[i]+1;
   }

   for(int i=n-1;i>=0;i--){
      if(s[i]== '>')
     {
         if(numbers[i] <= numbers[i+1] )
            numbers[i] = numbers[i+1]+1;
      }
   }


   for(int i=0;i<=n;i++)
    sum = sum+numbers[i];


   cout<<sum<<endl;


 return 0;
 }


Measured memory_bytes: 7788
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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

int main() {
	ll N;
	cin >> N;

	vector<ll> A(N + 1);
	repn(i, N) cin >> A[i];
	sort(++A.begin(), A.end());

	ll b = N;

	ll ans = -A[1];

	for (ll i = 2; i <= N - 1; i++) {
		ans += max(A[i], -A[i]);

		if (A[i] > 0 && b == N) { b = i; }
	}

	ans += A[N];

	stack<ll> neg;
	for (ll i = 1; i < b; i++) { neg.push(A[i]); }
	stack<ll> pos;
	for (ll i = b; i <= N; i++) { pos.push(A[i]); }

	cout << ans << endl;

	repn(i, N - 1) {
		ll x = pos.top();
		pos.pop();

		ll y = neg.top();
		neg.pop();

		if(pos.empty()) {
			cout << x << " " << y << endl;
			pos.push(x - y);
		}

		else {
			cout << y << " " << x << endl;
			neg.push(y - x);
		}
	}
	system("PAUSE");
}


Measured memory_bytes: 3704
#include <iostream>
#include <cstring>

using namespace std;

const int INF = -1;

int N, W;
int v[101], w[101];
int dp[101][10001];

// i???????????§???????????§???j??\????????????
int solve(int i, int j) {
    if (dp[i][j] != INF) return dp[i][j];
    int res;
    if (i == N) res = 0;
    else if (j < w[i]) res = solve(i+1, j);
    else res = max(solve(i+1, j), solve(i+1, j - w[i]) + v[i]);
    return dp[i][j] = res;
}

int main() {
    memset(dp, -1, sizeof(dp));
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> v[i] >> w[i];
    cout << solve(0, W) << endl;
    return 0;
}

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

int N;

int main() {
    cin >> N;
    double p = (double) (N / 2 + 1) / (double) N;
    cout << (N % 2?  p : 0.5) << endl;
}



Measured memory_bytes: 256