akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl;
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2



int main() {
	int n;
	cin >> n;
	vector<int>v(n);
	rep(i, 0, n)cin >> v[i];
	
	int cnt = 0;
	rep(i, 1, n - 1) {
		vector<int>tmp;
		tmp.pb(v[i - 1]);
		tmp.pb(v[i]);
		tmp.pb(v[i + 1]);
		sort(all(tmp));
		if (tmp[1] == v[i])cnt++;
	}
	puts(cnt);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main(){
    string s;cin>>s;
    if(s[0]==s[1] ||
        s[1] == s[2]||
        s[2] == s[3]){
        cout << "Bad"<<endl;
    }else{
        cout << "Good" <<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int n;
char s1[60],s2[60];
int sort(int k,int last)
{
	if(k==n)return 1;
	long long count=0;
	if(k==n-1)return (3-last);
	if(k+1<n&&s1[k]==s1[k+1]&&s2[k]==s2[k+1])
	{
		if(last==0)count+=(int)(((long long)sort(k+2,2)*6)%1000000007);
		if(last==2)count+=(int)(((long long)sort(k+2,2)*3)%1000000007);
		if(last==1)count+=(int)(((long long)sort(k+2,2)*(3-last))%1000000007);
	}
	if(s1[k]==s2[k])count+=(int)(((long long)sort(k+1,1)*(3-last))%1000000007);
	return (count%1000000007);
}
int main()
{
	cin>>n;cin>>s1>>s2;
	cout<<sort(0,0);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<array>
#include<utility>

int main(){
	int N;
	std::cin >> N;
	
	std::array<int,100> A;
	
	for(int i=0;i<N;i++){
		std::cin >> A[i];
	}
	
	int change = 0;
	
	for(int i=0;i<N;i++){
		int min_num =std::min_element(A.begin()+i,A.begin()+N) - A.begin();
		if(i!=min_num){
			change++;
			std::swap(A[i],A[min_num]);
		}
	}
	
	for(int i=0;i<N;i++){
		std::cout << A[i];
		if(i!=N-1){
			std::cout<<" ";
		}else{
			std::cout<<std::endl;
		}
	}
	
	std::cout << change <<std::endl;
	
	return 0;
}

Measured memory_bytes: 3116
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int ans=0;
	if(k>=a){
		k-=a;
		ans+=a;
	}else ans+=k,k=0;
	if(k>=b){
		k-=b;
	}else k=0;
	ans-=min(k,c);
	cout<<ans;
	RE 0;
}




Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define ll long long
#define PLI pair<ll,int>
using namespace std;

int main()
{
//	freopen("UVA1636_input.txt","r",stdin); 
//	 freopen("UVA1636_out.txt","w",stdout);	
	ll a,b;
	cin>>a>>b;
	cout<<max(max(a+b,a-b),a*b)<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1145141919
#define LLINF 1145148101919
#define PI 3.14159265359
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        siz.assign(sz_, 1LL); // assign: 再代入
        par.resize(sz_);      // resize: 再確保
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x)
    { // 根の検索
        while (par[x] != x)
        {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y])
            swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y)
    { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x)
    { // 素集合のサイズ
        return siz[root(x)];
    }
};

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

vector<ll> decom;

void decompositPrime(ll n)
{
    ll a = 2;
    while (n >= a * a)
    {
        if (n % a == 0)
        {
            decom.push_back(a);
            n /= a;
        }
        else
        {
            a++;
        }
    }
    decom.push_back(n);
}

string S, T;
int ctoi_alpha(char c)
{
    if (c >= 'a' && c <= 'z')
    {
        return c - 'a';
    }
    return 0;
}

////////////////////////////////////////

int main()
{
    double N; cin >> N;
    vector<double> A(N);
    REP(i,N) cin >> A[i];

    vector<double> inv(N);
    REP(i,N) inv[i] = 1/A[i];
    double ans;
    REP(i,N){
        ans += inv[i];
    }

    std::cout << std::defaultfloat << std::setprecision(10);

    cout << 1/ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

struct edge {
    int from, to;
    ll cost;
};


int main(){
    int n, m;
    cin >> n >> m;
    vector<edge> G(m);

    rep(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        G[i] = {a, b, -c};
    }

    const ll INF = 1e18;
    vector<ll> d(n+1, INF);
    d[1] = 0;
    rep(i, n){
        rep(j, m){
            edge e = G[j];
            if(d[e.from] != INF && d[e.from] + e.cost < d[e.to]){
                d[e.to] = d[e.from] + e.cost;
            }
        }
    }

    vector<bool> update(n+1);
    rep(i, n){
        rep(j, m){
            edge e = G[j];
            if(d[e.from] != INF && d[e.from] + e.cost < d[e.to]){
                d[e.to] = d[e.from] + e.cost;
                update[e.from] = true;
                update[e.to] = true;
            }
        }
    }

    if(update[n]) cout << "inf" << endl;
    else cout << -d[n] << endl;
}

Measured memory_bytes: 256
def b_rgb_boxes(R, G, B, N):
    """Rr+Gg+Bb=N となる整数(r, g, b)の組はいくつか。"""
    ans = 0
    for r in range(N + 1):
        for g in range(N + 1):
            t = N - R * r - G * g
            if t >= 0 and (t % B == 0):
                ans += 1
    return ans

R, G, B, N = [int(i) for i in input().split()]
print(b_rgb_boxes(R, G, B, N))

Measured memory_bytes: 40684
from collections import Counter

n=int(input())
v=list(map(int,input().split()))

e=Counter(v[0::2])
o=Counter(v[1::2])
e_key=sorted(e.items(),reverse=True,key=lambda x:x[1])
o_key=sorted(o.items(),reverse=True,key=lambda x:x[1])

if e_key[0][0]!=o_key[0][0]: print(n-e_key[0][1]-o_key[0][1])
else:
    if len(e_key)==1 and len(o_key)==1: print(n//2)
    elif len(e_key)==1: print(n//2-o_key[1][1])
    elif len(o_key)==1: print(n//2-e_key[1][1])
    else:
        if e_key[0][1]>o_key[0][1]: print(n-e_key[0][1]-o_key[1][1])
        elif e_key[0][1]<o_key[0][1]: print(n-o_key[0][1]-e_key[1][1])
        else:
            if e_key[1][1]>o_key[1][1]: print(n-e_key[1][1]-o_key[0][1])
            else: print(n-o_key[1][1]-e_key[0][1])

Measured memory_bytes: 27452
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    std::cout<<std::fixed<<std::setprecision(10);
    
    int N; cin >> N;
    string S, T; cin >> S >> T;
    rep(i, N) cout << S[i] << T[i];
    cout << endl;
    return 0;
}

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

int main()
{
  string s;
  cin >> s;
  string ans(s.size(),'x');
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,H,xx=0;
	cin>>n;
	int x[n],y[n],h[n];
	for(int i=0;i<n;i++) cin>>x[i]>>y[i]>>h[i];
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			H=-1;
			vector<int> h0;
			for(int k=0;k<n;k++){
				if(H==-1){
					if(h[k]==0){
						h0.push_back(k);
						continue;
					}
					H=abs(i-x[k])+abs(j-y[k])+h[k];
				}
				if(max(H-abs(i-x[k])-abs(j-y[k]),0)!=h[k]) break;
				if(k==n-1){
					for(int l=0;l<h0.size();l++){
						if(H-abs(i-x[h0[l]])-abs(j-y[h0[l]])>0){
							xx=1;
							break;
						}
					}
					if(xx) break;
					cout<<i<<" "<<j<<" "<<H<<endl;
					return 0;
				}
				xx=0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


vector<int> z_algorithm(const string &s) {
  vector< int > prefix(s.size());
  for (int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    }
    else {
      int k = max(0, j + prefix[j] - i);
      while(i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = int(s.size());
  return prefix;
}

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

  int ans = 0;
  rep(i, N) {
    auto pre = z_algorithm(S.substr(i));
    rep(j, N-i) {
      chmin(pre[j], j);
    }
    chmax(ans, *max_element(ALL(pre)));
  }
  cout << ans << endl;
  return 0;
}


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

#define INF 100100100
#define MOD 1000000007

using namespace std;
using ll = long long;
using ull = unsigned long long ;

int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0); 
   int N;
   cin>>N;
   vector<int> p(N);
   for (int i = 0; i < N; i++)cin>>p[i];
   ull count=0;
   for (int i = 0; i < N-1; i++) {
      if(p[i]==i+1){
         int c=p[i];
         p[i]=p[i+1];
         p[i+1]=c;
         count++;
      }
      else if(i==N-2){
         if(p[i+1]==i+2){
            int c=p[i];
            p[i]=p[i+1];
            p[i+1]=c;
            count++;
         }
      }
   }
   cout<<count<<endl;
   return 0;
}


Measured memory_bytes: 640
def count(limit, max, n, queue, black_list)
  if queue.size == limit
    return queue.inject(:+) == max ? 1 : 0
  end

  result = 0
  (n..9).step do |i|
    queue << i
    result += count(limit, max, i + 1, queue, black_list)
    queue.pop
  end
  result
end

def bfs
  while gets
    limit, max = $_.split.map(&:to_i)
    break if limit == 0 && max == 0
    puts count(limit, max, 0, [], [])
  end
end

bfs

Measured memory_bytes: 8736
export class Main {
  static main(input): string {
    const tmp: string[] = input.split("\n");
    const [n, m]: number[] = tmp[0].split(" ").map(Number);
    let lM: number = 0;
    let rM: number = n;
    for (let i = 1; i <= m; ++i) {
      const t: number[] = tmp[i].split(" ").map(Number);
      if (lM < t[0]) {
        lM = t[0];
      }
      if (t[1] < rM) {
        rM = t[1];
      }
    }
    const t: number = rM - lM;
    return `${t < 0 ? 0 : t + 1}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 31120
num = gets.chomp.split().map(&:to_i) 
MOD = 10**9 + 7
bs = Array.new(num[0]+1, 0)
num[1].times do |n|
  a = gets.chomp.to_i
  bs[a] = -1
end

num1, num2, s = 0, 1, 0
(num[0]).times do |n|
  s = bs[n+1] < 0 ? 0 : (num1 + num2) % MOD
  num1 = num2
  num2 = s
end

puts s

Measured memory_bytes: 3836
import random

def calc(D, s, t):
  last = [0 for _ in range(26)]
 
  value = 0
  for i in range(D):
    day = i + 1
    value += s[i][t[i]-1]
    last[t[i]-1] = day
    for j in range(26):
      value -= c[j] * (day - last[j])
  return value

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [random.randint(1,26) for _ in range(D)]

val = calc(D, s, t)
for _ in range(1000):
  d_rand = random.randint(1,D)
  q_rand = random.randint(1,26)
  old = t[d_rand-1]
  t[d_rand-1] = q_rand
  if val > calc(D, s, t):
    t[d_rand-1] = old
  else:
    val = calc(D, s, t)
for i in range(D):
  print(t[i])

Measured memory_bytes: 78416
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int n;
vector<vector<int> > to;
vector<int> point;
priority_queue<int> q;
void dfs(int v,int p=-1){
  point[v]=q.top();
  q.pop();
  rep(i,to[v].size()){
    int nv=to[v][i];
    if(nv==p) continue;
    dfs(nv,v);
  }
}
int main(){
  cin >> n;
  to.resize(n,vector<int>(0));
  point.resize(n);
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ll score=0;
  rep(i,n){
    int c; cin >> c;
    q.push(c);
    score+=c;
  }
  score-=q.top();
  cout << score << endl;
  dfs(0);
  rep(i,n){
    cout << point[i] << " ";
  }cout << endl;
}

Measured memory_bytes: 8192
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int main(){
  FAST_IO
  int N, total = 0, maxEle = 0;

  cin >> N;

  for(int rep = 0, x; rep < N; ++rep){
    cin >> x;
    total += x;
    max_self(maxEle, x);
  }

  total -= maxEle / 2;
  cout << total << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>
#define PI 3.141592653589793

int main() {
    string s;
    cin >> s;
    int n = s.size();

    bool ok = 1;
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n - 1 - i]) ok = 0;
    }
    int l = 0, r = (n - 1) / 2 - 1;
    while (l <= r) {
        if (s[l] != s[r]) ok = 0;
        l++;  r--;
    }
    l = (n + 3) / 2 - 1;
    r = n - 1;
    while (l <= r) {
        if (s[l] != s[r]) ok = 0;
        l++;  r--;
    }
    cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;

int main() {
	int K, A, B;




	cin >> K >> A >> B;

	for (int i = A; i <=B; ++i) {

		if (i%K==0) {
			cout << "OK\n";
			break;
		}
		if (i% K!=0 && i==B) {
			cout << "NG\n";
		}
	}

	return 0;



}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
class abc
{
    public:
    ll a;
    ll ii;
};
bool fun(abc x,abc y)
{
    return x.a<y.a;
}
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    abc arr[n];
    rep (i,0,n)
    {
        cin>>arr[i].a;
        arr[i].ii=i+1;
    }
    sort (arr,arr+n,fun);
    rep (i,0,n)
    {
        cout<<arr[i].ii<<" ";
    }
}


Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

int ans = -1000000005;
int N, P[105][11], F[105][10];


int main(void) {
    scanf("%d", &N);
    rep(i, 0, N) {
      rep(j, 0, 10){
        scanf("%d", &F[i][j]);
      }
    }
    rep(i, 0, N) {
      rep(j, 0, 11){
        scanf("%d", &P[i][j]);
      }
    }
    
    for (int i = 1; i < 1<<10; i++) {
      int sum = 0;
      rep(j, 0, N) {
        int c = 0;
        rep(k, 0, 10) {
          if (F[j][k] & (i >> k)) c++;
        }
        sum += P[j][c];
      }
      ans = max(ans, sum);
    
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pl = pair<ll,ll>;

struct UF{
    int n;
    //正だったらその頂点の親,負だったら根で連結成分の個数
    vector<int> d;
    UF() {}
    UF(int N):n(N), d(N,-1){}
    int root(int v){
        if(d[v]<0) return v;
        return d[v]=root(d[v]);
    }
    bool unite(int X,int Y){
        X=root(X); Y=root(Y);
        if(X==Y) return false;
        if(size(X) < size(Y)) swap(X,Y);
        d[X]+=d[Y];
        d[Y]=X;
        return true;
    }
    int size(int v){ return -d[root(v)]; }
    bool same(int X,int Y){ return root(X)==root(Y); }
};

ll read()
{
    string s;
    cin >>s;

    int m = 1;
    if(s[0]=='-')
    {
        m = -1;
        s = s.substr(1);
    }

    int S = s.size();
    ll ret = atoll(s.substr(0,S-4).c_str())*1000 + atoll(s.substr(S-3).c_str());

    return m*ret;
}

int main()
{
    int n;
    scanf(" %d", &n);

    ll R = read();

    vector<pl> p(n);
    rep(i,n)
    {
        ll x=read(), y=read();
        p[i] = {x,y};
    }
    sort(all(p));

    UF uf(n);
    int idx = 0;
    set<pl> now;
    rep(i,n)
    {
        while(idx<n && p[idx].fi<=p[i].fi+R)
        {
            now.insert({p[idx].se,idx});
            ++idx;
        }

        auto itr = now.lower_bound({p[i].se-R,-1});
        while(itr!=now.end() && itr->fi<=p[i].se+R)
        {
            int id = itr->se;
            uf.unite(i,id);
            itr = now.erase(itr);
        }
    }

    set<int> s;
    rep(i,n) s.insert(uf.root(i));
    cout << s.size() << endl;
    return 0;
}



Measured memory_bytes: 19328
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(i64 i = 0; i < N; i++)
#define Rep(i, k, N) for(i64 i = k; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

i64 f(i64 n){
    int cnt = 0;
    while(n){
        n %= bitset<64>(n).count();
        cnt++;
    }
    return cnt;
}

i64 POW2[2][200010]; // [2^k % (popcount(X) + 1),  2^k % (popcount(X) - 1)]
i64 XmPC[2]; // [X % (popcount(X) + 1),  X % popcount(X - 1)]

int main(){
    int N;
    string X;
    cin >> N >> X;

    i64 popcnt = count(X.begin(), X.end(), '1');
    POW2[0][0] = 1 % (popcnt + 1);
    if(popcnt - 1 > 0) POW2[1][0] = 1 % (popcnt - 1);

    for(int i = 0; i < N; i++){
        XmPC[0] = ((2*XmPC[0]) + (X[i] - '0')) % (popcnt + 1);
        POW2[0][i+1] = (2*POW2[0][i]) % (popcnt + 1);
        if(popcnt - 1 > 0) {
            XmPC[1] = ((2*XmPC[1]) + (X[i] - '0')) % (popcnt - 1);
            POW2[1][i+1] = (2*POW2[1][i]) % (popcnt - 1);
        }
    }   

    for(int i = 0; i < N; i++){
        i64 b = (X[i] - '0');
        i64 p = (1 - 2*b);
        i64 n = (XmPC[b] + p*POW2[b][N-i-1]);
        while(n < 0) n += (popcnt + p);
        if(popcnt + p < 1) cout << 0 << endl;
        else cout << f(n % (popcnt + p)) + 1 << endl;
    }
}


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

signed main(){
  int N,A,B;
  cin>>N>>A>>B;
  int a,b,c;
  a=b=c=0;int k;
  for(int i=0;i<N;i++){
    cin>>k;
    if(k<=A)a++;
    else if(k>B)b++;
    else c++;
  }
  cout<<min(a,min(b,c))<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int h,w;
    while(true){
        cin >> h >> w;
        if(h != 0 or w != 0){
            for(int i = 1; i <= w; i++){
                cout << "#";
            }
            cout << endl;
            for(int i = 1; i <= h-2; i++){
                cout << "#";
                for(int j = 1; j <= w-2; j++){
                    cout << ".";
                }
                cout << "#" << endl;
            }
            for(int i = 1; i <= w; i++){
                cout << "#" ;
            }
            cout << endl << endl;
        } else {
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>

using namespace std;

 int main(void) {

	 int b, r, g, c, s, t;

	 while (1){
		 cin >> b >> r >> g >> c >> s >> t;
		 if (b == 0 && r == 0 && g == 0 && c == 0 && s == 0 && t == 0) break;
		 cout << 100 - (b * 5 + r * 3) * 2 - (t - b * 5 - r * 3) * 3 + b * 15 + r * 15 + b * 15 * 5 + r * 15 * 3 + g * 7 + c * 2 + s * 3 << endl;
	 }

	 return 0;
	
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int N;
int MAX = 1 << 20;

long long conv(int base) {
	int count[4] = {0,0,0};
	int n = 0;
	long long p = 1;
	long long ans = 0;
	while (base > 0) {
		int next = base % 4;
		if (next == 0)return -1;
		base /= 4;
		count[next]++;
		if (next == 1)ans += p * 3;
		else if (next == 2)ans += p * 5;
		else ans += p * 7;
		p *= 10;
	}
	if (count[3] > 0 && count[1] > 0 && count[2] > 0)return ans;
	else return -1;
}

int main() {
	cin >> N;
	int ans = 0;
	for (int base = MAX-1; base >= 0; base--) {
		long long res = conv(base);
		if (res != -1 && res <= N) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x,d; cin>>n>>x>>d;
    if (d==0){
        if (x!=0) cout<<n+1<<endl;
        else cout<<1<<endl;
        return 0;
    }
    map<ll,vector<pll> > Map;
    FOR(k,0,n){
        ll X = x*k;
        ll offset = X/d;
        ll mod = X%d;
        ll L = (ll)(k-1)*k/2 + offset;
        ll R = (ll)(n*2-k-1)*k/2 + offset;
        Map[mod].emplace_back(L,R);
    }
    ll ans=0;
    for(auto e:Map){
        auto rs = e.se;
        vll ps;
        unordered_map<ll,ll> zip,unzip;
        for(auto r:rs){
            ps.pb(r.fi);
            ps.pb(r.fi+1);
            ps.pb(r.se);
            ps.pb(r.se+1);
        }
        sort(all(ps));
        ps.erase(unique(all(ps)), ps.end());
        int sz = ps.size();
        rep(i,sz){
            zip[ps[i]] = i;
            unzip[i] = ps[i];
        }
        vi imos(sz+1,0);
        for(auto r:rs){
            int left = zip[r.fi];
            int right = zip[r.se];
            imos[left]++;
            imos[right+1]--;
        }
        rep(i,sz) imos[i+1]+=imos[i];
        rep(i,sz){
            if (imos[i] && !imos[i+1]) ans++;
            if (imos[i] && imos[i+1]) ans+=unzip[i+1]-unzip[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 87144
import math

N = int(input())
l = []
for i in range(N):
  l.append([int(x) for x in input().split()])
sum = 0
for i in range(N-1):
  for j in range(i+1, N):
    sum += math.sqrt((l[i][0] - l[j][0]) ** 2 + (l[i][1] - l[j][1])** 2)
ans = sum / N * 2
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull usigned long long
#define two(n) 1<<n
#define l(v) (int)v.size()
#define p_b push_back
#define m_p make_pair
const int pi=acos(-1.0);
const int int_max=1e9;
const long long ll_max=1e18;
string s,t;
int main()
{
	cin>>s>>t;
	int a=0;
	for(int i=0;i<3;i++)
		if(s[i]==t[i])
			a++;
	cout<<a;
	return 0;
}

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

#define int ll
#define FOR(i,n,k) for(int i=n;i<k;i++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    n--;
    int a[n],sum;
    FOR(i,0,n) cin>>a[i];
    sum = a[0];
    FOR(i,0,n-1) sum += min(a[i],a[i+1]);
    sum += a[n-1];
    cout<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    int ret=0;
    for(int i=0;i<a;i++){
        if(i<b)ret+=c;
        else ret+=d;
    }
    printf("%d\n",ret);
}

Measured memory_bytes: 128
#include <vector>
#include <iostream>
#include <queue>
#include <cassert>
#include <tuple>
#include <algorithm>

using namespace std;
typedef long long ll;

template<class D, int S>
struct WaveletTree {
    static const int N = 1<<S;
    typedef pair<D, int> P;
    int n;
    P x[N];
    int d[S+1][N];
    int lc[S][N];

    void built(int l, int r, int dps) {
        if (dps == S) return;
        int pl = l, md = (l+r)/2, pr = md;
        for (int i = l; i < r; i++) {
            if (d[dps][i] < md) {
                d[dps+1][pl++] = d[dps][i];
            } else {
                d[dps+1][pr++] = d[dps][i];
            }
            lc[dps][i] = pl-l;
        }
        built(l, md, dps+1);
        built(md, r, dps+1);
    }

    void init(int nn = N) {
        n = nn;
        for (int i = 0; i < N; i++) {
            x[i].second = i;
        }
        sort(x, x+n);
        for (int i = 0; i < N; i++) {
            d[0][x[i].second] = i;
        }
        built(0, N, 0);
    }
    //[l, r)??§k???????????°????????????
    int get(int l, int r, int k, int dps, int idx) {
        assert(1 <= k && k <= r-l);
        if (dps == S) {
            return d[dps][l];
        }
        int ls = (l > idx ? lc[dps][l-1] : 0);
        int c = lc[dps][r-1] - ls;
        if (k <= c) {
            return get(idx+ls, idx+ls+c, k, dps+1, idx);
        } else {
            int sz = 1<<(S-dps-1);
            return get(l+sz-ls, r+sz-(ls+c), k-c, dps+1, idx+sz);
        }
        return -1;
    }
    D get(int l, int r, int k) {
        return x[get(l, r, k, 0, 0)].first;
    }
    //[l, r)??§x?????????????????§?????????????????????????????????lower_bound
    int find(int l, int r, int x, int dps, int idx) {
        if (r <= l) return 1;
        if (dps == S) {
            return (x <= l) ? 1 : 2;
        }
        int ls = (l > idx ? lc[dps][l-1] : 0);
        int c = lc[dps][r-1] - ls;
        int sz = 1<<(S-dps-1);
        int md = idx+sz;
        if (x <= md) {
            return find(idx+ls, idx+ls+c, x, dps+1, idx);
        } else {
            return c+find(l+sz-ls, r+sz-(ls+c), x, dps+1, idx+sz);
        }
    }
    int find(int l, int r, D u) {
        return find(l, r, lower_bound(x, x+n, P(u, -1)) - x, 0, 0);
    }
};

WaveletTree<int, 17> st;
//StarrySkyTree<17> st;
int x[1<<17];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        st.x[i].first = x[i];
//        st.add(i, x[i]);
    }
    st.init(n);
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int l, r, e;
        cin >> l >> r >> e; l--;
        int mi = min(x[l], x[r-1]);
        int ma = max(x[l], x[r-1]);
        mi -= e;
        ma += e+1;
        int res = st.find(l, r, mi) + ((r-l) - st.find(l, r, ma));
        cout << res << endl;
    }
    return 0;
}    

Measured memory_bytes: 20500
if __name__ == '__main__':
    N = int(input())
    a = input()
    a = a.split(' ')
    a = list(map(int, a))

    num = 0
    
    for i in range(N):
        if i+1 == a[i]:
            if i == N - 1:
                tmp = a[i]
                a[i] = a[i-1]
                a[i] = tmp
                num += 1
            else:
                tmp = a[i+1]
                a[i+1] = a[i]
                a[i] = tmp
                num += 1

    print(num)


Measured memory_bytes: 14004
//file_name:ABC93_C.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


int main() {
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);

    if(b<a){
        swap(a,b);
    }
    if(c<b){
        swap(b,c);
    }
    if(b<a){
        swap(a,b);
    }
    //b=b-a;c=c-a;a=a-a;
    int ans=0;
    /*
    cout << a << b << c << endl;
    if((b-a)%2==1){
        while(b<c){
            a++
            b++
            ans++
        }
    }else{

    }
    */
    
    if((c-a)%2==0){
        if((c-b)%2==0){
            ans=(c-b)/2+(c-a)/2;
        }else{
            ans=(c-a)/2+(c+1-b)/2+1;
        }
    }else{
        if((c-b)%2==0){
            ans=(c-b)/2+(c-a+1)/2+1;
        }else{
            ans=1+(c-(b+1))/2+(c-a-1)/2;
        }
    }

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



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

int main() {
    int N ,count=0;
    cin >> N;
    unordered_map<string, int>mp;
    string S;
    for(int i=0; i<N; i++){
        cin >> S;
        auto is = mp.find( S );
        if( is == mp.end() ){
            mp[S] = 1;
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 17540
;; -*- coding:utf-8 -*-

(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter O3 '(optimize (speed 3) (safety 0) (debug 0)))
  (defparameter O2 '(optimize (speed 3) (safety 1))))

(defmacro print-line (obj &optional (stream '*standard-output*))
  `(prog1 (princ ,obj ,stream) (terpri ,stream)))


;; Hauptteil

(defun main ()
  (declare #.O3)
  (let* ((x (read))
	 (y (read)))
    (declare (fixnum x y))
    (loop for a of-type fixnum = x then (+ a a)
       for len of-type fixnum from 0
       while (<= a y)
       finally (print-line len))))


#-swank(main)


;; Für Test
(defun get-clipbrd ()
  (with-output-to-string (out)
    (run-program "C:/msys64/usr/bin/cat.exe" '("/dev/clipboard") :output out)))

(defun test ()
  (with-input-from-string (*standard-input* (delete #\return (get-clipbrd)))
    (main)))


;; Für Benchmark
(defparameter *file-path* *load-pathname*)
(defparameter *dir-path* (pathname (directory-namestring *file-path*)))
(defparameter *dat-path* (merge-pathnames "test.dat" *dir-path*))

#+swank
(with-open-file (out *dat-path*
		     :direction :output :if-exists :supersede)
  )

(defun bench ()
  (let ((*standard-output* (make-broadcast-stream)))
    (with-open-file (*standard-input* *dat-path*)
      (time (main)))))


Measured memory_bytes: 6632
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        string S;
        ll K;
        cin >> S >> K;
        ll cnt = 0;
        rep(i, 0, len(S)) {
                if (S[i]-'0' == 1) {
                        ++cnt;
                } else {
                        break;
                }
        }
        ll ans = 0;
        if (cnt >= K) {
               ans = 1; 
        } else {
                ans = S[cnt] - '0';
        }
        cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::max;

#[fastout]
fn main() {
    input! {
    n: usize,
    d: [[usize; 2]; n]
    }
    let mut count = 0;
    let mut p = 0;
    for i in 0..n {
        if d[i][0] == d[i][1] {
            count += 1;
        } else {
            p = max(count, p);
            count = 0;
        }
    }
    p = max(count, p);
    if p >= 3 {
        print!("Yes");
    } else {
        print!("No")
    }
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#define ALL(a) (a).begin(),(a).end()

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>que;

int main() {
  ll N;
  cin>>N;
  ll A[N];
  FOR(i,0,N-1){
    cin>>A[i];
  }
  sort(A,A+N);
  ll dif=1;
  ll same=0;
  FOR(i,1,N-1){
    if(A[i-1]==A[i]){
      same++;
    }else{
      dif++;
    }
  }

  if(same%2 ==1)dif--;

  cout<<dif<<endl;
return 0;
 
}

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

int LEN_MAX = 3000;
vector<vector<int>> dp(LEN_MAX + 1,vector<int>(LEN_MAX + 1,0));
string s,t;

int main(){
    cin >> s >> t;
    int slen = s.size(), tlen = t.size();

    for(int i = 0;i < slen;i++){
        for(int j = 0;j < tlen;j++){
            if(s[i] == t[j])
                dp[i+1][j+1] = dp[i][j] + 1;
            else
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
        }
    }

    string ans = "";
    int i = slen, j = tlen;
    while(i > 0 && j > 0){
        // 上に辿る
        if(dp[i][j] == dp[i][j-1])
            j--;
        // 左に辿る
        else if(dp[i][j] == dp[i-1][j])
            i--;
        // 斜めにたどる
        else{
            ans = s[i-1] + ans;
            i--; j--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const int mod=1000000007,INF=1001001001;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
 
 
//#define int ll
 
int n,t,x=0,mina,cnt=1;
int a[100010];
 
signed main(){
    cin>>n>>t;
    rep(i,0,n){
        cin>>a[i];
    }
    mina=a[0];
    
    rep(i,1,n){
        if(mina<a[i]){
            if(x==a[i]-mina)cnt++;
            if(x<(a[i]-mina)){
                x=a[i]-mina;
                cnt=1;
            }
        }
        mina=min(mina,a[i]);
    }
    
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,m;
    cin>>n>>m;
    if(n==0){
        if(m>1988)cout<<"H"<<m-1988<<endl;
        else if(m>1925)cout<<"S"<<m-1925<<endl;
        else if(m>1911)cout<<"T"<<m-1911<<endl;
        else cout<<"M"<<m-1867<<endl;
    }
    if(n==1)cout<<1867+m<<endl;
    if(n==2)cout<<1911+m<<endl;
    if(n==3)cout<<1925+m<<endl;
    if(n==4)cout<<1988+m<<endl;
    return 0;
}


Measured memory_bytes: 3072
import sys
from pprint import pprint

def solve(n, a):
    all_s = sum(a)
    half = all_s / 2
    s = 0
    for a_i in a:
        s += a_i
        if s >= half:
            if s - half >= half - (s - a_i):
                print(all_s - 2*s + 2*a_i)
            else:
                print(2*s - all_s)
            return

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = list(map(int, sys.stdin.readline().strip().split(" ")))
    solve(n, a)

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

using namespace std;
#define ll long long
int main() {
    //freopen("262144.in", "r", stdin);
    //freopen("262144.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ar[3];
    cin>>ar[0]>>ar[1]>>ar[2];
    sort(ar,ar+3);
    cout<<ar[0]+ar[1]<<endl;
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll t1,t2,a1,a2,b1,b2;cin>>t1>>t2>>a1>>a2>>b1>>b2;

  if(t1*a1+t2*a2==t1*b1+t2*b2) { cout<<"infinity"<<endl; return 0; }

  // A always runs long
  if(t1*a1+t2*a2<t1*b1+t2*b2) {
    swap(a1,b1);
    swap(a2, b2);
  }

  if(a1>b1) { cout<<0<<endl; return 0; }

  ll diff = (t1*a1+t2*a2) - (t1*b1+t2*b2);

  ll t1_diff = b1*t1-a1*t1;
  if(t1_diff==diff) { cout<<2<<endl; return 0; }

  ll result=(t1_diff/diff)*2+1;
  if(t1_diff%diff==0)result--;
  cout<<result<<endl;

//cout<<t1_diff<<' '<<diff<<endl;

  return 0;
}


Measured memory_bytes: 3612