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

int main(){
	int size=0;
	cin>>size;
	vector<int> A;
	vector<int>	B;
	for(int i=0;i<size;i++){
		int ai=0,bi=0;
		cin>>ai>>bi;
		A.push_back(ai);
		B.push_back(bi);
	}
	int maxIndex=-1;
	for(int i=0;i<size;i++){
		if(A[i]>A[maxIndex]){
			maxIndex=i;
		}
	}
	cout<<B[maxIndex]+A[maxIndex]<<endl;
}



Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,k,a[20]={};
    int ans=0,sum1=0;
    string s[10];
    cin>>h>>w>>k;
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
                a[i]++;
                a[j+h]++;
                sum1++;
            }
        }
    }
    for(int bit=0;bit<(1<<w+h);bit++){
        int c1=0,c2=0,sum=sum1,b[10],d[10];
        for(int i=0;i<w+h;i++){
            if(bit & (1<<i)){
                if(i>=h){
                    d[c2]=i;
                    c2++;
                }
                else{
                    b[c1]=i;
                    c1++;
                }
            }
        }
        for(int i=0;i<c1;i++){
            sum-=a[b[i]];
        }
        for(int i=0;i<c2;i++){
            sum-=a[d[i]];
        }
        for(int i=0;i<c1;i++){
            for(int j=0;j<c2;j++){
                if(s[b[i]][d[j]-h]=='#'){
                    sum++;
                }
            }
        }
        if(sum==k)
            ans++;
    }
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;
int main() {
  int A[3], N;
  cin >> N;
  for (int Q = 0; Q < N; Q++) {
    rep(i, 3) cin >> A[i];
    sort(A, A + 3);
    if (A[0] * A[0] + A[1] * A[1] - A[2] * A[2] == 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int H,W,N;
  cin >> H >> W >> N;
  int a = max(H,W);
  cout << (N+a-1)/a << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <algorithm>

int main()
{
    int N = 0, M = 0;
    long money = 0;

    scanf("%d %d", &N, &M);
    std::priority_queue<int> price;
    int p = 0;
    for (int i = 0; i < N; ++i)
    {
        scanf("%d", &p);
        price.push(p);
    }

    p = price.top();
    price.pop();
    int p2 = price.empty() ? 0 : price.top();
    // printf("p %d > p2 %d, M = %d\n", p, p2, M);
    while (1)
    {
        if (p >= p2)
        {
            p /= 2;
            --M;
            // printf("p %d > p2 %d, M = %d\n", p, p2, M);
            if (M == 0)
            {
                price.push(p);
                break;
            }
        }
        else
        {
            price.push(p);
            p = price.top();
            price.pop();
            p2 = price.top();
            // printf("p %d > p2 %d, M = %d\n", p, p2, M);
        }
        
        if (p == 0 && p2 == 0)
        {
            break;
        }
    }

    while (!price.empty())
    {
        money += price.top();
        price.pop();
    }

    // Output
    printf("%ld\n", money);

    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
        p[i]--;
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(p[i]==i){
            if(i<n-1)swap(p[i],p[i+1]);
            else swap(p[n-1],p[n-2]);
            ans++;
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 640
#include <cstdio>

typedef struct Node {
  int parent;
  int left;
  int right;
} Node;

const int N = 25, NIL = -1;
Node node[N];

void preOrder(int id) {
  if (id == NIL) {
        return;
  }
  printf(" %d", id);
  preOrder(node[id].left);
  preOrder(node[id].right);
}

void inOrder(int id) {
  if (id == NIL) {
        return;
  }
  inOrder(node[id].left);
  printf(" %d", id);
  inOrder(node[id].right);
}

void postOrder(int id) {
  if (id == NIL) {
        return;
  }
  postOrder(node[id].left);
  postOrder(node[id].right);
  printf(" %d", id);
}

int main() {
  for (int i = 0; i < N; i++) {
        node[i].parent = NIL;
  }
  int n, id, left, right, root;

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
        scanf("%d %d %d", &id, &left, &right);
        node[id].left = left;
        node[id].right = right;
        if (left != NIL) {
                node[left].parent = id;
        }
        if (right != NIL) {
                node[right].parent = id;
        }
  }
  root = 0;
  while (node[root].parent != NIL) {
        root++;
  }
  printf("Preorder\n");
  preOrder(root);
  printf("\n");
  printf("Inorder\n");
  inOrder(root);
  printf("\n");
  printf("Postorder\n");
  postOrder(root);
  printf("\n");

  return 0;
}

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

int main() {
    double A,B,H,M;
    cin >> A >> B >> H >> M;
    double X = H*30+M*0.5;
    double Y = M*6;
    double Z = max(X,Y)-min(X,Y);
    double D = min(Z,360-Z);
    double pi = 3.141592653589793238;
    double ans = A*A+B*B-2*A*B*cos(D/180.0*pi);
    ans = sqrt(ans);
    cout << fixed << setprecision(20) << ans << endl;
}



Measured memory_bytes: 4216
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=100005;
int n,i,a[N];
ll sum,w,c[N];
int main()
{
	//freopen("boxes.in","r",stdin);
	//freopen("boxes.out","w",stdout);
	scanf("%d",&n);
	for(i=1;i<=n;++i)
	{
		scanf("%d",a+i);
		sum+=a[i];
	}
	if(sum%(1ll*(1+n)*n/2))
	{
		printf("NO");
		return 0;
	}
	sum/=1ll*(1+n)*n/2;
	w=a[1]-a[n];
	for(i=2;i<=n;++i)
		w+=a[i]-a[i-1];
	if(w!=0)
	{
		printf("NO");
		return 0;
	}
	c[1]=a[1]-a[n];
	for(i=2;i<=n;++i)
		c[i]=a[i]-a[i-1];
	for(i=1;i<=n;++i)
		c[i]-=sum;
	for(i=1;i<=n;++i)
		if(c[i]>0||c[i]%n)
		{
			printf("NO");
			return 0;
		}
	for(i=1;i<=n;++i)
		sum+=c[i]/n;
	if(sum==0)
		printf("YES");
	else
		printf("NO");
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int N;
#define MAXN 200001
ll A[MAXN];
int main(){
    ll MAX = 0;
    ll MAX2 = 0;
    cin >> N;
    rep(i,N){
        cin >> A[i] ;
        if(A[i]>MAX2){
            if(A[i]>MAX){
            MAX = A[i];
        }else{
            MAX2 = A[i];
        }
        }
        
    }
    rep(i,N){
        if(A[i]==MAX)cout << MAX2 << endl;
        else cout << MAX << endl;
    }
    return 0;

}

Measured memory_bytes: 3200
#include<stdio.h>
  
int p[100001];
int s[100001];
int deg[100001];
int n;
  
int depth(int);
int height(int);
  
int main(int argc,char *argv[]) {
  int i,j;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    p[i] = -1;
    s[i] = -1;
    deg[i] = 0;
  }
  for(i = 0; i < n; ++i) {
    int id, left, right;
    scanf("%d %d %d", &id, &left, &right);
    if(left != -1) {
      p[left] = id;
      s[left] = right;
      deg[id]++;
    }
    if(right != -1) {
      p[right] = id;
      s[right] = left;
      deg[id]++;
    }
  }
  
  for(i = 0; i < n; ++i) {
    int dep = depth(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
           i, p[i], s[i], deg[i], dep, height(i));
    if(dep == 0) {
      printf("root\n");
    } else if(deg[i] == 0) {
      printf("leaf\n");
    } else {
      printf("internal node\n");
    }
  }
  return 0;
}
 
int depth(int i) {
  if(p[i] == -1) return 0;
  return depth(p[i]) + 1;
}
  
int height(int i) {
  int j, h = 0;;
 
  for(j = 0; j < n; ++j) {
    if(p[j] == i) {
      int tmp = height(j) + 1;
      if(tmp > h) h = tmp;
    }
  }
  return h;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

vll acc(100000, 0);

bool isprime(ll x){
    if(x <= 1) return 0;
    repr(i, 2, (ll)sqrt(x)+1){
        if(x % i == 0){
            return 0;
        }
    }
    return 1;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll q;
    cin >> q;
    ll cnt = 0;
    for(ll i = 1; i <= 99999; i += 2){
        if(isprime(i) && isprime((i+1)/2)){
            cnt++;
        }
        acc[i] = cnt;
    }
    vll l(q), r(q);
    rep(i, q){
        cin >> l[i] >> r[i];
        if(l[i] == 1){
            cout << acc[r[i]] << endl;
        }else{
            cout << acc[r[i]]-acc[l[i]-2] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    int d, n;
    cin >> d >> n;
    int num_cnt = 0;
    for ( int i = 1; i <= 1e8; ++i ) {
        int tmp_num = i;
        int cnt = 0;
        while(1) {
            if ( tmp_num % 100 != 0 ) {
                break;
            }
            ++cnt;
            tmp_num /= 100;
        }
        if ( cnt == d ) {
            ++num_cnt;
        }
//        cout << num_cnt << endl;
        if ( num_cnt == n ) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	string arr;
	cin>>arr;
	int o=0;
	for(int i=0;i<4;i++){
		if (arr[i]=='+'){
			o++;
		}
		else{
			o--;
		}
	}
  cout<<o<<endl;
	return 0;
}

Measured memory_bytes: 256
//DFS traversal
#include <bits/stdc++.h>
 
# define C continue;
# define R return
 
# define D double
# define I insert
# define ll long long
# define ld long double
 
# define ull unsigned long long
# define ui unsigned int
 
# define pb push_back
# define pf push_front
 
# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue
 
# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >
 
# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp
 
# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >
# define pipii pair<int, pii >
# define pcpii pair<char,pii>
 
# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >
 
# define vvpii vector < vector < pii > >
# define vpipii vector< pipii >
 
# define F first
# define S second
# define mp make_pair
 
# define unm unordered_map
# define unmii unm< int , int >
# define unmll unm< ll , ll >
# define unms unm<string,int>
# define unmci unm<char,int>
 
# define sortvia sort(a.begin(),a.end());
# define sortvib sort(b.begin(),b.end());
# define revsorta sort(a.begin(), a.end(), greater <int>());
# define revsortb sort(b.begin(), b.end(), greater <>());
# define loop(q,n) for(int i=q;i<n;i++)
# define loopj(r,n) for(int j=r;j<n;j++)
# define loopm(s,m) for(int k=s;k<m;k++)
# define test int t;cin >> t;while(t--)
# define nextline "\n"
# define tab "\t"
# define space " "
//YES
//NO
//cout
//true
//false
//yes
//no
 
const ll mod9=1e9+7;
const ll maxsize=2e9+1;
// const ll mod =998244353;
const ll mod2=1073741824;
using namespace std;
 
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
/*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif*/
    int n;
    cin>>n;
    vi temp(3);
    vi dp(3);
    vi new_dp(3);
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>temp[j];
        }
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j!=k){
                    new_dp[k]=max(new_dp[k],dp[j]+temp[k]);
                }
            }
        }
        dp=new_dp;
    }
    cout<<max({dp[0],dp[1],dp[2]});
    
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,D,H,K,L,M,N,T,W,X;
  string S;
  cin >> H >> W;
  vector<string> vec(H);
  for (int i=0;i<H;i++) {cin >> vec.at(i);}
  for (int j=0;j<H;j++) {
   for (int j2=0;j2<W;j2++) {
     if (vec.at(j).at(j2)=='.') {
       A=0;
       for (int j3=-1;j3<2;j3++) {
         for (int j4=-1;j4<2;j4++) {
           if (j+j3>=0 && j+j3<=H-1 && j2+j4>=0 && j2+j4<=W-1) {if (vec.at(j+j3).at(j2+j4)=='#') {A++;}}
         }
       }
       cout << A;
     }
     else {cout << '#';}
   }
   cout << endl;
  }
  
}

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

int main( void )
{
    int year, month, day;
    scanf( "%d/%d/%d", &year, &month, &day );
    if ( ( year <= 2019 ) && ( month <= 4 ) && ( day <= 30 ) )
    {
        cout << "Heisei" << endl;
    }
    else
    {
        cout << "TBD" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
__DEUBG__ = 0

import math

N = int(input())
t_prev = x_prev = y_prev = 0

def get_dist(x_old, y_old, x_new, y_new):
    return abs(x_old - x_new) + abs(y_old - y_new)

for _ in range(N):
    t, x, y = map(int, input().split())
    dist = get_dist(x_prev, y_prev, x, y)
    delta_t = t - t_prev
    if __DEUBG__:
        print()
        print(dist, delta_t)
    if dist > delta_t:
        print('No')
        exit(0)
    elif delta_t %2 != dist % 2:
        print('No')
        exit(0)
    t_prev, x_prev, y_prev = t, x, y
print('Yes')

Measured memory_bytes: 3064
n = int(input())
#A = list(map(int, input().split()))
#a, b = map(int, input().split())
S = []
AC=0
WA=0
TLE=0
RE = 0
for i in range(n):
    S.append(input())
    if S[i] == "AC":
      AC += 1
    elif S[i] == "WA":
      WA += 1
    elif S[i] == "TLE":
      TLE += 1
    elif S[i] == "RE":
      RE += 1

print("AC x "+str(AC))
print("WA x "+str(WA))
print("TLE x "+str(TLE))
print("RE x "+str(RE))

Measured memory_bytes: 16324
#include<iostream>

using namespace std;

int main() {
	int X;
	cin >> X;
	X = (X + 70 - 9) % 7;
	if (X == 0) {
		cout << "sat" << endl;
	}
	else if (X == 1) {
		cout << "sun" << endl;
	}
	else if (X == 2) {
		cout << "mon" << endl;
	}
	else if (X == 3) {
		cout << "tue" << endl;
	}
	else if (X == 4) {
		cout << "wed" << endl;
	}
	else if (X == 5) {
		cout << "thu" << endl;
	}
	else{
		cout << "fri" << endl;
	}
	return 0;
}


Measured memory_bytes: 3076
N, M = map(int, input().split())
X = [0 for _ in range(N)]
if N % 2 == 0:
    X = [0 for _ in range((N-1)//2)]
    l, r = 1, N // 2
    for i in range((N//2)//2):
        X[i] = [l, r]
        l += 1
        r -= 1
    l, r = N, N // 2 + 2
    for i in range((N-1)//2-(N//2)//2):
        X[i+(N//2)//2] = [l, r]
        l -= 1
        r += 1
    for i in range(M):
        print(X[i][0], X[i][1])
else:
    for i in range(M):
        print(N-i, i+1)

Measured memory_bytes: 19304
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
 int a,b;
 string s;
 cin >> a>> b>> s;
 s[b-1] +=32;
 cout << s << endl;
 return 0;
}

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

tmb=[1]*N#0-N-1
for i in range(0,M,1):
    A,B = map(int,input().split())#indずれ
    if H[A-1]==H[B-1]:
        tmb[A-1]=0
        tmb[B-1]=0
    elif H[A-1]<H[B-1]:
        tmb[A-1]=0
    elif H[B-1]<H[A-1]:
        tmb[B-1]=0

print(sum(tmb))

Measured memory_bytes: 84896
N = int(input())
S = input()
 
# at position 0
l_b = 0
r_w = S.count('.')
 
needHand = l_b + r_w
for i,v in enumerate(S):
  if S[i] == '#': #black
    l_b += 1
  else:
    r_w -= 1
  ret = l_b + r_w
  
  if ret <= needHand:
    needHand = ret
 
ans = needHand
print("{}".format(ans))

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

template<typename T>
struct SegmentTree{
  struct Node{
    T val;
    Node *lch,*rch;
    Node(T val):val(val),lch(nullptr),rch(nullptr){}
  };

  Node *root;
  ll sz;
  T id;

  T f(T x,T y){ 
    return max(x,y);  //changeable 
//    return x+y;      //RSQ
  }

  T g(T x,T y){ 
    return x;
    //return x+y;
  }
  
  T val(Node* t){return t ? t->val : id;}
  
  SegmentTree(ll sz_,T id_=0):root(nullptr),id(id_){
    sz=1;
    while(sz<sz_)sz*=2;
  }

  void erase(Node* t){
    if(t->lch)erase(t->lch);
    if(t->rch)erase(t->rch);
    delete t;
  }

  void erase(){
    erase(root);
  }

  Node* update(Node* t,ll k, ll l, ll r, T x){
    //assert(l<=k&&k<r);
    if(!t)t=new Node(id);
    if(r-l==1){
      t->val=g(x,t->val);
      return t;
    }
    if(k<(l+r)/2)t->lch=update(t->lch,k, l, (l+r)>>1, x);
    else t->rch=update(t->rch,k, (l+r)>>1, r, x);
    t->val=f(val(t->lch), val(t->rch));
    return t;
  }

  T get(Node* t, ll a,ll b,ll l, ll r){
    if(!t)return id;
    if(b<=l||r<=a)return id;
    if(a<=l&&r<=b)return t->val;
    T lx=get(t->lch, a, b, l, (l+r)>>1);
    T rx=get(t->rch, a, b, (l+r)>>1, r);
    return f(lx,rx);
  }
  
  void update(ll k,T x){
    root = update(root, k, 0, sz, x);
  }

  T get(ll a, ll b){
    return get(root, a, b, 0, sz);
  }
};


int main(){
  int n;
  cin >> n;
  vector<ll> h(n),a(n);
  rep(i,n){ cin >> h[i]; }
  rep(i,n){ cin >> a[i]; }
  SegmentTree<ll> sg(n+5);
 
  rep(i,n){
    ll ret = sg.get(0,h[i])+a[i];
    sg.update(h[i], ret);
  }
  cout << sg.get(0,n+1) << endl;
  return 0;
}



Measured memory_bytes: 15872
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<typename T>
struct BIT{ //1-indexed
    vector<T> bit;
    int size;
    BIT(int n):size(n), bit(n+1, 0){}
    T sum(int i){
        T s=0;
        while(i>0){
            s+=bit[i];
            i-=(i&(-i));
        }
        return s;
    }
    void add(int i, T x){
        while(i<=size){
            bit[i]+=x;
            i+=(i&(-i));
        }
    }
};
int main()
{
    int n, q;
	string s;
	cin>>n>>s>>q;
	vector<BIT<int>> bit(26, BIT<int>(n));
	for(int i=0; i<n; i++){
		bit[s[i]-'a'].add(i+1, 1);
	}
	for(int i=0; i<q; i++){
		int t;
		cin>>t;
		if(t==1){
			int k; char c;
			cin>>k>>c;
			bit[s[k-1]-'a'].add(k, -1);
			bit[c-'a'].add(k, 1);
			s[k-1]=c;
		}else{
			int l, r; cin>>l>>r;
			int ans=0;
			for(int j=0; j<26; j++){
				if(bit[j].sum(r)-bit[j].sum(l-1)>0) ans++;
			}
			printf("%d\n", ans);
		}
	}

	return 0;
}


Measured memory_bytes: 53696
def main():
    s = input()
    a = [0]*26
    ans = 1
    cnt = 0
    for c in s:
        ans += cnt - a[ord(c) - ord("a")]
        a[ord(c) - ord("a")] += 1
        cnt += 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3500
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int a;
    cin >> a;

    string s;
    cin >> s;

    if (a >= 3200)
        cout << s;
    else
        cout << "red";
}

Measured memory_bytes: 3568
import itertools, math

N = int(input())

ACGTList = ["A", "G", "C", "T"]
AGCList = ["ATGC", "AGTC", "AGGC"]
for ACGT in ACGTList:
    for AGC in ["AGC", "ACG", "GAC"]:
        AGCList.append(ACGT + AGC)
        AGCList.append(AGC + ACGT)

patternObj = itertools.product(ACGTList, repeat=3)
patternDict = {}
for i, pattern in enumerate(patternObj):
    strPattern = "".join(pattern)
    patternDict[strPattern] = 0 if strPattern in ["AGC", "ACG", "GAC"] else 1

for i in range(N - 3):
    nextPatternDict = dict.fromkeys(patternDict, 0)
    for pattern in patternDict:
        for ACGT in ACGTList:
            newPattern = pattern + ACGT
            if newPattern in AGCList:
                continue
            nextPatternDict[newPattern[:3]] += patternDict[newPattern[1:]]
    patternDict = nextPatternDict.copy()

ans = 0
devide = int(math.pow(10, 9)) + 7
for pattern in patternDict:
    ans += patternDict[pattern]
    ans %= devide

print(ans)

Measured memory_bytes: 3064
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ll n;
	cin>>n;
	cout<<n/500*1000+n%500/5*5<<endl;
	return 0;
}

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

using namespace std;

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

    int tiles_change = 0;
    char tile_check = '0';

    for(int i=0;i<S.size();i++){
        if(S[i]!=tile_check)tiles_change++;
        if(tile_check=='0')tile_check = '1';
        else tile_check = '0';
    }

    if(tiles_change > S.size()/2)tiles_change = S.size() - tiles_change;

    cout << tiles_change << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000002486618624LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


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

  std::cout << std::fixed << std::setprecision(6);

  std::string r, g, b;

  std::cin >> r >> g >> b;

  std::cout << (std::stoi(r + g + b) % 4 == 0 ? "YES" : "NO") << std::endl;;

  return 0;
}


Measured memory_bytes: 256
def merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    L.append(float("inf"))
    R.append(float("inf"))
    i = 0
    j = 0

    global cnt
    cnt += right - left
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)


n = int(input())
A = list(map(int, input().split()))
cnt = 0
mergeSort(A, 0, n)
print(*A)
print(cnt)



Measured memory_bytes: 61648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    int N;
    cin >> N;
    vector<int> A(N+2);
    REP(i, N) cin >> A[i+1];
    int sum = 0;
    REP(i, N+1) sum += abs(A[i+1] - A[i]);
    for (int i = 1; i < N+1; i++) {
        cout << sum - abs(A[i+1] - A[i]) - abs(A[i] - A[i-1]) + abs(A[i+1] - A[i-1]) << endl;
    }
}

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

using namespace std;

int main()
{
	vector<int> a(3);
	for (auto& x : a)
		cin >> x;
	int cnt = 0;
	while (true)
	{
		sort(a.begin(), a.end());
		if (a[0] == a[2])
			break;
		if (a[0] + 2 <= a[2])
			a[0] += 2;
		else 
			++a[0], ++a[1];
		++cnt;
	}
	cout << cnt << '\n';
}


Measured memory_bytes: 256
n = int(input())

data = []
for i in range(n):
    row = list(map(int, input().split()))
    data.append(row)

# n日目に act を行うときの最大値
dp = [None] * n

# 初期条件： 0日目にa, b, c (= 0, 1, 2) を行うときの最大値
dp[0] = [0, 0, 0]
dp[0][0] = data[0][0]
dp[0][1] = data[0][1]
dp[0][2] = data[0][2]

for d in range(1, n):
    dp[d] = [0, 0, 0]
    dp[d][0] = data[d][0] + max(dp[d - 1][1], dp[d - 1][2])
    dp[d][1] = data[d][1] + max(dp[d - 1][2], dp[d - 1][0])
    dp[d][2] = data[d][2] + max(dp[d - 1][0], dp[d - 1][1])

mx = max(dp[n - 1])

print(mx)

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
















int main(){

  
  string s,t;
  
  cin>>s>>t;
  
  map<char,char>  data1;
  
 
  string answer="Yes";
  
  for (int i=0;i<int(s.size());i++){
    if (data1.find(s.at(i))!=data1.end()){
      if (data1.at(s.at(i))!=t.at(i)){
        answer="No";
        break;
      }
    }
    
    else {
      data1[s.at(i)]=t.at(i);
    }
  }
  
  
  map<char,char> data2;
  
  
  for (int i=0;i<int(s.size());i++){
    if (data2.find(t.at(i))!=data2.end()){
      if (data2.at(t.at(i))!=s.at(i)){
        answer="No";
        break;
      }
    }
    
  else {
      data2[t.at(i)]=s.at(i);
    }
  }
  
  
  
  cout<<answer<<endl;
  
      
        
   

  

  
  
    
    
      
   
    
  
  
  

    
    
    

  
}

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

int main(){
    int n,m;
    cin>>n>>m;
    int ac;
    int wa[200010]={0};
    bool flg[100010]={false};
    rep(i,m){
        int p;
        string s;
        cin>>p>>s;
        p--;
        if(flg[p]) continue;
        else{
            if(s=="AC"){
                ac++;
                flg[p]=true;
            }
            else wa[p]++;
        }
    }
    int WA;
    rep(i, n){
        if(flg[i]) WA+=wa[i];
    }
    cout<<ac<<" "<<WA<<endl;
}

Measured memory_bytes: 4508
using namespace std;

#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <numeric>
#include <map>
using namespace std;


int main(void){
	int N,K;
  vector<pair<int, int>> r;
  int i = 0;

	cin >> N >> K;

  int last = 2, first = 1;
    r.emplace_back(first, last);
  while (last < N) {
    i += last - 1;
    r.emplace_back(first, ++last);
  }
  
  if (K > i) {
    cout << -1 << endl;
    return 0;
  }
  
  first = 2;
  last = 3;
  while (K < i) {
      r.emplace_back(first, last);
      last++;
    i--;
    if (last > N) {
      first++;
      last = first + 1;
    }
  }

  {
      cout << r.size() << endl;
    for (auto&& i : r)
      cout << i.first << " " << i.second << endl;
  }

	return 0;
}


Measured memory_bytes: 384
a, b, c, x, y = map(int, input().split())

cmx = max(x, y)*2

ans = 10**9+7
for cn in range(cmx+1):
    an = max(0, x - cn//2)
    bn = max(0, y - cn//2)
    total = an*a + bn*b + cn*c
    ans = min(ans, total)

print(ans)

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

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

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

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

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

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

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

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

fn main() {
    input! {
        s: chars
    }

    let mut ans = 0;
    for i in 0..s.len() {
        let mut j = i;
        while j < s.len() && (s[j] == 'A' || s[j] == 'T' || s[j] == 'G' || s[j] == 'C') {
            j += 1;
        }
        ans = std::cmp::max(ans, j - i);
    }

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


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

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

  string ans;

  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == '0') ans += '0';
    if (S.at(i) == '1') ans += '1';
    if (S.at(i) == 'B' && ans.size() != 0) ans.pop_back();
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
/*
    author: Salam_35
    Created at :

*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF	1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() int testsalam;cin >> testsalam;while(testsalam--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define endl '\n'
//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}
string inttostr(ll n){std::stringstream ss;ss << n;string out=ss.str();return out;}
ll stringtoint(string s){istringstream iss (s);ll n;iss >> n;return n;}
typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int main()
{
    long double m,n;
    cin >> m >> n ;
    cout<<(long long)(m*n)<<endl;
}


Measured memory_bytes: 3772
from itertools import product

N, M = map(int, input().split())
switches = [list(map(int, input().split()[1:])) for _ in range(M)]
p = list(map(int, input().split()))

num_pattern = 0
for pattern in product(*[range(2) for _ in range(N)]):
    on_switches = [0]*M  # the number of on switches for each bulb
    for i, switch in enumerate(switches):
        for s in switch:
            if pattern[s-1] == 1:
                on_switches[i] += 1
                
    for i, on_num in enumerate(on_switches):
        if on_num % 2 != p[i]:
            break
    else:
        num_pattern += 1
print(num_pattern)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main()
{
    string n;
    cin >> n;
    string ans;
    if(n.back()=='3'){
        ans="bon";
    }
    else if (n.back() == '0' || n.back() == '1' || n.back() == '6' || n.back() == '8'){
        ans="pon";
    }
    else{
        ans="hon";
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include<stdio.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for(v=0; v<n; v++){
        if(M[u][v] == 0) continue;
        if(color[v] == WHITE){
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

void dfs(){
    int u;

    for(u=0; u<n; u++){
        if(color[u] == WHITE) dfs_visit(u);
    }
    for(u=0; u<n; u++){
        printf("%d %d %d\n", u+1, d[u], f[u]);
    }
}

int main(){
    int u, v, k, i, j;

    scanf("%d", &n);
    for(i=0; i<n; i++){
        for(j=0; j<n; j++){
            M[i][j] = 0;
        }
    }

    for(i=0; i<n; i++){
        scanf("%d %d", &u, &k);
        u--;
        for(j=0; j<k; j++){
            scanf("%d", &v);
            v--;
            M[u][v] = 1;
        }
    }

    dfs();

    return 0;
}





Measured memory_bytes: 2056
bingo = []
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

N = int(input())

for i in range(N):
    n = int(input())
    if n in a:
        a[a.index(n)] = 0
    elif n in b:
        b[b.index(n)] = 0
    elif n in c:
        c[c.index(n)] = 0

if sum(a) == 0 or sum(b) == 0 or sum(c) == 0 or a[0]+ b[1] + c[2] == 0 or a[2] + b[1] + c[0] == 0 :
    print("Yes")
elif a[0] + b[0]+ c[0] ==0 or a[1] + b[1]+ c[1] == 0 or a[2] + b[2]+ c[2] == 0 :
    print("Yes")
else:print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int ans = 0;
	int A, B, N, x;
	
	cin>>A>>B>>N;
	
	x = min(B-1, N);
	
	int a = (A*x)/B, b = (x/B)*A;
	
	// ans = a - b;
	
	
	// for(int i = 0; i <= N; i++){
		// int a = (A*i)/B, b = (i/B)*A;
		// cout<<"i = "<<i<<" "<<a<<" "<<b<<" <><> "<<a-b<<endl;
		
		// ans = max(a - b, ans);
	// }
	
	// cout<<ans<<endl;
	
	cout<<a-b<<endl;
	
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <bitset>

using namespace std;

typedef long long ll;

int main() {
    ll a, b;
    cin >> a >> b;

    int t = -1;
    for(int i=0;i<=60;++i) {
        if(not ((1LL << i) & a) && ((1LL << i) & b)) {
            t = i;
        }
    }

    if(t == -1) {
        cout << 1 << endl;
        return 0;
    }

    for(int i=t+1;i<=60;++i) {
        if(((1LL << i) & a) && ((1LL << i) & b)) {
            a ^= (1LL << i);
            b ^= (1LL << i);
        }
    }

    ll l1 = a, r1 = (1LL << t) - 1, l2 = 0, r2 = 0;
    ll ans = 2 * (r1-l1+1);
    for(int i=t-1;i>=0;--i) {
        if((1LL << i) & b) {
            r2 = (1LL << (i+1)) - 1;
            break;
        }
    }
    ans += r2-l2+1;
    if(l1 <= r2) {
        ans -= r2-l1+1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
void YN(bool f){ cout << (f ? "YES" : "NO");}
void yn(bool f){ cout << (f ? "yes" : "no");}
void YeNo(bool f) {cout << (f ? "Yes" : "No");}
signed main(){
    int n,l;
    cin >> n >> l;
    vector<int>a(n);
    for(auto & e : a) cin >> e;
    bool flag = false;
    int idx = -1;
    for(int i = 1; i < a.size(); ++i){
        if(a[i] + a[i-1] >= l){
            flag = true;
            idx = i;
        }
    }
    if(flag){
        cout << "Possible" << endl;
        for(int i = n - 2; i >= idx; --i)
            cout << i + 1 << endl;
        for(int i = 0; i < idx; ++i){
            cout << i + 1 << endl;
        }
    } else {
        cout << "Impossible" << endl;
    }
}


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

int main(){
  int m;
  while(cin >> m,m){
    int sum = 0;
    m = 1000 - m;
    sum += m / 500;
    m %= 500;
    sum += m / 100;
    m %= 100;
    sum += m / 50;
    m %= 50;
    sum += m / 10;
    m %= 10;
    sum += m / 5;
    m %= 5;
    cout << sum + m << endl;
  }
}

Measured memory_bytes: 1156
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int N, Q;
int a[200005], b[200005], p[200005];
long long int x[200005];
vector<int>Adj[200005];

int par[200005];
int used[200005];

long long int val[200005];

void DFS(int k) {

	used[k] = 1;

	for (auto y: Adj[k]) {
		if (used[y] == 0) { par[y] = k; val[y] += val[k]; DFS(y); }
	}
}


int main(void) {
	cin >> N >> Q;

	for (int i = 1; i <= N - 1; i++) {
		cin >> a[i] >> b[i];
		Adj[a[i]].push_back(b[i]);
		Adj[b[i]].push_back(a[i]);
	}



	for (int i = 1; i <= Q; i++) {
		cin >> p[i] >> x[i];
		val[p[i]] += x[i];
	}

	DFS(1);

	for (int i = 1; i <= N; i++) {
		if (i != 1) { cout << " "; }
		cout << val[i];
	}cout << endl;

	return 0;
}

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

#define boost ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

using namespace std;
using LL = long long;

constexpr int MAXN = 2e5 + 5;

template <typename T>
inline void read(T &x) {
    int f = 1;
    x = 0;
    char ch = getchar();
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

int n, k, a[101][101], cnt;

int main() {
    // freopen("test.in", "r", stdin);
    // freopen("test.out", "w", stdout);
    boost;
    cin >> n >> k;
    for (int i = 1; i <= k; i++) {
        int d;
        cin >> d;
        for (int j = 1, tmp; j <= d; j++)
            cin >> tmp, a[tmp][d] = 1;
    }
    for (int i = 1; i <= n; i++) {
        bool no = true;
        for (int j = 1; j <= 100; j++)
            if (a[i][j]) no = false;
        if (no) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3680
import sys
out=[]
for line in sys.stdin.readlines():
    num = map(float, line.strip().split())
    x = (num[2]*num[4] - num[1]*num[5]) / (num[0]*num[4] - num[1]*num[3])
    y = (num[5]*num[0] - num[2]*num[3]) / (num[0]*num[4] - num[3]*num[1])
    if x == 0:
        x=0.00
    if y == 0:
        y=0.00
    out.append( "%.3f %.3f"%(round(x,3),round(y,3)))
for i in xrange(len(out)):
    print out[i]

Measured memory_bytes: 4260
n = int(input())
lst = [int(i) for i in input().split()]

lst_sorted = sorted(lst)

cnt = 0
for i in range(n):
    if lst[i] != lst_sorted[i]:
        cnt += 1

if cnt == 0 or cnt == 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int M= 1e5+10;
char s[M];
int main(){
    while(scanf("%s",s+1)!=EOF){
        for(int i=1;s[i];++i)
            if(i&1) putchar(s[i]);
        puts("");
    }
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n;
	map<string,int> mp;
	cin>>n;
	char last='!';
	string s;
	cin>>s;
	int l=s.length();
	last=s[l-1];
	mp[s]=1;
	FOR(i,0,n-1){
		cin>>s;
		if(mp[s]!=0||last!=s[0]){
			cout<<"No";
			return 0;
		}
		mp[s]=1;
		l=s.length();
		last=s[l-1];

	}
	cout<<"Yes";

    return 0;
}


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

int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int xa = min(k,a);
  k -= xa;
  int xb = min(k,b);
  k -= xb;
  int xc = k;

  int ans = xa - xc;
  cout << ans << endl;
  return 0;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
    
  int ans;
  ans = c-(a-b);
  
  if(ans<0){
  	cout << 0 << endl;  
  }
  else{
    cout << ans << endl;
  }
}

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

int main() {
    int n,r;
    cin >> n >> r;
    cout << ((n>=10)? r : r + 100*(10-n)) << endl; 
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll a,b;
    cin>>a>>b;
    ll ans=0;
    if(a*b==15){
        cout<<'*'<<endl;

    }else if(a+b==15){
        cout<<'+'<<endl;
    }else{
        cout<<'x'<<endl;
    }
    return  0;
}


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

int main() {
  int N, M, C;
  cin >> N >> M >> C;

  vector<int> B(M);
  rep(i, M) cin >> B[i];

  int ans = 0;
  rep(i, N) {
    int n = C;
    rep(j, M) {
      int A;
      cin >> A;
      n += A * B[j];
    }
    if (n > 0)
      ans++;
  }

  cout << ans << endl;
}

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

using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  map<int,int> mp;
  vector<long long int>count(n+1,0);
  for(int i=0;i<m;i++){
    int a;
    cin >> a;
    mp[a]=1;
   }
  count[0]=1;
  count[1]=mp[1]==0;
  for(int i=2;i<=n;i++){
      if(mp[i]==1)count[i]=0;
      else count[i]=(count[i-1]+count[i-2])%1000000007;
  }
  cout << count[n];
    
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n,k; cin >> n >> k;
  vi p(n);
  rep(i,n) cin >> p[i];
  sort(p.begin(), p.end());
  int ans =0;
  rep(i,k) {
    ans += p[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
void main(){
	int x = _scan();
	( (x/500)*1000 + (x%500)/5*5).writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2712