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

using namespace std;

const int MX = 307;

int dp[MX][MX][MX];

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    string s;
    cin >> s;
    int p;
    cin >> p;
    int n = s.size();
    for (int l = n - 1; l >= 0; l--) {
        for (int r = l; r < n; r++) {
            for (int k = 0; k <= p; k++) {
                dp[l][r][k] = 1;
                if (k > 0) {
                    dp[l][r][k] = max(dp[l][r][k], dp[l][r][k - 1]);
                }
                if (l != r && s[l] == s[r]) {
                    dp[l][r][k] = max(dp[l][r][k], dp[l + 1][r - 1][k] + 2);
                }
                if (l != r) {
                    dp[l][r][k] = max(dp[l][r][k], dp[l + 1][r][k]);
                    dp[l][r][k] = max(dp[l][r][k], dp[l][r - 1][k]);
                    if (k > 0) {
                        dp[l][r][k] = max(dp[l][r][k], dp[l + 1][r - 1][k - 1] + 2);
                    }
                }
            }
        }
    }
    cout << dp[0][s.size() - 1][p] << "\n";
}




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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct Dinic{
    struct edge{
        int to,cap,rev;
        edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
    };

    static const int INF=1001001001;
    vector<vector<edge>>G;
    vector<int>level,iter;
    Dinic(int v):G(v),level(v),iter(v){}

    void addEdge(int from,int to,int cap){
        G[from].push_back(edge(to,cap,G[to].size()));
        G[to].push_back(edge(from,0,G[from].size()-1));
    }

    void bfs(int s){
        fill(level.begin(),level.end(),-1);
        queue<int>que;
        level[s]=0;
        que.push(s);
        while(que.size()){
            int v=que.front();
            que.pop();
            for(auto &e:G[v]){
                if(e.cap&&level[e.to]==-1){
                    level[e.to]=level[v]+1;
                    que.push(e.to);
                }
            }
        }
    }

    int dfs(int v,int t,int f){
        if(v==t)return f;
        for(int &i=iter[v];i<G[v].size();i++){
            edge &e=G[v][i];
            if(e.cap>0&&level[v]<level[e.to]){
                int d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    G[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }

    int maxFlow(int s,int t){
        int flow=0;
        while(true){
            bfs(s);
            if(level[t]<0)return flow;
            fill(iter.begin(),iter.end(),0);
            int f;
            while((f=dfs(s,t,INF))>0)flow+=f;
        }
    }
};

int H,W;
string fld[222];

signed main(){
    cin>>H>>W;
    rep(i,H)cin>>fld[i];

    Dinic d(H+W+114);
    int src=H+W+1;
    int snk=src+1;

    rep(i,H)rep(j,W){
        if(fld[i][j]=='.')continue;
        int cost=1;
        if(fld[i][j]!='o')cost=Dinic::INF;
        d.addEdge(i,j+H,cost);
        d.addEdge(j+H,i,cost);
        if(fld[i][j]=='S')d.addEdge(src,i,Dinic::INF);
        if(fld[i][j]=='T') d.addEdge(i,snk,Dinic::INF);
    }

    int tmp=d.maxFlow(src,snk);
    if(tmp==Dinic::INF)cout<<-1<<endl;
    else cout<<tmp<<endl;
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
int v[100005];
int main()
{
   int n, L=0, l=0;
   cin >> n;
   for (int i = 0; i <n; ++i)
      cin >> v[i];
   sort (v, v+n);
   for (int i = n-2; i>=0; --i)
   {
      if (v[i] == v[i+1])
      {
          if (!L)
               L = v[i];
           else if (!l) l = v[i];
           --i;
       }
     }
      cout <<1LL* l*L;
    return 0;
}

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

int main() {
    ll H;
    ll a[500][500];
    std::cin >> H>>W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            ll tmp;
            std::cin >> tmp;
            if(tmp%2==0){
                a[i][j]=0;
            }else{
                a[i][j]=1;
            }
        }
    }
    string result;
    ll result_count =0;
    ll i=0;
    ll j=0;
    ll i_b=0;
    ll j_b=0;

    while(i<H){
        // 偶数なら右
        if(i%2==0){
            if(j<W-1){
                j++;
            }else{
                i++;
            }
        }else{
            if(j>0){
                j--;
            }else{
                i++;
            }
        }
        if(i==H){
            break;
        }
        
        if(a[i_b][j_b]==1){
            result_count++;
            result += to_string(i_b+1)+" "+to_string(j_b+1)+" "+to_string(i+1)+" "+to_string(j+1)+"\n";
            a[i][j]= (a[i][j]+1)%2;
        }
        i_b=i;
        j_b=j;
    }
    std::cout << result_count << std::endl;
    std::cout << result;
}


Measured memory_bytes: 4996
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i++)
#define RFOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i--)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
using ll = long long;

int main(){
  int n, l; cin >> n >> l;
  int a[n+1];
  FOR(i, 1, n+1){
    cin >> a[i];
  }

  ll ma = 0, ind;
  FOR(i, 1, n){
    if(a[i]+a[i+1] > ma){
      ma = a[i]+a[i+1];
      ind = i;
    }
  }

  if(ma < l){
    cout << "Impossible" << endl;
    return 0;
  }

  cout << "Possible" << endl;
  
  FOR(i, 1, ind) cout << i << endl;
  RFOR(i, n-1, ind) cout << i << endl;
  cout << ind << endl;

  return 0;
}


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

int main() {
	int n,m;
	cin >> n >> m;
	vector<int> g(n,-1);  // グループ番号を格納
	int g_num = 0;

	vector<pair<int,int>> f(m);
	rep(i,m) {
		int a,b;
		cin >> a >> b;
		a--, b--;
		f[i].first = a;
		f[i].second = b;
	}

	sort(f.begin(), f.end());

	vector<vector<int>> to(n);
	rep(i,m) {
		if (i>0) if (f[i].first==f[i-1].first && f[i].second==f[i-1].second) continue;
		int a = f[i].first;
		int b = f[i].second;
		to[a].push_back(b);
		to[b].push_back(a);
	}

	int ans = 1;
	vector<bool> visited(n, false);
	rep(i,n) {
		if (!visited[i]) {
			visited[i] = true;
			int cnt = 0;
			queue<int> q;
			q.push(i);
			while(!q.empty()) {
				int v = q.front();
				q.pop();
				cnt++;
				for (int nv : to[v]) {
					if (!visited[nv]) {
						visited[nv] = true;
						q.push(nv);
					}
				}
			}
			ans = max(cnt, ans);
		}
	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 16968
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)

#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll mod = 1e9 + 7;
const ll infl = 1e17;

typedef unsigned long long ull;

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

int main(){
    ll n;
    cin >> n;
    vector<pll> point(2 * n);
    ll x;
    rep(i,n){
        cin >> x;
        point[i] = mp(x, 0);
    }

    rep(i, n)
    {
        cin >> x;
        point[i+n] = mp(x, 1);
    }
    sort(all(point));
    ll now = 0;
    ll ans = 1;
    rep(i,2*n){
        if (point[i].S==0){
            if (now<0){
                ans = (ans * (-now)) % mod;
                now++;
            }
            else {
                now++;
            }
        }
        else {
            if (now>0){
                ans = (ans * now) % mod;
                now--;
            }
            else
                now--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) {
  ll a=max(x,y),b=min(x,y),c;
  while (b>0) {
    c=a;
    a=b;
    b=c%b;
  }
  return a;
}
  
int main() {
  ll A,B,C;
  cin >> A >> B >> C;
  if (C%gcd(A,B)==0) cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n;cin>>n;
	pair<pair<string,ll> , ll> a[n];
	For(i,0,n){
		cin>>a[i].fi.fi>>a[i].fi.se;
		a[i].fi.se *= (-1);
		a[i].se = i;
	}
	sort(a,a+n);

	ll ans[n];

	For(i,0,n){
		cout<<a[i].se+1<<endl;
	}











	
}

Measured memory_bytes: 256
#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint998244353;
//using mint = modint1000000007;
#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;
//using i128 = __int128_t;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
constexpr char ln = '\n';
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
inline int topbit(int x) {return x == 0 ? -1 : 31-__builtin_clz(x);}
inline int topbit(long long x) {return x == 0 ? -1 : 63-__builtin_clzll(x);}
inline int botbit(int x) {return x == 0 ? 32 : __builtin_ctz(x);}
inline int botbit(long long x) {return x == 0 ? 64 : __builtin_ctzll(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
inline int kthbit(long long x, int k) {return (x>>k)&1;}
inline void print() {cout << "\n";}
template<class T>
inline void print(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cout << *itr << " ";
    print();
}
template<class T, class... Args>
inline void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
#ifdef MINATO_LOCAL
#define dump(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
inline void debug() {cerr << endl;}
template<class T>
inline void debug(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cerr << *itr << " ";
    debug();
}
template<class T, class... Args>
inline void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
#else
#define dump(x) void(0)
inline void debug() {}
template<class T> inline void debug(const vector<T> &v) {}
template<class T, class... Args> inline void debug(const T &x, const Args &... args) {}
#endif
struct Fast_ios {Fast_ios() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);};} fast_ios;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    int x; cin >> x;
    cout << 1-x << ln;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int X=in(),Y=in(),A=in(),B=in(),C=in();
	vector<ll> P=vecin<ll>(A);
	vector<ll> Q=vecin<ll>(B);
	sort(ALL(P),greater<ll>());
	sort(ALL(Q),greater<ll>());

	ll S=0;
	priority_queue<ll> QR;
	priority_queue<ll,vector<ll>,greater<ll>> QP,QQ;
	REP(i,X){
		QP.push(P[i]);
		S+=P[i];
	}
	REP(i,Y){
		QQ.push(Q[i]);
		S+=Q[i];
	}
	REP(i,C) QR.push(in());

	while(!QR.empty()){
		ll p=QP.top();
		ll q=QQ.top();
		ll r=QR.top();QR.pop();

		if(r<=p && r<=q) break;
		else{
			if(p>q){
				QQ.pop();
				QQ.push(r);
				S += r-q;
			}
			else{
				QP.pop();
				QP.push(r);
				S += r-p;
			}
		}
	}
	
	out(S);
	return 0;
}


Measured memory_bytes: 4724
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        SP[] sparr = new SP[n];
        for (int i = 0; i < n; i++) {
            String[] arr = reader.readLine().split(" ");
            sparr[i] = new SP(i + 1, arr[0], Integer.parseInt(arr[1]));
        }
        Arrays.sort(sparr);
        for (SP sp : sparr) {
            System.out.println(sp.id);
        }
    }
    private static class SP implements Comparable<SP> {
        int id;
        String s;
        int p;
        private SP(int id, String s, int p) {
            this.id = id;
            this.s = s;
            this.p = p;
        }
        public int compareTo(SP o) {
            int result = this.s.compareTo(o.s);
            return (result == 0) ? Integer.compare(o.p, this.p) : result;
        }
    }
}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-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; }

int main(){
    ll H,W,ans=0;
    cin>>H>>W;
    vector<vector<ll>> c(10,vector<ll> (10));
    vector<vector<ll>> A(H,vector<ll> (W));
    for(ll i=0;i<10;i++){
        for(ll j=0;j<10;j++) cin>>c[i][j];
    }
    for(ll i=0;i<H;i++){
        for(ll j=0;j<W;j++) cin>>A[i][j];
    }
    for(ll k=0;k<10;k++){
        for(ll i=0;i<10;i++){
            for(ll j=0;j<10;j++){
                c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
            }
        }
    }
    for(ll i=0;i<H;i++){
        for(ll j=0;j<W;j++){
            if(A[i][j]!=-1) ans+=c[A[i][j]][1];
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define INF ((1<<30)-1)  //int32_t
#define MOD 1000000007
#define MOD2 

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

#define mkp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main(){

    bool flag=true;

    ll ans=0,sum=0;
    
    string s;
    ll k;
    cin >>s>>k;
    ll n = s.length();

    vector<int> len(n,0);

    int i=0,cnt=0,st=0;
    int last=0;

    while (i < n){
        bool f=false;
        cnt = 1;
        st = i;

        while (s[(i+1)%n] == s[i] && i < n)
        {
            ++cnt;

            if(i==n-1){
                len[st] = cnt + len[0] -1;
                if(st!=0)len[0] = 0;
                f=true;

                if(len[st] == n){
                    ans += (n*k)/2;
                    cout << ans << endl;
                    return 0;
                }

                if(len[st]%2==0)ans -= 1;

                break; 
            }
            
            ++i;
            
        }
        
        if(!f)len[st] = cnt;
        
        if(cnt>1)last=st;

        ++i;
    }

    //for(int a:len)cout << a << " ";
    //puts("\n");

    for (int i = 0; i < n; i++){
        ans += (len[i]/2)*k;
    }


    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
import math

N, D = map(int, input().split())
XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append([x,y])

cnt = 0
for xy in XY:
    if math.sqrt(pow(xy[0], 2) + pow(xy[1], 2)) <= D:
        cnt += 1
print(cnt)



Measured memory_bytes: 39176
#include <cstdio>
using namespace std;
const int N = 1e5 + 5;
struct ZHI {
	int n, per[N];
	ZHI() {}
	ZHI operator * (const ZHI &d) {
		ZHI ret;
		ret.n = n;
		for (int i = 1; i <= n; ++i) ret.per[i] = per[d.per[i]];
		return ret;
	}
	ZHI inv() {
		ZHI ret;
		ret.n = n;
		for (int i = 1; i <= n; ++i) ret.per[per[i]] = i;
		return ret;
	}
	void print() {
	    for (int i = 1; i <= n; ++i) printf("%d ", per[i]);
	    printf("\n");
	}
} p, q, base[2], ho[6];
ZHI ksm(ZHI x, int y) {
	ZHI ret;
	ret.n = x.n;
	for (int i = 1; i <= x.n; ++i) ret.per[i] = i;
	for (; y; y >>= 1, x = x * x)
		if (y & 1) ret = ret * x;
	return ret;
}
int n, k;
int main() {
	scanf("%d%d", &n, &k);
	p.n = n, q.n = n;
	for (int i = 1; i <= n; ++i) scanf("%d", &p.per[i]);
	for (int i = 1; i <= n; ++i) scanf("%d", &q.per[i]);
	ho[0] = q.inv() * p;
	ho[1] = p;
	for (int i = 2; i <= 5; ++i) ho[i] = ho[i - 1] * ho[i - 2].inv();
	base[0] = q * p.inv() * q.inv() * p;
	base[1] = base[0].inv();
	ZHI ans = ksm(base[0], k / 6) * ho[k % 6] * ksm(base[1], k / 6);
	ans.print();
	printf("\n");
	return 0;
}

Measured memory_bytes: 9080
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto N = RD;
	auto X = RD;
	auto M = RD;
	
	auto pos = new long[](M);
	pos[] = -1;
	auto a = X;
	pos[a] = 0;
	auto cnt = new long[](M);
	cnt[0] = a;
	long ans = a;
	foreach (i; 1..min(N, M+1))
	{
		auto last = cnt[a];
		a = (a*a) % M;
		if (pos[a] == -1)
		{
			pos[a] = i;
			cnt[a] = last + a;
			ans += a;
		}
		else
		{
			auto len = i - pos[a];
			auto loopCnt = last - cnt[a] + a;
			auto rem = N - i;
			auto loop = rem / len;
			auto loopRem = rem % len;
			ans += loop * loopCnt;
			foreach (j; 0..loopRem)
			{
				ans += a;
				a = (a*a) % M;
			}
			break;
		}
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 4104
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  int ans = a - 2 * b;
  if(ans < 0) ans = 0;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int l,a,b,c,d;
	cin>>l>>a>>b>>c>>d;
	while(1){
		if(a<=0 && b<=0)break;
		a-=c;
		b-=d;
		l--;
	}
	cout<<l<<endl;
	return 0;
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> list(n);
	for(int i=0;i<n;i++){
		cin >> list[i];
	}
	for(int i=n-1;i>=0;i--){
		cout << list[i];
		if(i!=0)cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>

using namespace std;

const int MAXN = 101;
int n , m , sum = 0;
int a[MAXN] , b[MAXN * 10];
int main(){
	cin >> n >> m;
	for(int i = 1 ; i <= m ; ++ i)
		cin >> a[i];
	if(m == 1){
		if(a[1] == 1)
			cout << 1 << endl << 1 << endl << 1 << endl;
		else
			cout << a[1] << endl << 2 << endl << a[1] - 1 << " " << 1 << endl; 
		return 0;
	}
	for(int i = 2 ; i < m ; ++ i)
		if(a[i] & 1)
			swap(a[1] , a[i]);
	for(int i = 2 ; i < m ; ++ i)
		if(a[i] & 1)
			swap(a[i] , a[m]);
	for(int i = 2 ; i < m ; ++ i)
		if(a[i] & 1){
			cout << "Impossible" << endl;
			return 0;
		}
	if(a[1] & 1){
		if(a[1] > 1)
			b[++ sum] = a[1] - 1;
	}
	else{
		if(a[1] == 2)
			b[++ sum] = 1;
		else{
			b[++ sum] = a[1] - 2;
			b[++ sum] = 1;
		}
	}
	for(int i = 2 ; i < m ; ++ i)
		b[++ sum] = a[i];
	b[++ sum] = a[m] + 1;
	for(int i = 1 ; i <= m ; ++ i)
		cout << a[i] << " ";
	cout << endl;
	cout << sum << endl;
	for(int i = 1 ; i <= sum ; ++ i)
		cout << b[i] << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
#define MAX_N 200005
ll inv[MAX_N], fac[MAX_N], finv[MAX_N];
void make() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i=2; i<MAX_N; i++) {
    inv[i] = mod - inv[mod%i] * (mod/i) % mod;
    fac[i] = fac[i-1] * (ll)i % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}
ll perm(ll n, ll r) {
  if(n < 0)       return 0;
  else if(n < r)  return 0;
  else            return (fac[n] * finv[n-r]) % mod;
}
ll comb(ll n, ll r) {
  ll ans = 1;
  ans = perm(n, r); // n * (n-1) * ... * (n-r+1)
  ans = (ans * finv[r]) % mod; // フェルマーの小定理
  return ans;
}
int main() {
  int n;
  ll k;
  cin >> n >> k;
  make();
  ll ans = 0;
  rep(i, min((ll)n, k+1)) ans += comb(n, i) * comb(n-1, i), ans %= mod;
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector <int> h(N);
  int maxh = 0;
  for (int i = 0; i < N; ++i) {
    cin >> h[i];
    maxh = max(maxh, h[i]);
  }
  
  int ans = 0;
  for (int i = 0; i < maxh; ++i) {
    bool watering = false;
    for (int j = 0; j < N; ++j) {
      if (h[j] > 0) {
        watering = true;
        h[j]--;
      } else {
        if (watering) {
          ans++;
        }
        watering = false;
      }
    }
    if (watering) {
      ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  int num = 'z'-'a'+1;
  vector<int> cnt(num, 1001001001);
  rep(_,n) {
    string s;
    cin >> s;
    vector<int> res(num, 0);
    rep(i,(int)s.length()) {
      res[s[i]-'a']++;
    }
    rep(i, num) {
      chmin(cnt[i], res[i]); //minを格納
    }
  }
  string ans = "";
  rep(i,num) {
    char x = 'a'+i;
    debug(cnt[i]);
    if (cnt[i] > 0) {
      ans += string(cnt[i], x);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		String ans;
		int[] nums = new int[num];
		int cnt = 0, prev = 1;
		int[] downIndex = new int[num];
		for(int i = 0; i < num; i++){
			nums[i] = sc.nextInt();
			if(nums[i] < prev){
				downIndex[cnt] = i;
				cnt++;
			}
			prev = nums[i];
		}

		switch(cnt){
			case 0:
			ans = "YES";
			break;

			case 1:
			int index = downIndex[0];
			ans = (nums[index-2] < nums[index] && nums[index-1] < nums[index+1]) ? "YES" : "NO";
			break;

			case 2:
			int index1 = downIndex[0];
			int index2 = downIndex[1];
			ans = (nums[index2-1] < nums[index1-1] && nums[index2] < nums[index1]) ? "YES" : "NO";
			break;

			default:
			ans = "NO";
		}
		System.out.println(ans);

	}
}


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

using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


#define BOOST        ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define AZ(x)        x.begin(),x.end()
#define fi           first
#define se           second
#define pb           push_back
#define emp          emplace_back
#define mp           make_pair
#define mt           make_tuple
#define debug(x)     cerr << #x << " : " << x << endl;
#define For(i,a,n)   for(auto i = a; i < n; i++)


template<typename T> using V = vector<T>;
template<typename T, typename U> using P = pair<T,U>;

typedef long long ll;
typedef long double ld;


template<typename T>
// for super_map add a parameter Y above and replace "null_type" with "Y"

// set with two additional super powers
    // find_by_order(int k) - returns k'th smallest element (0-indexed)
    // order_of_key(int k) - returns number of elements strictly smaller than k.
using super_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


const int mod = 1e9+7, N = 1e5+5;
const ll INF = 1e18;



ll power(ll a,ll b)
{
    a = a%mod;
    ll result = 1;

    while(b)
    {
        if(b&1)
            result = (result*a)%mod;
        b >>= 1, a = (a*a)%mod;
    }
    return result;
}

ll super_rand(ll n) // Random number from set [0,n-1]
{
    uniform_int_distribution<ll> uid(0, n - 1);
    return uid(rng);
}



/*



1. Make sure you're taking all the inputs.
2. In case of nested loops, remember to use different variables.
3. If in doubt, do int -> ll
4. Don't fight the question, try solving the next one.
5. ffs (positon of first set bit), clz (leading 0s, max->32), ctz (trailing 0s), popcount (set bits). Don't use any of these on 0;



*/



// Don't code anything above this //








void add_self(int &a, int b)
{
	a += b;
	if(a >= mod)
		a -= mod;
}

int dp[100*N] = {};		// dp[i] : number of ways to pair popcount(i) number of men, i represents set of women ;	
	

int main()
{
    BOOST

	int n;
	cin >> n;
	int c[n+1][n+1];
	
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			cin >> c[i][j];

	int dim = 1 << n;
	dp[0] = 1;
	
	for(int mask = 0; mask < dim - 1; mask++)
	{
		int num_man = __builtin_popcount(mask);
		for(int i = 0; i < n; i++)
			if(c[num_man][i] && !(mask & (1 << i)))
				add_self(dp[mask | (1 << i)], dp[mask]);
	}

	cout << dp[dim - 1] << "\n";

	return 0;
}



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

using namespace std;

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

	vector<int> v = {1};
	int cnt = 1;
	int idx = 0;

	while (1) {
		if (cnt == k) {
			break;
		}

		if (idx == -1) {
			v = vector<int>(v.size() + 1, 0);
			v[0] = 1;
			cnt++;
			idx = v.size() - 1;
		} else if (v[idx] == 9) {
			idx--;
		} else {
			int x = v[idx] + 1;
			if (idx > 0 && abs(v[idx-1] - x) > 1) {
				idx--;
				continue;
			}

			v[idx]++;
			for (int i = idx + 1; i < v.size(); i++) {
				v[i] = max(0, v[i-1] - 1);
			}
			cnt++;
			idx = v.size() - 1;
		}
	}

	for (auto x: v) {
		cout << x;
	}
	cout << endl;
	return 0;
}


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

template<class T>
T gcd(T a, T b)
{
    if (a == 0) return b;
    else if (b == 0) return a;

    if (b > a) swap(a, b); // assume a >= b

    T ret = b;
    while (a % b != 0) {
        ret = a % b;
        a = b;
        b = ret;
    }
    return ret;
}

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

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

    // 左から1つずつ要素を増やすgcdと、
    // 右から1つずつ要素を減らすgcdをリスト保持

    vector<int> left_gcd(N);
    vector<int> right_gcd(N);
    left_gcd[0] = 0;
    right_gcd[N-1] = 0;

    for (int i = 1; i < N; ++i) {
        left_gcd[i] = gcd(left_gcd[i-1], A[i-1]);
        right_gcd[N-i-1] = gcd(right_gcd[N-i], A[N-i]);
    }

    int max_gcd = 1;
    for (int i = 0; i < N; ++i) {
        max_gcd = max(max_gcd, gcd(left_gcd[i], right_gcd[i]));
    }
    cout << max_gcd << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  int a,b,c; cin>>a>>b>>c;
  cout<<a+b+c-max({a,b,c})<<endl;
}













Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)                    cerr<<#x<<": "<<x<<endl
#define trace2(x, y)                 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)                 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)             cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)         cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    map<char , ll> mp;
    for(ll i=0; i<s.size(); i++){
        mp[s[i]]++;
        if(mp[s[i]]>1){
            cout << "no";
            return  0;
        }
    }
    cout << "yes";
    return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 256
// -*- coding: utf-8 -*-
//import java.awt.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    InputStream inputStream;
    if (args.length > 0 && args[0].equals("devTesting")) {
      try {
        inputStream = new FileInputStream(args[1]);
      } catch(FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    } else {
      inputStream = System.in;
    }
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskC solver = new TaskC();
    solver.solve(1, in, out);
    out.close();
  }
  
  static class TaskC {    
    int n;
    int[] a;
    
    void solve(int testNumber, InputReader in, PrintWriter out) {
      n = in.nextInt();
      a = new int[n];
      int min = Integer.MAX_VALUE / 2, max = 0;
      int[] freq = new int[n];
      for (int i = 0; i < n; ++i) {
        a[i] = in.nextInt();
        min = Math.min(min, a[i]);
        max = Math.max(max, a[i]);
        ++freq[a[i]];
      }
      if (freq[min] > 2) {
        out.println("Impossible");
        return;
      }
      for (int i = max; i > min; --i)
        if (freq[i] < 2) {
          out.println("Impossible");
          return;
        }
      if (freq[min] == 1 && max % 2 != 0 || freq[min] == 2 && max % 2 == 0) {
        out.println("Impossible");
        return;
      }
      out.println("Possible");
    }
    
  }
      
  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

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

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

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

    public long nextLong() {
      return Long.parseLong(next());
    }
    
    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public boolean hasInput() {
      try {
        if (tokenizer != null && tokenizer.hasMoreTokens()) {
          return true;
        }
        reader.mark(1);
        int ch = reader.read();
        if (ch != -1) {
          reader.reset();
          return true;
        }
        return false;
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }
    
  }
}


Measured memory_bytes: 8532
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n;
ll a[101010];
ll cof1[101010], cof2[101010]; // coefficient
int main() {
    cin>>n;
    REP(i, 0, n) cin>>a[i];

    sort(a, a+n);

    cof1[0]=-1;
    REP(i, 1, n-1) cof1[i] = 2*(i%2 ? 1 : -1);
    cof1[n-1]=(cof1[n-2]>0 ? -1 : 1);
    sort(cof1, cof1+n);

    cof2[0]=1;
    REP(i, 1, n-1) cof2[i] = 2*(i%2 ? -1 : 1);
    cof2[n-1]=(cof2[n-2]>0 ? -1 : 1);
    sort(cof2, cof2+n);

    ll sum1=0, sum2=0;
    REP(i, 0, n){
        sum1+=cof1[i]*a[i];
        sum2+=cof2[i]*a[i];
    }
    cout<<max(sum1, sum2)<<endl;
    return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

template<class T>
struct Vec2
{
	Vec2(){}
	Vec2(T _x, T _y) : x(_x), y(_y) {}

	Vec2 operator+(const Vec2& rhs) const { return Vec2(x + rhs.x, y + rhs.y); }
	Vec2 operator-(const Vec2& rhs) const { return Vec2(x - rhs.x, y - rhs.y); }
	T sqlength() const { return x*x + y*y; }
	bool operator<(const Vec2& rhs) const {
		return x < rhs.x;
	}

	T x, y;
};

typedef Vec2<double> Vec;
typedef long long ll;

static int Rand()
{
	static int r = 123456789;
	r = r ^ (r << 13);
	r = r ^ (r >> 17);
	r = r ^ (r << 5);
	return r;
}

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

	const double xs = Rand() % 1000, ys = Rand() % 1000;

	vector<Vec> P;
	P.reserve(n);
	for (int i = 0; i < n; i++) {
		double x, y;
		scanf("%lf%lf", &x, &y);
		P.push_back(Vec(x*xs-y*ys, x*ys+y*xs));
	}
	sort(P.begin(), P.end());

	double ans = HUGE_VAL;
	for (size_t i = 0; i < P.size(); i++) {
		double mindsq = HUGE_VAL;
		for (size_t j = i + 1; j < P.size(); j++) {
			if (P[i].x + ans < P[j].x) break;
			double dsq = (P[i] - P[j]).sqlength();
			mindsq = min(mindsq, dsq);
		}
		ans = min(ans, sqrt(mindsq));
	}

	printf("%.10f\n", ans/hypot(xs,ys));
	return 0;
}


Measured memory_bytes: 4520
#include<iostream>
#include<string.h>
using namespace std;

void ss(string *s) {
	for (int i = 0; i < s->size(); i++) {
		int min = s->at(i);
		int ii = i;
		for (int k = i; k < s->size(); k++) {

			if (min > s->at(k)) {
				min = s->at(k);
				ii = k;
			}
		}
		int swap = s->at(i);
		s->at(i) = min;
		s->at(ii) = swap;
	}
}
void tt(string* t) {
	for (int i = 0; i < t->size(); i++) {
		int min = t->at(i);
		int ii = i;
		for (int k = i; k < t->size(); k++) {

			if (min < t->at(k)) {
				min = t->at(k);
				ii = k;
			}
		}
		int swap = t->at(i);
		t->at(i) = min;
		t->at(ii) = swap;
	}
}
int main() {
	string s, t;
	cin >> s >> t;
	int ln, lm;
	ln = s.size();
	lm = t.size();

	ss(&s);
	tt(&t);
	int i = 0;
	while (i<ln&&i<lm&&s.at(i) == t.at(i)) {
		i++;
	}
	if (i == ln) {
		if (ln < lm)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else if (i == lm) cout << "No" << endl;
	else {

		if (s.at(i) < t.at(i))cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	

}

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

#define INFTY 1000000001

typedef struct{
  char mark;
  int num;
}Card;

int count=0;

void quicksort(Card [], int, int);
int partition(Card [], int, int);
void swap(Card *, Card *);
void merge(Card [],int,int,int);
void mergeSort(Card [],int,int);

int main(){
  Card *A, *B;
  int max=0, stb=1, n;
  int i;

  scanf("%d",&n);

  A = (Card *)malloc(n * sizeof(Card));
  B = (Card *)malloc(n * sizeof(Card));
 
  for(i=0; i<n; i++){
    scanf(" %c %d",&A[i].mark ,&A[i].num);
    B[i] = A[i];
    
    if(max < A[i].num)
      max = A[i].num;
  }
  
  quicksort(A, 0, n-1);
  mergeSort(B, 0, n);

  for(i=0; i<n; i++){
    if(A[i].mark != B[i].mark)
      stb = 0;
  }

  if(stb)
    printf("Stable\n");
  else
    printf("Not stable\n");

  for(i=0; i<n; i++)
    printf("%c %d\n", A[i].mark, A[i].num);

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

void quicksort(Card A[], int p, int r){
  int q;
  
  if(p < r){
    q = partition(A, p, r);
    quicksort(A, p, q-1);
    quicksort(A, q+1, r);
  }
}

int partition(Card A[], int p, int r){
  int x;
  int i, j;
  
  x = A[r].num;
  i = p-1;

  for(j=p; j<r; j++){
    if(A[j].num <= x){
      i++;
      swap(&A[i], &A[j]);
    }
  }

  swap(&A[i+1], &A[r]);
  return i+1;
}

void swap(Card *a, Card *b){
  Card tmp;

  tmp = *a;
  *a = *b;
  *b = tmp;
}

void merge(Card A[],int l,int m,int r){
  Card *L, *R;
  int n1, n2;
  int i, j, k;
  
  n1 = m-l;
  n2 = r-m;

  L = (Card *)malloc((n1+1) * sizeof(Card));
  R = (Card *)malloc((n2+1) * sizeof(Card));

  for(i=0; i<n1; i++)
    L[i] = A[l+i];

  for(i=0; i<n2; i++)
    R[i] = A[m+i];

  L[n1].num = INFTY;
  R[n2].num = INFTY;

  i = j = 0;
  for(k=l; k<r; k++){
    if(L[i].num <= R[j].num){
      A[k] = L[i];
      i++;
      count++;
    }
    
    else{
      A[k] = R[j];
      j++;
      count++;
    }
  }
  
  free(L);
  free(R);
  return;
}

void mergeSort(Card A[],int l,int r){
  int m;
  
  if(l+1 < r){
    m = (l+r)/2;
    mergeSort(A, l, m);
    mergeSort(A, m, r);
    merge(A, l, m, r);
  }
}



Measured memory_bytes: 3760
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const ll INF=100000000;

int main(){
	ll n,k,a[100010];
	vector<int> v;
	ll min=INF*INF,sum=0,max=0;
	cin>>n>>k;
	REP(i,n){
		cin>>a[i];
	}
	for(int i=0;i<n-k+1;i++){
		ll res=a[i+k-1]-a[i]+std::min(abs(a[i]),abs(a[i+k-1]));
		if(min>res){
			min=res;
		}
		DEB(res)END
	}
	cout<<min<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <array>

using namespace std;

int main(int argc, const char *argv[])
{
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < s.size(); i++) {
    s[i] += n;
    if (s[i] > 'Z') {
      s[i] = 'A' + s[i] - 'Z' - 1;
    }
  }
  
  cout << s << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,num[20],ans;
bool honest[20];
struct node
{
	int who;
	bool sign;
};
node tem[20][20];
void get_honest(int a)
{
	for(int i=1;i<=n;i++)
	{
		honest[i]=a%2;
		a>>=1;
	}
}
bool check()
{
	for(int i=1;i<=n;i++)
	{
		if(honest[i]==false)
			continue;
		for(int j=1;j<=num[i];j++)
		{
			if(honest[tem[i][j].who]!=tem[i][j].sign)
				return false;
		}
	}
	return true;
}
int get_num()
{
	int res=0;
	for(int i=1;i<=n;i++)
		res+=(int)honest[i];
	return res;
}
void solve()
{
	int limit=(1<<n)-1;
	for(int i=0;i<=limit;i++)
	{
		memset(honest,0,sizeof(honest));
		get_honest(i);
		bool flag=check();
		if(flag)
			ans=max(get_num(),ans);
	}
}
void fl()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
int main()
{
//  fl();
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&num[i]);
		for(int j=1;j<=num[i];j++)
		{
			node tmp;
			scanf("%d%d",&tmp.who,&tmp.sign);
			tem[i][j]=tmp;
		}
	}
	ans=0;
	solve();
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256