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

using namespace std;

typedef long long ll;

int N;
int A[100];

void show() {
  for (int i = 0; i < N; i++) {
    printf("%d%c", A[i], i == N - 1 ? '\n' : ' ');
  }
}

int main() {
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  show();
  for (int i = 1; i < N; i++) {
    int v = A[i];
    int j = i - 1;
    while(j >= 0 && A[j] > v) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    show();
  }
}

Measured memory_bytes: 3212
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ub              upper_bound
#define lb              lower_bound
#define isrt            insert
#define clr             clear
#define rsz             resize
#define ff              first
#define ss              second
#define lli             long long int
#define pb              push_back
#define pf              push_front
#define mkp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<int>
#define mii             map<lli,lli>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define INF             1e9
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define endl            "\n"
const double PI = acos(-1);

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

lli maxm(lli a, lli b)
{
  return (a >= b ? a : b);
}


lli minm(lli a, lli b)
{
  return (a <= b ? a : b);
}

lli power(lli x, lli y, lli p)
{
  lli res = 1;

  x = x % p;
  if (x == 0)
    return 0;

  while (y > 0)
  {

    if (y & 1)
      res = (res * x) % p;


    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

lli nCrmodp(lli n, lli r, lli p)
{
  if (r == 0)
    return 1;
  if (r == 1)
    return n;


  lli pro = 1, k = n;
  while (k > r)
  {
    pro *= k;
    pro %= p;
    --k;
  }

  k = 2;
  while (k <= (n - r))
  {
    pro *= power(k, (p - 2), p);
    pro %= p;
    ++k;
  }

  return pro;
}


lli first_big(lli n, lli k, vector<lli> arr)
{
  lli l, r, ans = n;
  l = 0;
  r = n - 1;

  while (l <= r) {
    lli m = l + (r - l) / 2;

    if (arr[m] > k) {
      ans = m;
      r = m - 1;
    }

    else
      l = m + 1;
  }

  return ans;
}

lli last_small(lli n, lli k, vector<lli> arr)
{
  lli l, r, ans = -1;
  l = 0;
  r = n - 1;

  while (l <= r)
  {
    lli mid = (l + r) / 2;

    if (arr[mid] <= k)
    {
      ans = mid;
      l = mid + 1;
    }
    else
      r = mid - 1;
  }

  return ans;
}

void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int main()
{
  c_p_c();

  lli a, b, c, d;

  cin >> a >> b >> c >> d;

  lli ans = 1e18;
  ans *= (-1);

  ans = maxm(ans, a * c);
  ans = maxm(ans, a * d);
  ans = maxm(ans, b * c);
  ans = maxm(ans, b * d);

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

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int x,y;
    cin>>x>>y;
    const long long INF=1LL<<60;
    long long int ans1=INF,ans2=INF,ans3=INF,ans4=INF;
    long long int tmp_x=-1*x;
    long long int tmp_y=-1*y;
    if (y-x>=0) {
        ans1=y-x;
    }
    if (y-tmp_x>=0) {
        ans2=y-tmp_x+1;
    }
    if (tmp_y-x>=0) {
        ans3=tmp_y-x+1;
    }
    if (tmp_y-tmp_x>=0) {
        ans4=tmp_y-tmp_x+2;
    }
    cout<<min(ans1,min(ans2,min(ans3,ans4)))<<endl;
}

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

struct Record
{
	Record()
		:b(0), f(0), r(0), v(0)
	{}
	int b;
	int f;
	int r;
	int v;
};

struct RecordComparator
{
	bool operator()( const Record& r1, const Record& r2 ) const
	{
		if( r1.b < r2.b ) return true;
		else if( r1.b > r2.b ) return false;
		else if( r1.f < r2.f) return true;
		else if( r1.f > r2.f) return false;
		else if( r1.r < r2.r) return true;
		else if( r1.r > r2.r) return false;
		else if( r1.v < r2.v) return true;
		else return false;
	}

	static bool isEqual( int b, int f, int r, Record& rec )
	{
		return ( b==rec.b && f==rec.f && r==rec.r );
	}
};

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

	vector<Record> vRec;
	vRec.reserve(n);

	for(int i = 0; i < n; ++i){
		Record rec;
		cin >> rec.b >> rec.f >> rec.r >> rec.v;
		vRec.push_back(rec);
	}

	std::sort(vRec.begin(), vRec.end(), RecordComparator());

	int recIndex = 0;

	for(int b = 1; b <= 4; b++){
		for(int f = 1; f <= 3; f++){
			for(int r = 1; r <= 10; ++r){
				cout << " ";
				bool isExist = false;
				if( recIndex < vRec.size() ) 
				{
					Record& rec = vRec[recIndex];
					if( RecordComparator::isEqual( b, f, r, rec ))
					{
						int total = rec.v;
						while(recIndex < vRec.size() - 1 && RecordComparator::isEqual( b, f, r, vRec[++recIndex] ))
							total += vRec[recIndex].v;
						cout << total;
						isExist = true;
					}
				}

				if( !isExist )
					cout << 0;					
			}
			cout << "\n";
		}
		if ( b != 4 )
			cout << "####################\n";
	}

	return 0;
}

Measured memory_bytes: 1204
H, W, M = gets.chomp.split(" ").map(&:to_i)
R = Array.new(H, 0)
C = Array.new(W, 0)
G = Array.new(M).map{
  r, c = gets.chomp.split(" ").map(&:to_i)
  R[r-1] += 1
  C[c-1] += 1
  (r-1)*W+c-1
}

r_m, c_m = R.max, C.max
r_i = R.map.with_index{|r, i| r==r_m ? i : nil}.compact
c_i = C.map.with_index{|c, i| c==c_m ? i : nil}.compact
G.sort!
flg = false
r_i.each{|r|
  c_i.each{|c|
    flg = true if G.bsearch{|x| x>=r*W+c} != r*W+c
  }
  break if flg
}

puts flg ? r_m+c_m : r_m+c_m-1


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

using namespace std;

struct Info{int l,r,s;};
vector<Info> V;
int N, X, M;
int cage[10],sum[10], ans[10];
int anssum = -1;

void rec(int rev, int tmpsum){
  if(rev == N){
    sum[0] = 0;
    for(int i = 1; i <= N; i++) sum[i] = sum[i-1] + cage[i-1];
    
    bool valid = true;
    for(int i = 0; i < M; i++)
      valid = valid&&(sum[V[i].r]-sum[V[i].l-1]==V[i].s);
    
    if(valid && tmpsum > anssum){
      for(int i = 0; i < N; i++) ans[i] = cage[i];
      anssum = tmpsum;
    }
    
  }else{
    for(int i = 0; i <= X; i++){
      cage[rev] = i;
      rec(rev+1, tmpsum + i);
      cage[rev] = 0;
    }
  }
}

int main(){

  cin >> N >> X >> M;
  V.resize(M);
  for(int i = 0; i < M; i++) cin >> V[i].l >> V[i].r >> V[i].s;
  rec(0,0);
  if(anssum == -1) cout << "-1" << endl;
  else{
    for(int i = 0; i < N; i++){
      if(i) cout << " ";
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}

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

typedef vector<int > vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
#define sz(a)  int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define forn(i,n) for(int i=0;i<n;++i)
#define foru(i,n) for(int i=1;i<=n;++i)
#define fortr(i,v) for(auto &i:v)
#define set(n) __builtin_popcount(n)
#define ll long long
#define prime 1000000007
int main()
{
	int m,n;
	cin>>n>>m;
	int A[n][m];
	char x;
	forn(i,n)
	{
		forn(j,m)
		{
			cin>>x;
			if(x=='#')
				A[i][j]=0;
			else A[i][j]=1;
		}	
	}

	int dp[n][m];
	forn(i,m)
	{
		if(i==0)dp[0][0]=1;
		else
		{
			
			if(dp[0][i-1]==0)
			{
				dp[0][i]=0;
			}
			else
			{
				if(A[0][i]==0)
				{
					dp[0][i]=0;
				}
				else
				{
					dp[0][i]=dp[0][i-1];
				}
			}
		}
	}
	forn(i,n)
	{
		if(i==0)dp[0][0]=1;
		else
		{
			
			if(dp[i-1][0]==0)
			{
				dp[i][0]=0;
			}
			else
			{
				if(A[i][0]==0)
				{
					dp[i][0]=0;
				}
				else
				{
					dp[i][0]=dp[i-1][0];
				}
			}
		}
	}
	foru(i,n-1)
	{
		foru(j,m-1)
		{
			if(A[i][j]==0)
			{
				dp[i][j]=0;
			}
			else
			{
				dp[i][j]=(dp[i][j-1]+dp[i-1][j])%prime;
			}
		}
	}
	cout<<dp[n-1][m-1]<<endl;
}

Measured memory_bytes: 8064
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main(){
        int a,b;
        scanf("%d %d",&a,&b);
        if(a==b || (int)abs(a-b) <= (16-2*min(a,b))/2 ) printf("Yay!\n");
        else printf(":(\n");
        return 0;
}


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

int main() {
  ll N, x; cin >> N >> x;
  ll a[N];
  for (ll i = 0; i < N; i++) {cin >> a[i];}
  ll res = 0;
  for (ll i = 0; i < N-1; i++) {
    if (a[i]+a[i+1] > x && a[i] <= x) {
      ll y = a[i]+a[i+1]-x;
      a[i+1] -= y;
      res+=y; 
    } 
    else if (a[i] > x) {
      ll y = a[i]-x;
      ll z = a[i]+a[i+1]-x;
      a[i+1] = 0;
      a[i] -= y;
      res+=z; 
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define f first
#define s second
#define int long long

using namespace std;

const int N = 3005;

double p[N];
double dp[N][N];

int32_t main()
{
    ios::sync_with_stdio(false);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    for(int i = 1;i <= n; ++i)
    {
        cin >> p[i];
    }
    for(int i = 0;i <= n; ++i)
    {
        for(int j = 0;j <= n; ++j)
            dp[i][j] = 1;
    }
    dp[1][0] = double(1 - p[1]);
    for(int i = 1;i <= n; ++i)
    {
        for(int j = 0;j <= i; ++j)
        {
            if(j == 0 && i == 1)
                continue;
            if(j == 0)
            {
                dp[i][j] = dp[i-1][j] * (1 - p[i]);
            }
            if(i == j)
            {
                dp[i][j] = dp[i-1][j-1] * p[i];
            }
            else
                dp[i][j] = dp[i-1][j] * (1 - p[i]) + dp[i-1][j-1] * (p[i]);
        }
    }
    int mid = n / 2 + n % 2;
    double ans = 0;
    for(int i = mid; i <= n; ++i)
    {
        ans += dp[n][i];
    }
    cout << fixed << setprecision(10) << ans;
}

Measured memory_bytes: 70784
#!/usr/bin/env python3
#AGC24 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
p = [I() for _ in range(n)]
inde = [0]*n
for i in range(n):
    inde[p[i]-1] = i
cnt = 1
ans = 0
for i in range(1,n):
    if inde[i-1] < inde[i]:
        cnt += 1
    else:
        ans = max(ans,cnt)
        cnt = 1
ans = max(ans,cnt)
ans = n - ans
print(ans)


Measured memory_bytes: 52828
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <assert.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VL a(n);
    ll ans = 0;
    map<ll, ll> mp;
    ll sum = 0;
    mp[0] = 1;
    REP(i,n){
        a[i] = lin();
        sum += a[i];
        ans += mp[sum];
        mp[sum]++;
    }
    cout << ans << endl;

    return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int t, d, l;
	while (cin >> t >> d >> l, t) {
		int rem = 0;
		int ans = 0;
		REP(i, t) {
			int x;
			cin >> x;
			if (rem > 0) {
				ans++;
				rem--;
			}
			if (x >= l)rem = d;

			
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3032
M = 2019
dp = [0] * M
s = input()
x = 0
for c in s:
    c = int(c)
    dp2 = [0] * M
    for j in range(M):
        index = (j*10 + c) % M
        dp2[index] += dp[j]
    dp = dp2
    dp[c] += 1
    x += dp[0]
print(x)


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

using namespace std;

int main()
{
    int n, ans=INT_MAX;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++)
        cin >> v[i];
    for(int i=1; i<=100; i++){
        int s=0;
        for(int j: v)
            s+=abs(j-i)*abs(j-i);
        ans=min(ans, s);
    }
    cout << ans << endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  float f;
  if(N%2 == 0){
   f = 1.0/2.0;
  }
  if(N%2 == 1){
   f = (float)(N-(N-1)/2)/N;
  }
  cout << f << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int i,sum = 0,ave;
int data[5];
 for(i = 0; i < 5; i ++ ){
   scanf("%d?\n",&data[i]);
    if(40 <= data[i]){
      sum += data[i];
    }else{
      data[i] = 40;
      sum += data[i];
    }
  }
ave = sum / 5;
printf("%d\n",ave);
return 0;
}

Measured memory_bytes: 612
#include <iostream>
typedef long long int ll;
using namespace std;
int main() {
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  ll total_distance = abs(a-b);
  ll interval_distance = (v-w)*t;
  if (total_distance <= interval_distance) {
  	cout << "YES";
  } else {
    cout << "NO";
  } 
  return 0;
}
  	
   


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

using namespace std;

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

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


int main() {

	IO;

	int n;
	cin >> n;
	
	ll dp[N];
	dp[0] = 1;
	
	for (int i = 3; i <= n; ++i) {
		for (int j = 3; j <= i; ++j) {
			dp[i] += dp[i-j];
			dp[i] %= INF;
		}
	}
	
	
	cout << dp[n]; 

}


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

using namespace std;
double All[105];
int main()
{
    double all=0.0,ans=100000000.0;
    int how,i,N;
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {

        scanf("%lf",&All[i]);
        all+=All[i];
    }
    for(i=0;i<N;i++)
    {
        if(max((All[i]-all/(double) N),(all/(double) N-All[i]))<ans)
        {
            how=i;
            ans=max((All[i]-all/(double) N),(all/(double) N-All[i]));
        }
    }
    printf("%d\n",how);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,m;
int ned[100100];
int val[100100];
long long f[100100];
long long ans;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>ned[i]>>val[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=m;j>=ned[i];j--)
		{
			f[j]=max(f[j],f[j-ned[i]]+val[i]);
			ans=max(ans,f[j]);
		}
	}
	cout<<ans;
	return 0;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> v(n), c(n);
    rep(i,n) cin >> v[i];
    rep(i,n) cin >> c[i];
    int sum = 0;
    rep(i,n) {
        if (v[i] > c[i]) sum += v[i] - c[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict,deque

N, M = map(int, input().split())
d = defaultdict(list)
for i in range(M):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

dist = [None]*N
q = deque()

s = 1  # スタート
q.append(s)
dist[s-1] = 0

while len(q)!=0:
    From = q.popleft()
    for To in d[From]:
        if dist[To-1] == None:
            q.append(To)
            dist[To-1] = From


if None in dist:
    print("No")
else:
    print("Yes")
    for i in range(1,N):
        print(dist[i]) 

Measured memory_bytes: 106312
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  string s;
  cin >> s;

  int ans = 0;
  if (s == "RRR") {
    ans = 3;
  } else if (s.find("RR") != s.npos) {
    ans = 2;
  } else if (s.find("R") != s.npos) {
    ans = 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include <stdio.h>          // printf(), fprintf(), scanf()

const char NUL = '\0';
unsigned char hash_t[1 << 22] = { 0 };

int
key(const char c)
{
	switch (c)
	{
	case 'A':
		return 0;

	case 'C':
		return 1;

	case 'G':
		return 2;

	case 'T':
	default:
		return 3;
	}
}

int
hash(const char* s)
{
	int u = 1;
	while (*s != NUL)
	{
		u = u * 4 + key(*s);
		s++;
	}

	return u;
}

int
main(int argc, char** argv)
{
	char command[8];
	char str[14];
	int n;

	scanf("%d", &n);
	while (n--)
	{
		scanf("%s %s", command, str);
		int h = hash(str);
		int u = h >> 3;
		int v = 1 << (h & 7);
		switch (command[0])
		{
		case 'i':
			hash_t[u] |= v;
			break;

		case 'f':
		default:
			if ((hash_t[u] & v) != 0)
				printf("yes\n");
			else
				printf("no\n");
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 768
N,Q = map(int,input().split())
S = str(input())
l,r = [0]*Q,[0]*Q
for i in range(Q):
    l[i],r[i] = map(int,input().split())
count_list = []
count = 0
count_list.append(0)
for i in range(1,N):
    if S[i-1] == "A" and S[i] == "C":
        count += 1
        count_list.append(count)
    else:
        count_list.append(count)   
for j in range(Q):
    print(count_list[r[j]-1]-count_list[l[j]-1])

Measured memory_bytes: 14164
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long n,m,r,a,b,c,dist[205][205]={};
  cin >> n >> m >> r;
  int rr[r]={};
  for(int i=0; i<r; i++) {
    cin >> rr[i];
    rr[i]--;
  }
  sort(rr,rr+r);
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      if(i!=j) {
        dist[i][j]=1e18;
      }
    }
  }
  for(int i=0; i<m; i++) {
    cin >> a >> b >> c;
    a--,b--;
    dist[a][b]=dist[b][a]=c;
  }
  for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {
      for(int k=0; k<n; k++) {
        if(i!=j&&i!=k&&j!=k) {
          dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k]);
        }
      }
    }
  }
  long long cnt,ans=1e18;
  do{
    cnt=0;
    for(int i=0; i<r-1; i++) {
      cnt+=dist[rr[i]][rr[i+1]];
    }
    ans=min(ans,cnt);
  }while(next_permutation(rr,rr+r));
  cout << ans << endl;
}
         
    
                
          


Measured memory_bytes: 512
import java.util.Scanner;

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();

        if (a == b) {
            System.out.println(c);
        } else if (a == c) {
            System.out.println(b);
        } else {
            System.out.println(a);
        }
    }

}

Measured memory_bytes: 21844
# include<iostream>
using namespace std;
int main ()
{
	 int N;
	 cin>>N;
	 char s[N];
	 for(int i=0;i<N;i++)
	 {
	 	 cin>>s[i];
	 }
	 char str=s[0];
	 int sum=0;
	 for(int i=1;i<N;i++)
	 {
	 	 if(s[i]!=str)
	 	 {
	 	 	 sum++;
	 	 	 str=s[i];
		  }
	 }
	 cout<<sum+1<<endl;
}

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

const int maxn=1e6+10;
int A[maxn];

int H;
 
 int left(int i)
 {
 	return 2*i;
 }
 
 int right(int i)
 {
 	return 2*i+1;
 }
 
 void maxHeapify(int i)
 {
 	int Max;
 	int l=left(i);
 	int r=right(i);
 	if(l<=H&&A[l]>A[i]){
 		Max=l;
	 }else{
	 	Max=i;
	 }
	 if(r<=H&&A[r]>A[Max]){
	 	Max=r;
	 }
	 if(Max!=i){
	 	swap(A[Max],A[i]);
	 	maxHeapify(Max);
	 }
 }
 
 void print()
 {
 	for(int i=1;i<=H;i++){
 		cout<<' '<<A[i];
	 }
	 cout<<endl;
 }
 
 int main()
 {
 	memset(A,0,sizeof(A));
 	cin>>H;
 	for(int i=1;i<=H;i++)cin>>A[i];
 	for(int i=H/2;i>=1;i--)maxHeapify(i);//以H/2为起点，1为终点 
 	print();
 	return 0;
 }


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

int main(){
  int x;
  cin >> x;
  
  int flag = 0;
  int i;
  
  for(i=x;;i++){
    flag=0;
    for(int j=2;j<=sqrt(i);j++){
      if(i%j==0)flag=1;//素数じゃない
    }
    if(flag==0)break;
  }
  cout << i;
  return 0;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, mod = 1000003;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define HelloFile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define ll long long
int main()
{
    Hello
    ll sum = 0, n, m, arr[N];
    priority_queue<int> pq;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        pq.push( arr[i] );
        sum += arr[i];
    }
    for(int i = 0; i < m; i++)
    {
        ll cur = pq.top();
        pq.pop();
        sum -= cur;
        cur /= 2;
        pq.push(cur);
        sum += cur;
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
/*------- Constants---- */

#define LL                      long long
#define Ulong                   unsigned long long
#define REP(i,n)                for(long long i=0; i < n ; i++ )
#define mp                      make_pair
#define pb                      push_back
#define all(x)                  (x).begin(),(x).end()
#define PI                      acos(-1.0)
#define EPS                     1e-14
#define F                       first
#define S                       second
#define di(x)                   int x; input(x)
#define in(x)                   input(x)
#define in2(x,y)                in(x),in(y)
#define in3(x,y,z)              in(x),in2(y,z)
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl
#define nl                      cout<<endl
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))
#define IO                      ios_base::sync_with_stdio(0);cin.tie(0)
#define READ                    freopen("/home/matrixcode/Desktop/in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
template<class T> inline void input(T &x) {
  register char c = getchar();x = 0;
  int neg = 0;
  for(; ((c<48 || c>57) && c != '-'); c = getchar());
  if(c=='-'){neg = 1;c = getchar();}
  for(; c>47 && c<58 ; c = getchar()){x = (x<<1) + (x<<3) + c - 48;}
  if(neg) x = -x;
}
inline long long bigmod(long long p,long long e,long long M){
  long long ret = 1;
  for(; e > 0; e >>= 1){
    if(e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/***************************** END OF TEMPLATE *******************************/

const int N = 3e5+5;
vector<int> G[N];
vector<int> top;
bool vis[N];
int dp[N];

void dfs(int u) {
  if(vis[u]) return;
  vis[u] = 1;
  for(auto x: G[u]) dfs(x);
  top.push_back(u);
}

int main()
{
  int n,m;
  in2(n,m);
  for(int i = 0; i < m; i ++) {
    int x,y;
    in2(x,y);
    G[x].push_back(y);
  }

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

  reverse(top.begin(), top.end());

  memset(dp, 0, sizeof dp);
  for(auto x: top) {
    for(auto v: G[x]) {
      dp[v] = max(dp[v], 1 + dp[x]);
    }
  }
  cout << *max_element(dp + 1, dp + n + 1)<< endl;
}

Measured memory_bytes: 14200
//Pradeep_7
//double tt = clock();
//if((clock()-tt)/CLOCKS_PER_SEC > 1) break;
#include<bits/stdc++.h>
#define mp make_pair 
#define pb push_back
#define fi first
#define se second 
#define IO ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define ll long long int
#define nn cout<<"\n"
#define tcc int tc;	cin>>tc; while(tc--)
#define arr(a,n)	for(int i=0;i<n;i++)		cin>>a[i]
#define all(a)	a.begin(),a.end()
#define rall(a)	a.rbegin(),a.rend()
using namespace std;
int main()
{
	string a;
	cin>>a;
	stack<char> s;
	for(auto c : a)
	{
		if(c=='B')
		{
   			if(!s.empty())
   			{
   				s.pop();
   			}
		}
		else
		{
			s.push(c);	
		}
	}
	string ans="";
	while(!s.empty())
	{
		ans += s.top();
		s.pop();
	}
	reverse(all(ans));
	cout<<ans;
}       

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

int a[5500];
int L[5500][5500], R[5500][5500];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, k; cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	long long tot = 0;
	for (int i = 1; i <= n; i++) tot += a[i];
	if (tot < k) {
		cout << n << endl;
		return 0;
	}
	L[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= 5001; j++) {
			if (L[i - 1][j]) {
				L[i][j] = 1;
				int k = j + a[i]; if (k > 5001) k = 5001;
				L[i][k] = 1;
			}
		}
	}
	R[n + 1][0] = 1;
	for (int i = n; i >= 1; i--) {
		for (int j = 0; j <= 5001; j++) {
			if (R[i + 1][j]) {
				R[i][j] = 1;
				int k = j + a[i]; if (k > 5001) k = 5001;
				R[i][k] = 1;
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		vector<int> v1, v2;
		for (int j = 0; j <= 5001; j++) if (L[i-1][j]) v1.push_back(j);
		for (int j = 0; j <= 5001; j++) if (R[i+1][j]) v2.push_back(j);
		bool ok = 1;
		int cnt = v2.size();
		for (int u : v1) {
			int val = k - a[i] - u;
			while (cnt && v2[cnt - 1] >= val) cnt--;
			if (cnt == v2.size()) continue;
			if (u + v2[cnt] < k) {
				ok = 0;
				break;
			}
		}
		ans += ok;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 219520
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
	long x,k,d;
    cin>>x>>k>>d;
  	long kk = abs(x)+d;//距離
    long nn = 0;//何回でアウトしたか
    
    nn = abs(x)/d;
    if(nn > k) nn = k;
    kk = abs(x)-nn*d;
    
  
    long nokori = k-nn;
    if(nokori%2 == 0) cout<<kk;
    else cout<<abs(kk -d);
    return 0;
}

Measured memory_bytes: 3148
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


s = deque(S())
t = deque(S())
n = len(s)
for i in range(n):
    s.appendleft(s.pop())
    if s == t:
        print('Yes')
        break
else:
    print('No')

Measured memory_bytes: 39664
s = input()

s_val = int(s, 2)


s1 = ''
s2 = ''
for i in range(len(s)):
    if i%2==0:
        s1 = s1 + '1'
        s2 = s2 + '0'
    else:
        s1 = s1 + '0'
        s2 = s2 + '1'

num = min(str(bin(s_val^int(s1,2))).count('1'), str(bin(s_val^int(s2,2))).count('1'))
print(num)

Measured memory_bytes: 3444
n,a,b = map(int, input().split())

res = 0

for i in range(1,n+1):
    x5 = i//10000
    x4 = (i-x5*10000)//1000
    x3 = (i-x5*10000-x4*1000)//100
    x2 = (i-x5*10000-x4*1000-x3*100)//10
    x1 = i % 10
    
    xx = x5+x4+x3+x2+x1
    if b >= xx >= a:
        res += i

print(res)

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

#define FOR(i, a, b) for (int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define GO(to, a) for (auto to : a)

#define f first
#define s second
#define eb emplace_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()

int k;
long long dp [105][5][2];

string cur;

int solve (int n, int m, bool tight) {
	if (m > k) return 0;
	if (n < 0) {
		return (m == k);
	}
	if (~dp[n][m][tight]) return dp[n][m][tight];
	long long tot = 0;
	int lim = cur[n] - '0';
	for (int i = 0; i <= (tight ? 9 : lim); i++) {
		if (i) {
			tot += solve (n - 1, m + 1, tight | (i < lim));
		} else {
			tot += solve (n - 1, m, tight | (i < lim));
		}
	}
	return dp[n][m][tight] = tot;
}

void GetSolve (string w) {
	memset (dp, -1, sizeof(dp));
	cur = w;
	reverse (all(cur));
	cout << solve (sz(w) - 1, 0, false) << '\n';
}

int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string w;
	cin >> w >> k;
	GetSolve (w);
  return 0;
}

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

#define     bip(a)         __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     u              unsigned
#define     pb             push_back
#define     pf             push_front ///for list
#define     mp             make_pair
#define     is             insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))

///s.lower_bound(a),s.upper_bound(a), for set
///nCr(x, y) = nCr(x-1, y-1) + nCr(x-1, y)
///factorial digit   ((n * log10(n / e) +log10(2 * pi * n) /2.0));


int main()
{
    /*int a,b,c,d,f;
    cin>>a>>b>>c>>d>>f;
    int ar[10];
    ar[a]=1;
    ar[b]=2;
    ar[c]=3;
    ar[d]=4;
    ar[f]=5;
    cout<<ar[0]<<endl;*/
    int x,y;
    cin>>x>>y;
    if(y>=x*2&&y<=x*4&&y%2==0)cout<<"Yes\n";
    else cout<<"No\n";
}



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

int main(){
  int A,B,C,X,x,ans;
  cin >> A >> B >> C >> X ;
  x=X/50;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        if((10*i+2*j+k)==x)
          ++ans;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{
	long long int num1=0,num2=0,num3=0,num4=0,num5=0,num6=0,num7=0,num8=0;
	cin>>num1>>num2>>num3;
	num4=num1/num3;
	num5=num2/num3;
	num6=num5-num4;
	num8=num6;
	num7=num1%num3;
	if(num7==0){
		num6=num6+1;
		cout<<num6;
	}
	else{
		cout<<num8;
	}
	cout<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a[3];
  int min, max;
  scanf("%d%d%d", &a[0], &a[1], &a[2]);
  min = 100;
  max = 2;
  int i;
  for (i = 0; i < 3; i++) {
    if (min > a[i]) {
      min = a[i];
    }
    if (max < a[i]) {
      max = a[i];
    }
  }
  int result;
  result = max - min;
  printf("%d\n", result);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;
 
int main(){
  int N, M;
  cin >> N >> M;
  int sa = N-1;
  int kuchi = 1;
  for(int i=0;i<1000000;i++){
    if(M <= kuchi){
      cout << i << endl;
      break;
    }
    kuchi += sa;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back
#define vs vector<string>

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll N;
    cin>>N;
    vl a(N);
    rep(i,N)cin>>a[i];
    sort(all(a));
    ll MAX=a[N-1];
    ll r=(MAX+1)/2;
    ll d=INF;
    ll A;
    rep(i,N-1){
        ll x=abs(r-a[i]);
        if(x<d){
            d=x;
            A=a[i];
        }else{
            cout<<MAX<<" "<<A<<endl;
            return 0;
        }
        if(i==N-2){
            cout<<MAX<<" "<<A<<endl;
        }
    }
}


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

#define ll long long
#define pb push_back
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define inf 0x3f3f3f3f
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/* 
* stuff you should look for
* int overflow, array bounds
* special cases (n=1?), set tle
*/

int main(){
    fcin;
	int a;
	string s;
	cin >> a >> s;
	if(a >= 3200) cout << s << endl;
	else cout << "red";
    return 0;
}



Measured memory_bytes: 256
import collections
n=int(input())
S=[]
for i in range(n):
    S.append(input())
SS=collections.Counter(S).most_common()
s,ct=SS[0]
Ans=[]
for s,c in SS:
    if c==ct:
        Ans.append(s)
Ans.sort()
for ans in Ans:
    print(ans)


Measured memory_bytes: 45084
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;


int main(){
    
    vector<int> a(3);
    rep(i,3) cin >> a[i];
    SORT(a);
    vector<int> b = {5, 5, 7};
    if (a == b) cout << "YES";
    else cout << "NO";
    rn 0;
}


Measured memory_bytes: 888
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # 要素xの根の値を取得
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def resolve():
    N, M = list(map(int, input().split()))
    P = list(map(int, input().split()))
    XY = [list(map(int, input().split())) for _ in range(M)]
    uf = UnionFind(N)
    for xy in XY:
        uf.union(xy[0]-1, xy[1]-1)
    cnt = 0
    for i in range(N):
        if uf.same(i, P[i]-1):
            cnt += 1

    print(cnt)
    
    
if '__main__' == __name__:
    resolve()

Measured memory_bytes: 35736
s = input()
t = input()

# dp[i][j] : s[:i], t[:j]のLCS. ただしi==0 or j==0のとき0
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])

i = len(s)
j = len(t)
ans = ""

while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans += s[i-1]
        i -= 1
        j -= 1

ans = ans[::-1]
print("".join(ans))

Measured memory_bytes: 112220
def main():
    n = int(input())
    s = input()
    west = [0 for _ in range(n)]
    west[0] = 1 if s[0] == "W" else 0
    for i in range(1, n):
        if s[i] == "W":
            west[i] = west[i - 1] + 1
        else:
            west[i] = west[i - 1]
    answer = n - west[-1]
    if s[0] == "E":
        answer -= 1
    for i in range(1, n):
        answer = min(answer, west[i - 1] + n - i - west[-1] + west[i - 1])
    tmp = 0 if s[-1] == "E" else 1
    answer = min(answer, west[-1] - tmp)
    print(answer)


if __name__ == '__main__':
    main()



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

using namespace std;

using ll = long long;
using vi = vector<int>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl

int main() {
  IN(N);

  vi A(N);
  int min_idx = 0;
  REP(i, N) {
    cin >> A[i];
    if (abs(A[i]) < abs(A[min_idx]))
      min_idx = i;
  }
  FOR(i, 0, min_idx)
    if (A[i] < 0) {
      A[i] *= -1;
      A[i+1] *= -1;
    }

  for (int i = N-1; i > min_idx; --i)
    if (A[i] < 0) {
      A[i] *= -1;
      A[i-1] *= -1;
    }

  ll sum = 0;
  REP(i, N)
    sum += A[i];

  OUT(sum);

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define ALL(a) (a).begin(), (a).end()

const ll mod = 1000000007;
const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T &r, T &l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;  // for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}

// void numlist( vector<ll> &li , n ,){

// }

int main() {
  ll n;
  cin >> n;
  vector<ll> d(n);
  cin >> d;

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

  // nが奇数なら無理　未満なので含まないため
  ll ans=0;
  if (n%2==1){
    ans=0;
  }else{
    ll c = n/2;
    if ( d[c-1] < d[c] ){
      ans = d[c] - d[c-1];
    }else{
      ans = 0;
      // ll num = d[c];
      // for (ll i = c-1-1; i >=0; i--){
      //   ll dist = c-1 - i;
      //   ans = 1;
      //   if (!(( d[i] == num && d[c+dist] ==num ) || ( d[i] != num && d[c+dist] !=num ))){
      //     ans = 0;
      //     break;
      //   }
      // }

    }

  }



  cout<< ans<<endl;


}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))
B = []
for i in A:
    if i % 2 == 0:
        B.append(i)
ans = 0
for i in B:
    if i % 3 != 0 and i % 5 != 0:
        ans = 1
        break
if ans == 1:
    print('DENIED')
else:
    print('APPROVED')

Measured memory_bytes: 3064
import bisect
n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(n - 1, 0, -1):
    for j in range(i - 1, 0, -1):
        ans += max(0, (j - bisect.bisect_right(L, L[i] - L[j])))
print(ans)


Measured memory_bytes: 3316
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
 
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout<< min((a+b), min(b+c,c+a));
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    N=0
    id=[[None]*n for _ in range(n)]
    for i in range(n):
        for j in range(i+1,n):
            id[i][j]=N
            N+=1
    to_id=lambda i,j:id[min(i,j)][max(i,j)]

    E=[[] for _ in range(N)]
    for i in range(n):
        A=tuple(map(int,input().split()))
        for j in range(n-2):
            u=to_id(i,A[j]-1)
            v=to_id(i,A[j+1]-1)
            E[u].append(v)

    # longest path problem
    dp=[None]*N

    def dfs(v):
        if(dp[v] is not None): return dp[v]
        dp[v]=-1
        res=0
        for nv in E[v]:
            if(dp[nv]==-1):
                print(-1)
                exit(0)
            res=max(res,dfs(nv)+1)
        dp[v]=res
        return res

    print(max(dfs(v) for v in range(N))+1)
resolve()

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

struct mystring{
  char str[13];
  bool operator<(mystring s){
    return strcmp(str, s.str)<0;
  }
  bool operator==(mystring s){
    return strcmp(str, s.str)==0;
  }
  bool operator==(char* s){
    return strcmp(str, s)==0;
  }
};

template <typename T>
class BinaryTree{
  private:
    struct TreeNode{
      T value;
      TreeNode* left, *right, *parent;
    };

    struct Tree{
      TreeNode* root;
      TreeNode* nil;
    };

    Tree self;

    TreeNode* makeNode(T v, TreeNode* l, TreeNode* r, TreeNode* p){
      TreeNode* newNode = new TreeNode;
      newNode->left = l;
      newNode->right = r;
      newNode->parent = p;
      newNode->value = v;
      return newNode;
    }

  public:
    BinaryTree(){
      mystring s;
      self.nil = makeNode(s, nullptr, nullptr, nullptr);
      self.root = self.nil;
    }

    TreeNode* newNode(T v){
      return makeNode(v, self.nil, self.nil, self.nil);
    }

    void insert(T value){
      TreeNode* z = newNode(value);
      TreeNode* y = self.nil;
      TreeNode* x = self.root;
      while ( x != self.nil ){
        y = x;
        if ( z->value < x->value )
          x = x->left;
        else
          x = x->right;
      }
      z->parent = y;


      if ( y == self.nil )
        self.root = z;
      else if ( z->value < y->value )
        y->left = z;
      else
        y->right = z;
    }

    bool find(T value){
      return find(value, self.root);
    }

    bool find(T value, TreeNode* node){
      if (node == self.nil)
        return false;
      if (node->value == value) return true;
      if (value < node->value)
        return find(value, node->left);
      else
        return find(value, node->right);
    }

    void printInorder(TreeNode* root){
      if (root == self.nil) return;
      printInorder(root->left);
      printf(" %d", root->value);
      printInorder(root->right);
    }

    void printPreorder(TreeNode* root){
      if (root == self.nil) return;
      printf(" %d", root->value);
      printPreorder(root->left);
      printPreorder(root->right);
    }

    void print(void){
      printInorder(self.root);
      printf("\n");
      printPreorder(self.root);
      printf("\n");
    }
};

int main(){
  BinaryTree<mystring> bTree;
  mystring str;
  char ins[]="insert", fin[]="find";
  int n;
  cin >> n;
  for (int i=0;i<n;i++){
    scanf("%s", str.str);
    if (str == ins){
      mystring value;
      scanf("%s", value.str);
      bTree.insert(value);
    }
    else if (str == fin){
      mystring value;
      scanf("%s", value.str);
      cout << ((bTree.find(value))?"yes":"no") << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 29920
//This code is solely the property of StarnyC

#include<bits/stdc++.h>
using namespace std;
int main()

{
int sx,sy,tx,ty;
cin>>sx>>sy>>tx>>ty;

int x,y;

x=tx-sx;
y=ty-sy;

for(int i1=0;i1<x;i1++){cout<<"R";}
for(int j1=0;j1<y;j1++){cout<<"U";}
for(int i2=0;i2<x;i2++){cout<<"L";}
for(int j2=0;j2<y;j2++){cout<<"D";}
cout<<"D";
cout<<"R";
for(int i3=0;i3<x;i3++){cout<<"R";}
cout<<"U";
for(int j3=0;j3<y;j3++){cout<<"U";}
cout<<"L";
cout<<"U";
cout<<"L";
for(int i4=0;i4<x;i4++){cout<<"L";}
for(int j4=0;j4<y;j4++){cout<<"D";}
cout<<"D";
cout<<"R";


}


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

int main() {
  int K,A,B;
  cin>>K>>A>>B;
  if(B<=A+2){
    cout<<K+1<<endl;
  }
  else{
    long long int bis=1;
    int i;
    for(i=1;i<K;i++){
      if(bis>=A){
        bis=bis-A+B;
        i++;
      }
      else bis++;
    }
    if(i==K)bis++;
    cout<<bis<<endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
const int MAXN = 85,N = (2*80-1)*80;
int n,m,k,ans=INF,val[MAXN][MAXN];
char dp[MAXN][MAXN][2*N+5];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(m);
	for(ri i=1;i<=n;++i)
		for(ri j=1;j<=m;++j)
			read(val[i][j]);
	for(ri i=1;i<=n;++i)
		for(ri j=1;j<=m;++j)
			read(k),val[i][j]-=k;
	dp[1][1][N+val[1][1]]=dp[1][1][N-val[1][1]]=1;
	for(ri i=1;i<=n;++i)
		for(ri j=1;j<=m;++j)
			for(ri k=0;k<=80*(i+j-1)+N;++k){
				if(!dp[i][j][k]) continue;
				if(i!=n){
					dp[i+1][j][k+val[i+1][j]]=1;
					dp[i+1][j][k-val[i+1][j]]=1;
				}
				if(j!=m){
					dp[i][j+1][k+val[i][j+1]]=1;
					dp[i][j+1][k-val[i][j+1]]=1;
				}
			}
	for(ri i=0;i<=2*N;++i) if(dp[n][m][i])
		ans=min(ans,abs(i-N));
	print(ans);
	return 0;
}

Measured memory_bytes: 170240