akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<set>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define repd(i,x,y) for(int i=x; i>=y; --i)
#define mid (l+r>>1)

using namespace std;
const int N=10005;
int n,h[N],cnt,tot,ans[N],c[N],d[N];
struct edge{int v,n;} e[N<<1];
struct data
{
	int x,d;
	bool operator < (const data &t) const 
	{
		return d==t.d?x<t.x:d<t.d;
	}
} ;
set <data> st;

void addedge(int u,int v)
{
	e[cnt]=(edge){v,h[u]},h[u]=cnt++,++d[u];
	e[cnt]=(edge){u,h[v]},h[v]=cnt++,++d[v];
}

int main()
{
	scanf("%d",&n);
	memset(h,-1,sizeof(h));
	rep(i,1,n-1)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		addedge(u,v);
	}
	rep(i,1,n) st.insert((data){i,d[i]});
	rep(i,1,n) scanf("%d",&c[i]),tot+=c[i];
	sort(c+1,c+1+n),tot-=c[n];
	rep(i,1,n)
	{
		int x=st.begin()->x;
		st.erase(st.begin());
		ans[x]=c[i];
		for(int j=h[x]; j!=-1; j=e[j].n)
			if(!ans[e[j].v])
			{
				st.erase((data){e[j].v,d[e[j].v]});
				st.insert((data){e[j].v,--d[e[j].v]});
			}
	}
	printf("%d\n",tot);
	rep(i,1,n-1) printf("%d ",ans[i]);
	printf("%d\n",ans[n]);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#define NONE -1

const char hand[26] = {
    0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0
};

int main(void)
{
    int count, prev, t;

    while(1)
    {
        prev = NONE, count = 0;

        while((t = getchar()) != '\n')
        {
            if(t == '#') return 0;

            if(prev != NONE &&
               prev != hand[t-'a']) count++;

            prev = hand[t-'a'];
        }

        printf("%d\n", count);
    }

    return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
#define INF 1e9
using namespace std;

int main() {
    string s; cin >> s;
    int minnum = INF;
    for(int i = 0; i < s.size()-2; i++){
        string ch,a,b,c;
        a = s[i];
        b = s[i+1];
        c = s[i+2];

        ch = a+b+c;
        int num;
        num = stoi(ch);
        minnum = min(minnum,abs(753-num));
    }
    cout << minnum << endl;

    return 0;
}

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

int main(){
    int N; cin>>N;
    int a[1000001];
    rep(i,1000001)a[i]=0;
    int ans=0;
    rep(i,N){
        int x; cin>>x;
        if(x>N){
            ans++;
            continue;
        }
        a[x]++;
        ans++;
        if(a[x]==x)ans-=x;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7456
import sys


class AlgSegmentTreeMin:
    def __init__(self, n, default_value):
        self.Nelem = n
        self.default_value = default_value
        self.size = 1 << (n.bit_length())
        self.data = [default_value] * (2 * self.size)

    def update(self, i, x):
        i += self.size
        self.data[i] = x
        i >>= 1
        while i:
            x = self.data[i + i]
            y = self.data[i + i + 1]
            self.data[i] = x if x < y else y
            i >>= 1

    def get_value(self, left, right):
        left += self.size
        right += self.size + 1
        x = self.default_value
        while left < right:
            if left & 1:
                y = self.data[left]
                if x > y:
                    x = y
                left += 1
            if right & 1:
                right -= 1
                y = self.data[right]
                if x > y:
                    x = y
            left >>= 1
            right >>= 1
        return x


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, input().rstrip('\n').split()))
    stree = AlgSegmentTreeMin(n, 10 ** 15)
    lrc = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]
    lrc.sort()
    stree.update(0, 0)
    for l, r, c in lrc:
        l -= 1
        r -= 1
        tm = stree.get_value(l, r-1)
        now = stree.get_value(r, r)
        tm = tm + c if tm + c < now else now
        stree.update(r, tm)
    mt = stree.get_value(n-1, n)
    print(mt if mt != stree.default_value else -1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 99164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000007 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_V = 15;

int V, E;
int s, t, d;

int G[MAX_V][MAX_V];
int dp[MAX_V][1<<MAX_V][MAX_V];

int rec(int, int, int);

int main() {
    cin >> V >> E;
    REP(i, V) {
        REP(j, V) {
            G[i][j] = INF;
        }
    }
    REP(i, E) {
        cin >> s >> t >> d;
        G[s][t] = d;
    }

    REP(i, V) {
        REP(bit, 1<<V) {
            REP(j, V) dp[i][bit][j] = -1;
        }
    }

    int ans = INF;
    REP(i, V) {
        ans = min(ans, rec(i, (1<<V)-1, i));
    }
    if (ans == INF) ans = -1;
    PRINT(ans);
    
}

int rec(int s, int bit, int v) {
    if (dp[s][bit][v] != -1) return dp[s][bit][v];
    if (bit == 1<<v) return dp[s][bit][v] = G[s][v];
    int res = INF;
    int prev_bit = bit & ~(1<<v);
    REP(u, V) {
        if (!(prev_bit & (1<<u))) continue;
        if (G[u][v] == INF) continue;
        res = min(res, rec(s, prev_bit, u) + G[u][v]);
    }   
    return dp[s][bit][v] = res;
}


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

int main(void) {
    int n, k, max;

    cin >> n >> k;
    
    if (n % 2 == 0) {
        max = n / 2;
    } else {
        max = (n+1) / 2;
    }
    
    if (max >= k) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

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

const ll mod = 1e9 + 7;
const ll infl = 1e17;

typedef unsigned long long ull;

ll find(vector<ll> &root, ll x)
{
    if (root[x] >= 0)
    {
        root[x] = find(root, root[x]);
        return root[x];
    }
    return x;
}
void unit(vector<ll> &root, ll a, ll b)
{
    ll ra, rb;
    ra = find(root, a);
    rb = find(root, b);
    if (ra == rb)
    {
        return;
    }
    else if (root[ra] <= root[rb])
    {
        root[ra] += root[rb];
        root[rb] = ra;
    }
    else
    {
        root[rb] += root[ra];
        root[ra] = rb;
    }
    return;
}

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> root(n + m, -1);
    ll k, l;
    rep(i,n){
        cin >> k;
        rep(j,k){
            cin >> l;
            unit(root, i, n + l - 1);
        }
    }
    ll rr = find(root, 0);
    repf(i,1,n){
        if (rr!=find(root,i)){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
   int n;
   int i;
   int a,b,c;
   
   scanf("%d",&n);
   for(i=0;i<n;i++){
       scanf("%d %d %d",&a,&b,&c);
       if(a*a+b*b==c*c || b*b+c*c==a*a || c*c+a*a==b*b){
           puts("YES");
       }else{
           puts("NO");
       }
       
   }
    return 0;       
}
    




Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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; }

int main(){
    string s,t,ans="";
    cin>>s>>t;
    vector<char> v(26,'{');
    for(ll i=0;i<s.size();i++){
        int cha=(int)t[i]-'a';
        if(v[cha]=='{'||v[cha]==s[i]) v[cha]=s[i];
        else{
            cout<<"No"<<endl;
            return 0;
        }
    }
    set<char> se;
    for(int i=0;i<26;i++){
        if(!se.count(v[i])||v[i]=='{') se.insert(v[i]);
        else{
            cout<<"No"<<endl;
            return 0;
        }
    }
    for(ll i=0;i<t.size();i++){
        int cha=(int)t[i]-'a';
        ans+=v[cha];
    }
    if(ans==s) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 1032
#include <iostream>

using namespace std;

int n;
int adja[100][100];

int spanning() {
    int visit[100] = {}, cost = 0;
    visit[0] = 1;
    while (1) {
        int minj, minc = 2001;
        for (int i = 0; i < n; ++i) {
            if (visit[i]) {
                for (int j = 0; j < n; ++j) {
                    if (adja[i][j] >= 0 && !visit[j] && minc > adja[i][j]) {
                        minc = adja[i][j];
                        minj = j;
                    }
                }
            }
        }
        if (minc == 2001)
            break;
        cost += minc;
        visit[minj] = 1;
    }
    return cost;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> adja[i][j];
        }
    }
    cout << spanning() << endl;

    return 0;
}


Measured memory_bytes: 3156
#!/usr/bin/env python3
import sys

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

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


def main():
    N, M = map(int, input().split())
    a, b = [], []
    for _ in range(M):
        aa, bb = map(int, input().split())
        a.append(aa - 1)
        b.append(bb - 1)
    count = 0
    for i in range(M):
        uf = UnionFind(N)
        for j in range(M):
            if j == i:
                continue
            uf.union(a[j], b[j])
        if uf.group_count() != 1:
            count += 1
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/*
    In the name of
        "ALLAH"
    And say "AL-HAM-DU-LILLAH"
*/

#include<bits/stdc++.h>
#define ll long long
#define llu unsigned long long

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

}
double ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}

#define Int take()
#define Dnt ttake()
#define LL takes()
#define done {return 0;}
#define fr(n) for(int i=1;i<=n;i++)
#define FR(a,b,x) for(int i=(a);i<=(b);i+=(x))
#define rfr(n) for(int i=n;i>=1;i--)
int cas;
#define print printf("Case %d:",++cas)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pii pair<int,int>
#define vii vector<pii>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mk  make_pair
#define fill(x,v) memset(x,v,sizeof x)

using namespace std;

bool approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define STR {struct info}
#define dbg(x) {cout<<"ekhane"<<x<<endl;}
#define  SS second
#define  FF first
#define PQ priority_queue
#define great greatest
#define less lesser
#define mii map<int,int>
#define mil map<int,ll>
#define mll map<ll,ll>
#define msb map<string,bool>
#define M 100005
//////////////////////////////////////////

int t[M],x[M],y[M];

int main(){

   int n=Int;

   fr(n){
      t[i]=Int,x[i]=Int,y[i]=Int;
   }
   ll cx=0,cy=0,ct=0;
   fr(n){
       ll d=abs(x[i]-cx)+abs(y[i]-cy);
        ll f=(t[i]-ct)-d;
        if(f%2 || f<0){
             printf("No");done;
        }

        cx=x[i],cy=y[i],ct=t[i];
   }
   printf("Yes\n");

    done;
}




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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
  int x;
  cin >> x;
  for (int a = 1;; a++)
  {
    for (int b = a - 1; a * a * a * a * a - b * b * b * b * b <= x; b--)
    {
      if (a * a * a * a * a - b * b * b * b * b == x)
      {
        cout << a << " " << b << endl;
        goto L;
      }
    }
  }
L:
{
}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0L;i--)
#define prep(i,n) for(int64_t i=1;i <= (int64_t)(n);i++)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  fspcnt = 0;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  char b;
  cin >> b;
  switch(b){
    case 'A':
      cout << 'T' << endl;
      break;
    case 'T':
      cout << 'A' << endl;
      break;
    case 'G':
      cout << 'C' << endl;
      break;
    case 'C':
      cout << 'G' << endl;
      break;
    default:
      break;
      }
  
  
    
  
    
}

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

int main() {
  ll n; cin >>n;
  vector<ll> a(n+1), b(n);
  for (int i=0; i<n+1; i++) cin >>a.at(i);
  for (int i=0; i<n; i++) cin >>b.at(i);
  ll ans = 0;
  for (int i=0; i<n; i++){
    if (i==0){
      if (a.at(i)>=b.at(i)){
        ans += b.at(i);
        b.at(i) = 0;
      }else{
        ans += a.at(i);
        b.at(i) -= a.at(i);
      }
    }else{
      if (a.at(i)>=(b.at(i)+b.at(i-1))){
        ans += b.at(i)+b.at(i-1);
        b.at(i) = 0;
      }else{
        ans += a.at(i);
        if (b.at(i-1)<a.at(i)){
          b.at(i) -= a.at(i)-b.at(i-1);
        }
      }
    }
    if (i==n-1){
      ans += min(a.at(n),b.at(n-1));
    }
  }
  
  cout <<ans;
  cout <<endl;
}

Measured memory_bytes: 1792
/*
 Templatka c++ Kacper Fis																							   																											   //
*/

#include <iostream>
#include <cstdio>
#include <limits>
#include <cstdlib>
#include <utility>
#include <iterator>
#include <bitset>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <time.h>
#include <iomanip>
#include <sstream>
#include <bits/stdc++.h>

using namespace std;

const int INF = 1000000001;
const float PI = 3.14;
typedef long long LL;

typedef vector<int> vi;
typedef list<int> li;
typedef queue<int> qi;
typedef pair<int,int> ii;
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra

list<int>::iterator it;
list<int>::iterator it1;
vector<int>::iterator it2;
vector<int>::iterator it3;
set<int>::iterator it4;
map<string, int>::iterator it5;
vector<ii>::iterator iter;

#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x, y) make_pair(x, y)
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////



///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{ios_base::sync_with_stdio(false); cin.tie(NULL);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	int a, b;

	cin >> a >> b;

	int x, y, z;

	x = a + b;
	y = a - b;
	z = a * b;

	vi V;
	V.pb(x);
	V.pb(y);
	V.pb(z);

	sort(V.begin(), V.end());
	reverse(V.begin(), V.end());
	cout << *V.begin();











	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int ans = 0, n;
	cin >> n;
	for (int i = 0; i < 100; ++i)
	{
		for (int j = 0; j < 100; ++j)
		{
			if (i * 4 + j * 7 == n)
			{
				++ans;
			}
		}
	}
	cout << ((ans == 0)?"No":"Yes") << endl;
	return 0;
}

Measured memory_bytes: 256
/*

please pass my code

use a kruskal's idea
every edge should be between adjacent connected components
(no idea why this is the case, it just seems to work)

*/

#include <stdio.h>
#include <set>
#include <utility>

long long minn(long long a,long long b){return a<=b?a:b;}

int n;
long long d;
int a[200005];

// segment is [i,ptr2[i])
int ptr1[200005];
int ptr2[200005];
long long c1[200005];
long long c2[200005];

std::set<std::pair<int,int>> kruskal;
bool done[200005];
long long ans=0;

int main()
{
    #ifdef NOT_DMOJ
    freopen("data.txt","r",stdin);
    #endif // NOT_DMOJ
    scanf("%d%lld",&n,&d);
    for (int i=1; i<=n; i++) {
        scanf("%d",a+i);
        ptr1[i]=i-1;
        ptr2[i]=i+1;
        c1[i]=c2[i]=a[i];
    }
    for (int i=2; i<=n; i++) {
        //kruskal.insert({c2[i-1]+c1[i],i});
        kruskal.insert({c2[i-1],i});
        kruskal.insert({c1[i],i});
    }
    done[1]=1;
    done[n+1]=1;
    while (!kruskal.empty()) {
        // pop lowest edge from set
        int i2=kruskal.begin()->second;
        kruskal.erase(kruskal.begin());
        if (done[i2]) continue;
        done[i2]=1;
        int i3=ptr2[i2];
        int i1=ptr1[i2];
        int i0=ptr1[i1];
        ans+=c2[i1]+d+c1[i2];
        //printf("%d ans+=%d\n",i2,c2[i1]+d+c1[i2]);
        // ptr stuff
        ptr2[i0]=i1;
        ptr2[i1]=i3;
        ptr1[i3]=i1;
        ptr1[i1]=i0;
        // merge i1 with i2
        if (c1[i1]>c1[i2]+(i2-i1)*d) {
            c1[i1]=c1[i2]+(i2-i1)*d;
            kruskal.insert({c2[i0],i1});
            kruskal.insert({c1[i1],i1});
        }
        c2[i1]=minn(c2[i2],c2[i1]+(i3-i2)*d);
        kruskal.insert({c2[i1],i3});
        kruskal.insert({c1[i3],i3});
        //printf("new ends %lld %lld\n",c1[i1],c2[i1]);
    }
    printf("%lld\n",ans);
}


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

using namespace std;

int main() {
    while (true) {
        int m, f, r;
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) {
            break;
        }
        if (m == -1 || f == -1) {
            cout << 'F' << '\n';
        }
        else if (m + f >= 80) {
            cout << 'A' << '\n';
        }
        else if (m + f >= 65) {
            cout << 'B' << '\n';
        }
        else if (m + f >= 50) {
            cout << 'C' << '\n';
        }
        else if (m + f >= 30) {
            if (r >= 50) {
                cout << 'C' << '\n';
            }
            else {
                cout << 'D' << '\n';
            }
        }
        else {
            cout << 'F' << '\n';
        }
    }
    return 0;
}


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

int index(int numToFind, std::vector<int> vectorToFindIn) {int len = vectorToFindIn.size();for (int i = 0; i < len; i++){if (vectorToFindIn[i] == numToFind){return i;}}return -1;}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c-min(a-b,c);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define dbg(x) cout<<#x<<" = "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) vdsd.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________________
ld a,b;
ld calcAngle(double h, double m)
{
    // validate the input
    if (h <0 || m < 0 || h >12 || m > 60)
        printf("Wrong input");

    if (h == 12) h = 0;
    if (m == 60) m = 0;

    // Calculate the angles moved
    // by hour and minute hands
    // with reference to 12:00
    ld hour_angle = 0.5 * (h * 60 + m);
    ld minute_angle = 6 * m;

    // Find the difference between two angles
    ld angle = abs(hour_angle - minute_angle);

    // Return the smaller angle of two possible angles
    angle = min(360 - angle, angle);
   ld pi = 3.1415926535897932384626433832795028841971693993;
   pi /= 180.00;
   angle *= pi;
   ld xx = (a*a)+(b*b)-2*a*b*cos(angle);
   return sqrt(xx);
}
int main()
{
       cout<<setprecision(45);
       ld h,m;
       cin>>a>>b>>h>>m;
       cout<<calcAngle(h,m);
}


Measured memory_bytes: 4156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  ll n, ans = 0;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    ans = 0;
    REP(y, sqrt(i) + 1) {
      REP(z, sqrt(i) + 1) {
        if (y == 0 || z == 0) continue;
        ll b = (y + z);
        ll c = y * y + z * y + z * z - i;
        ll d = b * b - 4 * c;
        if (d < 0) continue;
        ll x = ((ll)sqrt(d) - b) / 2;
        if (x * x + y * y + z * z + x * y + y * z + z * x > i) break;
        if (abs((ll)sqrt(d) - sqrt(d)) < 0.000001) {
          if (((ll)sqrt(d) - b) % 2 == 0 && x > 0 && x != 0 &&
              x * x + y * y + z * z + x * y + y * z + z * x == i) {
            ans++;
          }
        }
      }
    }
    cout << ans << "\n";
  }

  return 0;
}


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

int main()
{
    int n;
    cin>>n;
    vector<ll> a(n);
    for (int i=0; i<n; i++) cin>>a[i];
    sort(a.begin(), a.end(), greater<int>());
    int r = n%2, t = n/2;
    ll res = a[0];
    for (int i=1; i<t; i++) res += (2ll * a[i]);
    if (r == 1) res += a[t];
    cout << res << '\n';
    return 0;
}

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

struct edge{
	int t1, t2, t3;
};
bool operator < (const edge &e1, const edge &e2){
	if(e1.t1 < e2.t1)return true;
	else if(e1.t1 == e2.t1){
		if(e1.t2 < e2.t2)return true;
		else if(e1.t2 == e2.t2){
			if(e1.t3 < e2.t3)return true;
			else false;
		}else return false;
	}else return false;
}

map<edge, int> mp;
int main(){
	int n, a[3], ans = 0;
	scanf("%d", &n);
	
	for(int i = 0;i < n;i++){
		for(int j = 0;j < 3;j++)scanf("%d", &a[j]);
		sort(a, a+3);
		edge e = (edge){a[0], a[1], a[2]};
		if(mp[e])ans++;
		else mp[e] = 1;
	}
	
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#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, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(n);
    map<ll,ll> mp;
    ll ans=0;
    REP(i,n){
        cin >> a[i];
        mp[a[i]]++;
        ans+=a[i];
    }
    int q;cin >> q;
    while(q--){
        ll b,c;cin >> b >> c;
        ans+=(c-b)*mp[b];
        cout << ans << endl;
        mp[c]+=mp[b];
        mp[b]=0;
    }
}


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

int main(void)
{
    char s[101];
    int k;
    scanf("%d\n%s\n",&k,s); //整数入れるときは&をつける

    if(strlen(s) > k){
        s[k] = 0 ;
        printf("%s...\n",s);
    }else{
        printf("%s\n",s);
    }
    return 0;
}

Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1000000000000000018
#define mod 1000000007
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int> > PQG;

PQ qr;
PQG ql;
int n, a[300005], suml, sumr, kl[100005], kr[100005], ans = -INF;

signed main()
{
    cin >> n;
    for(int i = 0; i < 3 * n; i++){
        cin >> a[i];
        if(i < n){
            ql.push(a[i]);
            suml += a[i];
        }
        else if(i >= 2 * n){
            qr.push(a[i]);
            sumr += a[i];
        }
    }
    kl[0] = suml;
    for(int i = n; i < 2 * n; i++){
        ql.push(a[i]);
        suml += a[i];
        suml -= ql.top();
        ql.pop();
        kl[i - n + 1] = suml;
    }
    kr[n] = sumr;
    for(int i = 2 * n - 1; i >= n; i--){
        qr.push(a[i]);
        sumr += a[i];
        sumr -= qr.top();
        qr.pop();
        kr[i - n] = sumr;
    }
    for(int i = 0; i <= n; i++){
        ans = max(ans, kl[i] - kr[i]);
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 5876
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
   char s[20];
   scanf("%s",s);
   int l=strlen(s);
   int sum=(l-1)*9;
   if(s[0]!='1')
       sum+=(s[0]-'0')-1;
       if(l==1) sum++;
       int i;
    for(i=1;i<l;i++)
        if(s[i]!='9') break;
    if(i==l) sum=(l-1)*9,sum+=(s[0]-'0');
    printf("%d\n",sum);
    return 0;
}


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

typedef long long ll;

#define PB push_back
#define MP make_pair

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll h, w, k; cin >> h >> w >> k;
	char grid[h][w];
	for (ll i = 0; i < h; ++i) {
		string s; cin >> s;
		for (ll j = 0; j < w; ++j) 
			grid[i][j] = s[j];
	}
	ll ans = 0; 
	for (int i = 0; i < (1 << h); ++i) {
		for (int j = 0; j < (1 << w); ++j) {
			int tmp = 0;
			for (int r = 0; r < h; ++r) {
				for (int c = 0; c < w; ++c) {
					if (i & (1 << r) && j & (1 << c) && grid[r][c] == '#') tmp++;
				}
			}
			if (tmp == k) ans++;
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3648
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, D;
    cin >> N >> D;
    vector<ll> d(N);
    for (ll i = 0; i < N; i++) {
        cin >> d[i];
    }
    ll Q;
    cin >> Q;
    vector<ll> q(Q);
    for (ll i = 0; i < Q; i++) {
        cin >> q[i];
        q[i]--;
    }

    vector<ll> A(N + 1);
    A[0] = D;
    for (ll i = 0; i < N; i++) {
        A[i + 1] = min(A[i], abs(A[i] - d[i]));
    }

    vector<ll> B(N + 1);
    B[N] = 1;
    for (ll i = N - 1; i >= 0; i--) {
        if (B[i + 1] <= d[i] / 2) {
            B[i] = B[i + 1];
        } else {
            B[i] = B[i + 1] + d[i];
        }
    }

    for (ll i = 0; i < Q; i++) {
        cout << (A[q[i]] >= B[q[i] + 1] ? "YES" : "NO") << endl;
    }
}

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

int n,m;
vector<int> c;
int dp[50001][20];
void sortt(){
	sort(c.begin(),c.end());
	reverse(c.begin(),c.end());
}

void ume(){

	for(int i=0;i<20;++i){
		dp[0][i]=0;
		for(int j=1;j<50001;++j){
			dp[j][i]=100000;
		}
	}
}
void toku(){
	for(int i=1;i<n+1;++i){//??????
		for(int j=0;j<m;++j){//?????¨???????????????
			if(i-c[j]>=0){
				dp[i][j]=dp[i-c[j]][j]+1;
			}
			if(j!=0){

				dp[i][j]=min(dp[i][j],dp[i][j-1]);
			}

		}
	}
}


int main(){
	
	cin>>n>>m;
	
	for(int i=0;i<m;++i){
		int a;
		cin>>a;
		c.emplace_back(a);


	}
	sortt();
	ume();
	toku();

	

	cout<<dp[n][m-1]<<endl;
}



Measured memory_bytes: 7056
# coding: utf-8
# Your code here!

a=[1 for i in range(1000001)]
b=[0,0]
a[0]=a[1]=0
c=0
for i in range(2,1000001):
    if a[i]==1:
        c+=1
        for j in range(i*2,1000001,i):
            a[j]=0
    b.append(c)

while True:
    try:
        print(b[int(input())])
    except EOFError:
        break


Measured memory_bytes: 23792
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#include <queue>
struct Node{
	int x,y;
	Node(int a,int b){
		x = a;
		y = b;
	}
	Node(){;}
};
 
queue<Node> q;
int N,M;
int xx[] = {0,0,0,1,-1};
int yy[] = {0,1,-1,0,0};
char str[1010][1010];
int F[1010][1010] = {0};
int main(){
	memset(F,0x3f,sizeof F);
	scanf("%d%d",&N,&M);
	for(int i = 1;i <= N;i++)scanf("%s",str[i]+1);
	for(int i = 1;i <= N;i++){
		for(int j = 1;j <= M;j++){
			if(str[i][j] == '#'){
				F[i][j] = 0;
				q.push(Node(i,j));
			}
		}
	}
	while(!q.empty()){
		Node D= q.front();
		q.pop();
		for(int i = 1;i <= 4;i++){
			int x = D.x + xx[i],y = D.y + yy[i];
			if(x < 1 || y < 1 || x > N || y > M)continue;
			if(F[x][y] > F[D.x][D.y] + 1){
				F[x][y] = F[D.x][D.y] + 1;
				q.push(Node(x,y));
			}
		}
	}
	int ans = 0;
	for(int i = 1;i <= N;i++){
		for(int j = 1;j <= M;j++){
			ans = max(ans,F[i][j]);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 13456
<?php
$n = trim(fgets(STDIN));
$a = explode(" ", trim(fgets(STDIN)));
$c = 0;
for($i = 0; $i < $n; $i++){
    if($a[$i] == $i+1){
        $c++;
        $a[$i+1] = 0;
    }
}
echo $c,"\n";


Measured memory_bytes: 12920
#include <iostream>
#include <cassert>
#include <queue>
#include <string>
#include <typeinfo>
#include <cstdlib>

#define INF 922337203685477580
typedef long long ll;

using namespace std;

ll stack[1000];
int sp = 0;  // ?¬???????????????°???????????????

void push(ll v) {
  // cout << "push: " << v << endl;
  stack[sp] = v;
  sp++;
}
ll pop() {
  // cout << "pop: " << stack[sp - 1] << endl;
  sp--;
  return stack[sp];
}
ll top() {
  return stack[sp - 1];
}

int main() {
  string x;

  while (1) {
    cin >> x;

    if (cin.eof()) break;

    if (x == "+") {
      ll a = pop();
      ll b = pop();
      push(a + b);
    } else if (x == "-") {
      ll a = pop();
      ll b = pop();
      push(b - a);
    } else if (x == "*") {
      ll a = pop();
      ll b = pop();
      push(a * b);
    } else{
      push(atoi(x.c_str()));
    }
  }

  cout << pop() << endl;
  return 0;
}

Measured memory_bytes: 3136
import java.util.*;
public class Main{
    public static void main(String[] args){
	Scanner kbd = new Scanner(System.in);
	
	while(kbd.hasNext()){
	    
	    int r = kbd.nextInt();
	    int c = kbd.nextInt();

	    if(r!=0 && c!=0){
		if((r*c)%2==0) System.out.println("yes");
		else System.out.println("no");
	    }
	}
    }
}
	

Measured memory_bytes: 20908
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var ABCD = ReadText();
            var A = int.Parse(ABCD[0].ToString());
            var B = int.Parse(ABCD[1].ToString());
            var C = int.Parse(ABCD[2].ToString());
            var D = int.Parse(ABCD[3].ToString());

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        var ans = A;
                        if (i == 0)
                        {
                            ans += B;
                        }
                        else
                        {
                            ans -= B;
                        }
                        if (j == 0)
                        {
                            ans += C;
                        }
                        else
                        {
                            ans -= C;
                        }
                        if (k == 0)
                        {
                            ans += D;
                        }
                        else
                        {
                            ans -= D;
                        }
                        if (ans == 7)
                        {
                            return
                                A + (i == 0 ? "+" : "-") +
                                B + (j == 0 ? "+" : "-") +
                                C + (k == 0 ? "+" : "-") +
                                D + "=7";
                        }
                    }
                }
            }

            return null;
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>

using namespace std;
using pii=pair<int,int>;
using ll=long long;

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n+1);
    vector<int> b(n+1);
    for(int i=1; i<=n; i++) cin>>a[i];
    vector<int> answer;
    for(int i=n; i>=1; i--){
        int cnt=0;
        for(int j=i+i; j<=n; j+=i) cnt=(cnt+b[j])%2;
        b[i]=(a[i]-cnt+2)%2;
        if(b[i]!=0) answer.push_back(i);
    }
    cout<<answer.size()<<"\n";
    for(int ans : answer) cout<<ans<<" ";
    return 0;
}


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

using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

	string T;
	cin >> T;
	for(int i = 0; i < T.size(); ++i) if(T[i] == '?') T[i] = 'D';
	cout << T << "\n";

	return 0;
}

Measured memory_bytes: 3740
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
a=[[0,0] for _ in range(n-1)]
for i in range(n-1):
    a[i][0],a[i][1]=map(int,input().split())
a.sort()
p=[[0,0] for _ in range(q)]
for k in range(q):
    p[k][0],p[k][1]=map(int,input().split())
p.sort()
t=[[i] for i in range(1,n+1)]
ans=[0 for _ in range(n)]
for i in range(q):
    ans[p[i][0]-1]+=p[i][1]
for i in range(n-1):
    ans[a[i][1]-1]+=ans[a[i][0]-1]  
print(' '.join(map(str,ans)))


Measured memory_bytes: 120972
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()

dp=[[0]*3 for i in range(n+1)]

for i in range(n):
    if t[i]=='r':
      dp[i+1][2]=max(dp[i+1-k][0],dp[i+1-k][1])+p
      dp[i+1][1]=max(dp[i+1-k][0],dp[i+1-k][2])
      dp[i+1][0]=max(dp[i+1-k][1],dp[i+1-k][2])
    

    elif t[i]=='s':
      dp[i+1][0]=max(dp[i+1-k][1],dp[i+1-k][2])+r
      dp[i+1][1]=max(dp[i+1-k][0],dp[i+1-k][2])
      dp[i+1][2]=max(dp[i+1-k][0],dp[i+1-k][1])
      
      
    else:
      dp[i+1][1]=max(dp[i+1-k][0],dp[i+1-k][2])+s
      dp[i+1][0]=max(dp[i+1-k][1],dp[i+1-k][2])
      dp[i+1][2]=max(dp[i+1-k][0],dp[i+1-k][1])
      


ans=0

for i in range(1,k+1):
  ans+=max(dp[-i])


print(ans)

Measured memory_bytes: 86132
while 1:
 H, W = map(int,raw_input().split())
 if H + W == 0:break
 for h in range(H):
  if h % 2 == 0:
   if W % 2 == 0:
    print ('#.'*(W//2))
   else:
    print ('#.'*(W//2)+'#')
  else:
   if W % 2 == 0:
    print ('.#'*(W//2))
   else:
    print ('.#'*(W//2)+'.')
 print ''

Measured memory_bytes: 6440
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


int main(void){
	int N;
	cin>>N;
	int s[100];
	ll ans=0,sum=0;
	rep(i,N){
		cin>>s[i];
		sum+=s[i];
	}
	sort(s,s+N);
	if(sum%10==0){
		rep(i,N){
			if(s[i]%10!=0){
				ans=sum-s[i];
				break;
			}
		}
	}else{
		ans=sum;
	}

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

Measured memory_bytes: 256
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)

#define MP       make_pair
#define PB       push_back
#define ALL(x)   (x).begin(),(x).end()

const int INF = 1<<29;
const double EPS = 1e-9;
double zero(double d){
  return d < EPS ? 0.0 : d;
}

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


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(7);

  int n;
  cin >> n;
  
  LL res=1L;
  REP(i,n){
    res *= i+1;
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 1156
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);

		String b = scan.next();
		char c[] = b.toCharArray();

		scan.close();

		int count = 0;

		for(int i=0;i<3;i++) {
			if(c[i]=='R') {
				count++;
			}
		}

		if(count==3) {
			System.out.println("3");
		}else if(count==1) {
			System.out.println("1");
		}else if(count==2){
			if(c[1]=='S') {
				System.out.println("1");
			}else {
				System.out.println("2");
			}
		}else {
			System.out.println("0");
		}
	}

}


Measured memory_bytes: 35440
#include <bits/stdc++.h>
typedef long long int ll;
//typedef unsigned long long int ull;
typedef long double ld;
 
#define endl '\n'
#define loop(i, m, n) for (ll i = m; i < n; i++)
#define loope(i, m, n) for (ll i = m; i <= n; i++)
#define epool(i, m, n) for (ll i = m; i >= n; i--)
#define mod 1000000007
#define mod2 998244353
#define vi vector<li>
#define fi first
#define se second
#define pb push_back
#define MP make_pair
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x,0;
#define all(v) v.begin(),v.end()

#define naman                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;

ll mpow(ll base, ll exp){
    base %= mod;
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

const ll INF=1e8;
const double PI=4*atan(1);
//char a[100][1000];

void solve(){
    ll a,b;
    cin >> a >> b;
    cout << a*b << endl;

}

int32_t main(){
    naman
    ll i = 0,j = 0;

#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    //cout << fixed << setprecision(10);

    int t;
    t=1;
    //cin >> t;
    //ll cno=0;
    while (t--){
        solve();

    }

}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> a(N), bucket(N+1, 0);
    for (int i=0; i<N; i++) {
        cin >> a[i];
    }
    
    int ans=0;
    for (int i=0; i<N; i++) {
        if (a[i]>N) {
            ans++;
        }
        else{
            bucket[a[i]]++;
        }
    }
    
    for (int i=0; i<N+1; i++) {
        if (bucket[i]<i) {
            ans+=bucket[i];
        }
        else{
            ans+=bucket[i]-i;
        }
    }
    
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

const int MAX_N = 5e5 + 5;

int N;
char s[MAX_N];
int pre[MAX_N], nxt[MAX_N];
int dp[MAX_N];

void solve()
{
  pre[0] = s[0] == '0' ? 0 : -1;
  for (int i = 1; i < N; ++i) {
    if (s[i] == '0') {
      pre[i] = i;
    } else {
      pre[i] = pre[i - 1];
    }
  }
  nxt[N - 1] = s[N - 1] == '0' ? N - 1 : N;
  for (int i = N - 2; i >= 0; --i) {
    if (s[i] == '0') {
      nxt[i] = i;
    } else {
      nxt[i] = nxt[i + 1];
    }
  }
  for (int i = 0; i < N; ++i) {
    dp[i + 1] = max(dp[i + 1], dp[i]);
    if (i - 2 >= 0 && s[i - 2] == '1' && s[i - 1] == '0' && s[i] == '1') {
      int j = pre[i - 2];
      dp[i + 1] = max(dp[i + 1], dp[j + 1] + i - 2 - j);
      if (j != i - 3) {
        dp[i + 1] = max(dp[i + 1], dp[j + 2] + i - 3 - j);
      }
    }
    if (i + 2 < N && s[i] == '1' && s[i + 1] == '0' && s[i + 2] == '1') {
      int j = nxt[i + 2];
      dp[j] = max(dp[j], dp[i] + j - i - 2);
      if (j != i + 3) {
        dp[j - 1] = max(dp[j - 1], dp[i] + j - i - 3);
      }
    }
  }
  printf("%d\n", dp[N]);
}

int main()
{
#ifdef linjian
freopen("C:\\Users\\linjian\\Documents\\in.txt", "r", stdin);
#endif
  scanf("%d%s", &N, s);
  solve();
  return 0;
}


Measured memory_bytes: 6528
using System;
using System.Collections;

class Program {

    public struct Pointset {
        public int a;
        public int b;
        public int c;
        public long d;

        public Pointset (int _a, int _b, int _c, long _d) {
            a = _a;
            b = _b;
            c = _c;
            d = _d;
        }
    }

    static void Main (string[] args) {
        string[] S = Console.ReadLine ().Split (' ');
        int N = int.Parse (S[0]);
        int M = int.Parse (S[1]);
        int Q = int.Parse (S[2]);

        int[] A = new int[M];

        Pointset[] pointsets = new Pointset[Q];

        for (int i = 0; i < Q; i++) {
            string[] S1 = Console.ReadLine ().Split (' ');
            pointsets[i] = new Pointset (int.Parse (S1[0]) - 1, int.Parse (S1[1]) - 1, int.Parse (S1[2]), int.Parse (S1[3]));
        }

        long ans = ForeachCombination (M, N, pointsets);
        if (ans < 0) {
            ans = 0;
        }
        Console.WriteLine (ans);
    }

    static long ForeachCombination (int n, int k, Pointset[] pointsets) {
        int[] indexes = new int[k];
        return RecursiveCombination (indexes, n - 1, k, pointsets);
    }

    static long RecursiveCombination (int[] indexes, int s, int rest, Pointset[] pointsets) {
        if (rest == 0) {
            long total = 0;
            foreach (Pointset p in pointsets) {
                if (indexes[p.b] == indexes[p.a] + p.c) {
                    total += p.d;
                }
            }
            return total;
        } else {
            if (s < 0) return -1;
            long max = -1;
            for (int i = 0; i <= s; i++) {
                indexes[rest - 1] = i;
                max = Math.Max (max, RecursiveCombination (indexes, i, rest - 1, pointsets));
            }
            return max;
        }
    }
}

Measured memory_bytes: 27488