akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;

int reduce_ene(int day, int except_num, vector<int> &c, vector<int> &last){
    int i;
    int sum_reduce;
    sum_reduce = 0;

    for(i=0;i<c.size();i++){
        if(i != except_num-1){
            sum_reduce += c[i] * (day+1 - last[i]);
        }
    }
    return sum_reduce;
}

int plus_ene(int day, vector<int> &t, vector<vector <int> > &s){
    return s[day][t[day] - 1];
}


int ene_cal(int D, vector<int> &t, vector<vector <int> > &s, vector<int> &c){
    int day;
    int ene;
    ene = 0;
    vector<int> last(c.size(), 0);
    for(day=0;day<D;day++){
        ene += plus_ene(day, t, s);  
        ene -= reduce_ene(day, t[day], c, last);
        //cout << ene << endl;
        last[t[day] - 1] = day + 1;
    }
    return ene;

}




int main(){
    /* init */

    int i,j;
    int D;
    vector<int> c;
    vector<int> t;

    cin >> D;
    int sum_c; 
    sum_c = 0;
    for(i=0;i<26;i++){
        int ci;
        cin >> ci;
        c.push_back(ci);
        sum_c += ci;
    }


    vector<vector <int> > s(D, vector<int>(c.size(), 0));

    for(j=0;j<D;j++){
        for(i=0;i<c.size();i++){
            int sij;
            cin >> sij;
            s.at(j).at(i) = sij;
    }}

    for(i=0;i<D;i++){
        int ti;
        cin >> ti;
        t.push_back(ti);
    }

    //end init
    long int ene;

    int M;
    cin >> M;
    vector<int> d;
    vector<int> q;
    for(i=0;i<M;i++){
        int di, qi;
        cin >> di >> qi;
        d.push_back(di);
        q.push_back(qi);
    }

    ene = ene_cal(D, t, s, c);
    int ene_old;
    int t_old;
    for(i=0;i<M;i++){
        t_old = t[d[i]-1];
        ene_old = ene;
        t[d[i]-1] = q[i];
        ene = ene_cal(D, t, s, c);
        /*
        if(ene < ene_old){
            t[d[i]-1] = t_old; 
            ene = ene_old;
        }
        */
        cout << ene << endl;

    }







    return 0;
}


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

int main(){
    vector<int> v(4);
    for(int i=0; i<3; i++){
        int t, s;
        cin >> t >> s;
        v[t-1]++;
        v[s-1]++;
    }
    int a = 0, b = 0;
    for(auto x: v){
        if(x == 1) a++;
        if(x == 2) b++;
    }
    if(a == 2 && b == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    S = input()

    zeroQue = []
    oneQue = []
    sIndex = 0
    out = 0

    for s in S:
        if s == '0':
            if len(oneQue) == 0:
                zeroQue.append(sIndex)
            else:
                out += 2
                oneQue.pop()

        else:
            if len(zeroQue) == 0:
                oneQue.append(sIndex)
            else:
                out += 2
                zeroQue.pop()

        sIndex += 1
    print(out)

if __name__ == '__main__':
    main()


Measured memory_bytes: 7156
# include <cstdio>
# include <algorithm>
using namespace std;

# define REP(i, n) for (int i = 1; i <= n; ++ i)
# define NR 101000

typedef long long ll;

int n, E, T;
ll f[NR], x[NR];

int main() {
	scanf ("%d%d%d", &n, &E, &T);
	int p = 0;
	ll s = 1e12;
	REP (i, n) {
		scanf ("%lld", &x[i]);
		
		while (p < i && 2 * (x[i] - x[p + 1]) >= T) {
			s = min (s, f[p] - x[p] - 2 * x[p + 1]);
			++ p;
			
		}
		f[i] = s + 3 * x[i];
		//printf ("(p:%d) ", p);
		if (p != i) f[i] = min (f[i], f[p] - x[p] + x[i] + T);
		//printf ("%I64d ", f[i]);
	}
	
	printf ("%lld\n", f[n] + E - x[n]);
	
	return 0;
}

//j -> i -> j+1 -> i

//f[i] = f[j] + x[i] - x[j] + max(2 * (x[i] - x[j + 1]), T)
//f[i] = f[j] - x[j] + x[i] + T
//f[i] = f[j] - x[j] - 2 * x[j + 1] + 3 * x[i]


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <math.h>
#include <bits/stdc++.h>
#include <iomanip> 



using namespace std;

int main(){
 
  int a;
  int b;
  int h;
  int m;
  long double hs;
  long double ms;
  long double ans;
  const double PI=3.14159265358979323846;

  cin>>a>>b>>h>>m;


  hs=(h*60+m)*0.5;
  ms=m*6;
  
  
  
  ans= sqrt(a * a + b * b - 2 * a * b * cos(((hs-ms)/180)*PI));

  
  cout<<fixed<<setprecision(20)<<ans<<endl;
  
  


}

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

int N, K;
int A[110];
int dp[100010];

int main()
{
    cin >> N >> K;
    for(int i = 0; i < N; i++)cin >> A[i];

    dp[0] = 0;
    vector<int> mem;
    for(int i = 1; i <= K; i++)
    {
        mem.clear();
        for(int j = 0; j < N; j++)
        {
            if(i - A[j] >= 0)mem.push_back(dp[i - A[j]]);
        }
        sort(mem.begin(), mem.end());
        mem.erase(unique(mem.begin(), mem.end()), mem.end());
        for(int j = 0; j <= mem.size(); j++)
        {
            if(j == (int)(mem.size()))
            {
                dp[i] = j;
                break;
            }
            if(j != mem[j])
            {
                dp[i] = j;
                break;
            }
        }
    }

    if(dp[K])cout << "First" << endl;
    else cout << "Second" << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

vector<vi> Graph(100100); 

struct Node{
  int now;
  int sub;
  long cost;
};

bool operator<(const Node &a, const Node &b){
  if(a.cost != b.cost){
    return a.cost < b.cost;
  }else{
    return a.now * 3 + a.sub < b.now * 3 + b.sub;
  }
}

bool operator>(const Node &a, const Node &b){
  if(a.cost != b.cost){
    return a.cost > b.cost;
  }else{
    return a.now * 3 + a.sub > b.now * 3 + b.sub;
  }
}

int main(){
  int n,m;
  cin >> n >> m;
  rep(i,m){
    int u,v;
    cin >> u >> v;
    u--;v--;
    Graph.at(u).push_back(v);
  }
  int s,t;
  cin >> s >> t;
  s--;t--;
  vector<vector<long>> dist(n+1,vl(3,1e9));
  dist.at(s).at(0) = 0;
  priority_queue<Node, vector<Node>, greater<Node>> que;
  que.push(Node{s,0,0});
  while(que.size()){
    Node node = que.top();
    que.pop();
    if(node.cost > dist.at(node.now).at(node.sub)) continue;
    for(int next : Graph.at(node.now)){
      if(dist.at(node.now).at(node.sub) == 1e9) continue;
      if(dist.at(next).at((node.sub+1)%3) > dist.at(node.now).at(node.sub) + 1){
        dist.at(next).at((node.sub+1)%3) = dist.at(node.now).at(node.sub) + 1;
        que.push(Node{next,(node.sub+1)%3,dist.at(next).at((node.sub+1)%3)});
      }
    }
  }
  if(dist.at(t).at(0) == 1e9) cout << -1 << endl;
  else cout << dist.at(t).at(0)/3 << endl;
}

Measured memory_bytes: 12928
import Base.parse
import Base.StringVector
using DataStructures

parse(::Type{String},  str::AbstractString) = str

isdelim(x::UInt8, xs::Set{UInt8}) = x in xs

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        if !isdelim(c, delims)
            break
        end
    end
    push!(out, c)
    if eof(s)
        return out
    end
    while !eof(s)
        c = read(s, UInt8)
        if isdelim(c, delims)
            break
        end
        push!(out, c)
    end
    return out
end

delimset = Set([0x0a, 0x20])

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

readvec(tys::Tuple , len::Signed)::Vector{Tuple{tys...}} = @inbounds Tuple{tys...}[reads(tys...) for i in 1:len]

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i = 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

function rewrite(con, root, index=1, depth=0)
    arr = Set(Int[])
    return root
end

function main()
    N,M = reads(Int,Int)
    con = [Set(Int[]) for i in 1:N]
    for i in 1:M
        a,b = reads(Int,Int)
        push!(con[a], b)
        push!(con[b], a)
    end
    root = Union{Tuple{Int,Int},Nothing}[nothing for i in 1:N]
    root[1] = (0,0)
    q = PriorityQueue{Int,Int}()
    enqueue!(q, 1, 0)
    while !isempty(q)
        index = dequeue!(q)
        for n in con[index]
            if isnothing(root[n]) || root[n][2] > root[index][2]+1
                v = root[index][2]+1
                root[n] = (index, v)
                get(q,n,9223372036854775807) > v && enqueue!(q, n, v)
            end
        end
    end
    ans = root
    for i in ans[2:end]
        if isnothing(i)
            println("No")
            return
        end
    end
    println("Yes")
    for i in 2:N
        println(ans[i][1])
    end
end

main()


Measured memory_bytes: 290700
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define Fi first
#define Se second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>

void fsscan(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

void scani(int &x)
{
    register int c = gc();x = 0;int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

int sumd(int n)
{
    int c=0;
    while(n)
    {
        c+=n%10;
        n=n/10;
    }
    return c;
}

int main()
{
    fsscan();
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    
    int x=0;
    while(1)
    {
        if(((k-1)*x+k)>=n)
        break;
        else
        x++;
    }
    cout<<x+1;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF 100000000
#define MAX 100001
#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

signed main(){ INIT;
    VAR(ll, a, b);
    if((a*b)%2){
        OUTL("Odd");
    } else {
        OUTL("Even");
    }
RET;}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define SZ(a) ((int)(a).size())
int main()
{
	string s;
	cin >> s;
	for (int i = 0; i + 1 < SZ(s); ++i)
		if (s[i] == 'A' && s[i+1] == 'C') {
			cout << "Yes\n";
			return 0;
		} 
	cout << "No\n";
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = sorted([LI() for _ in range(n)], reverse=True)
    b = set([tuple(LI()) for _ in range(n)])
    r = 0
    for c in a:
        t = (-1, 10000)
        for d in b:
            if c[0] < d[0] and c[1] < d[1] and t[1] > d[1]:
                t = d
        if t != (-1, 10000):
            r += 1
            b.remove(t)

    return r


print(main())




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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  
  rep(i,W+2) cout << '#';
  cout << endl;
  
  rep(i,H) {
    cout << '#';
    cin >> a[i];
    cout << a[i];
    cout << '#' << endl;
  }
  
  rep(i,W+2) cout << '#';
  cout << endl;
  
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

struct SegmentTree {
private:
    int n;
    vector<int> node;
public:
    SegmentTree(vector<int> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1,0);
        for (int i = 0;i < sz;++i) node[i+n-1] = v[i];
        for (int i = n-2;i >= 0;--i) node[i] = max(node[2*i+1],node[2*i+2]);
    }
    void update(int x,int val) {
        x += (n-1);
        node[x] = val;
        while (x > 0) {
            x = (x-1)/2;
            node[x] = max(node[2*x+1],node[2*x+2]);
        }
    }

    int getmax(int a,int b,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return 0;
        if (a <= l && r <= b) return node[k];
        int vl = getmax(a,b,2*k+1,l,(l+r)/2);
        int vr = getmax(a,b,2*k+2,(l+r)/2,r);
        return max(vl,vr);
    }
};

int main() {
    int n,k;
    cin >> n >> k;
    SegmentTree seg(vector<int>(300010,0));
    for (int i = 0;i < n;++i) {
        int a;
        cin >> a;
        seg.update(a,seg.getmax(a-k,a+k+1)+1);
    }
    cout << seg.getmax(0,300010) << newl;
}

Measured memory_bytes: 8548
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
    int a[3];
    for(int i=0;i<3;i++)cin>>a[i];
    sort(a,a+3);
    if(a[0]==5&&a[1]==5&&a[2]==7)puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 764
import heapq as h
n = int(input())
l = list(map(int,input().split()))
ls = [0]*(n+1)
rs = [0]*(n+1)
ll = l[:n]
rl = list(map(lambda x:-x,l[2*n:]))
h.heapify(ll)
h.heapify(rl)
ls[0] = sum(ll)
rs[n] = sum(rl)
for i in range(n):
  c = h.heappushpop(ll,l[n+i])
  ls[i+1] = ls[i] + l[n+i] - c
  c = h.heappushpop(rl,-l[2*n-1-i])
  rs[-2-i] = rs[-1-i] - l[2*n-i-1] - c
ans = ls[0]+rs[0]
for i in range(n+1):
  if ans < ls[i]+rs[i]:
    ans = ls[i]+rs[i]
print(ans)
# print(ls)
# print(rs)


Measured memory_bytes: 38288
#include <cmath>
#include <climits>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;

#define MAX_V 202

struct edge { int to,cap,rev; };

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from,int to,int cap){
    G[from].push_back((edge){to,cap,G[to].size()});
    G[to].push_back((edge){from,0,G[from].size()-1});
}

void bfs(int s){
    memset(level,-1,sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
        int v = que.front();que.pop();
        for(int i = 0;i < G[v].size();i++){
            edge &e = G[v][i];
            if(e.cap > 0 && level[e.to] < 0){
                level[e.to] = level[v]+1;
                que.push(e.to);
            }
        }
    }
}

int dfs(int v,int t,int f){
    if(v == t) return f;
    for(int &i = iter[v];i < G[v].size();i++){
        edge &e = G[v][i];
        if(e.cap > 0 && level[v] < level[e.to]){
            int d = dfs(e.to,t,min(f,e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s,int t){
    int flow = 0;
    while(1){
        bfs(s);
        if(level[t] < 0) return flow;
        memset(iter,0,sizeof(iter));
        int f;
        while((f = dfs(s,t,INT_MAX)) > 0) {
            flow += f;
        }
    }
}

int main(){
  int i,j;
  int h,w;
  cin >> h >> w;
  string str;
  for(int i = 0;i < h;i++){
    cin >> str;
    for(int j = 0;j < w;j++){
      switch(str[j]){
        case 'S':
        add_edge(h+w,i,100000);
        add_edge(h+w,j+h,100000);
        break;
        case 'T':
        add_edge(i,h+w+1,100000);
        add_edge(j+h,h+w+1,100000);
        break;
        case 'o':
        add_edge(i,j+h,1);
        add_edge(j+h,i,1);
        break;
      }
    }
  }
  int ans = max_flow(h+w,h+w+1);
  if(ans > 10000) ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
    
int main() {
    string a, b, c;
    cin >> a >> b >> c;
    if (a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0]) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}

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

using namespace std;
using ll=long long;

int main()
{
   int n;cin>>n;
   ll a[n];
   int co=0;
   ll sum=0;
   ll mint=10010010011;
   for(int i=0;i<n;i++){
    cin >> a[i];
    sum+=abs(a[i]);
    if(a[i]<0)co++;
    mint=min(abs(mint),abs(a[i]));
   }
   ll ans;
   if(co%2==0){
    ans=sum;
   }
   else {
    ans=sum-abs(mint)*2;
   }
   cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <string>
using namespace std;
const int MAX_N =1e9 - 1;
int main()
{
	int n, i, j, k, count = 0;
	
	cin >> n;
	long int a[n];
	for(i = 0;i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	for(i = 0;i < n; i++)
	{
		for(j =i+1; j < n; j++)
		{
			for(k =j+1; k < n; k++)
			{
				if(a[k] < a[j] + a[i])
				{
					if(a[k] != a[j] && a[j] != a[i] && a[k] != a[i])
						count++;
				}
			}
		}
	}
	cout << count << endl;
	return 0;
	
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

//最大公約数を求める
long long gcd(long long a, long long b){
  if(b == 0){
    return a;
  }
  return gcd(b, a%b);
}

//最小公倍数を求める
long long lcm(long long a, long long b){
  return a*b/gcd(b, a%b);
}

int main() {
  int N;
  long long ans = 0;

  cin >> N;

  vector<long long> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  long long tmp = lcm(a[0], a[1]);
  for(int i = 2; i < N; i++){ 
    tmp = lcm(tmp, a[i]);
  }

  for(int i = 0; i < N; i++){
//    ans += (tmp-1) % a[i];
      ans += (a[i] -1);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
S = input()
N = len(S)
S1 = S[0:int((N-1)/2)]
S2 = S[int((N+1)/2):]


if (S1 ==S1[::-1]) and (S2 ==S2[::-1]) and (S ==S[::-1]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
int main(void)
{
    int N;
    cin >> N;
    int *a;
    a = new int[N];
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    int cnt = 1;
    int cnt2 = 1;
    for (int i = 0; i < N; i++)
    {
        if (a[i] % 2 == 0)
        {
            cnt2 *= 2;
        }
        cnt *= 3;
    }
    int ans = cnt - cnt2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#if DEBUG
using Console = Atcoder.Helper.HelperConsole;
using AtcoderHelper = Atcoder.Helper.AtcoderHelper;
#endif

namespace Atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
#if DEBUG
            var url = @"
https://atcoder.jp/contests/abc142/tasks/abc142_b
";
            AtcoderHelper.RunTestCases(url);
        }
        public static void Code()
        {
#endif
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var pair = a.Select((x, i) => new Pair() { X = x, I = i }).ToList();
            pair.Sort(new Comp());
            var ans = string.Join(" ", pair.Select(p => p.I + 1).ToArray());
            Console.WriteLine(ans);
        }

        class Comp : IComparer<Pair>
        {
            public int Compare(Pair x, Pair y)
            {
                if(x.X == y.X) { return 0; }
                return x.X > y.X ? 1 : -1;
            }
        }

        struct Pair
        {
            public int X;
            public int I;
        }
    }
}


Measured memory_bytes: 34140
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * \
                modinv[self.mod % i] % self.mod
        return modinv


MOD = 10 ** 9 + 7


def main():
    N = II()

    if N == 1:
        print(0)
        return
    if N == 2:
        print(2)
        return

    tmp10 = pow(10, N, MOD)
    tmp9 = pow(9, N, MOD)
    tmp8 = pow(8, N, MOD)
    ans = tmp10 - 2 * tmp9 + tmp8
    ans %= MOD

    print(ans)


main()


Measured memory_bytes: 65200
N = int(input())
edge = [[] for _ in range(N)]
for lose in range(1, N):
    win = int(input())
    edge[win - 1].append(lose)

order = []
from collections import deque
que = deque([0])
while que:
    v = que.popleft()
    order.append(v)
    for w in edge[v]:
        que.append(w)

depth = [0] * N
for v in reversed(order):
    d = []
    for w in edge[v]:
        d.append(depth[w])
    d.sort(reverse=True)
    for plus, d in enumerate(d, 1):
        depth[v] = max(depth[v], d + plus)

print(depth[0])

Measured memory_bytes: 65568
import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    private static int[][][] ary;
    public static void main(String[] args) throws Exception {
        int n = sc.nextInt();
        ary = new int[4][3][10];
        for (int i = 0;i < n;i++) {
            int b = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            int v = sc.nextInt();
            calc(b, f, r, v);
        }
        disp();
    }
    
    private static void calc(int b, int f, int r, int v) {
        ary[b-1][f-1][r-1] += v;
    }
    
    private static void disp() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0;i < 4;i++) {
            for (int j = 0;j < 3;j++) {
                for (int k = 0;k < 10;k++) {
                    sb.append(" ").append(ary[i][j][k]);
                }
                System.out.println(sb.toString());
                sb = new StringBuilder();
            }
            if (i == 3) break;
            System.out.println("####################");
        }
    }
}

Measured memory_bytes: 28988
#include <bits/stdc++.h>
using namespace std; 
int main(){
//  freopen("test.in","r",stdin);
//  freopen("test.out","w",stdout);
	int n;
	double answer;
	cin>>n;
	if(n&1) {
		answer=1.0*((n+1)/2)/n;
		printf("%.10f",answer);
	}
	else 
	printf("0.5000000000");
	
    return 0;
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	set<int> d;
	for (int i = 0; i < n; ++i) {
		int t;
		cin >> t;
		d.insert(t);
	}
	cout << d.size() << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;





// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};



int main(){

    int k,x;
    cin >> k >> x;
    cout << (k*500 >= x? "Yes":"No");
    
}


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

using namespace std;

void solve()
{
	int sum = 0;
	string str;
	while(getline(cin, str))
	{
		int size = str.size();
		
		for(int i = 0; i < size; ++i)
		{
			if('0' <= str[i] && str[i] <= '9')
			{
				string temp;
				while('0' <= str[i] && str[i] <= '9')
				{
					temp += str[i];
					++i;
				}
				int size2 = temp.size();
				int a = 1;
				for(int j = size2 - 1; j >= 0; --j)
				{
					sum += (temp[j] - '0') * a;
					a *= 10;
				}
			}
		}
	}
	cout << sum << endl;
}

int main()
{
	solve();
	return(0);
}

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

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

    int n, c1 = 0, c2 = 0, c3 = 0, c4 = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if(s == "AC") {
            c1++;
        }
        if(s == "WA") {
            c2++;
        }
        if(s == "TLE")
            c3++;

        if(s == "RE")
            c4++;

    }
    cout << "AC x " << c1 << "\n";
    cout << "WA x " << c2 << "\n";
    cout << "TLE x " << c3 << "\n";
    cout << "RE x " << c4 << "\n";
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<vector>
using namespace std;
int main(){

  int N;
  int M;
  int X;
  cin>>N>>M>>X;
  vector<int>A(M);
  int costA=0;
  int costB=0;
  for(int i=0;i<=M-1;i++){
  
    cin>>A[i];
  }
  for(int i=0;i<=M-1;i++){
    
    if(A[i]==X){
    
      costA=i+1;
      costB=M-i;
      break;
    }
    if(A[i]>X){
    
      costA=i;
      costB=M-i;
      break;
    }
  }
  //cout<<costA<<endl<<costB<<endl;
  costA<=costB?cout<<costA:cout<<costB;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=310;
char s[N];
int dp[N][N][N],k,n;
int solve(int l,int r,int k) {
	if (dp[l][r][k]!=-1) {
		return dp[l][r][k];
	}
	if (l>r) {
		return dp[l][r][k]=0;
	}
	if (l==r) {
		return dp[l][r][k]=1;
	}
	int &v=dp[l][r][k];
	v=0;
	v=max(v,solve(l,r-1,k));
	v=max(v,solve(l+1,r,k));
	if (s[l]==s[r]) v=max(v,solve(l+1,r-1,k)+2);
	else if (k>0) v=max(v,solve(l+1,r-1,k-1)+2);
	return v;
}
int main() {
	scanf("%s",s);
	scanf("%d",&k);
	n=strlen(s);
	memset(dp,-1,sizeof(dp));
	printf("%d\n",solve(0,n-1,k));
}

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

const ll x = 1000100010001;

ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main(){
    ll n;
    cin >> n;
    ll min = x;
    rep(i, n){
        if(i * i > n){
            i = n;
        }
        ll a;        
        if(n % i == 0){
            a = n / i;
            ll ans = (a - 1) + (i - 1);
            if(ans < min){
                min = ans;
            }else if(ans > min){
                break;
            }
        }
    }    
    cout << min << endl;
    return 0;
}

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

int main() {
  int a, b, c, d;
  string ans;
  cin >> a >> b >> c >> d;
  while(1) {
    c = c - b;
    if (c <= 0) {
      ans = "Yes";
      break;
    }
    a = a - d;
    if (a <= 0) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#define X 10000
#define W 0
#define B 1

int n;
int G[100][100],d[100],p[100],c[100];
int Pr(void);

int main(){
  int i,j;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    for(j=0; j<n; j++) {
      scanf("%d",&G[i][j]);
    }
  }
  printf("%d\n",Pr());
  return 0;
}

int Pr(void){
  int min,u,v,i,wgt=0;
  for(u=0; u<n; u++){
    d[u]=X;
    p[u]=-1;
    c[u]=W;
  }
  d[0]=W;
  while(1){
    min=X;
    for(i=0; i<n; i++){
      if(c[i]!=B && d[i]<min){
	min=d[i];
	u=i;
      }
    }
    if(min==X) break;
    c[u]=B;
    for(v=0; v<n; v++){
      if(G[u][v]!=-1){
	if(c[v]!=B && G[u][v]<d[v]){
	  p[v]=u;
	  d[v]=G[u][v];
	}
      }
    }
  }
  for(i=0; i<n; i++) wgt+=d[i];
  return wgt;
}



Measured memory_bytes: 2036
import sys

number_of_line = int(sys.stdin.readline())

sum = 0
height = 0
line = sys.stdin.readline()
humans = line.split(' ')
steps = 0
for human in humans:
    human_height = int(human)
    if human_height < height:
        steps += (height - human_height)
    height = max(human_height, height)

print(steps)


Measured memory_bytes: 25160
import java.util.*;

/**
 * Created by Santa.
 */
public class Main {

    static int N;
    static int M;
    static int A;
    static long B;
    static long C;
//    static int[][] map;
    static int min = 9999999;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String s = scanner.nextLine();

        int cnt = 0;
        int ok = 1;
        for (int i = 0; i < s.length(); i++) {
            if(i == 0){
                if(s.charAt(0) != 'A')ok = 0;
            }else if(i == 1){
                if(s.charAt(1) == 'C')ok = 0;
                if(s.charAt(1) == 'A')ok = 0;
                String temp  = String.valueOf(s.charAt(i));

                if(temp.equals(temp.toUpperCase()))ok = 0;

            }else{
                String temp  = String.valueOf(s.charAt(i));



                if(s.charAt(i) == 'C'){
                    if(cnt == 1)ok = 0;
                    cnt = 1;
                }else{
                    if(temp.equals(temp.toUpperCase()))ok = 0;
                }
            }
        }

        if(s.charAt(s.length() - 1) == 'C')ok = 0;
        if(cnt == 0)ok = 0;

        if(ok == 1){
            System.out.println("AC");
        }else{
            System.out.println("WA");
        }
    }




}



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

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

Measured memory_bytes: 3592
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>

int f(const void *a, const void *b)
{
	return (*(int *)a - *((int *)b));
}
int main(void)
{
	int n;
	int *d;
	int i = 0;
	scanf("%d",&n);
	d = (int *)malloc(sizeof(int)*(n+2));
	while (i < n)
	{
		scanf("%d",&d[i]);
		i++;
	}
	qsort(d, n, sizeof(int), f);
	printf("%d\n",d[(n/2)]-d[(n/2)-1]);
	return(0);
}


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

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

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--, y1--, x2--, y2--;
    vector<string> field(h);
    rep(i,h) cin >> field[i]; 

    vector<vector<int>> dist(h, vector<int>(w, -1));
    dist[x1][y1] = 0;

    queue<pair<int, int>> que;
    que.push(make_pair(x1, y1));

    while(!que.empty()){
        pair<int, int> current_pos = que.front();
        int x = current_pos.first;
        int y = current_pos.second;
        que.pop();
        
        rep(d,4){
            rep(i, k){
                int next_x = x + (i+1)*dx[d];
                int next_y = y + (i+1)*dy[d];
                if(next_x < 0 || next_x >= h || next_y < 0 || next_y >= w) break;
                if(field[next_x][next_y] == '@') break;
                if(dist[next_x][next_y] <= dist[x][y] && dist[next_x][next_y] != -1) break;
                if(dist[next_x][next_y] == dist[x][y]+1) continue;

                que.push(make_pair(next_x, next_y));
                dist[next_x][next_y] = dist[x][y] + 1;
            }
        }
    }

    /*for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << dist[i][j] << ' ';
        }
        cout << endl;
    }*/
 
    cout << dist[x2][y2] << endl;
}


Measured memory_bytes: 12144
// Last Change: 06/17/2019 19:15:31.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll W, H, x, y;
  cin >> W >> H >> x >> y;

  double ansArea = static_cast<double>(W * H) / 2;
  int ans;
  if (2 * x == W and 2 * y == H) {
    ans = 1;
  } else {
    ans = 0;
  }

  cout << fixed << setw(8) << ansArea << ' ';
  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 888
H, W = map(int, input().split())
Grid = [input() for _ in range(H)]

d = [(1,0),(-1,0),(0,1),(0,-1)]
ans = True

for i in range(H):
    for j in range(W):
        if Grid[i][j] == '#':
            count = 0
            for dx, dy in d:
                if 0 <= i + dy and i + dy <= H-1 and 0 <= j + dx and j + dx <= W-1:
                    if Grid[i+dy][j+dx] == '#':
                        count += 1
        
            if count == 0:
                ans = False
                break

if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import sys
input = sys.stdin.buffer.readline

class UnionFind:
    __slots__ = ["data"]
    
    def __init__(self, n=0):
        self.data = [-1]*(n+1)
    
    def root(self, x):
        if self.data[x] < 0:
            return x
        self.data[x] = self.root(self.data[x])
        return self.data[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.data[x] < self.data[y]:
                self.data[x] += self.data[y]
                self.data[y] = x
            else:
                self.data[y] += self.data[x]
                self.data[x] = y
    
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def size(self, x):
        return -self.data[self.root(x)]
                


def main():
    n, m, k = map(int, input().split())
    friends = [[] for _ in range(n+1)]
    blocks = [[] for _ in range(n+1)]
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(int, input().split())
        friends[a].append(b)
        friends[b].append(a)
        uf.unite(a, b)
    for _ in range(k):
        c, d = map(int, input().split())
        blocks[c].append(d)
        blocks[d].append(c)
    for i in range(1, n+1):
        nf = len(friends[i])
        nb = sum([uf.same(i, b) for b in blocks[i]])
        ans = uf.size(i) - 1 - nf - nb
        print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 140596
while True:
    d = [int(i) for i in input().split()]
    if d[0] == 0:
        break
    w = ["#" for i in range(d[1])]
    print("".join(w))
    m = "#"+"".join(["." for i in range(d[1]-2)])+"#"
    for i in range(d[0]-2):
        print(m)
    print("".join(w))
    print("")


Measured memory_bytes: 5628
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <cassert>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;



void solve()
{
    int n;
    scanf("%d", &n);
    map<int, int> z;
    int i;
    for (i = 0; i < n; i++) {
        int tmp;
        scanf("%d", &tmp);
        z[tmp]++;
    }
    ll ans = 0;
    auto it = z.begin();
    for (; it != z.end(); ++it) {
        int tmp=it->first;
        int num = it->second;
        if (num >= tmp) {
            ans += (num-tmp);
        }
        else {
            ans += num;
        }
    }
    printf("%lld\n", ans);


    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 4736
N = int(input())
A = list(map(int,input().split()))

A.sort(reverse=True)

ans = []
i = 0
while i < N-1:
    if A[i] == A[i+1]:
        ans.append(A[i])
        i += 1
    if len(ans) == 2: break
    i += 1

if len(ans) in (0,1): print(0)
else: print(ans[0]*ans[1])

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

int n, k;
int m[102];
int t[102][102];
int r[102];

int main(){
  while(cin >> n, n){
    for(int i = 0; i < n; i++){
      cin >> m[i];
      for(int j = 0; j < m[i]; j++){
        cin >> t[i][j];
      }
    }

    cin >> k;

    for(int i = 0; i < k; i++){
      cin >> r[i];
    }

    vector<int> v;

    for(int i = 0; i < n; i++){
      bool flg = true;

      for(int j = 0; j < k; j++){
        if(find(t[i], t[i] + m[i], r[j]) == t[i] + m[i]){
          flg = false;
          break;
        }
      }

      if(flg) v.push_back(i + 1);
    }

    if(v.size() == 1){
      cout << v[0] << endl;
    }
    else{
      cout << "-1\n";
    }
  }
}

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

#define int long long

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

int ans = 0;
int n;
vector<int> v;

void rec(int m, int res) {
    if(m==n && res%2==0) {
        ans++;
        return;
    }
    else if(m==n) return;
    for(int i=0; i<3; ++i) {
        int nm = v[m] + dx[i];
        rec(m+1, res*nm);
    }
}

signed main() {
    cin >> n;
    for(int i=0; i<n; ++i) {
        int a;
        cin >> a;
        v.push_back(a);
    }

    rec(0, 1);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
s = gets.to_i
M = 1_000_000_007

fac = Array.new(s, 1)
(s-1).times {|i| fac[i+1] = fac[i] * (i+1) % M}
inv_fac = Array.new(s)
inv_fac[-1] = fac[-1].pow(M - 2, M)
(s - 2).downto(0) {|i| inv_fac[i] = inv_fac[i+1] * (i+1) % M}

com =->(a, b){fac[a] * inv_fac[b] * inv_fac[a-b] % M}

ans = 0
(1..).each do |i|
    break if 3 * i > s
    x = s - 3 * i
    ans = (ans + com.(x + i - 1, i - 1)) % M
end

p ans

Measured memory_bytes: 14316
#include<stdio.h>

#define MAX 300
#define MIN 3

int main()
{
	int i, j, H, W;
	while (1)
	{
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0)
			break;
		else if (MIN<=H,W&&H, W <= MAX)
		{
			for (i = 1; i <= H; i++){
				for (j = 1; j <= W; j++){
					if (i!= 1&&j!=1 && i != H&&j != W)
						putchar('.');
					else
						putchar('#');
				}
				printf("\n");
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 576
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      d: usize,
      g: usize,
      pc: [(usize, usize); d],
   }
   let mut ans = 1001;
   for k in 0..1 << d {
      let us: Vec<_> = (0..d).map(|i| (k >> i) & 1 == 1).collect();
      let mut score = 0;
      let mut count = 0;
      for i in 0..d {
         if us[i] {
            score += 100 * (i + 1) * pc[i].0;
            score += pc[i].1;
            count += pc[i].0;
         }
      }
      for i in (0..d).rev() {
         if score >= g {
            break;
         } else if !us[i] {
            if score + 100 * (i + 1) * (pc[i].0 - 1) < g {
               score += 100 * (i + 1) * (pc[i].0 - 1);
               count += pc[i].0 - 1;
            } else {
               let k = (g - score - 1) / (100 * (i + 1)) + 1;
               score += 100 * (i + 1) * k;
               count += k;
            }
         }
      }
      if score >= g {
         ans = std::cmp::min(count, ans);
      }
   }
   println!("{}", ans);
}


Measured memory_bytes: 4352