akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	ll n;
	cin >> n;
	vector<ll> A(n);
	for(ll i = 0;i<n;i++)cin >> A[i];
	ll cnt = 0;
	ll ans = 0;
	ll mn = INT_MAX;
	bool zero = false;
	for(auto i:A){ans += abs(i);if(i<0)cnt++;if(i==0)zero=true;mn =min(mn,abs(i));}
	//cout<<(cnt%2==0)<<';'<<zero<<endl;
	if(cnt%2==0||zero==true)
	{
		cout<<ans<<endl;
	}
	else
	{
		//cout<<ans<<endl;
		cout<<ans-mn*2<<endl;
	}
	return 0;
}

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

int main(){
  int X,Y,A,B,C;
  cin >> X >> Y >> A >> B >> C;
  vector<long long> P(A),Q(B),R(C);
  for(int i=0;i<A;i++) cin >> P[i];
  for(int i=0;i<B;i++) cin >> Q[i];
  for(int i=0;i<C;i++) cin >> R[i];
  sort(P.begin(),P.end());
  reverse(P.begin(),P.end());
  sort(Q.begin(),Q.end());
  reverse(Q.begin(),Q.end());
  sort(R.begin(),R.end());
  reverse(R.begin(),R.end());
  
  vector<long long> V(0);
  for(int i=0;i<X;i++) V.push_back(P[i]);
  for(int i=0;i<Y;i++) V.push_back(Q[i]);
  sort(V.begin(),V.end());
  reverse(V.begin(),V.end());
  for(int i=1;i<X+Y;i++) V[i] += V[i-1];
  for(int i=1;i<C;i++) R[i] += R[i-1];
  
  long long ans = V[X+Y-1];
  if(X+Y>C){
    for(int i=0;i<C;i++) ans = max(ans,V[X+Y-2-i]+R[i]);
  }
  else{
    for(int i=0;i<X+Y-1;i++) ans = max(ans,V[X+Y-2-i]+R[i]);
    ans = max(ans,R[X+Y-1]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4724
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var d = o.a();
  var ans = "Christmas";
  for(; d< 25; d++)ans += " Eve";
  return ans;
}

Measured memory_bytes: 21064
(defun split (string &key (delimiterp #'(lambda (c) (char= c #\Space))))
  (loop :for beg = (position-if-not delimiterp string)
        :then (position-if-not delimiterp string :start (1+ end))
        :for end = (and beg (position-if delimiterp string :start beg))
        :when beg :collect (subseq string beg end)
        :while end))

(defun ce (a b c count)
  (if (and (evenp a) (evenp b) (evenp c))
      (ce (/ (+ b c) 2) (/ (+ a c) 2) (/ (+ a b) 2) (+ count 1))
      count))

(destructuring-bind (a0 b0 c0) (mapcar #'parse-integer (split (read-line)))
  (format t "~d~%"
          (if (and (evenp a0)
                     (evenp b0)
                     (evenp c0)
                     (= a0 b0 c0))
              -1
              (ce a0 b0 c0 0))))


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

int main(){
  string s; cin >> s;
  int n = s.size();
  ll ans = 0;
  for(int i = 0; i < n; i++) ans += s[i]-'0';
  if(ans%9 == 0)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

vector<int> a;

int rec(int h,int w){
    if(h == 1) return a[w];
    int t = 1;
    while(t < h){
        t *= 2;
    }
    t /= 2;
    return rec(h - t, w + t) ^ rec(h - t, w);
}

int main(){
    int n;cin >> n;
    string s;cin >> s;
    a.resize(n-1);
    int c2 = 0, c1 = 0, c0 = 0;
    for (int i = 0; i < n-1; i++) {
        a[i] = abs(s[i+1] - s[i]);
        if(a[i] == 2) c2++;
        else if(a[i] == 1) c1++;
        else c0++;
    }
    if(c1 == 0){
        for (int i = 0; i < n-1; i++) {
            a[i] /= 2;
        }
        cout << (rec(n-1,0)?2:0) << endl;
    }
    else{
        for (int i = 0; i < n-1; i++) {
            a[i] %= 2;
        }
        cout << rec(n-1,0) << endl;
    }
    return 0;
}


Measured memory_bytes: 5252
#include<iostream>
using namespace std;
int main(){
	int n,b,f,r,v,y,z,a,i,j,l,k,math[4][3][10]={0},x;
	cin>>n;
	for(l=0;l<n;l++){
	cin>>x>>y>>z>>v;
	math[x-1][y-1][z-1]+=v;
	}
	for(k=0;k<4;k++){
		for(i=0;i<3;i++){
			
		for(j=0;j<10;j++){

		cout<<" "<<math[k][i][j];
		}
		cout<<endl;
		}
		if(k==3){
			break;
		}
		cout<<"####################"<<endl;
	}
return 0;
}

Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 100001

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

    ll n;
    cin>>n;
    pair<string, pll> p[n];
    loop(i,0,n){
        ll x;
        cin>>p[i].fi>>x;
        p[i].se.fi = -x;
        p[i].se.se=i;
    }
    sort(p,p+n);
    ll ans[n];
    loop(i,0,n){
        print(p[i].se.se+1);
    }
    

    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i] << " "
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
bool isPerfectSquare(long double x) {   
    long double sr = sqrt(x); 
    return ((sr - floor(sr)) == 0); 
} 
bool isPrime(int x){
    for(int i = 2; i * i <= x; ++i){
        if(x % i == 0) return 0;
    }
    return 1;
}
int fun(int n){
    if(n & 1) return 3 * n + 1;
    else return n/2;
}
int32_t main(){
    SPEED;
    string w;
    cin >> w;
    map<int , int> fre;
    for(char c: w){
        ++fre[c];
    }
    for(auto it: fre){
        if(it.se & 1){
            cout << "No" ;
            return 0;
        }
    }
    cout << "Yes" ;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

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

  if(s[0]==s[2]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

int main(){
    int64_t n;
    cin >> n;
    int64_t ans=0;
    int64_t tmp;
    for(int64_t i=1;i<=n;i++){
        tmp = n/i;
        ans += i*(tmp+1)*tmp/2;
    }
    cout << ans;
}

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

int main() {
  int N,i;
  cin >> N;
  for(i=0;i<N;i++){
    string s;
    cin >>s;
    if(s == "Y"){
      cout << "Four"<< endl;
      break;
    }
    if(i == N-1){
      cout << "Three" << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	string s;
	cin>>s;
	rep(i,0,3) if (s[i]==s[i+1]) {
		cout<<"Bad\n";
		return 0;
	}
	cout<<"Good\n";
}


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

using namespace std;

int main()
{
    string s, t;
    cin>>s>>t;

    vector<string> T(t.size()+1);
    for (int i=1; i<=(int)s.size(); i++)
    {
        vector<string> P = T;
        T = vector<string>(t.size()+1);
        for (int j=1; j<=(int)t.size(); j++)
        {
            if (P[j].size() > T[j].size())
                T[j] = P[j];
            if (T[j-1].size() > T[j].size())
                T[j] = T[j-1];
            if (s[i-1] == t[j-1] && P[j-1].size()+1 > T[j].size())
                T[j] = P[j-1] + s[i-1];
        }
    }
    cout<<T[t.size()]<<endl;
}


Measured memory_bytes: 8832
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main () {

    int d[2];
    while( scanf("%d %d", &d[0], &d[1]) != EOF ) {
        int b, s;
        if ( d[0] > d[1] ) {
            b = d[0];
            s = d[1];
        } else {
            b = d[1];
            s = d[0];
        }

        int a = b;
        int c = s;
        int gcd;
        while ( gcd = (a % c) ) {
            a = c;
            c = gcd;
        }

        int lcm = b / c * s;
        printf("%d %d\n", c, lcm);
    }
    return 0;
}

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

int main(){
    int H, A;
    cin >> H >> A;
    if (H%A ==0)
    {
        cout << H/A << endl;
    }
    else
    {
        cout << H/A + 1 << endl;
    }
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

#define N 100005

ll powa(ll a, ll b, ll c)
{
    a%=c;
    ll res = 1;
    while(b>0)
    {
        if(b&1)
            res*=a, res%=c;
        a*=a, a%=c;
        b>>=1;
    }
    return res;
}

ll fact[N];
ll ifact[N];
ll ncr(ll n, ll r)
{
    ll ans = fact[n];
    ans*=ifact[r];
    ans%=mod;
    ans*=ifact[n-r];
    ans%=mod;
    return ans;
}

int main()
{
   FAST/**/
   
   fact[0] = 1;
   for(ll i=1;i<N;i++)
        fact[i] = fact[i-1]*i, fact[i]%=mod;
   for(ll i=0;i<N;i++)
        ifact[i] = powa(fact[i],mod-2,mod);
   
   ll n;
   cin>>n;
   
   ll arr[n];
   rep(n)
        cin>>arr[i];
   
   ll ans = 0;
   ll temp = 0;
   rep(n-1)
        temp+=arr[i], temp%=mod;
   
   //cout<<"temp = "<<temp<<"\n";
   
   ll fsum[N];
   fsum[2] = powa(2,mod-2,mod);
   for(ll i=3;i<N;i++)
   {
       ll t1 = 2;
       t1*=ncr(i,2);
       t1%=mod;
       t1 = powa(t1,mod-2,mod);
       fsum[i] = fsum[i-1] + t1;
       fsum[i]%=mod;
   }
   
   //cout<<"fsum at "<<"2 = "<<fsum[3]<<"\n";
   
   temp*=fact[n-1];
   temp%=mod;
   
   //cout<<"temp = "<<temp<<"\n";
   
   //cout<<"temp = "<<temp<<"\n";
   
   
   for(ll i=1;i<n-1;i++)
   {
       //cout<<"at "<<i+1<<" = "<<(((fsum[i+1])%mod)*fact[n-1])%mod<<"\n";
       ans+=(((arr[i]*fsum[i+1])%mod)*fact[n-1])%mod;
       //cout<<"after "<<i+1<<" = "<<ans<<"\n";
       ans%=mod;
   }
   
  // ans+=(arr[n-1]*fact[n-1])%mod;
  //  ans%=mod;
   
   //cout<<"ans = "<<ans<<"\n";
   
   for(ll i=1;i<=n-1;i++)
   {
       ans+=(((arr[n-1]*fact[n-1])%mod)*powa(i,mod-2,mod))%mod;
       ans%=mod;
   }
   
   ans-=temp;
   ans%=mod;
   if(ans<0)
        ans+=mod;
   
   cout<<ans;
   
   return 0;        
}  
   

Measured memory_bytes: 3456
import collections

N, Q = map(int, input().split())
Links = [[] for _ in range(N)]
AnsArr = [0] * N

# 辺の数だけ
for i in range(N - 1):
    a, b = map(int, input().split())
    Links[a - 1].append(b - 1)
    Links[b - 1].append(a - 1)

for i in range(Q):
    p, x = map(int, input().split())
    AnsArr[p - 1] += x

# BFS
# 頂点1から開始
q = collections.deque([0])
visited = [0] * N
while q:
    t = q.pop()
    visited[t] = 1
    for e in Links[t]:
        if visited[e] == 1:
            continue
        visited[e] = 1
        # 親の値を子に受け継ぐ
        AnsArr[e] += AnsArr[t]
        q.appendleft(e)

print(*AnsArr)


Measured memory_bytes: 56108
#include <iostream> 
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	int m,n,a,sum=0;
	scanf("%d %d %d",&m,&n,&a);
	for(int i=m;i<=n;i++){
		if(i%a==0)
			sum++;
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 3824
s=input()
t=''
while s!='':
  if len(s)<=4:
    break
  elif s[:5]=='dream':
    if len(s)>=10 and s[5:10]=='erase':
      s=s[5:]
      continue
    elif len(s)>=7 and s[5:7]=='er':
      s=s[7:]
      continue
    else:
      s=s[5:]
      continue
  elif s[:5]=='erase':
    if len(s)>=6 and s[5]=='r':
      s=s[6:]
      continue
    else:
      s=s[5:]
      continue
  
  elif s[:5]!='dream' and s[:5]!='erase':
    break
      
    
if s=='':
  print('YES')
  
else:
  print('NO')

Measured memory_bytes: 75704
n = int(input())
arr = list(map(int, input().split()))
d0 = {0:0}
d1 = {0:0}
for i,a in enumerate(arr):
  if i%2==0:
    if a not in d0:
      d0[a] = 1
    else:
      d0[a] += 1
  else:
    if a not in d1:
      d1[a] = 1
    else:
      d1[a] += 1
pairs0 = sorted(d0.items(), key=lambda x:x[1])[::-1]
pairs1 = sorted(d1.items(), key=lambda x:x[1])[::-1]
a0, maxlen0 = pairs0[0]
a1, maxlen1 = pairs1[0]

if a0!=a1:
  print(n - maxlen0 - maxlen1)
else:
  if maxlen0<maxlen1:
    print(n - maxlen1 - pairs0[1][1])
  elif maxlen0>maxlen0:
    print(n - maxlen0 - pairs1[1][1])
  else:
    if len(pairs0)>len(pairs1):
      pairs0, pairs1 = pairs1, pairs0
    flag = False
    for i,p in enumerate(pairs0):
      if i==0:
        continue
      x0, x1 = p[1], pairs1[i][1]
      if x0!=x1:
        flag = True
        break
    if flag:
      print(n - maxlen0 - max(x0, x1))
    else:
      print(n - maxlen0 - pairs1[1][1])

Measured memory_bytes: 20716
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n string

	fmt.Scanf("%s", &n)

	N := strings.Split(n, "")
	sum := 0
	for _, i := range N {
		j, _ := strconv.Atoi(i)
		sum += j
	}

	if sum%9 == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 6552
import java.util.*;                                                                                  

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] l = line.split(" ");
        int W = Integer.parseInt(l[0]); //rectangle width
        int H = Integer.parseInt(l[1]); //rectangle height
        int x = Integer.parseInt(l[2]); //circle x
        int y = Integer.parseInt(l[3]); //circle y
        int r = Integer.parseInt(l[4]); //circle radius.

        if(x + r > W || x - r < 0 || y + r > H || y - r < 0) {
          System.out.println("No");
        } else {
          System.out.println("Yes");
        }   
    }   
}

Measured memory_bytes: 26064
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define range_for(i, b, e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define pb push_back
# define len(x) ((int)(x).size())
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
# define LINT_MAX (LONG_LONG_MAX)
# define cauto const auto
using namespace std;
using lint = long long;
template <class Type> inline constexpr bool InRange(const Type& x, const Type& i, const Type& a) { return (i <= x) && (x <= a); }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a<b) { a=b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Integer>bool IsOdd(Integer &n) { return n & 1; }
template<class Integer>bool IsEven(Integer &n) { return !(n & 1); }
int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
string YesNo(bool b) { return b ? "Yes" : "No"; }
string YESNO(bool b) { return b ? "YES" : "NO"; }
string yesno(bool b) { return b ? "yes" : "no"; }
int dy[4] = {0, 1, 0, -1};
int dx[4] = {1, 0, -1, 0};

// 整数の桁数を返す ( log(N) )
template <class Integer> Integer GetDigit(Integer n) {
    if (n == 0) return 1;
    Integer d = 0;
    while (n) {
        n /= 10;
        d++;
    }
    return d;
}

// 素数かどうかを返す ( O(sqrt(N)) )
template <class Integer>
constexpr bool IsPrime(const Integer n) noexcept {
    if (n < 4) return n == 2 || n == 3;
    if (n % 2 == 0 || n % 3 == 0 || (n % 6 != 1 && n % 6 != 5)) return false;
    for (Integer i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;
}


int main()
{
    int N; cin >> N;
    map<int, int> mp;
    rep(i,N-1)
    {
        int a; cin >> a;
        mp[a]++;
    }

    reps (i, N)
    {
        cout << mp[i] << "\n";
    }


    return 0;
}



Measured memory_bytes: 13012
#include <iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n,p[10000],d[10000],e[10000],c[10000],max=0,num=0,i;
    while(cin>>n){
        if(n==0)break;
        for(i=0;i<n;i++){
            cin>>p[i]>>d[i]>>e[i];
        }
        for(i=0;i<n;i++){
            c[i]=d[i]+e[i];
        }
        for(i=0;i<n;i++){
            if(max<=c[i]){
                max=c[i];
                num=i;
            }
        }
        cout<<p[num]<<" "<<max<<endl;
        max=0;
    }
      return 0;
}

Measured memory_bytes: 3164
N = int(input())
bar = [int(x) for x in input().split()]
ls = set()
a,b = 0,0
for x in bar:
    if x>b:
        if x in ls:
            ls.remove(x)
            if x>a:
                b = a
                a = x
            else:
                b = x
        else:
            ls.add(x)
print(a*b)

Measured memory_bytes: 14252
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> c(h);
  rep(i, h) cin >> c[i];

  int ans = 0;
  int cnt;
  rep(i, 1 << h) {
    rep(j, 1 << w) {
      cnt = 0;
      rep(s, h) {
        rep(t, w) {
          if (i & (1 << s)) continue;
          if (j & (1 << t)) continue;
          if (c[s][t] == '#') ++cnt;
        }
      }
      if (cnt == k) ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3636
# Prime Number

import sys


MAX_NUM = 1000000
ROOT_MAX_NUM = 1000

primes = [1] * MAX_NUM

primes[0] = primes[1] = 0

for i in xrange(2, ROOT_MAX_NUM):
	if not primes[i]:
		continue
	for j in xrange(i+i, MAX_NUM, i):
		primes[j] = 0

datas = []

for line in sys.stdin:
	datas.append(int(line))

for data in datas:
	count = 0
	for i in xrange(data+1):
		if primes[i]:
			count += 1
	print count

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

/**
 * ランレングス圧縮
 */
vector<pair<char, ll>> RLE(const string &S) {
    ll cnt = 0;
    vector<pair<char, ll>> res;
    for (ll i = 0; i < (ll) S.size(); i++) {
        cnt++;
        if (i == (ll) S.size() - 1) {
            res.emplace_back(S[i], cnt);
            break;
        }
        if (S[i] != S[i + 1]) {
            res.emplace_back(S[i], cnt);
            cnt = 0;
        }
    }
    return res;
}

void Main() {
    string X;
    cin >> X;
    auto rle = RLE(X);
    ll ans = 0;
    ll last = 0;
    rep(i, rle.size()) {
        auto p = rle[i];
        if (p.first == 'T') {
            if (i == 0)continue;
            if (p.second >= last) {
                ans += last;
                last = 0;
            } else {
                ans += p.second;
                last -= p.second;
            }
        } else {
            last += p.second;
        }
    }
    cout << X.size() - 2 * ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 2700
#include<bits/stdc++.h>
#include<unordered_map>
#include<string>
#include<math.h>
#define ll long long
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const ll N= 1e8;
inline void fastio()
{ 
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
int main()
{
    int x, n, ans=300;
    cin >> x >> n;
    int p[102];
    memset(p, 0, sizeof(p));
    for (int i = 0; i < n;i++) 
    {
        int temp;
        cin>>temp;
        p[temp] = 1;
    }
    for (int i = 0; i <= 101;i++)
        if(p[i]!=1)  ans = abs(x - i) < abs(ans-x) ? i:ans;
    cout << ans;
    system("pause");
    return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
const int MAX_V = 100000;
const int MAX_LOG_V = 30;
vector<int> G[MAX_V];
int root;
int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];
 
void dfs(int v, int p, int d){
  parent[0][v] = p;
  depth[v] = d;
  for(int i=0;i<G[v].size();i++)
    if(G[v][i] != p) dfs(G[v][i], v, d+1);
}
 
void init(int n){
  dfs(root, -1, 0);
  for(int k=0;k+1<MAX_LOG_V;k++){
    for(int v=0;v<n;v++){
      if(parent[k][v] < 0) parent[k+1][v] = -1;
      else parent[k+1][v] = parent[k][parent[k][v]];
    }
  }
}
 
int lca(int u, int v){
  if(depth[u] > depth[v]) swap(u,v);
  for(int k=0;k<MAX_LOG_V;k++)
    if((depth[v] - depth[u]) >> k & 1)
      v = parent[k][v]; 
  if(u == v) return u;
  for(int k=MAX_LOG_V-1;k>=0;k--){
    if(parent[k][u] != parent[k][v]){
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}
int N;
typedef long long ll;
int main(){
  cin >> N;
  for(int i=1;i<N;i++){
    int p; cin >> p;
    --p;
    G[p].push_back( i );
  }
  init(N);
  vector<int> R;
  queue<int> q;
  q.push( 0 );
  while( !q.empty() ){
    int p = q.front(); q.pop();
    R.push_back( p );
    for(int i=0;i<(int)G[p].size();i++){
      int to = G[p][i];
      q.push( to );
    }    
  }
 
  ll res = 0;
  for(int i=0;i<(int)R.size()-1;i++){
    res += - 2 * depth[lca(R[i],R[i+1])] + depth[R[i]] + depth[R[i+1]];
  }
  cout << res << endl;
  
  
}

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

int main(){
	char *dotw[7] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
	int mod[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	int i, day, mon, dcnt;
	while(true){
		dcnt = 0;
		cin>>mon>>day;
		if(mon==0)
			break;
		for(i=1;i<mon;i++){
			dcnt += mod[i-1];
		}
		dcnt += day + 2;
		cout << dotw[dcnt%7] << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i<n;i++)
#define fod(i,n) for(i=n-1;i>=0;i--)
#define MAX std::numeric_limits<lld>::max();
#define MIN std::numeric_limits<lld>::min();
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main (){
    FastIO
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
    	cout << "Yes\n";
    else
    	cout <<  "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
  int N, T;
  cin >> N >> T;
  int t[N];
  for (int i = 0; i < N; i++) {
    cin >> t[i];
  }
  int result = 0;
  int diff = 0;
  for (int i = 0; i < (N - 1); i++) {
    diff = t[i + 1] - t[i];
    if (diff <= T) {
      result += diff;
    } else {
      result += T;
    }
  }
  cout << (result + T) << endl;
  return 0;
}

Measured memory_bytes: 1024
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
l = [2**i for i in range(29, -1, -1)]
ans = 0
for i in range(N):
    flag = False
    for j in range(len(l)):
        if A[i] % l[j] == 0 and flag==False:
            ans += 29 - j
            flag = True
print(ans)

Measured memory_bytes: 4148
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	L, R := nextInt(), nextInt()

	if R-L > 2019 {
		fmt.Println(0)
		return
	}

	min := 100000000

	for i := L; i <= R-1; i++ {
		for j := L + 1; j <= R; j++ {
			if min > i*j%2019 {
				min = i * j % 2019
			}
		}
	}

	fmt.Println(min)
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}


Measured memory_bytes: 640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
    public static void Main()
    {
        string a = GetString();
        string s = GetString();
        string c = GetString();

        Console.WriteLine($"A{s[0]}C");
    }
}

public static class MyIO
{
    private static string[] args = null;
    private static int num = -1;
    private static int used = -1;

    private static string getArg()
    {
        if (used == num)
        {
            args = Console.ReadLine().Split(' ');
            num = args.Length;
            used = 0;
        }
        return args[used++];
    }

    public static int GetInt() { return int.Parse(getArg()); }
    public static long GetLong() { return long.Parse(getArg()); }
    public static double GetDouble() { return double.Parse(getArg()); }
    public static string GetString() { return getArg(); }
}


Measured memory_bytes: 13140
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN = 100000;
const int MAXM = MAXN - 1;
typedef struct E { int a, b, c; } E;
bool operator<(const E &p, const E &q) { return p.c > q.c; }

int n, m;
E e[MAXM];

int par[MAXN], sz[MAXN]; ll val[MAXN];

int find(int a) { if (par[a] == a) return a; int b = par[a]; par[a] = find(b); if (par[a] != b) val[a] += val[b]; return par[a]; }

void run() {
	scanf("%d", &n); m = n - 1; REP(i, m) { scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].c); --e[i].a, --e[i].b; }

	sort(e, e + m);
	REP(i, n) par[i] = i, sz[i] = 1, val[i] = 0;
	REP(i, m) {
		int a = find(e[i].a), b = find(e[i].b); assert(a != b);
		if (sz[a] < sz[b]) swap(a, b);
		val[a] += (ll)e[i].c*sz[b];
		val[b] += (ll)e[i].c*sz[a];
		val[b] -= val[a]; par[b] = a; sz[a] += sz[b];
		//printf("state:"); REP(j, n) printf(" %d=(%d,%d,%lld)", j + 1, par[j] + 1, par[j] == j ? sz[j] : -1, val[j]); puts("");
	}
	REP(i, n) {
		int rt = find(i);
		ll curval = i == rt ? val[i] : val[i] + val[rt];
		printf("%lld\n", curval);
	}
}

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


Measured memory_bytes: 4480
//  RAKSHIT KADAM
 #include <bits/stdc++.h>
 
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
 #warning !!!check the size of arrayss!!!
 
 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define newMOD  998244353
 #define MAX 300006
            
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define endl "\n"
 #define x first
 #define y second
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define INF 1000000000000000005
 #define vi vector<ll>
#define pi 3.1415926535897932384626433832795
#define Endl endl
#define lb lower_bound
#define ub upper_bound
using namespace std;
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}
 
//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}} // if a and m are relativelyprime

void solve()
{
    ll n;cin>>n;ll sum=0;
    for(ll i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)sum+=i;
    }
    cout<<sum<<endl;
}
signed main()
{
 
   
    Need_for_speed(activated);
//satisfy
//    {
//   solve();
//    }

  solve();
    return 0;
    
}
 


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

left_to_me = [0]*(N+1)
for i, a in enumerate(A):
    left_to_me[i+1] = left_to_me[i]+a

right_to_me = [0]*(N+1)
for i in range(N-1, -1, -1):
    right_to_me[i-1] = right_to_me[i]+A[i]

min_cost = 10**24
for i, a in enumerate(A):
    target = abs(left_to_me[i]-right_to_me[i])
    cost = abs(target-a)
    min_cost = min(min_cost, cost)

print(min_cost)

Measured memory_bytes: 30828
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,M;
void input(){
    fast_io();
    cin >> N >> M;
}
ll const mod = 1e9+7;
ll fact_db[110000];
ll fact(ll x){
    if(x==0) return 1;
    if(fact_db[x]) return fact_db[x]%mod;
    return fact_db[x] = x*fact(x-1)%mod;
}

int solve(){
    if(abs(N-M)>=2) {cout << 0 << endl; return 0;}
    else if(abs(N-M)==1){
        ll ans = fact(N)%mod;
        ans *= fact(M)%mod;
        ans %= mod;
        cout << ans << endl;
    }
    else{
        ll ans = fact(N)%mod;
        ans *= fact(N)%mod;
        ans *= 2;
        ans %= mod;
        cout << ans << endl;
    }
    return 0;
}   

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

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

using namespace std;

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

  string s;
  int64_t k;
  cin >> s >> k;
  int ss = s.size();

  char ans = '1';
  for (int i = 0; i < ss; ++i) {
    if (i == k - 1) {
      ans = s[i];
      break;
    }
    if (s[i] != '1') {
      ans = s[i];
      break;
    }
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3632
import java.util.*;
import java.io.*;

class Main {

	void solve() {

		int n = inint(), a = inint(), b = inint();
		out.println(Math.min(a*n, b));

	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}
	
	public String instr() {
		return in.next();
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

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

int N, M, X, A[200];
int main()
{
	scanf("%d%d%d", &N, &M, &X);
    for(int i = 0; i < M; ++i) scanf("%d", &A[i]);
    int l=0, h=0;
	for(int i=0; i<M; i++){
		if(A[i]<X) l++;
      	else h++;
    }
  	printf("%d\n", min(l, h));
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

int main(){

	int n,x;
	int ans;

	while (1){
		ans = 0;
		cin >> n >> x;
		if (n == 0 && x == 0 ) break;

		for (int i = 1; i <= n; i++){
			for (int j = i + 1; j <= n; j++){
				for (int k = j + 1; k <= n; k++){
					if ((i + j + k) == x) ans++;
					else if ((i + j + k) > x) break;
				}
			}
		}

		cout << ans << endl;
	}



	return 0;
}

Measured memory_bytes: 1160
// B - Snake Toy

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int l[50];

int main() {
	int N, K;
	cin >> N >> K;

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

	sort(l, l+N, greater<int>());

	int ans = 0;

	for (int i=0; i<K; i++) {
		ans += l[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque

def main():
    s = list(input())
    k = int(input())
    for i in range(len(s)):
        if s[i] == 'a':
            continue
        if k >= ord('z') - ord(s[i]) + 1:
            k -= ord('z') - ord(s[i]) + 1
            s[i] = 'a'
            if k == 0:
                break
    
    if k > 0:
        s[-1] = chr((ord(s[-1]) + k - 97)%26 + 97)
    
    print(''.join(s))
if __name__ == '__main__':
    main()


Measured memory_bytes: 4412
#include<stdio.h>

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

    long long int max;
    if(b>0){
        if(d>=0){
            if(b*d>=a*c){
                max=b*d;
            }else{
                max=a*c;
            }
        }else if(a<0){
            max=a*c;
        }else{
            max=a*d;
        }
    }else if(b<0){
        if(c<=0){
            max=a*c;
        }else{
            max=b*c;
        }
    }else{
        if(c<=0){
            max=a*c;
        }else{
            max=b*c;
        }
    }
    printf("%lld\n",max);
    return 0;
}

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

void Bubblesort(vector<int> A){
    int count=0;
    for(int i=0;i<A.size()-1;i++){
        for(int j=A.size()-1;j>=i+1;j--){
            if(A.at(j)<A.at(j-1)){
                swap(A.at(j),A.at(j-1));
                count++;
            }
        }
    }
    for(int i=0;i<A.size();i++){
        if(i) cout << " ";
        cout << A.at(i);
    }
    cout << endl;
    cout << count << endl;
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A.at(i);
    }
    Bubblesort(A);
}


Measured memory_bytes: 3164
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>
using namespace std;
 
typedef long long ll;

int main(){
	ll n;
    cin >> n;
    vector<pair<ll,ll>> a(n);
    vector<ll> k(n);
    ll x;
    for(ll i=0;i<n;i++){
    	cin >> x;
        a[i] = make_pair(x,i);
    }
    sort(a.begin(),a.end());
    
    
    ll count=0,sum=0;
    for(ll i=0;i<n;i++){
        if(count==0){
        	for(int j=0;;j++){
        		if(a[i].first == a[i+j].first){
            		count++;
            	}else{
       				break;
           		}
        	}
            x = count-1;
            sum += count*(count-1)/2;
            k[a[i].second]=-x;
            count--;
        }else{
        	k[a[i].second]=-x;
            count--;
        }
    }
    for(ll i=0;i<n;i++){
    	cout << k[i]+sum << endl;
    }
}

Measured memory_bytes: 7296
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n, m; cin >> n >> m;
    ll a[100001]; INITA(a, 0, 100000, 0);
    ll f[100001]; INITA(f, 0, 100000, 0);

    ll rp = 0;
    REP(i, n) {
        a[i] = 1;

        if (i == 0) {
            f[i] = true;
        } else {
            f[i] = false;
        }
    }

    REP(i, m) {
        ll x, y; cin >> x >> y;
        a[x-1]--;
        a[y-1]++;

        if (f[x-1]) {
            // 赤がありえる場合は移動先も赤になりえる
            f[y-1] = true;
        }
        if (a[x-1] == 0) {
            // 移動元がカラになったら赤の可能性がなくなる
            f[x-1] = false;
        }
    }

    ll res = 0;
    REP(i, n) {
        if (f[i]) {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

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

int gcd(int x, int y) {
    if (x < y) swap(x, y);
    int r = x%y;
    if (r == 0) {
        return y;
    }
    return gcd(y, r);
}

int main(){
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    if (A >= K) {
        cout << K << endl;
        return 0;
    }
    if (A + B >= K) {
        cout << A << endl;
        return 0;
    }
    cout << A - (K - (A + B)) << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct range_update_point_value{
	int N;
	vector<pair<T, int>> ST;
	int t;
	range_update_point_value(int n){
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<pair<T, int>>(N * 2 - 1, make_pair(0, 0));
		t = 1;
	}
	range_update_point_value(int n, T x){
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<pair<T, int>>(N * 2 - 1, make_pair(0, 0));
		for (int i = 0; i < n; i++){
			ST[N - 1 + i] = make_pair(x, 1);
		}
		t = 2;
	}
	range_update_point_value(vector<T> A){
		int n = A.size();
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<pair<T, int>>(N * 2 - 1, make_pair(0, 0));
		for (int i = 0; i < n; i++){
			ST[N - 1 + i] = make_pair(A[i], 1);
		}
		t = 2;
	}
	T operator [](int k){
		k += N - 1;
		T ans = ST[k].first;
		T time = ST[k].second;
		while (k > 0){
			k = (k - 1) / 2;
			if (ST[k].second > time){
				ans = ST[k].first;
				time = ST[k].second;
			}
		}
		return ans;
	}
	void update(int L, int R, T x, int i, int l, int r){
		if (R <= l || r <= L){
			return;
		} else if (L <= l && r <= R){
			ST[i] = make_pair(x, t);
		} else {
			int m = (l + r) / 2;
			update(L, R, x, i * 2 + 1, l, m);
			update(L, R, x, i * 2 + 2, m, r);
		}
	}
	void range_update(int L, int R, T x){
		update(L, R, x, 0, 0, N);
		t++;
	}
};
int main(){
  int n, q;
  cin >> n >> q;
  range_update_point_value<int> a(n, 2147483647);
  for (int c = 0; c < q; c++){
    int T;
    cin >> T;
    if (T == 0){
      int s, t, x;
      cin >> s >> t >> x;
      a.range_update(s, t + 1, x);
    }
    if (T == 1){
      int i;
      cin >> i;
      cout << a[i] << endl;
    }
  }
}


Measured memory_bytes: 4860
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
	while(true) {
		int a=scan.nextInt();
		String op=scan.next();
		int b=scan.nextInt();
		if (op.equals("?")) break;
		else if(op.equals("+")) System.out.println(a+b);
		else if(op.equals("-")) System.out.println(a-b);
		else if(op.equals("*")) System.out.println(a*b);
		else if(op.equals("/")) System.out.println(a/b);

	}}
}


Measured memory_bytes: 26320
#include <iostream>
#include <algorithm>
using namespace std;
static const int N = 100;
int main(){
  int n,k,cnt,c[N],i,j,l,m,bcmax,acmax,x;
  while(1){
    cin >> n >> k;
    if(n==0&&k==0) break;
    for(i=0;i<n;i++){
      cin >> c[i];
    }
    bcmax=0;
    for(i=0;i<=n-k;i++){
      cnt=k;
      x=1;
      j=i;
      while(cnt){
	x*=c[j];
	j++;
	cnt--;
      }
      bcmax=max(bcmax,x);
    }
    acmax=0;
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	if(i!=j){
	  swap(c[i],c[j]);
	  for(l=0;l<=n-k;l++){
	    cnt=k;
	    x=1;
	    m=l;
	    while(cnt){
	      x*=c[m];
	      m++;
	      cnt--;
	    }
	    acmax=max(acmax,x);
	  }
	  swap(c[i],c[j]);
	}
      }
    }
    //if(acmax-bcmax>=0)
    cout << acmax-bcmax << endl;
    //else cout << "NO GAME" << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        String T = s.next();
        int flag=0;
       for (int i=0;i<2;i++){
           if(T.charAt(i)!=T.charAt(i+1))
               flag=1;
       }
       if(flag==1)
           System.out.println("Yes");
       else
           System.out.println("No");
    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int l,r,d,x=0,i;
   cin>>l>>r>>d;
   for(i=l;i<=r;i++)
   {
       if(!(i%d))
        x++;
   }
   cout<<x<<endl;
   return 0;


}

Measured memory_bytes: 3560
#include <algorithm>
#include <chrono>
#include <climits>
#include <iostream>
#include <locale>
#include <stack>
#include <unordered_set>
#include <utility>
#include <vector>

using i32 = int32_t;
using i64 = uint64_t;
using u32 = uint32_t;
using u64 = uint64_t;

struct Tenbodai {
  u32 height;
  bool has_good_site;
  std::unordered_set<size_t> neibor_ids;
  Tenbodai(u32 _height) : height(_height), has_good_site(true) {}
  template <typename A>
  void assign_neibor(size_t id, const A &arr) {
    if (neibor_ids.find(id) == neibor_ids.end()) {
      neibor_ids.insert(id);
      has_good_site = height > arr[id - 1].height ? has_good_site : false;
    }
  }
};

int main() {
  using namespace std;
#ifdef _WIN32
  locale::global(locale(""));
#endif
  ios_base::sync_with_stdio(false);
  vector<Tenbodai> tenbodai_array;
  u32 n_tenbodai, n_paths;
  cin >> n_tenbodai >> n_paths;
  for (u32 i = 0; i < n_tenbodai; ++i) {
    tenbodai_array.push_back(Tenbodai([]() {
      u32 h;
      cin >> h;
      return h;
    }()));
  }
  for (u32 i = 0; i < n_paths; ++i) {
    const std::pair startend = []() {
      size_t start, end;
      cin >> start >> end;
      return make_pair(start, end);
    }();
    tenbodai_array[startend.first - 1].assign_neibor(
      startend.second, tenbodai_array);
    tenbodai_array[startend.second - 1].assign_neibor(
      startend.first, tenbodai_array);
  }

  cout << count_if(
            tenbodai_array.begin(), tenbodai_array.end(),
            [](const Tenbodai &t) { return t.has_good_site; })
       << '\n';
  return 0;
}


Measured memory_bytes: 19012