akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main(void) {
    vector< vector<int> > A(3, vector<int>(3));
    vector< vector<int> > ans(3, vector<int>(3));
    for(int i=0; i<3; i++) {
        for(int j=0; j<3; j++) {
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;
    while(N--) {
        int b;
        cin >> b;
        for(int i=0; i<3; i++) {
            for(int j=0; j<3; j++) {
                if(A[i][j] == b) {
                    ans[i][j] = 1;
                }
            }
        }
    }

    bool flag = false;
    for(int i=0; i<3; i++) {
        int cnt = 0;
        for(int j=0; j<3; j++) {
            cnt += ans[i][j];
        }
        if(cnt == 3) {
            flag = true;
        }
    }
    for(int i=0; i<3; i++) {
        int cnt = 0;
        for(int j=0; j<3; j++) {
            cnt += ans[j][i];
        }
        if(cnt == 3) {
            flag = true;
        }
    }

    if(ans[0][0] + ans[1][1] + ans[2][2] == 3) {
        flag = true;
    }
    if(ans[0][2] + ans[1][1] + ans[2][0] == 3) {
        flag = true;
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int c = (n - 1) * (n - 2) / 2;
    if(k > c) {
        cout << -1 << endl;
        return 0;
    }
    int m = n - 1 + c - k;
    cout << m << endl;
    for(int i = 0; i < n - 1; i++) {
        cout << 1 << " " << i + 2 << endl;
    }
    c -= k;
    if(c == 0) {
        return 0;
    }
    for(int i = 2; i <= n; i++) {
        for(int j = i + 1; j <= n; j++) {
            cout << i << " " << j << endl;
            c--;
            if(c == 0) {
                break;
            }
        }
        if(c == 0) {
            break;
        }
    }
}


Measured memory_bytes: 256
import fractions

n,x=map(int,input().split())
a=list(map(int,input().split()))

b=[]
for i in a:
    b.append(abs(x-i))

if n==1:
    print(abs(x-a[0]))

else:
    ans=fractions.gcd(b[0],b[1])

    for i in range(2,n):
        ans = fractions.gcd(ans ,b[i])

    print(ans)


    





Measured memory_bytes: 16244
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  int q; cin >> q;
  rep(_, q) {
    int k; cin >> k;
    ll d = 0, m = 0, cnt = 0, ans = 0;
    rep(i, n) {
      if(i >= k) {
        if(s[i-k] == 'D') {
          d--;
          cnt -= m;
        } else if(s[i-k] == 'M') {
          m--;
        }
      }
      if(s[i] == 'D') {
        d++;
      } else if(s[i] == 'M') {
        m++;
        cnt += d;
      } else if(s[i] == 'C') {
        ans += cnt;
      }
    }
    cout << ans << endk;
  }
  return 0;
}


Measured memory_bytes: 4240
class _Node {
  constructor(id, parent, children) {
    this.id = id;
    this.parent = parent;
    this.children = children;
  }
  get type() {
    if (this.parent === null) return 'root';
    if (this.children.length === 0) return 'leaf';
    return 'internal node';
  }
  get depth() {
    const getDepth = (node, i) => {
      return node.parent === null ? i : getDepth(node.parent, i + 1);
    };
    return getDepth(this, 0);
  }
  toString() { return `node ${this.id}: parent = ${this.parent !== null ? this.parent.id : -1}, depth = ${this.depth}, ${this.type}, [${this.children.map(n => n.id).join(', ')}]`; }
};

class Tree {
  constructor(n) { this.nodes = []; }
  static get Node() { return _Node; }
  add(id, childrenIds) {
    let node = this.find(id);
    childrenIds.forEach((cid) => {
      let c = this.find(cid);
      c.parent = node;
      c.id = cid;
      node.children.push(c);
    })
  }
  find(id) { return this.nodes[id] || (this.nodes[id] = new Tree.Node(id, null, []));}
  print() { console.log(this.nodes.sort((a, b) => a.id - b.id).map(n => n.toString()).join('\n')); }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  let tree = new Tree(n);
  let id;
  lines.map(l => l.split(' ').map(Number)).forEach(function(line) {
    id = line.shift();
    line.shift();
    tree.add(id, line);
  });
  tree.print();
})();



Measured memory_bytes: 148092
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int jQuot = N /7;
        boolean can = false;

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

            if((N - (i * 7)) % 4 == 0 ) {
                can = true;
            }
        }
        System.out.println(can ? "Yes" : "No");
    }
}

Measured memory_bytes: 21844
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int arr[500010];
int count = 0;
int n;
void Merge(int start, int mid, int end) {
    int sta = start;
    int SecStart = mid + 1;
    int tmpSize = (end - start + 1);
    int *tmp = (int *) malloc(sizeof(int) * tmpSize);
    int index = 0;
    while (start <= mid && SecStart <= end) {
        count++;
        if (arr[start] > arr[SecStart]) {
            tmp[index++] = arr[SecStart++];
        } else {
            tmp[index++] = arr[start++];
        }
    }
    while (SecStart <= end) {
        count++;
        tmp[index++] = arr[SecStart++];
    }
    while (start <= mid) {
        count++;
        tmp[index++] = arr[start++];
    }
    memcpy(arr + sta, tmp, sizeof(int) * tmpSize);
    free(tmp);

}

void MergeSort(int start, int end) {
    if (start < end) {
        int mid = (start + end) / 2;
        MergeSort(start, mid);
        MergeSort(mid + 1, end);
        Merge(start, mid, end);
    }
}

int main() {

    //freopen("../in.txt", "r", stdin);

    int i;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &(arr[i]));
    }
    bool flag = true;
    MergeSort(0, n - 1);
    for (i = 0; i < n; i++) {
        if (flag) {
            flag = false;
        } else {
            printf(" ");
        }
        printf("%d", arr[i]);
    }
    printf("\n%d\n", count);

    return 0;
}



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


int main(){

    int S,N;

    scanf("%d %d",&S,&N);
    if(S>N){
        printf("safe");
    }
    else{
        printf("unsafe");
    }


    return 0;
}



Measured memory_bytes: 1736
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

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

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  string s; cin >> s;
  if (s.find("AC") == string::npos) {
    No();
  } else {
    Yes();
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

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


const long long int mod = 1000000007;
const long long int INF = 1e18;




long long int N,M;
string a;

int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>M;
    cout<<N*(N-1)/2+M*(M-1)/2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i,x,n;
  cin >> x >> n;
  vector<int> vec(n);
  for(i=0; i<n; i++){
    cin >> vec[i]; 
  }
  
  for(i=1; i<=100; i++){
    if(count(vec.begin(), vec.end(), x) == 0){
      cout << x << endl;
      break;
    }
    else if(count(vec.begin(), vec.end(), x-i) == 0){
      cout << x-i << endl;
      break;    
    }
    else if(count(vec.begin(), vec.end(), x+i) == 0){
      cout << x+i << endl;
      break;    
    }
  }
}

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

long long a, b, c, d, n, co[5], cost2=INT_MAX, cost1=INT_MAX, ans;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> a >> b >> c >> d >> n;
    co[0]=a*8;
    co[1]=b*4;
    co[2]=c*2;
    co[3]=d;
    for(int i=0; i<4; i++)
        cost2 = min(cost2, co[i]);
    co[0]=a*4;
    co[1]=b*2;
    co[2]=c;
    for(int i=0; i<3; i++)
        cost1 = min(cost1, co[i]);

    while(n>0) {
        if(n-2>=0) {
            n-=2;
            ans += cost2;
        }
        else {
            n--;
            ans += cost1;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

    int result = 0;
    rep(i, s.size() - 1)
    {
        if (s[i] != s[i + 1]) {
            result++;
        }
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
 
int main(void)
{
 int d, t, s;
  
  scanf("%d %d %d", &d, &t, &s);
  
  double time_d;
  
  time_d = (double) d / (double) s;
  
  if (time_d > t){
    printf("No");
  }
  else{
    printf("Yes");
  }
  return 0;
}

Measured memory_bytes: 2108
#include<stdio.h>
#include<stdlib.h>
  
int insertionSort(int *A, int n, int g) {
  int i, j, k;
  int count = 0;
  
  for(i = g; i < n; i++) {
    k = A[i];
    j = i-g;
    while(j >= 0 && A[j] > k) {
      A[j+g] = A[j];
      j = j-g;
      count++;
    }
    A[j+g] = k;
  }
  return count;
}
  
int shellSort(int *A, int n, int m, int *G) {
  int i;
  int count = 0;
  
  for(i = 0; i < m; i++) {
    count += insertionSort(A, n, G[i]);
  }
  return count;
}
  
int main() {
  int n, m, i;
  int count = 0;
  int *A;
  int G[100], *L;
  
  scanf("%d", &n);
  A = malloc(n*sizeof(int));
  for(i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  
  G[0] = 1;
  for(i = 1; i < 100; i++) {
    G[i] = 3*G[i-1]+1;
  }
  
  m = 1;
  while(G[m] < n && m < 100) {
    m++;
  }
  
  L = malloc(m*sizeof(int));
  for(i = m; i >= 0; i--) {
    L[m-i] = G[i-1];
  }
  
  count = shellSort(A, n, m, L);
  
  printf("%d\n", m);
  for(i = 0; i < m; i++) {
    printf("%d", L[i]);
    if(i != m-1) {
      printf(" ");
    }
  }
  printf("\n");
  
  printf("%d\n", count);
  
  for(i = 0; i < n; i++) {
    printf("%d\n", A[i]);
  }
  
  return 0;
}

Measured memory_bytes: 4512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,x;
  int ans=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(x==500*i+100*j+50*k){
          ans++;
        }
      }
    }
  }
  
  cout<<ans<<endl;
  
  
}

Measured memory_bytes: 256
def changer(x):
    if x=='A':
        return 1
    elif x=='B':
        return 2
    elif x=='C':
        return 3
    elif x=='D':
        return 4
    elif x=='E':
        return 5
    elif x=='F':
        return 6
    else:
        return 0
a,b=map(str,input().split())
if changer(a)>changer(b):
    print('>')
elif changer(a)==changer(b):
    print('=')
else:
    print('<')

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

using namespace std;

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

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------

ll f(ll n, ll b) {
    if (n < b) return n;
    else return f(n / b, b) + n % b;
}

int main() {
    ll n, s;
    cin >> n >> s;

    if (n == s) {
        cout << n + 1 << endl;
        return 0;
    }

    REP(b, 2, sqrt(n) + 1) {
        if (f(n, b) == s) {
            cout << b << endl;
            return 0;
        }
    }

    for (ll p = ceil(sqrt(n)) - 1; p >= 1; p--) {
        ll b = (n - s) / p + 1;
        if (b < 2) continue;
        if (f(n, b) == s) {
            cout << b << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>

#define INF 1<<29

using namespace std;

int main(void) {
	long long n, a, b;
	cin >> n >> a >> b;
	if (n == 1) {
		if (a == b) {
			cout << 1;
		}
		else {
			cout << 0;
		}
	}
	else {
		if (a > b) {
			cout << 0;
		}
		else {
			cout << (n - 2)*(b - a) + 1;
		}
	}
	return 0;
	
}

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

int main()
{
  string W, T;
  cin >> W;
    
  int count = 0, size = 0, i;
    
  while(1)
  {
    T = "END_OF_TEXT";
    cin >> T;
      
    if( T == "END_OF_TEXT" ) break;
    
    size = T.size();
      
    for( i = 0; i < size; i++ )
    {
      if( 'A' <= T[i] && T[i] <= 'Z' )
      {
        T[i] += 'a' - 'A';
      }
    }
      
    if( T == W )
    {
      count++;
    }
  }
    
  cout << count << endl;
    
  return 0;
}


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

int main()
{
	int a2,a3,b1,b2,b3;
	int x[4][4];
	
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			cin>>x[i][j];
		}
	}
	
	b1=x[1][1];
	b2=x[1][2];
	b3=x[1][3];
	
	a2=x[2][1]-b1;
	a3=x[3][1]-b1;
	
	if(a2+b2==x[2][2]&&a2+b3==x[2][3]&&\
	a3+b2==x[3][2]&&a3+b3==x[3][3])
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	
	cout<<"No"<<endl;
}

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

int main()
{
	int a, b, k; cin >> a >> b >> k;
	
	vector<int> c;

	for (int i = a; i <= b; i++) {

		if (i - a + 1 <= k  || b - i + 1 <= k) c.push_back(i);

	}

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

	for (int i = 0; i < c.size(); i++) cout << c[i] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long a, b, c, d = 0, e = 0, f = 0, g = 0;
	cin >> a >> b >> c;
	if (a == b && b == c && a == c && a % 2 == 0) {
		cout << "-1" << endl;
	}
	else {
		while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
			e = a;
			f = b;
			g = c;
			a = f / 2 + g / 2;
			b = e / 2 + g / 2;
			c = e / 2 + f / 2;
			d++;
		}
		cout << d << endl;
	}
	cin >> e;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    if(a>b){
        printf("a > b\n");
    }else if(a<b){
        printf("a < b\n");
    }
    else{
        printf("a == b\n");
    }
    return 0;
}


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

int main() {
    string S;
    cin >> S;
    int l = S.size();
    int sum_max = 0;
    int k = 0;

    for (int i = 0; i < l; i++) {
        if (S.at(i) == 'A' || S.at(i) == 'G' || S.at(i) == 'T' || S.at(i) == 'C') {
            k++;
        }

        else {
            sum_max = max(sum_max,k);
            k = 0;
        }

    }

    sum_max = max(sum_max,k);

    cout << sum_max << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int r, D, x2000;
  int i;
  
  scanf("%d %d %d",&r, &D, &x2000);
  
  for(i = 1; i <= 10; i++)
    printf("%d\n", x2000 = (r*x2000-D));
  
  return 0;
}

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

#define M 1046527
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

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

int find(char str[]){

  long long key, i, h;
  key = getKey(str);
  for(i=0; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h], str) == 0) return 1;
    else if (strlen(H[h]) == 0) return 0;
  }

  return 0;

}

int insert(char str[]){

  long long key, i, h;
  key = getKey(str);

  for(i=0; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h], str) == 0) return 1;
    else if (strlen(H[h]) == 0){
      strcpy(H[h], str);
      return 0;
    }
  }    
  return 0;

}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
  scanf("%d", &n);
    
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
	
    if ( com[0] == 'i' ){
      insert(str);
    } else {
      if (find(str)){
	printf("yes\n");
      } else {
	printf("no\n");
      }
    }
  }

  return 0;
}

Measured memory_bytes: 14916
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll N;string S;cin>>N>>S;
    ll cr=0,cg=0,cb=0;
    REP(i,N){
        (S[i]=='R'?cr:S[i]=='G'?cg:cb)++;
    }
    //cout<<cr<<" "<<cg<<" "<<cb<<"\n";
    ll cnt=cr*cg*cb;
    
    for(ll i=0;i<N-2;i++){
        for(ll k=1;i+2*k<N;k++)
        if((S[i]!=S[i+k] and S[i+k]!=S[i+2*k] and S[i]!=S[i+2*k]))cnt--;
    }
    cout<<cnt<<"\n";
}

Measured memory_bytes: 3588
#include <iostream>
#include <math.h>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstdlib>
#include <unordered_map>
#include <numeric>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

typedef long long ll;
typedef pair<int, int> P;

typedef long long ll;
typedef pair<int, int> P;

const ll mod = 1000000007;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

ll dp[51][51][2510];

int main() {
    
    ll n, K;
    cin >> n >> K;

    for(int i = 0; i < 51; i++){
        for(int j = 0; j < 51; j++){
            fill(dp[i][j], dp[i][j]+2510, 0);
        }
    }

    dp[0][0][0] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= n; j++){
            for(int k = 0; k <= n * n; k++){
                ll v = 0;
                if(k - 2 * j >= 0){
                    ll v1 = dp[i-1][j][k-2*j];     // i番目同士でペアを作る
                    ll v2 = mul(j, dp[i-1][j][k-2*j]);   // 上のi番目と保留している下のものとでペア。下のi番目は保留
                    ll v3 = mul(j, dp[i-1][j][k-2*j]);   // 上のi番目と保留している下のものとでペア。下のi番目は保留
                    v = add(v, add(v1, add(v2, v3)));
                }
                if(k - 2 * (j+1) + 2 >= 0) {
                    ll v4 = mul((j+1) * (j+1), dp[i - 1][j + 1][k - 2 * (j+1) + 2]);
                    v = add(v, v4);
                }
                if(k - 2 * (j-1) - 2  >= 0 && j-1 >= 0){
                    ll v5 = dp[i-1][j-1][k - 2 * (j-1) - 2];
                    v = add(v, v5);
                }
                dp[i][j][k] = v;
            }
        }
    }
//    cout << dp[1][1][2] << endl;
    cout << dp[n][0][K] << endl;


    return 0;
}

Measured memory_bytes: 51456
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
using namespace std;

int main(int argc, char const *argv[]) {

 char s[5];
 int n, count=0, ret;


 ret = scanf("%d", &n);
 sprintf(s, "%d", n);
 for(int i=0; i<4; i++){
   if(s[i]=='2') count++;
 }
 printf("%d\n", count);

 return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using i64 = long long;



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

  int d,n;
  cin>>d>>n;

  int k=n;
  if (k==100) k++;
  rep(i,0,d) k*=100;
  cout<<k<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
#define EN cout<<endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


template <int MOD>
struct ModInt {
    int val;
 
    // constructor
    ModInt(ll v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };
 
    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }
 
    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(ll n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }
 
    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = ll(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }
 
    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }
 
    // I/O
    friend istream& operator>>(istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend ostream& operator<<(ostream& os, const ModInt& x) noexcept { return os << x.val; }
};
constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;


int main() {
    ll n,k;
    mint ans=0,c[202020]={};
    cin>>n>>k;
    REPR(i,1,k+1){
      ll nn=1,f=0,a=i;
      c[i]=mint(k/i).pow(n);
      while(a+i<=k){
        a+=i;
        c[i]-=c[a];
        
      }
      ans+=c[i]*i;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 4428
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn gcd (x:i64,y:i64) -> i64 {
    if x == 0 {
        return y;
    }else{
        return gcd(y%x,x);
    }
}

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let c: i64 = read();
    let d: i64 = read();

    let g = gcd(c,d);
    let l = (c*d)/g;

    //全体 - cで割り切れる数(倍数)の個数 - dで割り切れる数(倍数)の個数 + c*dで割り切れる数(倍数)の個数
    let all = b - b/c - b/d + b/l;
    let a_made = (a-1) - (a-1)/c - (a-1)/d + (a-1)/l;

    println!("{}", all - a_made);
}


Measured memory_bytes: 4352
function Main(input) {
  input = input.split('\n');
  let temp = [];
  for (let i in input) {
    temp.push(input[i].split(' '))
  }

  const N = parseInt(temp[0][0])
  const M = parseInt(temp[0][1])
  const Q = parseInt(temp[0][2])

  temp.shift();

  let [a, b, c, d] = [[], [], [], []];
  for (let i in temp) {
    [a[i], b[i], c[i], d[i]] = [parseInt(temp[i][0]), parseInt(temp[i][1]), parseInt(temp[i][2]), parseInt(temp[i][3])]
  }

  let A = [];

  function recursive(current){
    if (current.length >= N){
      A.push(current);
      return;
    }
    for (let i = 1; i <= M; i++){
      if(!current.length){
        recursive([i]);
      } else if (current[current.length - 1] <= i){
        recursive([...current, i])
      }
    }
  }

  recursive([]);

  let max = 0; // Ab - Aa = c
  for (let value of A){
    let sum = 0;
    for (let i = 0; i < Q; i++) {
      if (value[b[i] - 1] - value[a[i]- 1] === c[i]){
        sum += d[i]
      }
    }
    if (max <= sum){
      max = sum;
    }
  }

  console.log(max)
}

// Main('3 4 3\n1 3 3 100\n1 2 2 10\n2 3 2 10');

// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 92212
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000
using namespace std;
int main()
{
    int n;
    char c;
    string s;
    cin >> n;
    rep(i, n)
    {
        cin >> c;
        s += c;
    }
    rep(i, 10000)
    {
        //cout << s.find(to_string(i)) << " " << to_string(i) << endl;
        if (s.find(to_string(i)) == -1)
        {
            cout << i << endl;
            break;
        }
    }
    return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

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

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

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


constexpr ll MAX = 1000000;
constexpr ll MOD = mod2;


ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

ll COM(int n, int k) {
	if (n < k || n < 0 || k < 0) return (0);
	return (fac[n] * (finv[k] * finv[n - k] % MOD) % MOD);
}


void Main() {
	ll N, M, K;
	cin >> N >> M >> K;
	ll sum = 0;
	ll weight = M;

	COMinit();
	for (ll i = N-1; i >= 0; i--) {
		if (i <= K) (sum += weight * COM(N-1, i)) %= mod2;
		(weight *= M-1) %= mod2;
	}
	cout << sum << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 27096
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main() {
    int h, w, d;
    cin >> h >> w >> d;
    vector<vector<int>> a(h, vector<int>(w));
    vector<pair<int, int>> xy(h*w+1);
    rep(i, h)rep(j, w) {
        cin >> a[i][j];
        xy[a[i][j]] = make_pair(i, j);
    }

    vector<ll> b(h*w+1, 0LL);
    for(int i=d+1; i<=h*w; i++){
        ll x = xy[i].first, y = xy[i].second;
        ll px = xy[i-d].first, py = xy[i-d].second;

        b[i] = b[i-d] + abs(x-px) + abs(y-py);
    }
    int q;
    cin >> q;
    int l, r;
    rep(i, q){
        cin >> l >> r;
        cout << b[r] - b[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
using namespace std;
int main(){
	int n, k;
	string s;
	cin >> n >> s >> k;
	for (int i=0; i<s.size(); i++) {
		if(s[i]!=s[k-1]){
			s[i]='*';
		}
	}cout << s << endl;
}


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

int main(void)
{
    int n, m, p, score[1000];
    int max;
    int i, j;
    
    
    while (1){
        memset(score, 0, sizeof(score));
        scanf("%d%d", &n, &m);
        if (n == 0 && m == 0){
            break;
        }
        
        for (i = 0; i < m; i++){
            for (j = 0; j < n; j++){
                scanf("%d", &p);
                score[j] += p;
            }
        }
        max = 0;
        for (j = 0; j < n; j++){
            if (max < score[j]){
                max = score[j];
            }
        }
        printf("%d\n", max);
    }
    return (0);
}



Measured memory_bytes: 2080
def main():
    n = int(input())
    AB = [[int(e) for e in input().split()] for i in range(n)]

    Ma = sorted([ab[0] for ab in AB])
    Mb = sorted([ab[1] for ab in AB])
    if n % 2 == 1:
        mi = Ma[((n + 1) // 2) - 1]
        ma = Mb[((n + 1) // 2) - 1]
        print(ma - mi + 1)

    else:
        mi = (Ma[n // 2 - 1] + Ma[n // 2])
        ma = (Mb[n // 2 - 1] + Mb[n // 2])
        print(ma - mi + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 139024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

struct Dinic {
    struct Edge {int to, rev, cap;};
    vector<vector<Edge>> Graph;
    vector<int> dist, iter;
    Dinic(int v) : Graph(v) {}
    void AddEdge(int from, int to, int cap) {
        Graph[from].push_back({to, SZ(Graph[to]), cap});
        Graph[to].push_back({from, SZ(Graph[from]) - 1, 0});
    }
    bool bfs(int s, int t) {
        dist.assign(SZ(Graph), -1);
        queue<int> q;
        dist[s] = 0;
        q.push(s);
        while (!q.empty() && dist[t] == -1) {
            int v = q.front();
            q.pop();
            for (const auto &e: Graph[v]) {
                if (e.cap > 0 && dist[e.to] == -1) {
                    dist[e.to] = dist[v] + 1;
                    q.push(e.to);
                }
            }
        }
        return dist[t] != -1;
    }
    int dfs(int now, int t, int mn) {
        if (now == t) return mn;
        for (int &i = iter[now]; i < SZ(Graph[now]); ++i) {
            Edge &e = Graph[now][i];
            if (e.cap > 0 && dist[now] + 1 == dist[e.to]) {
                int d = dfs(e.to, t, min(mn, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    Graph[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    int MaxFlow(int s, int t) {
        int ans = 0;
        while (bfs(s, t)) {
            iter.assign(SZ(Graph), 0);
            int f = 0;
            while ((f = dfs(s, t, 1001001001)) > 0) ans += f;
        }
        return ans;
    }
};

int main() {
    int h, w;
    cin >> h >> w;
    int s = 0, t = 0;
    vector<vector<char>> a(h, vector<char>(w));
    REP(i, h) REP(j, w) {
        cin >> a[i][j];
        if (a[i][j] == 'S') s = i * w + j;
        if (a[i][j] == 'T') t = i * w + j;
    }
    if (s / w == t / w || s % w == t % w) {
        cout << -1 << "\n";
        return 0;
    }
    
    Dinic D(h * w * 2 + h + w);
    REP(i, h) REP(j, w) {
        if (a[i][j] == '.') continue;
        D.AddEdge(h * w * 2 + i, i * w + j, 1000000000);
        D.AddEdge(h * w * 2 + h + j, i * w + j, 1000000000);
        D.AddEdge(i * w + j, i * w + j + h * w, 1);
        D.AddEdge(i * w + j + h * w, h * w * 2 + i, 1000000000);
        D.AddEdge(i * w + j + h * w, h * w * 2 + h + j, 1000000000);
    }
    cout << D.MaxFlow(s + h * w, t) << "\n";
    return 0;
}


Measured memory_bytes: 5712
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

int main()
{
    long int n;
    long int a[200000];
    
    cin >> n;
    long int top = 1;
    long int c = 0;
    
    for (long int i = 0;i < n;i++){
        cin >> a[i];
        if (a[i] == top){
            top++;
        }
        else {
            c++;
        }
    }
    
    if (c == n){
        c = -1;
    }
    
    cout << c << endl;
}


Measured memory_bytes: 1792
N = int(input())

i = 1
f = lambda x : (x//2) if x%2 == 0 else x*3+1
l = [N]
val = N

while True:
    val = f(val)
    if val in l:
        print(i+1)
        break
    else:
        l.append(val)    
        i+=1
    

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N;
vector<long long> A,B;
int mass[20];
ll ans = 1e18;

ll calc(){
    for(int i = 0;i < N;i++){
       // cout<<mass[i]<<" ";
    }
  //  cout<<endl;
    int odd = 0, even = 0;
    vector<pair<int, int>> v,v1,v2;
    for(int i = 0;i < N;i++){
        if(i % 2 == 0){
            if(mass[i]){
                odd++;
                v1.push_back({B[i], i});
            }else{
                even++;
                v2.push_back({A[i], i});
            }
        }else{
            if(mass[i]){
                even++;
                v2.push_back({B[i], i});
            }else{
                odd++;
                v1.push_back({A[i], i});
            }
        }
    }

    if(odd != N / 2)return 1e18;
    if(even != (N+1) / 2)return 1e18;

    vector<int> ww;
    int od = 0, ev = 0;

    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    for(int i = 0;i < N;i++){
        if(i%2 == 0){
            v.push_back(v2[i/2]);
        }else{
            v.push_back(v1[i/2]);
        }
    }
    for(int i = 0;i < N-1;i++){
        if(v[i].first > v[i+1].first)return 1e18;
    }
    ll cnt = 0;

    for(int i = N-1;i >= 0;i--){
        for(int j = 0;j < i;j++){
            if(v[j].second > v[i].second)cnt++;
        }
    }
    return cnt;
}

int zrk(int i){
    if(N == i){
        ans = min(ans, calc());
        return 0;
    }
    mass[i] = 0;zrk(i+1);
    mass[i] = 1;zrk(i+1);
}

void solve(long long _N, std::vector<long long> _A, std::vector<long long> _B){
    N = _N;
    A = _A;
    B = _B;
    zrk(0);
    if(ans == 1e18){
        cout<<-1<<endl;
        return;
    }
    cout<<ans<<endl;
}

int main(){
    long long _N;
    scanf("%lld",&_N);
    std::vector<long long> _A(_N);
    for(int i = 0 ; i < _N ; i++){
        scanf("%lld",&_A[i]);
    }
    std::vector<long long> _B(_N);
    for(int i = 0 ; i < _N ; i++){
        scanf("%lld",&_B[i]);
    }
    solve(_N, std::move(_A), std::move(_B));
    return 0;
}


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

vector<vector<int> > d(10, vector<int>(10));

void warshall_floyd(void){
    rep(k, 10)rep(i, 10)rep(j, 10) d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
}
int main(void){
    int h, w;
    cin>>h>>w;
    vector<vector<int> > v(h, vector<int>(w));
    rep(i, 10) rep(j, 10) cin>>d[i][j];
    rep(i, h)  rep(j, w) cin>>v[i][j];
    warshall_floyd();
    int ans=0;
    rep(i, h)rep(j, w){
        if(v[i][j]==-1) continue;
        ans+=d[v[i][j]][1];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 100005
using namespace std;
const int inf=1e9;
struct trie{
	int mn,mx;
}t[N<<2];
int n,m,Q,a[N],sum[N],fa[N][25],b[N];
void build(int k,int l,int r){
	if(l==r){
		t[k].mx=-inf;t[k].mn=inf;
		if(l&1) t[k].mx=a[l]-sum[l-1];
		else t[k].mn=m-sum[l-1]-a[l];
		return;
	}
	int mid=l+r>>1;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
	t[k].mx=max(t[k<<1].mx,t[k<<1|1].mx);
	t[k].mn=min(t[k<<1].mn,t[k<<1|1].mn);
}
int query(int k,int l,int r,int L,int R,int A){
	if(L>R) return n+1;
	if(t[k].mx<A&&t[k].mn>A) return n+1;
	if(l==r) return l;
	int mid=l+r>>1,ans=n+1;
	if(L<=mid) if((ans=query(k<<1,l,mid,L,R,A))!=n+1) return ans;
	if(R>mid) ans=query(k<<1|1,mid+1,r,L,R,A);
	return ans;
}
int get(int x){
	int l=1,r=n,mid,ans=0;
	while(l<=r){
		mid=l+r>>1;
		if(b[mid]<=x) ans=mid,l=mid+1;
		else r=mid-1;
	}
	return ans;
}
int main(){
	scanf("%d%d",&m,&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),b[i]=a[i];
	for(int i=n;i;i--) a[i]=a[i]-a[i-1];
	for(int i=1,op=-1;i<=n;i++,op=-op) sum[i]=sum[i-1]+a[i]*op;
	build(1,1,n);
	for(int i=0;i<=20;i++) fa[n+1][i]=n+1;
	for(int i=n;i;i--){
		int A=(i&1)?0:m;
		fa[i][0]=query(1,1,n,i+1,n,A-sum[i]);
		for(int p=1;p<=20;p++) fa[i][p]=fa[fa[i][p-1]][p-1];
	}
	scanf("%d",&Q);
	for(int i=1,y,A;i<=Q;i++){
		scanf("%d%d",&y,&A);
		int x=get(y);
		int pos=query(1,1,n,1,n,A);
		if(pos>x){
			int ans=A+sum[x]+((x&1)?y-b[x]:b[x]-y);
			ans=min(ans,m);ans=max(ans,0);
			printf("%d\n",ans);
			continue;
		}
		for(int p=20;~p;p--) if(fa[pos][p]<=x) pos=fa[pos][p];
		int ans=(pos&1)?0:m;
		if(x&1) ans+=y-b[x];
		else ans-=y-b[x];
		ans+=sum[x]-sum[pos];
		ans=min(m,ans);ans=max(0,ans);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 14208
import numpy as np
L, R = map(int, input().split())
mod = 2019
l_mod = L % mod
r_mod = R % mod
lr_range = R - L + 1
if lr_range >= 2019:
    ans = 0
elif l_mod < r_mod:
    ans = 2018
    q = np.arange(l_mod, r_mod+1)
    for i in range(len(q)):
        min_i = (q * q[i]) % mod
        min_i[i] = 2018
        ans = min(min(min_i), ans)
else:
    ans = 0

print(ans % mod)


Measured memory_bytes: 19472
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;

int main() {
    long long n;
    cin >> n;
    vector<long long> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b.begin(), b.end(), greater<long long>());
    long long mx1 = b[0], mx2 = b[1];

    for (int i = 0; i < n; i++) {
        if (a[i] == b[0]) cout << b[1] << endl;
        else cout << b[0] << endl;
    }
    return 0;
}

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

int main() {
  string s;
  cin>>s;
 int k=s.size();
  int a=0,b=0,c=0,d=0;
  for(int i=0;i<k;i++){
if(s[i]=='N')a++;
    if(s[i]=='S')b++;
    if(s[i]=='W')c++;
    if(s[i]=='E')d++;
  
  }
  if(a >=1 && b >=1 && c >=1 && d >=1)cout << "Yes";
  else if(a==0 && b==0 && c >=1 && d>=1)cout << "Yes";
  else if(c==0 && d==0 && a >=1 && b>=1)cout << "Yes";
else cout << "No" <<endl;

}


Measured memory_bytes: 3612
Str = input().split()
A = int(Str[0])
B = int(Str[1])
import math 
amin = math.ceil(A/0.08)
amax = (A+1)/0.08
if amax == math.floor(amax):
  amax= amax-1
else:
  amax = math.floor(amax)

i = amin
ans = -1
while i <= amax:
  if int(i*0.1) == B:
    ans = i
    break
  i+=1

print(ans)

Measured memory_bytes: 3064