akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define        sqr(a)       ((a)*(a))


#define MAX 500009

int n,m,a[MAX];


int block;

struct Query
{
    int L, R, index, result;
};
Query q[MAX];
bool compare(Query x, Query y)
{
    if (x.L / block != y.L / block)
        return x.L / block < y.L / block;
    return x.R < y.R;
}

bool compare1(Query x, Query y)
{
    return x.index < y.index;
}

void abal()
{

    block = (int)sqrt(n);
//for(int i = 0;i<m;i++)cout<<q[i].L<<" "<<q[i].R<<endl;
    sort(q, q + m, compare);
//for(int i = 0;i<m;i++)cout<<q[i].L<<" "<<q[i].R<<endl;
    int currL = 0, currR = 0;
    int curr_Diff_elements = 0;

    int freq[MAX] = { 0 };

    for (int i = 0; i < m; i++)
    {


        int L = q[i].L, R = q[i].R;


        while (currL < L)
        {

            // element a[currL] is removed
            freq[a[currL]]--;
            if (freq[a[currL]] == 0)
                curr_Diff_elements--;

            currL++;
        }


        while (currL > L)
        {
            freq[a[currL - 1]]++;

            if (freq[a[currL - 1]] == 1)
                curr_Diff_elements++;

            currL--;
        }
        while (currR <= R)
        {
            freq[a[currR]]++;

            if (freq[a[currR]] == 1)
                curr_Diff_elements++;

            currR++;
        }


        while (currR > R + 1)
        {

            freq[a[currR - 1]]--;
            if (freq[a[currR - 1]] == 0)
                curr_Diff_elements--;

            currR--;
        }
        q[i].result = curr_Diff_elements;
    }
}


int main()
{
    int i,j,k;
    cin >> n >> m;

    for(i=0; i<n; i++)cin>>a[i];

    for(i=0; i<m; i++)
    {
        cin >> q[i].L >> q[i].R;
        q[i].L--;
        q[i].R--;
        q[i].index = i;
        q[i].result = 0;

    }

    abal();
    sort(q, q + m, compare1);

    for(i=0; i<m; i++)cout<<q[i].result<<endl;
}



Measured memory_bytes: 15468
//
// Created on 2019-02-09.
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }

#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

#define PB push_back
#define INF 1e9
#define MOD 1e9+7
#define EPS 1e-9

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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



    map<int,int> m;
    int a, b;
    REP(i,3){
        cin >> a >> b;
        m[a-1]++;
        m[b-1]++;
    }

    int odd = 0;
    REP(i,4){
        if (m[i]%2 == 1){
            odd++;
        }

    }

    if (odd==2 || odd == 0) cout << "YES" << endl;
    else cout << "NO" << endl;



}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

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

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
int main() {
  cin >> N;
  int even = 0;
  int odd = 0;
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    if (x % 2 == 1){
      odd++;
    }else{
      even++;
    }
  }
  even = (even + odd / 2);
  if (even > 0){
    even = 1;
  }
  odd %= 2;

  int res = even ^ odd;
  if (res){
    cout << "YES" << endl;
  }else{
    cout << "NO"  << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    int a, b, c; cin >> a >> b >> c;
    if (a == 5 && b == 5 && c == 7) cout << "YES" << endl;
    else if (a == 5 && b == 7 && c == 5) cout << "YES" << endl;
    else if (a == 7 && b == 5 && c == 5) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int N,i,T=100,m,count=0,flag=1;
  scanf("%d",&N);
  int a[N];
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
}
  while(flag){
    flag=0;
  for(i=0;i<N-1;i++){
    if(a[i]>a[i+1]){
      m=a[i];
      a[i]=a[i+1];
      a[i+1]=m;
      count++;
      flag=1;
    }
  }
  }
  for(i=0;i<N-1;i++){
    printf("%d ",a[i]);
    
}
  printf("%d",a[N-1]);
   printf("\n");
    printf("%d\n",count);
}
    
    



Measured memory_bytes: 2076
#include<stdio.h>

int bubbleSort(int*, int);

int main()
{
  int a[100];
  int i, N, swapcnt;

  scanf("%d", &N);
  for(i=0;i<N;i++)
    {
      scanf("%d", &a[i]);
    }

  swapcnt = bubbleSort(a, N);

  for(i=0;i<N;i++)
    {
      if(i)printf(" ");
      printf("%d", a[i]);
    }
  printf("\n%d\n", swapcnt);
  
  return 0;
}

int bubbleSort(int* a, int N)
{
  int flag=1, i=0, j, cnt=0, num;

  while(flag)
    {
      flag = 0;
      for(j=N-1;j>=i+1;j--)
	{
	  if(a[j]<a[j-1])
	    {
	      num = a[j-1]; a[j-1] = a[j]; a[j] = num;
	      cnt++;
	      flag = 1;
	    }
	}
      i++;
    }
  
  return cnt;
}



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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

bool chk(string s)
{
    bool f = true;
    char c = s[0];
    REP(i,1,SZ(s)) {
        if(s[i] != c) {
            f = false;
            break;
        }
    }
    return f;
}

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

    ll ans = SZ(S);
    if(SZ(S) == 1) ans = 0;
    else {
        REP(c,'a','z'+1) {
            string t = S;
            REP(i,0,SZ(S)-1) {
                if(chk(t)) {
                    ans = MIN(ans,i);
                    break;
                }
                t = t.substr(0, SZ(t)-1);
                REP(j,0,SZ(t)-1) {
                    if(t[j+1] == c) t[j] = c;
                }
            }
        }
    }
    PR(ans);

    return 0;
}

/*



*/

Measured memory_bytes: 3544
using System;
using System.Linq;
using System.Collections.Generic;

namespace Contest
{
    partial class Program
    {
        static void Main(string[] args)
        {
            ABC152_A();
        }
        #region ABC152
        static void ABC152_A()
        {
            var nm = ReadIntN();
            Console.WriteLine(nm[0] == nm[1] ? "Yes" : "No");
        }
        static void ABC152_B()
        {
            var ab = ReadIntN();
            var A = ab[0];
            var B = ab[1];
            Console.WriteLine(A < B ? String.Join("", Enumerable.Repeat(A, B)) : String.Join("", Enumerable.Repeat(B, A)));
        }
        static void ABC152_C()
        {
            var N = ReadInt();
            var P = ReadIntN();
            int min = P[0];
            int count = 0;
            for (int i = 0; i < N; ++i)
            {
                if (min >= P[i])
                {
                    count += 1;
                    min = P[i];
                }
            }
            Console.WriteLine(count);
        }
        static void ABC152_D()
        {
            var N = ReadInt();
            long[,] count = new long[10, 10];
            for (int i = 1; i <= N; ++i)
            {
                var A1 = i;
                while (A1 > 9) { A1 /= 10; }
                var A0 = i % 10;
                count[A1, A0]++;
            }
            Console.WriteLine(Enumerable.Range(1, 9).Select(i => Enumerable.Range(1, 9).Select(j => count[i, j] * count[j, i]).Sum()).Sum());
        }
        static void ABC152_E()
        {
            var N = ReadInt();
            var A = ReadIntN();
        }
        #endregion


        static string ReadStr()
        {
            return Console.ReadLine();
        }
        static string[] ReadStrN()
        {
            return Console.ReadLine().Split(' ');
        }
        static int ReadInt()
        {
            return Convert.ToInt32(Console.ReadLine());
        }
        static int[] ReadIntN()
        {
            return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
        }
        static long ReadLong()
        {
            return Convert.ToInt64(Console.ReadLine());
        }
        static long[] ReadLongN()
        {
            return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
        }
        static Tuple<long, long>[]  ReadTupleLong(int n)
        {
            List<Tuple<long, long>> list = new List<Tuple<long, long>>();
            for (int i = 0; i < n; ++i)
            {
                var ab = ReadLongN();
                list.Add(new Tuple<long, long>(ab[0], ab[1]));
            }
            return list.ToArray();
        }
    }
}


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

int main(){
  int a[10];
  for(int i=0;i<10;i++){
    cin >> a[i];
  }
  sort(a,a+10,greater<int>());
  cout << a[0] << endl << a[1] << endl << a[2] << endl;
  return 0;
}

Measured memory_bytes: 3152
#include <set>
#include <map>
#include <list>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int maxn = 1e6 + 7;
const LL INF = 1e18;

int main() {
    int n,m;
    cin >> n >> m;
    if(n > m) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>


using namespace std;
int main() {
	int n, m;
	cin >> n >> m;

	int a;
	int sum = 0;
	for (int i = 0; i < m; i++) {
		cin >> a;
		sum += a;
	}

	if (n < sum)cout << -1 << endl;
	else cout << n-sum << endl;

	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n);
    ll res=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());
    if(n%2==0){
        for(int i=0;i<n/2-1;i++){
            res+=a[i];
        }
        for(int i=0;i<n/2-1;i++){
            res+=a[i+1];
        }
        res+=a[n/2-1];
    }
    else{
        for(int i=0;i<n/2;i++){
            res+=a[i]*2;
        }
        res-=a[0];
        res+=a[n/2];
    }
    cout << res << endl;
}


Measured memory_bytes: 4780
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)
#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;
    cin>>N;
    
    if(N%2){ cout1(2*N);
    }else{ cout1(N);}
}

Measured memory_bytes: 256
#include<cstdio>



int main() {

    int S;

    scanf("%d",&S);
    int h = S / 3600;//時間
    S %= 3600;// S = S % 3600
    int m = S / 60;//分
    int s = S % 60;//秒

    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2696
package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scanf("%s", &s)
	fmt.Scanf("%s", &t)

	count := 0
	for i:=0; i < len(s); i++{
		if (s[i] != t[i]) {
			count++
		}
	}

	fmt.Printf("%d", count)
}


Measured memory_bytes: 4592
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#define ll long long
#define inf 20021225
using namespace std;

int n,a[110]; vector<int> tmp; int ans[110];
int main()
{
	scanf("%d",&n); bool flag=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		tmp.push_back(a[i]);
		if(a[i]>i)	flag=1;
	}
	for(int opt=n;opt;opt--)
	{
		vector<int>::iterator it,qwq;
		int cnt=0,id=0;
		for(it=tmp.begin();it!=tmp.end();it++)
		{
			cnt++;
			if((*it)==cnt)	id=cnt,qwq=it;
		}
		if(!id)	flag=1;
		else	tmp.erase(qwq),ans[opt]=id;
	}
	if(flag)	printf("-1\n");
	else
	{
		for(int i=1;i<=n;i++)	printf("%d\n",ans[i]);
	}
	return 0;
}

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

long long gcd(int a, int b){
  int x = max(a,b);
  int y = min(a,b);
  if ( y == 0){
    return x;
  } else {
    return gcd(x % y, y);
  }
}

long long gmv(long long a, long long b){
  long long g = gcd(a,b);
  return a * b / g;
}


long long gcdv(vector<long long> v){
  long long res = 1;
  for ( int i = 0; i < n; i++){
    res = gmv(v[i], res);
    if ( (res / v[i]) % 2 == 0 || res > m){
      return 0;
    }
  }
  return res;
}

int main(){
  cin >> n >> m;
  vector<long long> a(n+1);
  int tmp;
  for ( int i = 0; i < n; i++){
    cin >> tmp;
    a[i] = tmp/2;
  }

  long long res = gcdv(a);

  if(res == 0){
    cout << 0 << endl;
    return 0;
  } else {
    cout << (m/res + 1) / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
h, w = map(int, input().split())
list = [[0 for i in range(w)] for j in range(h)]
for y in range(h):
    s = input()
    for x in range(w):
        if s[x] == "#": 
            list[y][x] = 1
for y in range(h):
    anslist = []
    for x in range(w):
        cnt = 0
        if list[y][x] == 1: anslist.append("#")
        else:
            if y >= 1: cnt += sum(list[y - 1][max(x - 1, 0):min(w, x + 2)])
            cnt += sum(list[y][max(x - 1, 0):min(w, x + 2)])
            if y <= h - 2: cnt += sum(list[y + 1][max(x - 1, 0):min(w, x + 2)])
            anslist.append(str(cnt))   
    print(''.join(anslist))

Measured memory_bytes: 3064
public class Main {

	public static void main(String[] args) {
//		int x = new java.util.Scanner(System.in).nextInt();
//		System.out.println(x * x * x);
		
		java.util.Scanner scanner = new java.util.Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		System.out.print(a * b);
		System.out.print(" ");
		System.out.println(a * 2 + b * 2);
	}

}

 

Measured memory_bytes: 26188
import string
 
S = input()
if len(S) < 26:
    for c in string.ascii_lowercase:
        if c not in S:
            break
    print(S + c)
else:
    ret = None
    for i in range(1, 26):
        idx = 25 - i
        if max(S[idx:]) != S[idx]:
            mc = min([c for c in S[(idx+1):] if c > S[idx]])
            ret = S[:idx] + mc
            break
    if ret is None:
        print(-1)
    else:
        print(ret)

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define forr(a,b,c) for(int a=b;a<c;a++)
#define forrev(a,b,c) for(int a=b;a>c;a--)
#define all(v) v.begin(),v.end()
#define revall(v) v.rbegin(),v.rend()
#define ff first
#define ss second
#define next ksfhuksfkhdn
#define prev uegrfjsfgsji
#define count jgsfhksadvk
#define x1 khgrkgbdjkgbjd
#define y1 bjdlgbdfshfbvl
#define left lihfjksfhskk
#define right kgsfskgfksh
#define mod 1000000007
#define eps 1e-9
#define inf INT_MAX
#define infl LONG_LONG_MAX
#define N 100009

void output();

int Y[] = {-1,1,0,0,-1,-1,1,1};// up, down, left, right, up-left, up-right, low-left, low-right
int X[] = {0,0,-1,1,-1,1,-1,1};

int n,m,a,b,c,d,k,h,w,x,y,p,q,t,ans,res,ma,mi,T,act=0,pas=1,cur,flag,now;

int uu,vv,ww,l,r;
int dp,dp2,cnt;
char s[N],S[N];
//vector<string> s;
double f,z,e;
vector<int> v, vec;
set<int> sett;
typedef map<int,int> Mapp;
Mapp mapp;


void input()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin >> S;
}
void solve()
{
	n = strlen(S);
	ans = N;

	for(char c = 'a'; c <= 'z'; c++)
	{
		p = n;
		strcpy(s,S);

		cur = 0;

		while(1) // moves
		{
			k = 0;

			forr(i,0,p)
				if( s[i] != c ) break;
				else k++;

			if( k == p ) break;

			forr(i,0,p-1)
			{
				if( s[i+1] == c )
					s[i] = c;
			}

			cur++;
			p--;
		}

		ans = min( ans, cur );
	}

	cout << ans << endl;
}
void output()
{
	//Case #1: 4 3
	cout << "Case #" << ++cur << ": ";
}

int main() 
{
	input();
	solve();
	//output();
	return 0;
}

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

using  namespace std;

int main()
{
  long long n; cin >> n;
  vector<long long int> iv;

  for (int i = 0; i < n; i++) {
    long long int x; cin >> x;
    iv.push_back(x - i);
  }

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

  // ivの中央値を計算する
  long long int size = iv.size();
  long long int b = iv[size / 2];

  long long int sad = 0;

  for (long long int x : iv) {
    sad += abs(x - b);
  }

  cout << sad << endl;

  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
struct edge{int to,cost;};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000005;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    int memo=modpow(a,b/2);
    return memo*memo%MOD;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
    x=modpow(x,MOD-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
double dist(double ax,double ay,double bx,double by){
    return sqrt((bx-ax)*(bx-ax)+(ay-by)*(ay-by));
}
int r1,c1,r2,c2;
int calc(int r,int c){
    int res=1;
    res*=(r+2);
    res*=comb(c+r+2,r+2);
    res%=MOD;
    res-=(c+1);
    res+=MOD;
    res%=MOD;
    res*=inv(c+1);
    res%=MOD;
    return res;
}
signed main(){
    cin>>r1>>c1>>r2>>c2;
    init_fact();
    int ans=0;
    ans+=calc(r2,c2);
    ans-=calc(r2,c1-1);
    ans+=MOD;
    ans%=MOD;
    ans-=calc(r1-1,c2);
    ans+=MOD;
    ans%=MOD;
    ans+=calc(r1-1,c1-1);
    ans%=MOD;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 15872
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int F = S / 100;
        int B = S % 100;
        System.out.println((F>=1&F<=12) ? (B>=1&B<=12) ? "AMBIGUOUS":"MMYY":(B>=1&B<=12) ? "YYMM":"NA");
        sc.close();
    }
}

Measured memory_bytes: 21716
from bisect import bisect_left, bisect_right
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
# print(a)

# a_cnt[k] = (num of a[i] where a[i] >= k)
a_cnt = [0] * (2 * a[-1] + 5)
for ai in a:
    a_cnt[ai] += 1
for i in reversed(range(len(a_cnt) - 1)):
    a_cnt[i] += a_cnt[i + 1]

# a_cs[i] = sum(a[n-i:])
a_cs = [0] * (n + 1)
for i in range(n):
    a_cs[i + 1] = a_cs[i] + a[n - 1 - i]


def check(x):
    # M回の握手の幸福度の最小値をx以上にできるか
    # つまり、M回の任意の握手の幸福度をx以上にできるか
    cnt = 0
    for ai in a:
        if x >= ai:
            idx = a_cnt[x - ai]
        else:
            idx = n
        cnt += idx
    return cnt >= m


lb = 1  # True
ub = 2 * a[-1] + 3  # False
while ub - lb > 1:
    mid = (ub + lb) // 2
    if check(mid):
        lb = mid
    else:
        ub = mid

# print(lb)

ans = 0
cnt = 0
for ai in a:
    if lb >= ai:
        idx = a_cnt[lb - ai]
    else:
        idx = n
    ans += ai * idx + a_cs[idx]
    cnt += idx
ans -= lb * (cnt - m)
print(ans)


Measured memory_bytes: 18516
n=input().split()
S=input()
N=int(n[0])
K=int(n[1])
S_list=list(S)
if S[K-1]=="A":
 S_list[K-1]="a"
elif S[K-1]=="B":
 S_list[K-1]="b"
elif S[K-1]=="C":
 S_list[K-1]="c"
S="".join(S_list)
print(S)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m,tmp;
	cin>>n>>m;
	vl cos(m);
	vl k(m);
	rep(i,m){
		cin>>cos[i];
		int num;
		cin>>num;
		rep(j,num){
			cin>>tmp;
			k[i]|=(1<<(tmp-1));
		}
	}
	vl ans(1<<n,LINF);
	ans[0]=0;
	rep(i,m){
		rep(j,ans.size()){
			chmin(ans[j|k[i]],ans[j]+cos[i]);
		}
	}
	cout<<(ans[(1<<n)-1]==LINF?-1:ans[(1<<n)-1])<<endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll MOD = 998244353;

class mint{
    ll n;
public:
    mint(ll m = 0){
        n = ((m % MOD) + MOD) % MOD;
    }
    bool operator==(const mint& m){
        return n == m.n;
    }
    mint operator-() const {
        return mint(-n);
    }
    mint& operator+=(const mint& m){
        n += m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator-=(const mint& m){
        n += MOD - m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& m){
        n *= m.n;
        n %= MOD;
        return *this;
    }
    mint operator+(const mint& m) const{
        mint res(*this);
        res += m;
        return res;
    }
    mint operator-(const mint& m) const{
        mint res(*this);
        res -= m;
        return res;
    }
    mint operator*(const mint& m) const{
        mint res(*this);
        res *= m;
        return res;
    }
    mint pow(ll t) const{
        if(t == 0) return mint(1);
        mint m = pow(t>>1);
        m *= m;
        if(t & 1 == 1) m *= *this;
        return m;
    }
    // for prime modulo
    mint inv() const{
        return pow(MOD-2);
    }
    mint& operator/=(const mint& m){
        (*this) *= m.inv();
        n %= MOD;
        return *this;
    }
    mint operator/(const mint& m) const{
        mint res(*this);
        res /= m;
        return res;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.n;
        return os;
    }
};


ll N,S;
ll A[3000];
mint dp[3050][3050];

int main(){
    cin >> N >> S;
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=0;i<=N;i++) dp[i][0] = mint(1);
    for(int i=0;i<N;i++){
        for(int j=0;j<=S;j++){
            if(dp[i][j] == mint(0)) continue;
            dp[i+1][j] += dp[i][j];
            if(j+A[i]<=S){
                dp[i+1][j+A[i]] += dp[i][j];
            }
        }
    }
    mint ans(0);
    for(int i=0;i<=N;i++) ans += dp[i][S];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 76284
n, a, b = map(int,input().split())
MOD = 10**9 + 7

ans1, ans2 = 1, 1
N = 3 * 10 ** 5
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
p = MOD
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
    
for i in range(a):
    ans1 = ans1 * (n-i) * inv[1+i] %MOD 
for i in range(b):
    ans2 = ans2 * (n-i) * inv[1+i] %MOD 

print((pow(2, n, MOD) + 2*MOD - 1 - ans1 - ans2)%MOD)

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

int main() {
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        cout << s << endl;
        cout << s << endl;
    }
}


Measured memory_bytes: 256
N = int(input())
A = [int(input()) for i in range(N)]
sorted_A = sorted(A)

pre = sorted_A[0]
ans = 0
if len(sorted_A) == 1:
    print(1)
else:
    count = 1
    for i in range(1, len(sorted_A)):
        if sorted_A[i] == pre:
            count += 1
            if i == len(sorted_A)-1:
                if count % 2 == 1:
                    ans += 1
        else:
            if i == len(sorted_A)-1:
                ans += 1
            if count % 2 == 1:
                ans += 1
            pre = sorted_A[i]
            count = 1
    print(ans)

Measured memory_bytes: 8276
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void)
{
    char c[4];
    scanf("%s", c);
    int i;
    if (c[0] == 'R' && c[1] == 'R' && c[2] == 'R')
    {
        printf("3\n");
    }
    else if ((c[0] == 'R' && c[1] == 'R') || (c[1] == 'R' && c[2] == 'R'))
    {
        printf("2\n");
    }
    else if (c[0] == 'R' || c[1] == 'R' || c[2] == 'R')
    {
        printf("1\n");
    }
    else
    {
        printf("0\n");
    }
    return 0;
}

Measured memory_bytes: 1644
#include<bits/stdc++.h>
using namespace std;
int n,a,ans=0;
int main(){
  stack<int> st;
  st.push(0);
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    while(st.top()>a)st.pop();
    if(st.top()<a){
      ans++;
      st.push(a);
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int compare3(string a, string b, string c){
  if (a == b&& b == c){
    return 0;
  }

  if(a.size() ==1){
    if (a == b || b ==c || c==a){
      return 1;
    }else{
      return 2;
     }
  }
  int mid, las, count;
  mid = a.size() / 2;
  las = a.size();
  count =  compare3(a.substr(0, mid), b.substr(0, mid), c.substr(0, mid)) + compare3(a.substr(mid, las - mid), b.substr(mid , las - mid), c.substr(mid, las -mid));
  return count;

}

int main(){
  int n, count;
  string a, b, c;
  cin >> n >> a >> b >> c;
  cout << compare3(a, b, c)<< endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt(),z=nxt(),w=nxt();
    vector <int> v(n);
    generate(all(v),nxt);
    int test=abs(w-v[n-1]);
    if(n>1)
        test=max(test,abs(v[n-1]-v[n-2]));
    cout<<test<<endl;
    
    
    return 0;   
}




 
 


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

vector<vector<int> > dp(2005,vector<int>(2005,-1));


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t,s;
    cin>>t>>s;
    
    vector<pair<int,int> > vec;
    for(int i=0;i<t;i++){
        int a,b;
        cin>>a>>b;
        vec.push_back(make_pair(a,b));
    }
    vector<long long> dp(s+1,0);
    dp[0]=1;
    
    for(int i=0;i<vec.size();i++){
        for(int j=dp.size()-1;j>=0;j--){
            if(dp[j] && j+vec[i].first <=s)
                dp[j+vec[i].first]=max(dp[j+vec[i].first],dp[j]+vec[i].second);
        }
    }
    long long ans=0;
    for(int i=0;i<dp.size();i++){
        ans=max(ans,dp[i]);
    }
    cout<<ans-1;
    
    
	return 0;
}

Measured memory_bytes: 16768
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

def main():
    H, W = mapint()
    ch, cw = mapint()
    dh, dw = mapint()
    maze = [list(input()) for _ in range(H)]
    
    dirc = ((-1, 0), (1, 0), (0, -1), (0, 1))
    magic = ((-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), (-1, -2), (-1, -1), (-1, 1), (-1, 2), (0, -2), (0, 2), (1, -2), (1, -1), (1, 1), (1, 2), (2, -2), (2, -1), (2, 0), (2, 1), (2, 2))
    from collections import deque
    Q = deque([(ch-1, cw-1)])
    
    dist = [[10**18]*W for _ in range(H)]
    dist[ch-1][cw-1] = 0
    while Q:
        y, x = Q.popleft()
        for dy, dx in dirc:
            ny, nx = y+dy, x+dx
            if ny<0 or ny>=H or nx<0 or nx>=W:
                continue
            if maze[ny][nx]=='#':
                continue
            if dist[ny][nx]>dist[y][x]:
                dist[ny][nx] = dist[y][x]
                Q.appendleft((ny, nx))
        
        for dy, dx in magic:
            ny, nx = y+dy, x+dx
            if ny<0 or ny>=H or nx<0 or nx>=W:
                continue
            if maze[ny][nx]=='#':
                continue
            if dist[ny][nx]>dist[y][x]+1:
                dist[ny][nx] = dist[y][x]+1
                Q.append((ny, nx))
    if dist[dh-1][dw-1]>=10**17:
        print(-1)
    else:
        print(dist[dh-1][dw-1])
main()

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

namespace CSharpConsoleApp {

    class Program {

        static int Main() {

            var input = Console.ReadLine();
            var cArray = input.ToCharArray();
            var first = cArray.First();
            var last = cArray.Last();
            var num = cArray.Count() - 2;
            Console.WriteLine(first.ToString() + num.ToString() + last.ToString());
            return 0;
        }
    }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;


int main(){
    ll n;cin >>n;
    string s;
    vector<ll>ans(26,INF);
    for (int i = 0; i < n; ++i) {
        vector<ll>now(26,0);
        cin >>s;
        ll m=s.size();
        for (int j = 0; j < m; ++j) {
            now[s[j] - 'a']++;
            //cout << s[i] - 'a' << endl;
        }
        for (int j = 0; j < 26; ++j) {
                ans[j] = min(ans[j], now[j]);
        }
       // for (int k = 0; k < 26; ++k) {
         //   cout <<char('a'+k)<<" "<<ans[k]<<endl;
        //}
        //cout <<'a'<<" " <<now[0]<<endl;
        //cout <<'b'<<" "<<now[1]<<endl;
    }
    for (int i = 0; i < 26; ++i) {
        if(ans[i]!=INF) {
            for (int j = 0; j < ans[i]; ++j) {
                cout << char('a' + i);
            }
        }
    }
    cout <<endl;
    return 0;
}

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

int main(){
  int N;
  std::cin >> N;
  std::vector<int> a(N);
  for(int i = 0; i < N; i++){
    std::cin >> a.at(i);
    a.at(i)--;
  }
  std::set<int> Done;
  int now = 0;
  Done.insert(0);
  bool canFinish = false;
  int count = 0;
  while(true){
    count++;
    if(a.at(now) == 1){
      canFinish = true;
      break;
    }
    auto itr = Done.find(a.at(now));
    if(itr != Done.end()) break;
    Done.insert(a.at(now));
    now = a.at(now);
  }
  if(canFinish) std::cout << count << std::endl;
  else std::cout << -1 << std::endl;
}

Measured memory_bytes: 5376
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i = (a);i < (b); i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int n;

struct futon
{
  int x, y; bool dir;
  futon(int x, int y, bool dir) : x(x), y(y), dir(dir) {}
};

vector<futon> v;
map<pair<int, int>, int> mem;

void input()
{
  v.clear();
  mem.clear();
  rep(i, n) {
    int x, y; char dir;
    cin >> x >> y >> dir;
    v.pb(futon(x, y, dir == 'x'));
    mem[mp(x, y)] = i;
  }
}

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

vector<vector<edge> > G;

const int dx1[] = {-2, -1, -1, 0, 0, 1, 1, 2};
const int dy1[] = {0, -1, 1, -1, 1, -1, 1, 0};
const int rev1[] = {-1, -1, -1, 1, 1, -1, -1, -1};

const int dx2[] = {-1, -1, 0, 0, 1, 1, 2, 2};
const int dy2[] = {-1, 0, -2, 1, -2, 1, -1, 0};
const int rev2[] = {-1, 1, -1, 1, 1, -1, 1, -1};

void gen()
{
  G.assign(n, vector<edge>());
  rep(i, n) {
    int x = v[i].x, y = v[i].y;
    if (v[i].dir) {
      rep(j, 8) {
	map<pair<int,int>,int>::iterator it = mem.find(mp(x + dx1[j], y + dy1[j]));
	if (it != mem.end()) {
	  int k = it->second;
	  if (v[k].dir) {
	    G[i].pb(edge(k, rev1[j]));
	    G[k].pb(edge(i, rev1[j]));
	  }
	}
	it = mem.find(mp(x + dx2[j], y + dy2[j]));
	if (it != mem.end()) {
	  int k = it->second;
	  if (!v[k].dir) {
	    G[i].pb(edge(k, rev2[j]));
	    G[k].pb(edge(i, rev2[j]));
	  }
	}
      }
    } else {
      rep(j, 8) {
	map<pair<int,int>,int>::iterator it = mem.find(mp(x + dy1[j], y + dx1[j]));
	if (it != mem.end()) {
	  int k = it->second;
	  if (!v[k].dir) {
	    G[i].pb(edge(k, rev1[j]));
	    G[k].pb(edge(i, rev1[j]));
	  }
	}
	it = mem.find(mp(x + dy2[j], y + dx2[j]));
	if (it != mem.end()) {
	  int k = it->second;
	  if (v[k].dir) {
	    G[i].pb(edge(k, rev2[j]));
	    G[k].pb(edge(i, rev2[j]));
	  }
	}
      }
    }
  }
}

vector<int> color;

bool bicolor(int v, int c)
{
  if (color[v])
    return color[v] == c;

  color[v] = c;
  rep(i, G[v].size())
    if (!bicolor(G[v][i].to, G[v][i].rev * c))
      return false;
  return true;
}

bool solve()
{
  color.assign(n, 0);
  rep(i, n)
    if (!color[i] && !bicolor(i, 1))
      return false;
  return true;
}

int main()
{
  while (cin >> n && n) {
    input();
    gen();
    cout << (solve() ? "Yes" : "No") << endl;
  }

  return 0;
}

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

signed main(){
    int n,k,ans=0;
    cin >>n;
    pair<int,int> a[n];
    for(int i=0;i<n;i++){
        cin >>k;
        a[i]= make_pair(k,i);
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)if((a[i].second)%2!=i%2)ans++;
    cout <<ans/2;

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int mod=998244353;
const int gs=3;
int n,m;
int f[205][20005],c[8005][8005],g[20005],h[20005];
long long ft[20005],fir[20005],inv[20005];
long long ksm(long long x,long long n)
{
	long long ans=1;
	while(n)
	{
		if(n&1) ans=ans*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return ans;
}
void NTT(int a[],int n,int ty)
{
	for(int i=0;i<n;i++)
	{
		int j=0;
		for(int m=1,k=i;m<n;m<<=1,j=(j<<1)|(k&1),k>>=1);
		if(i<j) swap(a[i],a[j]);
	}
	ft[0]=1;
	for(int m=1;m<n;m<<=1)
	{
		long long w=ksm(gs,(mod-1)/m/2);
		if(ty==-1) w=ksm(w,mod-2);
		for(int i=1;i<m;i++) ft[i]=ft[i-1]*w%mod;
		for(int k=0;k<n;k+=m<<1)
		for(int i=k;i<k+m;i++)
		{
			long long t0=a[i],t1=a[i+m]*ft[i-k]%mod;
			a[i]=(t0+t1)%mod,a[i+m]=(t0-t1+mod)%mod;
		}
	}
	if(ty==-1)
	{
		long long rev=ksm(n,mod-2);
		for(int i=0;i<n;i++) a[i]=a[i]*rev%mod;
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<=n+2;i++)
	{
		c[i][0]=1;
		for(int j=1;j<=i;j++)
		{
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
		}
	}
	fir[0]=fir[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=n+2;i++) fir[i]=fir[i-1]*i%mod;
	inv[n+2]=ksm(fir[n+2],mod-2);
	for(int i=n+1;i>=1;i--) inv[i]=inv[i+1]*(i+1)%mod;
	int l=1<<(int)ceil(log2(n+n+1));
	for(int i=0;i<=n;i++) f[m][i]=c[n][n-i];
	for(int i=1;i<=n;i++) h[i]=inv[i+2]%mod;
	NTT(h,l,1);
	for(int i=m-1;i>=0;i--) 
	{
		for(int j=0;j<=n;j++) g[j]=f[i+1][j]*fir[n-j+2]%mod;
		for(int j=n+1;j<l;j++) g[j]=0;
		NTT(g,l,1);
		for(int j=0;j<l;j++) g[j]=1ll*g[j]*h[j]%mod;
		NTT(g,l,-1);
		for(int j=0;j<=n;j++) f[i][j]=(g[j]*inv[n-j]%mod+1ll*f[i+1][j]*(c[n-j+1][2]+1)%mod)%mod;
	}
	printf("%lld\n",f[0][n]);
}

Measured memory_bytes: 166304
import itertools
import math
import copy

N, A, B, C = map(int, input().rstrip().split())

pattern = [list(itertools.combinations(range(x), 3)) for x in range(3, N+1)]

def stretch_shortening(sticks, A, B, C):
    min_cost = 1e10
    
    for i1, i2, i3 in pattern[len(sticks) - 3]:
        cost = abs(sticks[i1] - A) + abs(sticks[i2] - B) + abs(sticks[i3] - C)
        if min_cost > cost:
            min_cost = cost
    return min_cost

temp_set = set()
def connect(sticks, A, B, C):
    
    min_cost = stretch_shortening(sticks, A, B, C) + (N - len(sticks)) * 10
    
    if len(sticks) <= 3:
        return min_cost
    
    for i1, i2 in itertools.combinations(range(len(sticks)), 2):
        if sticks[i1] + sticks[i2] > sticks[-1] and sticks[-1] >= C:
            continue
        if sticks[i1] <= 10 or sticks[i2] <= 10:
            continue
        
        copied_sticks = copy.copy(sticks)
        copied_sticks[i1] += copied_sticks[i2]
        copied_sticks.pop(i2)
        copied_sticks = sorted(copied_sticks)
        
        len_set = len(temp_set)
        temp_set.add(''.join(["{:05d}".format(x) for x in copied_sticks]))
        if len_set == len(temp_set):
            continue
        
        min_cost_connect = connect(copied_sticks, A, B, C)

        if min_cost_connect < min_cost:
            min_cost = min_cost_connect
    
    return min_cost

sticks = []
for _ in range(N):
    sticks.append(int(input()))
sticks = sorted(sticks)

min_cost = connect(sticks, C, B, A) #, 1e10)
#min_cost = stretch_shortening(sticks, A, B, C)
#print(pattern)

print(min_cost)


Measured memory_bytes: 3972
stringSplit :: String -> [String]
stringSplit string
    | otherwise = _stringSplit "" string

_stringSplit :: String -> String -> [String]
_stringSplit to from
    | from == ""        = [to]
    | head from == ' '  = (if to == "" then [] else [to]) ++ (_stringSplit "" $ tail from)
    | otherwise         = _stringSplit (to ++ [head from]) $ tail from

myGcd x y
    | y == 0    = x
    | otherwise = myGcd y $ x `mod` y

data Array = EmptyArray | ArrayNode {index :: Int, arrayValue :: Int, leftArray :: Array, rightArray :: Array} deriving (Show, Read, Eq, Ord)

newArray :: Int -> Int -> Array
newArray l r
    | r - l == 0 = ArrayNode l 0 EmptyArray EmptyArray
    | r - l == 1 = ArrayNode r 0 (newArray l l)         EmptyArray
    | otherwise  = ArrayNode m 0 (newArray l (m - 1))   (newArray (m + 1) r)
    where
        m = (l + r) `div` 2

valueOf :: Array -> Int -> Int
valueOf (ArrayNode index value leftArray rightArray) ind
    | index == ind = value
    | index <  ind = valueOf rightArray ind
    | index >  ind = valueOf leftArray  ind

replace :: Array -> Int -> Int -> Array
replace (ArrayNode index value leftArray rightArray) ind val
    | index == ind = ArrayNode index val   leftArray                    rightArray
    | index <  ind = ArrayNode index value leftArray                    (replace rightArray ind val)
    | index >  ind = ArrayNode index value (replace leftArray ind val)  rightArray

turnListToArray :: [Int] -> Array
turnListToArray xxs
    | otherwise = _turnListToArray (newArray 0 (len + 1)) xxs 1 len
    where
        len = length xxs 

_turnListToArray :: Array -> [Int] -> Int -> Int -> Array
_turnListToArray array xxs l r
    | l > r     = array
    | otherwise = _turnListToArray (replace array l x) xs (l + 1) r
    where
        (x : xs) = xxs

--------------------------------------------------

leftGcd :: Array -> Array -> Int -> Int -> Array
leftGcd ret from l r
    | l > r     = ret
    | otherwise = leftGcd (replace ret l (myGcd (valueOf from l) (valueOf ret (l - 1)))) from (l + 1) r

rightGcd :: Array -> Array -> Int -> Int -> Array
rightGcd ret from l r
    | l > r     = ret
    | otherwise = rightGcd (replace ret r (myGcd (valueOf from r) (valueOf ret (r + 1)))) from l (r - 1)

getAns :: Array -> Array -> Int -> Int -> Int
getAns left right i n
    | i > n     = 0
    | otherwise = max (myGcd (valueOf left (i - 1)) (valueOf right (i + 1))) (getAns left right (i + 1) n)

_solve = do
    inputN <- getLine
    inputA <- getLine
    let
        n = read inputN
        a = map read (stringSplit inputA)
        arr = turnListToArray a
        left = leftGcd (newArray 0 n) arr 1 n
        right = rightGcd (newArray 1 (n + 1)) arr 1 n
        ans = getAns left right 1 n
    putStr $ show ans
    return ()

--------------------------------------------------

solve t
    | t == 0 = do
        return ()
    | otherwise = do
        _solve
        putStr "\n"
        solve (t - 1)

main = do
    -- t <- getLine
    solve (1)
    return ()

Measured memory_bytes: 192892
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

void trace(vector<int>& a) {
    for (int i = 0; i < a.size(); i++) {
        if (i > 0) {
            cout << " ";
        }
        cout << a[i];
    }
    cout << endl;
}

void selecitonSort(vector<int>& a) {
    int n = a.size();
    int count = 0;
    for (int i = 0; i < n; i++) {
        int mini = i;
        for (int j = i; j < n; j++) {
            if (a[j] < a[mini]) {
                mini = j;
            }
        }
        if (mini != i) {
            swap(a[i], a[mini]);
            count++;
        }
    }
    trace(a);
    cout << count << endl;
}

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    selecitonSort(a);
    return 0;
}

Measured memory_bytes: 3204
while 1:
    r,_=map(int,input().split())
    if r==0:break
    prv=[input().split() for _ in[0]*r]
    prv=map(list,zip(*prv))
    now=[int(''.join(x),2)for x in prv];a=0
    for i in range(1<<r):
        b=0
        for j in now:
            c=bin(i^j).count('1')
            b+=c if c>r//2else r-c
        a=max(a,b)
    print(a)

Measured memory_bytes: 9340