akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<par<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,k;
    cin>>n>>k;
    vi v(n);
    rep(i,n)cin>>v[i];
    int c=min(n,k);
    int ans=0;
    rep(i,c+1){
        rep(j,c+1){
            if(i+j>c)continue;
            int r=k-i-j;
            int t=0;
            vi a;
            rep(l,i){
                t+=v[l];
                if(v[l]<0)a.pb(v[l]);
            }
            rep(l,j){
                t+=v[n-l-1];
                if(v[n-k-1]<0)a.pb(v[n-l-1]);
            }
            SORT(a);
            rep(l,min((int)a.size(),r))t-=a[l];
            ans=max(ans,t);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
char s[11];
int l,f;
bool t[11];
inline int max(int x,int y){
	return x>y?x:y;
}
inline int read(){
	char c=getchar();
	int num=0,f=1;
	while(c<'0'||c>'9'){
		if(c=='-'){
			f=-1;
		}
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		num=(num<<1)+(num<<3)+(c^48);
		c=getchar();
	}
	return num*f;
}
inline void write(int x){
     if(x<0){
         putchar('-');
         x=-x;
     }
     if(x>9){
         write(x/10);
     }
     putchar(x%10+'0');
}
int main(){
	scanf("%s",s);
	l=strlen(s),f=0;
	for(register int i=l-1;i>=0;i--){
		if(s[i]=='B'){
			f++;
		}
		else{
			if(!f){
				t[i]=true;
			}
		    else{
		    	f--;
		    	f=max(f,0);
		    }
		}
	}
	for(register int i=0;i<l;i++){
		if(t[i]){
			putchar(s[i]);
		}
	}
	return 0;
}

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

#define ull unsigned long long
#define ll long long

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m);
    for(int i=0; i<m; ++i){
       cin >> a[i];
    }

    auto it = lower_bound(a.begin(), a.end(), x);
    int t = distance(a.begin(), it);

    int tb = t;
    int tf = m-t;

    cout << min(tb, tf);
    return 0;
}

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

int main()
{
	int a,b,c,d,e,k,i,count=0;
	int array[10];
	const char ans_1[5] = "Yay!";
	const char ans_2[5] = ":(";
	cin >> a >> b >> c >> d >> e >> k;
	array[0] = b - a;
	array[1] = c - a;
	array[2] = d - a;
	array[3] = e - a;
	array[4] = c - b;
	array[5] = d - b;
	array[6] = e - b;
	array[7] = d - c;
	array[8] = e - c;
	array[9] = e - d;

	for( i = 0; i < 10; i++ ){
		if( array[i] > k ){
			count++;
		}
	}

	if( count > 0 ){
		cout << ans_2 << endl;
	}else{
		cout << ans_1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import math

def findlex(a):
  max = math.factorial(len(a))
  current = 0
  current += (a[0]-1)*(max/len(a)) + lowerlex(a[0],a[1:])
  return current

def lowerlex(b,a):
  if len(a)<2:
    return 1
  else:
    max = math.factorial(len(a))
    for i in range(len(a)):
      if a[i]>b:
        a[i] -= 1
    return findlex(a)

n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
print(int(abs(findlex(p)-findlex(q))))


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

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end())); }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    cums(T& v){ T r; r.push_back(v[0]); for(int i=1; i<v.size(); i++) r.push_back(r[i-1] + v[i]); return r; }
TEMP_T void maxe(T& v, T m){ v = max(v, m); }
TEMP_T void mine(T& v, T m){ v = min(v, m); }

static inline int in(){ int x; scanf("%d", &x); return x; }

static inline int stoi(const string& s){
  int x = 0;
  for (int i = 0; i < s.size(); i++){
    x = x * 10 + (s[i] - '0');
  }
  return x;
}

struct Solver {
  Solver() {}
  void build(){
    queue<string> Q;
    int turn = 0;
    Q.push("01234567");
    while (!Q.empty()){
      queue<string> nQ;
      while (!Q.empty()){
        string s = Q.front();
        Q.pop();
        int mv = stoi(s);
        if (memo.find(mv) != memo.end()) continue;
        memo[mv] = turn;
        int zp = s.find('0');
        int zx, zy;
        zx = zp % 4;
        zy = zp / 4;
        for (int d = 0; d < 4; d++){
          static const int dx[] = {1, -1, 0, 0};
          static const int dy[] = {0, 0, 1, -1};
          int nx = zx + dx[d];
          int ny = zy + dy[d];
          if (nx < 0 || nx >= 4 || ny < 0 || ny >= 2) continue;
          string next_s = s;
          swap(next_s[zp], next_s[ny * 4 + nx]);
          nQ.push(next_s);
        }
      }
      swap(Q, nQ);
      turn++;
    }
  }
  int solve(const string& state){
    return memo[stoi(state)];
  }
  map<int, int> memo;
};

int main()
{
  Solver solver;
  solver.build();
  string s;
  while (getline(cin, s)){
    s.erase(remove(s.begin(), s.end(), ' '), s.end());
    printf("%d\n", solver.solve(s));
  }

  return 0;
}

Measured memory_bytes: 2312
N = int(input())
Pi = list(map(int, input().split()))

ref = [i+1 for i in range(N)]

count = 0
for i in range(N):
    if Pi[i] != ref[i]:
        count += 1

if count == 0 or count == 2:
    print('YES')

else:
    print('NO')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

int main(){
    string s; cin>>s;
    if(s=="ABC") cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
}

Measured memory_bytes: 3596
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#include <math.h>
#include <set>
#include <vector>
#include <algorithm>
#include <map>


using namespace std;

typedef long long ll;
#define INF 0x3f3f3f3f
#define ESP 1e-8
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
const double PI = acos(-1.0);

int n, cx, cy, H;
int x[105], y[105], h[105];
set<int> h0, h1;

bool func0(){
    set<int>::iterator it = h0.begin();
    for( ; it!=h0.end(); it++)
        if(H > abs(cx-x[*it]) + abs(cy-y[*it]))
            break;
    if(it != h0.end())
        return 0;
    return 1;
}

bool func1(){
    set<int>::iterator it = h1.begin();
    int eq = abs(cx-x[*it]) + abs(cy-y[*it]) + h[*it];
    it++;
    for(; it!=h1.end(); it++)
        if(abs(cx-x[*it]) + abs(cy-y[*it]) + h[*it] != eq)
            break;
    if(it != h1.end())
        return 0;
    return 1;
}

int main(){
    int i;
    while(scanf("%d", &n)!=EOF){
        h0.clear(), h1.clear();
        for(i = 1; i <= n; i++){
            scanf("%d%d%d", &x[i], &y[i], &h[i]);
            if(h[i])
                h1.insert(i);
            else
                h0.insert(i);
        }
        bool flag = 0;
        for(cx = 0; cx <= 100; cx++){
            for(cy = 0; cy <= 100; cy++){
                H = abs(cx-x[*h1.begin()]) + abs(cy-y[*h1.begin()]) + h[*h1.begin()];
                if(func1() && func0()){
                    flag = 1;
                    break;
                }
            }
            if(flag)
                break;
        }
        printf("%d %d %d\n", cx, cy, H);
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    int n,a[100010];
    cin >> n;
    a[0]=0;
    a[n+1]=0;
    rep(i,n)cin >> a[i+1];
    int load = 0;
    rep(i,n+1){
        load+=abs(a[i]-a[i+1]);
    }
    FOR(i,1,n+1){
        int ans = load - (abs(a[i-1]-a[i])+abs(a[i]-a[i+1]))+abs(a[i-1]-a[i+1]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    s = input()
    possible = [False] * (len(s) + 1)
    possible[0] = True

    candidates = ['dream', 'dreamer', 'erase', 'eraser']
    for i in range(len(s)):
        if not possible[i]:
            continue
        for c in candidates:
            if s[i:i+len(c)] == c:
                possible[i + len(c)] = True

    print('YES' if possible[-1] else 'NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 40820
# include "iostream"
# include "cstdio"

using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	if(n<1200){
		printf("ABC");
		return 0; 
	}else if(n<2800){
		printf("ARC");
		return 0; 
	}
	printf("AGC"); 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;

struct node {
	int id, parent, left, right;
};

int reconstruct(queue<node> &nodes, queue<int> &pre, queue<int> &in, int parent){
	if(!in.size()) return -1;
	
	node n;
	n.parent = parent;
	n.id = pre.front();
	pre.pop();
	
	bool toA = true;
	queue<int> inA, inB;
	while(in.size()){
		if(in.front() == n.id){
			in.pop();
			toA = false;
			continue;
		}
		(toA ? inA : inB).push(in.front());
		in.pop();
	}
	
	n.left = reconstruct(nodes, pre, inA, n.id);
	n.right = reconstruct(nodes, pre, inB, n.id);
	
	nodes.push(n);
	return n.id;
}

int main() {
	int n;
	scanf("%d", &n);
	
	queue<int> pre;
	for(int i = 0; i < n; i++){
		int num;
		scanf("%d", &num);
		pre.push(num);
	}
	
	queue<int> in;
	for(int i = 0; i < n; i++){
		int num;
		scanf("%d", &num);
		in.push(num);
	}
	
	queue<node> nodes;
	reconstruct(nodes, pre, in, -1);
	
	while(nodes.size()){
		printf("%d%c", nodes.front().id, nodes.size() == 1 ? '\n' : ' ');
		nodes.pop();
	}
	
	return 0;
}

Measured memory_bytes: 1260
import math, itertools
from functools import reduce
def gcd_list(numbers):
    return(reduce(math.gcd,numbers))
k=int(input())
ans=0
for numbers in itertools.combinations_with_replacement(range(1,k+1),3):
    a,b,c=numbers
    if a==b==c:
        ans+=gcd_list(numbers)
    elif a!=b and a!=c and b!=c:
        ans+=6*gcd_list(numbers)
    else:
        ans+=3*gcd_list(numbers)
print(ans)

Measured memory_bytes: 9556
// AOJ 2635 Snake
// 2018.3.19 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

// [library]

//#define getchar_unlocked()  getchar()
int in()	// get non-negative integer from stdin
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

typedef struct { int x, y; } PP;

#define INF		 1e8
#define EPS		 1e-8
#define EQ(a,b)  (fabs((a)-(b))<EPS)

PP vsub(PP p1, PP p2) { PP r; r.x = p1.x - p2.x, r.y = p1.y - p2.y; return r; }
long long cross(PP a, PP b) { return (long long)a.x * b.y - (long long)a.y * b.x; }

long long polygon_area(int n, PP *p)
{
   int i;
   long long s;

   if (n < 3) return 0;
   s = 0; p[n] = p[0];
   for (i = 0; i < n; i++) s += cross(p[i], p[i+1]);
   return s;
}

int cmp(PP *a, PP *b) {
	if (a->y - b->y) return a->y - b->y;
	return a->x - b->x;
}

int convex_hull(int n, PP *ps, PP *po)
{
	int i, k, j = 0;

	qsort(ps, n, sizeof(PP), cmp);
	for (i = 0; i < n; i++) {
		while (j > 1 && cross(vsub(po[j-1], po[j-2]), vsub(ps[i], po[j-1])) <= 0) j--;
		po[j++] = ps[i];
	}
	k = j;
	for (i = n - 2; i >= 0; i--) {
		while (j > k && cross(vsub(po[j-1], po[j-2]), vsub(ps[i], po[j-1])) <= 0) j--;
		po[j++] = ps[i];
	}
	return j-1;
}
// [\library]  

PP  snake[1002];
PP  pp[2][1002];

void reverse(int n, PP *p)
{
	int i, j;
	memcpy(pp[0], p, sizeof(PP)*n);
	j = n, i = 0; while (j--) p[i++] = pp[0][j];
}

int check(int n, PP *p)
{
	int i, k, k1, k2;
	long long prev, s;

	prev = 0, k = 0, k1 = 0, k2 = 1;
	for (i = 0; i < n; i++) {
		pp[k1][k++] = p[i];
		if (i < 2) continue;
		k = convex_hull(k, pp[k1], pp[k2]);
		s = polygon_area(k, pp[k2]);
		if (s == prev) return 0;
		prev = s, k1 = k2, k2 = !k2;
	}
	return 1;
}

int main()
{
	int n, i, ans;

	n = in();
	for (i = 0; i < n; i++) snake[i].x = in(), snake[i].y = in();
	ans = 0;
	if (check(n, snake)) {
		reverse(n, snake);
		if (check(n, snake)) ans = 1;
	}
	puts(ans? "Possible": "Impossible");
	return 0;
}


Measured memory_bytes: 2092
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

void InputNumbers(int, vector<int>&);
unsigned long long int CountUpFunc_n(vector<int>, int);

int main() {
	int N;
	vector<int>A;
	unsigned long long int num_of_combination = 0;
	cin >> N;

	InputNumbers(N, A);
	num_of_combination = CountUpFunc_n(A, N);
	cout << num_of_combination << endl;

	return 0;
}

void InputNumbers(int n, vector<int>& a) {
	for (int i = 0; i < n; i++) {
		int faker;
		cin >> faker;
		a.push_back(faker);
	}
	/*cout << a.size() << endl;
	for (int i = 0; i < n; i++) {
		cout << "ite:" << i << " A[]:" << a[i] << endl;
	}*/
}

unsigned long long int CountUpFunc_n(vector<int> a, int n) {
	/*cout << a.size();
	for (int i = 0; i < n; i++) {
		cout << "ite:" << i << " A[]:" << a[i] << endl;
	}*/
	if (n - 1 == 0) {
		if (a[n - 1] % 2 == 0) {
			return 1;
		}
		else {
			return 2;
		}
	}
	else {
		if (a[n - 1] % 2 == 0) {
			return 2 * CountUpFunc_n(a, n - 1) + (unsigned long long int)pow(3, n - 1);
		}
		else {
			return CountUpFunc_n(a, n - 1) + (unsigned long long int)2 * pow(3, n - 1);
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=200005;
int n;
long long a[maxn];
long long ans;
long long b;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]-=i;	
	} 
	sort(&a[1],&a[n+1]);
	if(n%2==0)
	{
		b=(a[n/2]+a[n/2+1])/2;
	}
	else b=a[n/2+1];
	for(int i=1;i<=n;i++)
	{
		ans+=abs(a[i]-b);
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 1792
from fractions import gcd
n = int(input())
lcm = list(map(int, input().split()))
ans = [1] * n
while len(lcm) < (1 << 14):
  lcm.append(1)
  ans.append(0)
for i in range(13, -1, -1):
  bit = 1 << i
  for j in range(bit):
    new = lcm[j] // gcd(lcm[j], lcm[j | bit]) * lcm[j | bit]
    ans[j] = new // lcm[j] * ans[j] + new // lcm[j | bit] * ans[j | bit]
    ans[j] %= 1000000007
    lcm[j] = new
print(ans[0])

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

using namespace std;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define forall(v)   v.begin(), v.end()
#define prec(x)     setprecision(x) << fixed

/* [💭] [💡] [🎈] */

constexpr ll f(ll n) {
    return n * (n + 1) / 2;
}

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

    string str;
    cin >> str;

    int n = str.length();
    vector<int> a(n + 1);

    ll sum = 0;
    int i = 0;
    while (i < n) {
        int j = i;
        char c = str[i];
        while (j < n && str[j] == c) j++;
        // [i, j)
        if (c == '>') {
            for (int k = j; k >= i; k--) {
                a[k] = max(a[k], j - k);
            }
        } else { // c == '<'
            for (int k = i; k <= j; k++) {
                a[k] = max(a[k], k - i);
            }
        }
        i = j;
    }

    for (ll x : a) {
        sum += x;
    }
    cout << sum;

    return 0;
}

Measured memory_bytes: 2844
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

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

  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }

  if (A >= 6 && B >= 6 && C >= 6) {
    cout << "Yes\n";
    map<string, int> mp;
    mp["AB"] = 1;
    mp["BC"] = 1;
    mp["AC"] = 1;
    for (int i = 0; i < N; i++) {
      cout << S[i][mp[S[i]]] << "\n";
      mp[S[i]] ^= 1;
    }
    return 0;
  }

  bool dp[N + 1][8][8][8] = {};
  for (int i = 0; i <= 6; i++) {
    for (int j = 0; j <= 6; j++) {
      for (int k = 0; k <= 6; k++) {
        dp[N][i][j][k] = 1;
      }
    }
  }

  for (int i = N - 1; i >= 0; i--) {
    for (int a = 0; a <= 6; a++) {
      for (int b = 0; b <= 6; b++) {
        for (int c = 0; c <= 6; c++) {
          if (S[i] == "AB") {
            if (a > 0) dp[i][a][b][c] |= dp[i + 1][a - 1][b + 1][c];
            if (b > 0) dp[i][a][b][c] |= dp[i + 1][a + 1][b - 1][c];
          } else if (S[i] == "BC") {
            if (c > 0) dp[i][a][b][c] |= dp[i + 1][a][b + 1][c - 1];
            if (b > 0) dp[i][a][b][c] |= dp[i + 1][a][b - 1][c + 1];
          } else if (S[i] == "AC") {
            if (a > 0) dp[i][a][b][c] |= dp[i + 1][a - 1][b][c + 1];
            if (c > 0) dp[i][a][b][c] |= dp[i + 1][a + 1][b][c - 1];
          }
        }
      }
    }
  }


  int a, b, c;  
  for (a = 0; a <= min(A, 6); a++) {
    for (b = 0; b <= min(B, 6); b++) {
      for (c = 0; c <= min(C, 6); c++) {
        if (dp[0][a][b][c]) {
          goto DONE;
        }
      }
    }
  }
  
  DONE:
  if (a <= A && b <= B && c <= C && dp[0][a][b][c]) {
    cout << "Yes\n";
    for (int i = 0; i < N; i++) {
      if (S[i] == "AB") {
        if      (b > 0 && dp[i + 1][a + 1][b - 1][c]) a++, b--, cout << "A\n";
        else if (a > 0 && dp[i + 1][a - 1][b + 1][c]) a--, b++, cout << "B\n";
      } else if (S[i] == "BC") {
        if      (c > 0 && dp[i + 1][a][b + 1][c - 1]) b++, c--, cout << "B\n";
        else if (b > 0 && dp[i + 1][a][b - 1][c + 1]) b--, c++, cout << "C\n";
      } else if (S[i] == "AC") {
        if      (a > 0 && dp[i + 1][a - 1][b][c + 1]) a--, c++, cout << "C\n";
        else if (c > 0 && dp[i + 1][a + 1][b][c - 1]) a++, c--, cout << "A\n";
      }
    }
  } else {
    cout << "No\n";
  }
}


Measured memory_bytes: 56264
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

char s[10],t[10];
int main(){
	scanf("%s %s",s,t);
    printf("%lld",(s[0]==t[0])+(s[1]==t[1])+(s[2]==t[2]));
}

Measured memory_bytes: 128
n,m=map(int,input().split())
a=[[] for _ in range(n)]
for i in range(m):
    p,y=map(int,input().split())
    a[p-1].append((y,i))

ans=[0]*m
for i in range(n):
    sa=sorted(a[i],key=lambda x:x[0])
    order=1
    for tpl in sa:
        ans[tpl[1]]='0'*(6-len(str(i+1)))+str(i+1)+'0'*(6-len(str(order)))+str(order)
        order+=1
print(*ans,sep='\n')

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

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


int main(){
    double b;
    unsigned long long a;
    cin>>a>>b;
    double e=b*1000;
    unsigned long long c=(unsigned long long)(e);
    unsigned long long d=a*c;
    cout<<(unsigned long long)(d/1000);
}



Measured memory_bytes: 3724
loop do
  l = (1..8).map{gets.chomp}.join
  puts "A" if l.include?("1100000011")
  puts "B" if l.include?("1000000010000000100000001")
  puts "C" if l.include?("1111")
  puts "D" if l.include?("1000000110000001")
  puts "E" if l.include?("11000000011")
  puts "F" if l.include?("100000001100000001")
  puts "G" if l.include?("110000011")
  break unless gets
end

Measured memory_bytes: 8684
#include<stdio.h>

int main (){
	int n,m,c;
	scanf("%d %d %d",&n,&m,&c);
	int a[n][m];
	int b[m];
	int i,j;
	for(i=0;i<m;i++){
		scanf("%d",&b[i]);
	}
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	int sum = 0;
	int count = 0;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			sum += a[i][j]*b[j];
		}
		if(sum+c>0) count++;
		sum = 0;
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define sd(t)       scanf("%d",&(t))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define hii         cout << "hii" << endl
#define okay        cout << "okay" << endl
#define hey         cout << "hey" << endl
const int INF = 1e16;
const int MOD = 998244353;
const int mod = 1e9+7;


template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.x << ' ' << v.y; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.x << "=>" << i.y << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


clock_t time_p=clock();
void starboy1299()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("jjj.txt", "w", stdout);
    #endif
} 

inline int mul(int a, int b, int m = mod) { return (a * b) % m; }
inline int add(int a, int b, int m = mod) { return (a + b) % m; }
inline int sub(int a, int b, int m = mod) { return (a - b + m) % m; }

const int N = 2e5+5;

void solve()
{
    int a, v;
    cin >> a >> v;

    int b, w;
    cin >> b >> w;

    int t;
    cin >> t;

    int dist1 = v*t;
    int dist2 = w*t;

    if(a <= b and a + dist1 >= b + dist2){
        cout << "YES" << endl;
    }
    else if(a > b and a - dist1 <= b - dist2){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;

}                            

int32_t main(){
    fast();
    int t = 1;
    // cin>> t;
    for(int i=1; i<=t; i++){
        // cout << "Case #" << i << ": ";
        solve();
    }
    starboy1299();
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define FOR(i,a,n) for(int i = (a); i<(n); ++i) 
#define endl "\n"
 


int main()
{     
     IOS;
      
     string s;
     cin>>s;
    set<char> st;
      
      FOR(i,0,3)  st.insert(s[i]);
      
    if(st.size()==2)  cout<<"Yes";
     else  cout<<"No";
  
        
    
      return 0;
} 



Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
int main(){
  int n;cin>>n;
  map<int,int> mp;
  for(int i=0;i<n;i++){
    int a;cin>>a;
    mp[a]++;
  }
  for(auto it=mp.begin();it!=mp.end();it++){
    if(it->second==2){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
  return 0;
}

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

int main(){
	string s;
	cin >> s;
	long long int num = s.size();
	long long int count = 0;
	long long int i=0;
	while(i<num-1){
		if(s.at(i) == s.at(i+1)){
			count++;
			i += 3;
		}else{
			i++;
		}
	}
	cout << num-count << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define fi first
#define se second
#define FIO {ios::sycnt2_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
 
int32_t main()
{
 int n,k;
 cin>>n>>k;
 int a[n];
 forn(i,n)cin>>a[i];
 sort(a,a+n);
 int s=0;
 forn(i,k)s+=a[i];
 cout<<s;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ForYellow
{
    class AGC014_D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            List<int>[] graph = new List<int>[n];
            for (int i = 0; i < n; i++)
            {
                graph[i] = new List<int>();
            }
            for (int i = 0; i < n - 1; i++)
            {
                int[] ab = ReadInts();
                int a = ab[0] - 1;
                int b = ab[1] - 1;
                graph[a].Add(b);
                graph[b].Add(a);
            }

            int[] parents = new int[n];
            var que = new Queue<int>();
            var stk = new Stack<int>();
            que.Enqueue(0);
            stk.Push(0);
            parents[0] = -1;
            while (que.Count > 0)
            {
                int now = que.Dequeue();
                foreach (int to in graph[now])
                {
                    if (to == parents[now])
                    {
                        continue;
                    }

                    parents[to] = now;
                    que.Enqueue(to);
                    stk.Push(to);
                }
            }

            while (stk.Count > 0)
            {
                int now = stk.Pop();
                if (graph[now].Count == 0)
                {
                    continue;
                }

                if (parents[now] == -1 || graph[parents[now]].Count == 0)
                {
                    WriteLine("First");
                    return;
                }

                graph[parents[now]].Clear();
            }

            WriteLine("Second");
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 51052
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

ll dp[100010][15];
const int MOD = 1e9+7;
int main(){
    string S;
    cin >> S;
    int n = S.size();
    //dp[i][j]:=i文字目まで見て、１３で割った余りがjになるものの数
    if(S[0]=='?')for(int i=0;i<=9;i++)dp[1][i]=1;
    else dp[1][S[0]-'0']=1;

    for(int i=1;i<n;i++){
        if(S[i]=='?'){
            for(int j=0;j<13;j++){
                for(int k=0;k<=9;k++){
                    int next = (j*10+k)%13;
                    dp[i+1][next]=(dp[i+1][next]+dp[i][j])%MOD;
                }
            }
        }else{
            for(int j=0;j<13;j++){
                int next = (j*10+(S[i]-'0'))%13;
                dp[i+1][next]=(dp[i+1][next]+dp[i][j])%MOD;
            }
        }
    }

    cout << dp[n][5] << endl;
    return 0;
}

Measured memory_bytes: 12160
#include <stdio.h>

int main(void)
{
	int n, m, a;
	int i, j, ind;
	int r[105];
	
	while(1){
		
		scanf("%d %d", &n, &m);
		
		if (n == 0 && m == 0){
			break;
		}
		for (i = 0; i < m; i++){
			r[i] = 0;
		}
		
		for (i = 0; i < n; i++){
			for (j = 0; j < m; j++){
				scanf("%d", &a);
				
				if (a == 1){
					r[j]++;
				}
			}
		}
		ind = 0;
		
		for (i = 0; i < m; i++){
			for (j = 0; j < m; j++){
				if (r[ind] < r[j]){
					ind = j;
				}
			}
			printf("%d", ind + 1);
			
			if (i != m - 1){
				printf(" ");
			}
			
			r[ind] = 0;
		}
		
		printf("\n");
	}
	
	return (0);
}
			 	

Measured memory_bytes: 600
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}
int main(){
    int x, y, z;
    cin >> x >> y >> z;
    int K;
    cin >> K;
    vector<ll> a(x), b(y), c(z);
    for(int i = 0; i < x; i++)cin >> a[i];
    for(int i = 0; i < y; i++)cin >> b[i];
    for(int i = 0; i < z; i++)cin >> c[i];
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    sort(c.rbegin(), c.rend());
    multiset<ll>st;
    for(int i = 0; i < x; i++){
        if(i + 1 > K)continue;
        for(int j = 0; j < y; j++){
            if((i + 1) * (j + 1) > K)continue;
            for(int k = 0; k < z; k++){
                if((i + 1) * (j + 1) * (k + 1) > K)continue;
                st.insert(a[i] + b[j] + c[k]);
                if(st.size() > K)st.erase(st.begin());
            }
        }
    }
    auto it = st.end();
    for(int i = 0; i < K; i++){
        it--;
        cout << *it << "\n";
    }
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<utility>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    int dt[n];
    rep(i,n){
      cin>>dt[i];
    }
    int sum=0;
    sort(dt,dt+n);
    dt[0]=dt[n-1]=0;
    rep(i,n){
      sum+=dt[i];
    }
    cout<<sum/(n-2)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1176
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

L,R,d = inpl()

count = 0
if L % d == 0:
    k = int(L/d)
else:
    k = int(L/d)+1

k = k* d
while k <= R:
    count += 1
    k += d
print(count)


Measured memory_bytes: 10540
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        int x;
        int y = 0;
        for(x = a;x <= b;x++){
        if(c % x == 0){
           y++; 
        }
        }
        System.out.println(y);
        
       
      
            
               
                
            
            
           
       
      

        }

    }


Measured memory_bytes: 26188
//dhruv
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define ll long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define fro(i,j,n) for(int i = (j);i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define ff first
#define ss second
const int mod = 1e9 + 7;
const int inf = 1e18 + 5;
 
template<typename T>
T binpow(T a,T b,T modi){
	T res = 1;
	while(b){
		if(b&1){
			res = (res*a)%modi;
		}
		b /= 2;
		(a *= a) %= modi;
	}
	return res;
}
 
 
template<typename T>
T binpow(T a,T b){
	T res = 1;
	while(b){
		if(b&1){
			res = (res*a);
		}
		b /= 2;
		a *= a;
	}
	return res;
}
 
template<typename T>
T add(T a,T b){
	return (a + b)%mod;
}
template<typename T>
T sub(T a,T b){
	return add(a,mod - b);
}
template<typename T>
T mul(T a,T b){
	return (a*b)%mod;
}

int make_int(string s){
	int x = 0;
	reverse(s.begin(),s.end());
	string tmp = s;
	for(int i = 0;i < s.length(); ++i){
		x *= 10;
		x += (int)(tmp.back() - '0');
		tmp.pop_back();
	}
	return x;
}
 
string make_string(int s){
	string x;
	while(s){
		x.push_back(char(s%10 + '0'));
		s /= 10;
	}
	reverse(x.begin(),x.end());
	return x;
}

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



const int N = 100;
int lp[N + 1];
vector<int> pr;
void ls(){
	for(int i = 2;i <= N; ++i){
		// means prime
		if(lp[i] == 0){
			lp[i] = i;
			pr.push_back(i);
		}
		for(int j = 0;j < pr.size() && pr[j] <= lp[i] && i*pr[j] <= N; j++){
			lp[i*pr[j]] = pr[j];
		}
	}
}


// getting the prime factorisation

vector<int> getfc(int n){
	vi fact;
	while(n != 1){
		int x = lp[n];
		fact.push_back(x);
		while(n%x == 0){
			n /= x;
		}
	}
	return fact;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	vi a(n);
	map<int,int> mp;
	int s = 0;
	ffor(i,n){
		cin >> a[i];
		mp[a[i]]++;
		s += a[i];
	}
	int q;
	cin >> q;
	while(q--){
		int x,y;
		cin >> x >> y;
		int num = mp[x];
		mp[x] = 0;
		mp[y] += num;
		s -= x*num;
		s += y*num;
		cout << s << '\n';
	}
	return 0;
}

Measured memory_bytes: 10084
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	s := scanner.Text()

	scanner.Scan()
	p := scanner.Text()

	sum_s := s
	for i, rune_s := range s {
		if i != (len(s)-1) {
			sum_s += string(rune_s)
		}
	}

	if strings.Contains(sum_s, p) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}



Measured memory_bytes: 1092
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef long double ld;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
const int MOD=1e9+7;
 
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a)  (a).begin(),(a).end()

const int N=1e6+5;

int n;
int a[N];
int dp[N];
int32_t main()
{
    IOS;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    dp[1]=abs(a[0]-a[1]);
    for(int i=2;i<n;i++)
    {
        dp[i]+=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));
    }
    cout<<dp[n-1]<<endl;

}

Measured memory_bytes: 5120
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;


int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	bool to[200001] = {};
	bool from[200001] = {};
	for(int i=0;i<M;i++){
		int a, b;
		cin >> a >> b;
		if (a == 1 || b == 1) {
			to[a] = true;
			to[b] = true;
		}
		if (a == N || b == N) {
			from[a] = true;
			from[b] = true;
		}
	}
	for (int i = 2; i < N; i++) {
		if (to[i] && from[i]) {
			cout << "POSSIBLE\n";
			return 0;
		}
	}
	cout << "IMPOSSIBLE\n";
	return 0;
}

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

int main(){
  int N,count;
  cin >> N;
  count = 1;
  vector<int> vec(N);
  
  rep(i,N){
    cin >> vec[i];
  }
  
  sort(vec.begin(), vec.end());
  
  rep(i,N-1){
    if(vec[i] != vec[i+1]) count++;
    else {
      int j =i+1;
      int c = 0;
      while(vec[i] == vec[j]){
        c++;
        j++;
      }
      if(c%2 == 1) count--;
      i = j-2;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int A[100020] = {};
int main() {
	int N;
	int sum = 0;
	int numbers = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		A[a]++;
	}
	for (int i = 0; i <= 100000; i++) {
		if (A[i] >= 1) {
			numbers++;
			sum = sum + A[i] - 1;
		}
	}
	sum = sum % 2;
	cout << numbers - sum;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()

alice = sum([a[i] for i in range(len(a)) if i % 2 == 0])
bob = sum([a[i] for i in range(len(a)) if i % 2 != 0])
print(alice-bob)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    std::string s;std::cin>>s;
    std::cout<<
        std::count(s.begin(),s.end(),'+')
        -std::count(s.begin(),s.end(),'-')
        <<'\n';
}


Measured memory_bytes: 256
# from: https://github.com/python/cpython/blob/3.6/Lib/heapq.py
class PQ
  attr_reader :heap, :sum

  def initialize(a)
    @heap = a.dup
    @sum = @heap.inject(0,:+)
    (@heap.size/2).downto(0){|i|
      sift_up(i)
    }
  end

  def sift_up(pos)
    last = @heap.size
    start = pos
    new_item = @heap[start]
    child = pos * 2 + 1
    while child < last
      right = child + 1
      child = right if right < last && @heap[child] >= @heap[right]
      @heap[pos] = @heap[child]
      pos = child
      child = pos * 2 + 1
    end
    @heap[pos] = new_item
    sift_down(start, pos)
  end

  def sift_down(start, pos)
    new_item = @heap[pos]
    while pos > start
      parent = (pos - 1) / 2
      parent_item = @heap[parent]
      break if new_item >= parent_item
      @heap[pos] = parent_item
      pos = parent
    end
    @heap[pos] = new_item
  end

  def [](i)
    @heap[i]
  end

  def to_a
    @heap
  end

  def empty?
    @heap.empty?
  end

  def push(item)
    @heap << item
    @sum += item
    sift_down(0, @heap.size-1)
    self
  end

  def <<(item)
    push(item)
  end

  def pop
    last_item = @heap.pop
    if @heap.empty?
      @sum -= last_item if last_item
      return last_item
    end
    res = @heap[0]
    @heap[0] = last_item
    sift_up(0)
    @sum -= res
    res
  end

  def push_pop(item)
    if @heap[0] < item
      @sum += item - heap[0]
      item, heap[0] = heap[0], item
      sift_up(0)
    end
    item
  end
end

def f(a, b)
  pq = PQ.new(a)
  [pq.sum] + (0...N).map{|i|
    pq.push_pop(b[i])
    pq.sum
  }
end

N = gets.to_i
car, mid, cdr = gets.split.map(&:to_i).each_slice(N).to_a
p f(car.sort, mid).zip(f(cdr.map{|v|-v}.sort, mid.map{|v|-v}.reverse).reverse).map{|a, b| a + b }.max


Measured memory_bytes: 39304
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
#include <fstream>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

using namespace std;

constexpr int INF = 1000000000;/* 1e+9a */
constexpr int MODULO = 1000000007;

typedef int64_t ll;

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

struct rect{
public:
    int w;
    int d;
    int old;

    int sqm(){return w * d;}
    int circ(){ return w + d; }
};

bool rect_less(rect a, rect b){
    if(a.old != b.old){
        return a.old < b.old;
    }
    return (a.sqm()) < (b.sqm());
}

bool rect_less_sqm(rect a, rect b){
    return (a.sqm()) < (b.sqm());
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, w, d;
    while(cin >> n >> w >> d){
        if(w == 0)
            return 0;
        vector<rect> rects;
        rects.push_back(rect{w,d,0});
        for (int i = 0; i < n; ++i) {
            int p, s;
            cin >> p >> s;
            p -= 1;
            s %= rects[p].circ();
            rect one, two;
            one = rects[p];
            two = rects[p];
            if(s < one.w){
                one.w -= s;
                two.w = s;
            }
            else{
                s -= one.w;
                one.d -= s;
                two.d = s;
            }
            one.old = two.old = i;
            rects[p] = one;
            rects.push_back(two);
            sort(rects.begin(), rects.end(), &rect_less);
//            for (auto && rc : rects) {
//                cout << rc.w << ',' << rc.d << ' ';
//            }
//            cout << "DEBUGS" << endl;
        }
        sort(rects.begin(), rects.end(), &rect_less_sqm);
        cout << rects[0].sqm();
        for (int j = 1; j < rects.size(); ++j) {
            cout << ' ' << rects[j].sqm() ;
        }
        cout << endl;
    }

}



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

int top,st[1000];

void push(int x){
   st[++top] = x;
}

int pop(){
    top--;
    return st[top+1];
}

int main(){
  int x,y;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
        y = pop();
        x = pop();
        push(x + y);
    } else if ( s[0] == '-' ){
        y = pop();
        x = pop();
        push(x - y);
    } else if ( s[0] == '*' ){
        y = pop();
        x = pop();
        push(x * y);
    } else {
      x = atoi(s);
      push(x);
    }
  }
  cout << pop() << endl;
  return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int N;
int pos[2][2020];
int L[2][2020][2020];
int dp[2020][2020];

int H,W;
string S[12];
int p[12];
bool q[12];

bool check(){
	bool b[12] = {};
	bool c = H&1;
	rep(i,H) if(!b[i]){
		for(int j = i+1; j < H; ++j) if(!b[j]){
			rep(k,W){
				if(S[i][p[k]] != S[j][p[W-1-k]]) break;
				if(k+1 == W) b[i] = b[j] = 1;
			}
			if(b[j]) break;
		}
		if(!b[i]){
			if(c){
				rep(k,W) if(S[i][p[k]] != S[i][p[W-1-k]]) return 0;
				c = 0;
			} else return 0;
		}
	}
	return 1;
}

bool solve(int a , int n , bool b) {
    if (a == W) return check();
    if (q[a]) return solve(a+1,n,b);
    if (b) {
        p[W/2] = a, q[a] = 1;
        if ( solve(a+1,n,0) ) return 1;
        q[a] = 0;
    }
    for(int i = a+1; i < W; ++i) {
        if (!q[i]) {
            p[n] = a, p[W-1-n] = i;
            q[a] = q[i] = 1;
            if (solve(a+1,n+1,b)) return 1;
            q[a] = q[i] = 0;      
        }
    }
    return 0;
}

int main(){
	cin >> H >> W;
	rep(i,H) cin >> S[i];
	cout << (solve(0,0,W&1)?"YES":"NO") << endl;
	return 0;
}

Measured memory_bytes: 3572