akhauriyash/Code-Regression huggingface dataset:
def m():
    n, x = map(int, input().split())
    a = list(map(int, input().split()))
    b = a.copy()
    ans = 0
    for i in range(n):
        if b[i] > x:
            b[i] = x

    for j in range(1, n):
        if b[j-1] + b[j] > x:
            b[j] -= (b[j-1] + b[j]) - x
        else:
            pass
    for k in range(n):
        ans += a[k] - b[k]
    return ans

print(m())

Measured memory_bytes: 14052
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(data, 10, sizeof(int), compare_int)

int main(){
	char c;
	scanf(" %c", &c);
	int f = 0;
	if((c >='A') && (c <= 'Z')) f = 1;
	if(f==1) printf("A\n");
	else printf("a\n");
	
	//printf("%d", count);
	
	return 0;
}


Measured memory_bytes: 1664
import sys
input = sys.stdin.readline

n,m,k = map(int, input().split())
ab = [list(map(int,input().split())) for _ in range(m)]
cd = [list(map(int,input().split())) for _ in range(k)]

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

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

uf = UnionFind(n+1)
for a,b in ab:
    uf.union(a,b)

f_num = [1] * (n+1)
b_num = [0] * (n+1)

for a,b in ab:
    f_num[a] += 1
    f_num[b] += 1

for c,d in cd:
    if(uf.same(c,d)):
        b_num[c] += 1
        b_num[d] += 1

ans = [0] * (n+1)

for i in range(1,n+1):
    ans[i] = uf.size(i) - f_num[i] - b_num[i]

print(' '.join(map(str, ans[1:])))

Measured memory_bytes: 127196
#include<iostream>
using namespace std;
  
  
int main()
{
    int n;
    int card[4][14] = { {0} };
    cin >> n;
    for (int i = 0; i < n; i++){
        char c;
        int num, mark;
        cin >> c >> num;
        if (c == 'S'){
            mark = 0;
        }
        else if (c == 'H'){
            mark = 1;
        }
        else if (c == 'C'){
            mark = 2;
        }
        else{
            mark = 3;
        }
        card[mark][num] = 1;
    }
    for (int i = 0; i < 4; i++){
        for (int j = 1; j < 14; j++){
            char c;
            if (card[i][j] == 0){
                if (i == 0){
                    c = 'S';
                }
                else if (i == 1){
                    c = 'H';
                }
                else if (i == 2){
                    c = 'C';
                }
                else{
                    c = 'D';
                }
                cout << c << " " << j << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s=="ooo")cout<<1000;
	else if(s=="xoo")cout<<900;
	else if(s=="oxo")cout<<900;
	else if(s=="oox")cout<<900;
	else if(s=="xxo")cout<<800;
	else if(s=="xox")cout<<800;
	else if(s=="oxx")cout<<800;
	else cout<<700;
	return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n;

int main() {
	cin >> n;
	
	incII(i, n, 999) {
		string s = to_string(i);
		if(s[0] == s[1] && s[1] == s[2]) { cout << s << endl; break; }
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;

  int **a = new int*[n];

  for (int i = 0; i < n; i++) {
    a[i] = new int[m];
  }
  int *b = new int[m];
  int *c = new int[n];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0 ; i < m; i++) {
    cin >> b[i];
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      c[i] += a[i][j] * b[j];
    }
  }

  for (int i = 0 ; i < n ; i++) {
    cout << c[i] << endl;
  }

  delete[] a;
  delete[] b;
  delete[] c;

  return 0;
}

Measured memory_bytes: 1232
def judge(A):
    if A[0][0]==A[1][1]==A[2][2]=="o" or A[0][2]==A[1][1]==A[2][0]=="o":
        return "Yes"
    for i in range(3):
        if A[i][0]==A[i][1]==A[i][2]=="o" or A[0][i]==A[1][i]==A[2][i]=="o":
            return "Yes"
    return "No"
a1=input().split()
a2=input().split()
a3=input().split()
A=[a1,a2,a3]
N=int(input())
for n in range(N):
    p=0
    b=input()
    for i in range(3):
        for j in range(3):
            if b==A[i][j]:
                A[i][j]="o"
                p=1
                break
        if p==1:
            break
print(judge(A))

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

typedef long long LL;
typedef unsigned long long ULL;

#define debug printf("fuck %d\n", __LINE__);

inline LL read() {
	LL res = 0, bo = 1; char ch = getchar();
	while(ch < '0' || ch > '9') { if (ch == '-') bo = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') { res = (res << 1) + (res << 3) + ch - '0'; ch = getchar(); }
	return bo * res;
}

template<typename T> void read(T &x) { x = read(); }
template<typename T, typename ...Argv> void read(T &a, Argv &...argv) { read(a); read(argv...); }

const int N = 4e5 + 100;

struct node {
	int pos, val;
	node() {}
	node(int pos, int val) : pos(pos), val(val) {}
} s[N];

int a[N], top, n;

void insert(int pos, int val) {
	while (top > 1 && s[top].pos > pos) -- top;
	if (s[top].pos == pos) ++ s[top].val;
	else s[++ top] = node(pos, 1);
	if (top > 1 && s[top].val >= val) -- top, insert(pos - 1, val);
}

bool check(int x) {
	s[top = 1] = node(0, 0);
	for (int i = 2; i <= n; ++ i) if (a[i] <= a[i - 1]) insert(a[i], x);
	return s[1].val == 0;
}

int main() {
	n = read();
	for (int i = 1; i <= n; ++ i) a[i] = read();
	int flag = 1;
	for (int i = 2; i <= n; ++ i) if (a[i] <= a[i - 1]) flag = 0;
	if (flag) return puts("1"), 0;
	int l = 2, r = n;
	while (l <= r) {
		int mid = (l + r) >> 1;
		if (check(mid)) r = mid - 1;
		else l = mid + 1;
	}
	std::cout << r + 1 << std::endl;
	return 0;
}

Measured memory_bytes: 1024
# Input(n = num of monsters/k = num of special attacks)
n, k = map(int, input().split())
monsters = sorted(list(map(int, input().split())), reverse=True)
# NOTE: The sorted() function is in an ascending order in default.
# NOTE: And it's reversed, so now it's in a descending order.

# Calculating and judging the minimal number of attacks fennec needs to win.
if len(monsters) <= k:
    print(0)
else:
    EntireMonsters = sum(monsters)
    destroyed = sum(monsters[:k])
    print(EntireMonsters - destroyed)





Measured memory_bytes: 26020
#include <stdio.h>
#include <math.h>
int Prime(int);
int main(){
  int n, i, j, input, count=0, frag;
  scanf("%d",&n);
  for(i=0; i<n; i++)
    {
      scanf("%d",&input);
      if(Prime(input) == 1)
	count++;
    }
  printf("%d\n",count);
  return 0;
}

int Prime(x){
  int i;
  if(x == 2) return 1;
  else if(x<2 || x%2==0) return 0;
  for(i=3; i<=sqrt(x); i=i+2){
    if(x%i==0) return 0;
  }
  return 1;
}

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

using namespace std;

int main(){
	
	vector<int> h(10);
	
	for(int i=0;i<10;i++)
		cin>>h[i];
	
	sort(h.begin(),h.end());
	
	for(int i=9;i>=7;i--)
		cout<<h[i]<<endl;
	
	
	}

Measured memory_bytes: 1212
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToList();
        a.Add(a.Aggregate(0, (x, y) => x ^ y));
        var b = Console.ReadLine().Split().Select(int.Parse).ToList();
        b.Add(b.Aggregate(0, (x, y) => x ^ y));
        if (a.OrderBy(x => x).Zip(b.OrderBy(x => x), (x, y) => x != y).Any(x => x))
        {
            Console.WriteLine(-1);
            return;
        }

        var compressed = a.Distinct().OrderBy(x => x).Select((elem, count) => new { elem, count }).ToDictionary(x => x.elem, x => x.count);
        int sameCount = 0;
        UnionFind uf = new UnionFind(compressed.Count);
        for (int i = 0; i < n; i++)
        {
            if (a[i] == b[i]) sameCount++;
            uf.TryUnite(compressed[a[i]], compressed[b[i]]);
        }
        //全ての違う変数を動かす+閉路の数だけ動かす必要がある 始点を閉路に組み込めているならば-1
        Console.WriteLine((n - sameCount) + uf.AllRepresents.Count(x => 2 <= uf.GetSize(x)) - (n != sameCount && b.IndexOf(a.Last()) != n ? 1 : 0));
    }
}


class UnionFind
{
    public int Size { get; private set; }
    public int GroupCount { get; private set; }
    List<int> Sizes;
    List<int> Parent;
    public UnionFind(int count)
    {
        Size = 0;
        GroupCount = 0;
        Parent = new List<int>(count);
        Sizes = new List<int>(count);
        ExtendSize(count);
    }
    public bool TryUnite(int x, int y)
    {
        int xp = Find(x);
        int yp = Find(y);
        if (yp == xp) return false;
        if (Sizes[xp] < Sizes[yp])
        {
            var tmp = xp;
            xp = yp;
            yp = tmp;
        }
        GroupCount--;
        Parent[yp] = xp;
        Sizes[xp] += Sizes[yp];
        return true;
    }
    public IEnumerable<int> AllRepresents => Enumerable.Range(0, Size).Where(x => x == Parent[x]);
    public int GetSize(int x) => Sizes[Find(x)];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int Find(int x)
    {
        while (x != Parent[x])
        {
            Parent[x] = Parent[Parent[x]];
            x = Parent[x];
        }
        return x;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void ExtendSize(int treeSize)
    {
        if (treeSize <= Size) return;
        Parent.Capacity = treeSize;
        Sizes.Capacity = treeSize;
        while (Size < treeSize)
        {
            Parent.Add(Size);
            Sizes.Add(1);
            Size++;
            GroupCount++;
        }
    }
}


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

int main()
{
  int n, t, a;
  double minavr = 1000;
  map<double, int> avr;
  cin >> n >> t >> a;
  for(int i=0; i<n; i++)
  {
    int h;
    cin >> h;
    double tmp = abs(t - h * 0.006 - a);
    avr[tmp] = i+1;
    minavr = min(minavr, tmp);
  }
  
  cout << avr[minavr] << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

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

    map<int,int> m;
    for(int i = 0; i < n; i++){
        if(!m.count(a[i]-1)){
            m[a[i]] = 1;
        }else{
            m[a[i]] = m[a[i]-1] + 1;
        }
    }
    int ans = 0;
    for(auto itr = m.begin(); itr !=  m.end(); itr++){
        //cout << itr->first << " " <<  itr->second << endl;
        ans = max(ans,itr->second);
    }

    cout << n - ans << endl;

    return 0;
}

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



int main() {
	stack<int> S;
	int a, b;
	string s;
	while (cin >> s){
		if (s[0] == '+') {
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			S.push(a + b);
		}
		else if (s[0] == '-') {
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			S.push(b - a);
		}
		else if (s[0] == '*') {
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			S.push(a * b);
		}
		else
			S.push(atoi(s.c_str()));
	}
	printf("%d\n", S.top());
}


Measured memory_bytes: 3296
#!/usr/bin/env python3

import numpy as np

def main():
    a, b, h, m = map(int, input().split())

    tyo = m * 6
    tan = h * 30 + m * 0.5
    deg = abs(tyo-tan)
    
    c = np.sqrt(a**2+b**2-2*a*b*np.cos(np.deg2rad(deg)))
    print(c)

if __name__ == '__main__':
    main()

Measured memory_bytes: 27224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) ;for (int i = 0; i<(int)(n); i++)
 
int main() {
  int N, a, b;
  a= 0;
  b=0;
  cin >> N;
  vector<int> vec(N);
  rep(i , N){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  if(N % 2 == 1){
    rep(i , N / 2){
    a += vec.at(2*i);
      b += vec.at(2*i + 1);
  }
    a += vec.at(N-1);
  }
  else{
        rep(i , N / 2){
    a += vec.at(2*i);
      b += vec.at(2*i + 1);
  }
  }
    cout << a-b << endl;
}

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

int main()
{
    int count = 0;
    string S;
    cin >> S;
    rep(i, S.size())
    {
        if (S[i] == '1')
        {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int c[509],s[509],f[509];
 
main()
{
   int n;
   cin>>n;
   for (int i=0; i<n-1; i++)
   {
       cin>>c[i]>>s[i]>>f[i];
   }
 
   for(int i=0; i<n; i++)
   {
       int t=0;
       for (int j=i; j<n-1; j++)
       {
           if(t<s[j])
           {
               t=s[j]+c[j];
           }
           else
           {
               while(t%f[j]!=0) t++;
               t+=c[j];
           }
       }
       cout<<t<<endl;
 }
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	bool flag = 1;
	if ( a == b || a == c || b == c) {
		if (a == b && a == c)
			flag = 0;
		if (a == c && a == b)
			flag = 0;
		if (b == c && a == b)
			flag = 0;	
	} else {
		flag = 0;
	}
	if (flag) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;
#define INF 100000

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int cnt = 0;
    rep(i, n-1){
        if(s[i] != s[i+1]) continue;
        else{
            cnt++;
            if(s[i+1] == '1'){
                s[i+1] = '0';
            }else{
                s[i+1] = '1';
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int mothernum, mother[100000];
int binary(int aim)
{
 int Start, End, Center;
   Start  = 0;
   End    = mothernum;
 
   while(Start < End){
     Center = (End + Start) / 2;
     if(mother[Center] > aim){
       End   = Center;
     } else if(mother[Center] < aim){
       Start = Center + 1;
     } else if(mother[Center] == aim){
       return 1;
     }
   }
 
 return 0;
 
}
int main()
{
 int  kidsnum, kids[50000], i, Count=0,flag;
  
 scanf("%d", &mothernum);
 for (i = 0; i < mothernum; i++) {
   scanf("%d", &mother[i]);
 }
   
 scanf("%d", &kidsnum);
 for(i = 0; i < kidsnum; i++) {
   scanf("%d", &kids[i]);
 }
 
 for(i = 0; i< kidsnum; i++){
   flag = binary(kids[i]);
   if(flag==1){
     Count++;
   }
 }
  
 printf("%d\n",Count);
 
 return 0;
}

Measured memory_bytes: 2360
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL

int main(){
  ll N, K;
  cin >> N >> K;
  map<ll, ll> ma;
  for(int i = 0; i < N; i++){
    ll A;
    cin >> A;
    if(!ma.count(A)) ma[A] = 1LL;
    else ma.at(A)++;
  }
  priority_queue<ll, vector<ll>, greater<ll>> que;
  for(auto ite = ma.begin(); ite != ma.end(); ite++){
    ll n = ite -> second;
    que.push(n);
  }
  ll syurui = ma.size();
  ll ans = 0;
  for(int i = 0; i < syurui - K; i++){
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 14964
S = input()
s = S[2:-1]
if S[0] != 'A':
    print('WA')
    exit()
flag = 0
for i in s:
    if i == 'C':
        flag += 1
if flag != 1:
    print('WA')
    exit()
l = list(S[1:])
l.remove('C')
l = ''.join(l)
if l != l.lower():
    print('WA')
    exit()
print('AC')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
Int INF = 1e18;
double EPS = 0.00000001;
//Int mod = 1e6+3;

int main() {
    Int n;
    cin >> n;
    Int ok = 0;
    Int ng = n;
    dump(0);
    string s;
    cin >> s;
    if (s == "Vacant") return 0;
    while (abs(ok - ng) > 1) {
        Int mid = (ok + ng) / 2;
        dump(mid);
        string t;
        cin >> t;
        if (t == "Vacant") return 0;
        if ((mid % 2 == 0 && s == t) || (mid % 2 == 1 && s != t)) {
            ok = mid;
        }
        else {
            ng = mid;
        }
    }
    return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define OUT(a) cout << (a) << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    ll H, W, h, w;

    cin >> H >> W >> h >> w;

    cout << H*W - (H*w + W*h - h*w) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define debug(X) cout << #X << " = " << X << endl

using namespace std;

const int oo = 1e9;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	#ifdef UTP
	freopen("input.txt", "r", stdin);
	#endif
	int n; cin >> n;
	long long total = 0;
	int mn = oo, cnt = 0;
	for (int i = 0; i < n; i++) {
        int x; cin >> x;
        if (x < 0) cnt++;
        mn = min(mn, abs(x));
        total += abs(x);
	}
    if (cnt % 2) total -= 2 * mn;
    cout << total << endl;
	return 0;
}


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

int main(){
    std::string s;
    std::vector<std::string> str = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};

    std::cin >> s;

    for(int i = 1; i <= 7; i++){
        if(s == str.at(i - 1)){
            std::cout << i << std::endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
# include <stdio.h>

int main(void)
{
    int N,D,X;
    int i,j,k,l;
    scanf("%d",&N);
    scanf("%d %d",&D,&X);

    int array[N];

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

    k=0;

    for(j=0;j<N;j++){
        l=0;
        while(array[j]*l+1<=D){
            l=l+1;
        }
        k=k+l;
    }
    k=k+X;

    printf("%d",k);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
   priority_queue<int> pq;
   int x, y, a , b, c;
   cin >> x >> y >> a >> b >> c;
   vector<int> ad(a);
   vector<int> bd(b);
   vector<int> cd(c);
   long long int sum = 0;
   for(int i = 0; i < a; i++)
      cin >> ad[i];
   for(int i = 0; i < b; i++)
      cin >> bd[i];
   for(int i = 0; i < c; i++)
      cin >> cd[i];
   sort(ad.rbegin(), ad.rend());
   sort(bd.rbegin(),bd.rend());
   for(int i = 0; i < x; i++)
      pq.push(ad[i]);
   for(int i=0; i < y; i++)
      pq.push(bd[i]);
   for(int i = 0; i < c; i++)
      pq.push(cd[i]);
   for(int i = 0; i< x+y; i++)
   {
      sum += pq.top();
      pq.pop();
   }


   cout << sum << endl;



}


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

template<class like_bool> inline void YES(like_bool condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class like_bool> inline void Yes(like_bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class like_bool> inline void POSS(like_bool condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class like_bool> inline void Poss(like_bool condition){ if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class like_bool> inline void First(like_bool condition){ if(condition)cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcount(n)

int main(){
    int N;
    cin >> N;
    long nums[N * 3];
    for(int i = 0; i < N * 3; i++){
        cin >> nums[i];
    }
    priority_queue<long, vector<long>, greater<long>> prefix_maximum;
    priority_queue<long, vector<long>, less<long>> suffix_minimum;
    long prefix_maximum_sum = 0, suffix_minimum_sum = 0;
    for(int i = 0; i < N; i++){
        prefix_maximum.push(nums[i]);
        prefix_maximum_sum += nums[i];
        suffix_minimum.push(nums[N * 3 - i - 1]);
        suffix_minimum_sum += nums[N * 3 - i - 1];
    }
    long prefix_maximum_sum_max[N + 1];
    long suffix_minimum_sum_min[N + 1];
    prefix_maximum_sum_max[0] = prefix_maximum_sum;
    suffix_minimum_sum_min[0] = suffix_minimum_sum;
    for(int i = N; i < N * 2; i++){
        prefix_maximum_sum += nums[i] - prefix_maximum.top();
        prefix_maximum.pop();
        prefix_maximum.push(nums[i]);
        prefix_maximum_sum_max[i - N + 1] = max(prefix_maximum_sum_max[i - N], prefix_maximum_sum);
        suffix_minimum_sum += nums[N * 3 - i - 1] - suffix_minimum.top();
        suffix_minimum.pop();
        suffix_minimum.push(nums[N * 3 - i - 1]);
        suffix_minimum_sum_min[i - N + 1] = min(suffix_minimum_sum_min[i - N], suffix_minimum_sum);
    }
    long ans = -1e18;
    for(int i = N; i <= N * 2; i++){
        ans = max(ans, prefix_maximum_sum_max[i - N] - suffix_minimum_sum_min[N * 2 - i]);
    }
    cout << ans << endl;
}


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

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;
 
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;

int main() {
  
  string s;
  cin >> s;
  
  int mn = 10000,t;
  
  for ( int i = 0; i < s.size() - 2; i++){
    t = ( s[i] - '0' ) * 100 + ( s[i+1] - '0' ) * 10 + ( s[i+2] - '0' ) ;
    if ( mn > abs( 753 - t ) ){
      mn = abs(753-t);
    }
  }
  
  cout << mn << endl;

}

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

using namespace std;

using ll = long long;

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

    int n; cin >> n;
    vector<int> p(n); for (int& x : p) cin >> x;
    vector<int> q = p;
    sort(q.begin(), q.end());

    int cnt = 0;
    for (int i = 0; i < n; i++) if (p[i] != q[i]) cnt++;
    cout << ((cnt > 2) ? "NO" : "YES") << endl;

    return 0;
}


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

int main(){
  string S,T;
  cin>>S>>T;
  int count=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)!=T.at(i))
      count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3928
cnt,target_amount = gets.chomp.split(" ").map(&:to_i)

    ans = "-1 -1 -1"
    is_hit = false
    (0..cnt).each do |yukichi_num|
        left_cnt = cnt - yukichi_num
        (0..left_cnt).each do |highchi_num|
            noguchi_num = left_cnt - highchi_num
            amount = 10000 * yukichi_num + 5000 * highchi_num + 1000 * noguchi_num
            # print (yukichi_num.to_s + "\t" + highchi_num.to_s + "\t" + noguchi_num.to_s + "\t" + amount.to_s + "\n")
            if (amount == target_amount) then
                ans = "%d %d %d" % [yukichi_num, highchi_num, noguchi_num]
                is_hit = true
            end
            break if is_hit
        end
        break if is_hit
    end
    print(ans)

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <iomanip>
#include <cmath>

using namespace std;

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

	string s;
	cin >> s;

	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 && s[i] == 'L') {
			cout << "No" << endl;
			return 0;
		}
		if (i % 2 == 1 && s[i] == 'R') {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#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);
    lint a,b,c,x,y;std::cin>>a>>b>>c>>x>>y;
    lint d=std::min(a+b,c+c),z=std::min(x,y);
    std::cout<<d*z+(x>y?std::min(a,c+c)*(x-z):std::min(b,c+c)*(y-z))<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int d,e,f;
  d=max(max(a,b),c);
  f=min(min(a,b),c);
  e=a+b+c-d-f;
  cout << 10*d+f+e << endl;
}

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

int main()
{
  int n,m;
  cin >> n >> m;
  for(int i = 0; i < m; ++i){
    int a;
    cin >> a;
    n -= a;
  }
  cout << max(-1, n) << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int c[1100][1100];
int bfs[1100][1100];
int dx[2][6]={{-1,0,1,1,0,-1},{0,1,1,0,-1,-1}};
int dy[2][6]={{0,1,0,-1,-1,-1},{1,1,0,-1,0,1}};
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++)for(int j=0;j<a;j++){
		scanf("%d",&c[i+1][j+1]);
	}
	queue<pair<int,int> > Q;
	Q.push(make_pair(0,0));
	while(Q.size()){
		int row=Q.front().first;
		int col=Q.front().second;
		Q.pop();
		for(int i=0;i<6;i++){
			int tr=row+dx[row%2][i];
			int tc=col+dy[row%2][i];
			if(tr<0||tc<0||tr>=b+2||tc>=a+2)continue;
			if(c[tr][tc])continue;
			if(bfs[tr][tc])continue;
			bfs[tr][tc]=1;
			Q.push(make_pair(tr,tc));
		}
	}
	//for(int i=1;i<=b;i++){
	//	for(int j=1;j<=a;j++)printf("%d ",bfs[i][j]);
	//	printf("\n");
	//}
	int ret=0;
	for(int i=1;i<=b;i++){
		for(int j=1;j<=a;j++){
			if(!c[i][j])continue;
			for(int k=0;k<6;k++){
				int tr=i+dx[i%2][k];
				int tc=j+dy[i%2][k];
				if(bfs[tr][tc])ret++;
			}
		}
	}
	printf("%d\n",ret);
}

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

using namespace std;
using i64 = std::int_fast64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<i64> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  i64 sum = 0, cnt = 0;
  for (int i = 0; i < N; i++) {
    sum += abs(A[i]);
    if (A[i] < 0) cnt++;
  }

  if (cnt % 2 != 0) {
    i64 minn = 1 << 28;
    for (int i = 0; i < N; i++) {
      minn = min(minn, abs(A[i]));
    }
    sum -= 2 * minn;
  }

  cout << sum << '\n';
  return 0;
}


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

int main(){
    int n;
    string before, now;
    set<string> used;
    
    cin >> n;
    cin >> before;
    used.insert(before);

    bool judge = true;
    for(int i = 1; i < n; i++){
        cin >> now;
        if(used.count(now) || before[before.length()-1] != now[0]){
            judge = false;
        }
        used.insert(now);
        before = now;
    }

    if(judge)   cout << "Yes" << endl;
    else        cout << "No" << endl;

    return 0;
}

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

int main(void){
	int N;
	scanf("%d",&N);
	int array[N];
	int i, T, S1 = 0, S2 = 0, min;
	
	for (i = 0; i < N; i++){
		scanf("%d",&array[i]);
	}

	min = 5050;
	for (T = 1; T <= N; T++){
		for (i = 0; i < T; i++){
			S1 += array[i];
		}
		for (i = T; i < N; i++){
			S2 += array[i];
		}
		if(min > abs(S1-S2)){
			min = abs(S1-S2);
		}
		S1 = 0;
		S2 = 0;
	}
	printf("%d\n",min);
	return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n = 5;
    vector<int> A(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    int res = 0;
    for (int i = 0; i < n; ++i) {
        if (A[i] != i + 1) {
            res = i + 1;
            break;
        }
    }

    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main() {
	char input[2];
	scanf("%c", input);

	char print;
	if (input[0] == 'A') 
	 print = 'T';
	if (input[0] == 'T')
		print = 'A';
	if (input[0] == 'C')
		print = 'G';
	if (input[0] == 'G')
		print = 'C';

	printf("%c", print);

	return 0;
}

Measured memory_bytes: 128
N = int(input())
H = list(map(int, input().split()))

for i in reversed(range(1,N)):
        if H[i-1] > H[i]:
                H[i-1] -= 1
        else:
                pass
        
ans = "Yes"

for i in (range(0,N-1)):
        if H[i+1] < H[i]:
                ans = "No"
                break
        else:
                pass

print(ans)

Measured memory_bytes: 14396
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
    double a,b;
    cin >> a >> b;
    cout << ceil((a + b) / 2) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
s = ["" for i in range(N)]
t = [0 for i in range(N)]
for i in range(N):
    s_str, t_str = input().split()
    s[i] = s_str
    t[i] = int(t_str)
    
X = input()
ans = 0
count = False
for i in range(N):
    if count:
        ans += t[i]
    if s[i] == X:
        count = True
print(ans)

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

const int mod = 1e9 + 7;

int P(int a, int b) {
	if(b == 0) return 1;
	if(b & 1) return (long long)P(a, b - 1) * a % mod;
	int t = P(a, b / 2);
	return (long long)t * t % mod;
}

int D(int a, int b) {
	return (long long)a * P(b, mod - 2) % mod;
}

const int N = 203, X = 100005;
int n, x, s[N], dp[X], pd[X];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> x;
	int ft = 1;
	for(int i = 1; i <= n; ++i) {
		cin >> s[i];
		ft = (long long)ft * i % mod;
	}
	sort(s + 1, s + n + 1, [](int a, int b) { return a > b; });
	dp[x] = 1;
	for(int i = 1; i <= n; ++i) {
		int prop = D(1, n + 1 - i), nprop = D(n - i, n + 1 - i);
		for(int j = 0; j <= x; ++j) {
			pd[j] = 0;
		}
		for(int j = 0; j <= x; ++j) {
			(pd[j % s[i]] += (long long)prop * dp[j] % mod) %= mod;
		}
		for(int j = 0; j <= x; ++j) {
			dp[j] = ((long long)dp[j] * nprop % mod + pd[j]) % mod;
		}
	}
	int fp = 0;
	for(int j = 0; j <= x; ++j) {
		(fp += (long long)dp[j] * j % mod) %= mod;
	}
	fp = (long long)fp * ft % mod;
	cout << fp << endl;
	return 0;
}


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

using LL = long long;
using LD = long double;
 
LL mod = 998244353;

int main()
{
	LL n;
	cin >> n;
	unordered_map<LL, string> mp;
	mp[0] = mp[1] = mp[6] = mp[8] = "pon";
	mp[2] = mp[4] = mp[5] = mp[7] = mp[9] = "hon";
	mp[3] = "bon";
	
	cout << mp[n%10] << "\n";
}

Measured memory_bytes: 3556
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    map <int,int>mp;
    int  n,cnt=1;  cin>>n;
    mp[n]++;
    while (true){
        cnt++;
        if (n&1) n = 3 * n + 1 ; 
        else n /= 2 ; 
        mp[n]++;
        if (mp[4]>=2 or mp[1]>=2 or mp[2]>=2) break;
    }
    cout << cnt << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

int main()
{
    int size, count_ac = 0, inicio, fin, times, ans;
    cin >> size >> times;
    string word;
    cin >> word;
    vector<int> v_ac;
    for(int i = 0; i < word.length(); i++)
    {
        if(word[i - 1] == 'A' && word[i]=='C')
        {
            count_ac++;
            v_ac.push_back(count_ac);
        }
        else
            v_ac.push_back(count_ac);
    }
    for (int i = 0; i < times; i++ )
    {
        cin >> inicio >> fin;
        
        ans = v_ac[fin - 1] - v_ac[inicio - 1];
        cout << ans << endl;
    }
return 0;
}

Measured memory_bytes: 1528
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]

// language: Rust(1.42.0)
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"
// My Library Repo' is at "https://github.com/Loptall/prcn_lib"

/*
    そう甘くはないんだな〜w
*/

// from std...
use std::cmp::{
    max, min, Ordering,
    Ordering::{Equal, Greater, Less},
    Reverse,
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::convert::TryInto;
use std::mem::swap;
use std::num::{NonZeroU32, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Index, IndexMut, Mul, MulAssign, Neg, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub,
    SubAssign,
};
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep' crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, multinomial, Integer};
use num_rational::Rational;
use num_traits::{clamp, one, pow, zero, Num, NumAssignOps, NumOps, One, Pow, Zero};
use permutohedron::Heap;
use proconio::{
    fastout, input, is_stdin_empty,
    marker::{Bytes, Chars, Isize1, Usize1},
};
use rand::random;

pub const MOD10E9_7: usize = 1000000007;
pub const MOD99_: usize = 998244353;
pub const MAX: usize = std::usize::MAX;
pub const PI: f64 = f64::consts::PI;
pub const A: u8 = 65;

// code...
// #[fastout]
fn main() {
    input! {
        n: usize
    }

    let ans = n.next_multiple_of(&1000) - n;
    println!("{}", ans);
}


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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N ;
  vi cnt(26,50);
  rep(i,N){
    string s; cin >> s ;
    vi cnt1(26);
    rep(j,s.size()) cnt1[int(s[j]-'a')]++;
    rep(k,26) chmin(cnt[k],cnt1[k]);
  }
  string ans = "";
  rep(k,26) ans += string(cnt[k],char('a'+k));
  cout << ans << endl;
  return 0;
}


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

int main(){
  ll i,j,k,N,c[3][3];
  rep(i,3){
    rep(j,3){
      cin>>c[i][j];
    }
  }
  set<ll> se;
  rep(i,3){
    rep(j,3){
      if(i==j)continue;
      se.insert(c[0][i]+c[1][j]+c[2][((i+1)^(j+1))-1]);
    }
  }
  if(se.size()==1){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i=0;i<(int)n;++i)

int N, K;
int V[51];

signed main()
{
	cin >> N >> K;
	rep(i, N) cin >> V[i];

	priority_queue<int,vector<int>,greater<int>> pq;

	int ans = 0;

	for (int i = -1; i < K; ++i) {
		for (int j = N; j > i; --j) {
			int len = (i + 1) + (N - j);

			if (len > K) continue;

			//printf("[0, %lld] and [%lld, %lld]\n", i, j, N-1);

			int sum = 0;

			for (int k = 0; k <= i; ++k) {
				sum += V[k];
				pq.push(V[k]);
			}

			for (int k = N - 1; k >= j; --k) {
				sum += V[k];
				pq.push(V[k]);
			}

			ans = max(ans, sum);
			int cnt = 0;
			while (not pq.empty() and cnt < K - len) {
				sum -= pq.top();
				ans = max(ans, sum);
				pq.pop();
				cnt++;
			}

			while (not pq.empty()) pq.pop();
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
class SegmentTreeRMQ {
    // st es el arreglo de nodos del segment tree
    vector<long long> arr, st;
    // leaf guarda la ubicaci??n de cada hoja en st
    vector<int> leaf; int n;

    // construir nodo u, que representa al rango [i,j]
    void build(int u, int i, int j) {
        // caso de que el rango representa una hoja
        if (i == j) {
            leaf[i] = u;
            st[u] = arr[i];
            return;
        }
        // l y r son los hijos izquierdo y derecho de u
        int m = (i+j)/2, l = u*2+1, r = u*2+2;
        build(l, i, m);
        build(r, m+1, j); // es importante el +1
        st[u] = min(st[l], st[r]); // range min. query
    }

    // query en el rango [a,b], considerando que nos
    // encontramos en el nodo u que representa a [i,j]
    long long query(int a, int b, int u, int i, int j) {
        // nodo fuera del rango [a,b], retornar neutro
        if (j < a or b < i)
            return 1e18; //infinito = neutro del m??n.
        // nodo totalmente contenido en [a,b]
        if (a <= i and j <= b)
            return st[u]; // responder directamente
        // si no, componer queries de ambos hijos
        int m = (i+j)/2, l = u*2+1, r = u*2+2;
        long long x = query(a, b, l, i, m);
        long long y = query(a, b, r, m+1, j); // +1 !!
        return min(x, y);
    }

    // actualizar nodo u considerando que uno de sus
    // hijos fue actualizado antes (o es una hoja)
    void update(int u) {
        int l = u*2+1, r = u*2+2;
        st[u] = min(st[l], st[r]); // actualizar info
        // si no es la ra??z (nodo 0) actualizar padre
        if (u != 0) update((u-1)/2);
    }

public:
    // construir segment tree a partir de un vector
    SegmentTreeRMQ(vector<long long>& v) {
        arr = v;
        n = v.size();
        leaf.resize(n);
        // reservar tama?±o para el peor caso, 4*N
        st.resize(n*4+5);
        // construir desde la ra??z
        build(0, 0, n-1);
    }

    // [a,b] es inclusivo inclusivo, indexado desde 0
    long long query(int a, int b) {
        // responder query procesando desde la ra??z
        return query(a, b, 0, 0, n-1);
    }

    // setea un valor en cierto ??ndice del arreglo
    void update(int index, long long value) {
        int u = leaf[index];
        arr[index] = value;
        st[u] = arr[index];
        // chequea si la hoja es ra??z por si N = 1
        if (u != 0) update((u-1)/2);
    }
};
int main(){
    int n,q;
    cin>>n;
    cin>>q;
    vector <long long> a(n);
    for(int i=0;i<n;i++){
        a[i]=pow(2,31)-1;
    }
    SegmentTreeRMQ st(a);
    for(int j=0;j<q;j++){
        int c,x,y;
        cin>>c;
        cin>>x;
        cin>>y;
        if(c==0){
            st.update(x,y);
        }
        else if(c==1){
            cout<<st.query(x,y)<<"\n";
        }
    }
return 0;
}

Measured memory_bytes: 7920
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input!(h: usize, w: usize, c: [[usize; 10]; 10], a: [[i32; w]; h]);
    let mut wf = c;
    for k in 0..10 {
        for i in 0..10 {
            for j in 0..10 {
                wf[i][j] = cmp::min(wf[i][j], wf[i][k] + wf[k][j]);
            }
        }
    }

    let mut ans = 0;
    for i in 0..h {
        for j in 0..w {
            if a[i][j] == -1 {
                continue;
            }
            let a = a[i][j] as usize;
            ans += wf[a][1];
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
// https://atcoder.jp/contests/aising2020/tasks/aising2020_c
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;
#define lli long long int
#define numberofdigits(x) floor(log10(x)) + 1

lli f[10004];

int main()
{
    lli n,i,j,k,c;
    for(i=1;i<=100;i++)
    {
        for(j=1;j<=100;j++)
        {
            for(k=1;k<=100;k++)
            {
                c=i*i+j*j+k*k+i*j+j*k+k*i;
                if(c<=10000)
                    f[c]++;
            }
        }
    }
    cin>>n;
    for(i=1;i<=n;i++)
        cout<<f[i]<<"\n";
    return 0;
}

Measured memory_bytes: 3660