akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int q[4]={0,1,-1,0};
int e[4]={1,0,0,-1};
int main(){
  ll h,w;
  cin>>h>>w;
  vector<vector<char>> t(h+2,vector<char> (w+2,'.'));
  for(int i=1;i<h+1;i++){
    for(int j=1;j<=w;j++){
      char a;
      cin>>a;
      t[i][j]=a;
    }
  }
  
  for(int i=1;i<h+1;i++){
    for(int j=1;j<=w;j++){
      if(t[i][j]=='#'){
        ll cu=1;
        rep(u,4){
          if(t[i+q[u]][j+e[u]]=='#'){
            cu=0;
          }
        }
        if(cu){
          COUT("No");
          return 0;
        }
      }
    }
  }
  COUT("Yes");
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

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

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong N, X;
	vector<llong> L;

	cin >> N >> X;
	L.resize(N);
	for (int i = 0; i < N; i++)
		cin >> L[i];

	llong sum = 0;
	int i;
	for (i = 0; i < N && sum + L[i] <= X; ++i) {
		sum += L[i];
	}

	cout << i+1 << endl;

	return 0;
}

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

int m,n;
char a[105][105];

int main()
{
    cin>>m>>n;
    for(int i=1;i<=m;i++)
        for(int j=1;j<=n;j++)
            cin>>a[i][j];
    for(int i=0;i<=m+1;i++)
    {
        a[i][0]='#';
        a[i][n+1]='#';
    }
    for(int i=0;i<=n+1;i++)
    {
        a[0][i]='#';
        a[m+1][i]='#';
    }
    for(int i=0;i<=m+1;i++)
    {
        for(int j=0;j<=n+1;j++)
            cout<<a[i][j];
        cout<<"\n";
    }
}


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

const int MAX = 1e5 + 111;

int n;

int a[MAX];

ll pr[MAX];

void init() {
    pr[0] = a[0];
    for (int i = 1; i < n; ++i) {
        pr[i] = pr[i - 1] + a[i];
    }
}

ll get(int l, int r) {
    if (l == 0)
        return pr[r];
    return pr[r] - pr[l - 1];
}

int bin(int l, int r, ll x) {
    int left = l;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (get(left, mid) <= 2 * x)
            l = mid;
        else
            r = mid;
    }
    if (get(left, l) > 2 * x)
        return -1;
    return l;
}

bool can(int id) {
    ll cur = pr[id];
    ++id;
    int prev = id;
    while (id != n) {
        id = bin(id, n, cur);
        if (id == -1)
            return false;
        cur += get(prev, id);
        ++id;
        prev = id;
    }
    return true;
}

int main() {
#ifdef LOCAL
    freopen("xxx.in", "r", stdin);
    freopen("xxx.out", "w", stdout);    
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n);
    init();
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (can(i))
            cerr << a[i] << "\n", ans++;
    }
    cout << ans;
    return 0;
}

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

int main(){
  while(1){
    int h,w;
    cin>>h>>w;
    if(!h&&!w)break;
    bool mp[11][10001];
    for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>mp[i][j];
    
    int ans=0;
    for(int i=0;i<(1<<h);i++){
      int cnt=0;
      for(int j=0;j<w;j++){
	int c=0;
	for(int k=0;k<h;k++)c+=((i>>k)&1) ? !mp[k][j]:mp[k][j];
	cnt+=max(c,h-c);
      }
      ans=max(ans,cnt);
    }
    cout <<ans<<endl;
  }
    return 0;
  }

Measured memory_bytes: 1264
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n, m;
    cin>>n>>m;
    ll a[n], b[n];
    vector<pair<ll, ll>> c(n);
    for(ll i=0;i<n;++i){
        cin>>a[i]>>b[i];
        c[i] = make_pair(a[i], b[i]);
    }

    sort(c.begin(), c.end());
    ll ans = 0;
    ll index = 0;
    ll count = 0;
    for(ll i=0;i<m;++i){
        if(c[index].second <= count){
            count = 0;
            index += 1;
        }
        ans += c[index].first;
        count++;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include<math.h>
int main()
{
    int n,i,d;
    scanf("%d",&n);
    if(n%1000==0)
        printf("0\n");
    else
    {
       d=ceil(n/1000.0);
       printf("%d\n",d*1000-n);
    }

}


Measured memory_bytes: 2220
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int n,N;
vector<int> v;

void init(){
    N=1;
    while(N<n) N*=2;
    v.assign(2*N-1,inf); //変更点
}

void init_u(){
    for(int i=N-2;i>=0;i--)
    v[i]=min(v[2*i+1],v[2*i+2]); //変更点
}

void update(int k,int a){
    k+=N-1;
    v[k]=a;
    while(k>0){
        k=(k-1)/2;
        v[k]=min(v[k*2+1],v[k*2+2]); //変更点
    }
}

//query(a,b,0,0,N);
int query(int a,int b,int k,int l,int r){
    if(r<=a || b<=l) return inf; //変更点
    if(a<=l && r<=b) return v[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr); //変更点
}

int main(){
    cin>>n; n+=2;
    init();
    n-=2;
    rep(i,n) cin>>v[i+N];
    v[N-1]=0; v[n+N]=0;
    init_u();
    ll ans=0;
    rep(i,n){
        ll a=v[i+N],L,R;
        int l=0,r=i+1,c;
        while(l!=r){
            c=(l+r+1)/2;
            int d=query(c,i+2,0,0,N);
            if(d<a) l=c;
            else r=c-1;
        }
        L=i+1-l;
        l=i+1; r=n+1;
        while(l!=r){
            c=(l+r)/2;
            int d=query(i+1,c+1,0,0,N);
            if(d<a) r=c;
            else l=c+1;
        }
        R=l-(i+1);
        ans+=L*R*a;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2432
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int inf=1e8;
const int L=5000;
int dp[L],dn[L];
int main() {
	int N,Ma,Mb;
	scanf("%d%d%d",&N,&Ma,&Mb);
	for(int i=1;i<L;i++){
		dp[i]=inf;
		dn[i]=inf;
	}
	int ret=inf;

	for(int i=0;i<N;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		int v=Ma*b-Mb*a;
		if(v==0){
			ret=min(ret,c);
		}
		else if(v>0){
			for(int j=L-1;j>=v;j--){
				dp[j]=min(dp[j],dp[j-v]+c);
			}
		}
		else{
			v=-v;
			for(int j=L-1;j>=v;j--){
				dn[j]=min(dn[j],dn[j-v]+c);
			}
		}
	}
	for(int i=1;i<L;i++){
		ret=min(ret,dp[i]+dn[i]);
	}
	if(ret==inf){
		puts("-1");
	}
	else{
		printf("%d\n",ret);
	}

	return 0;
}



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

typedef long long ll;
ll l, n, ans;
vector<ll> x;

ll solve(vector<ll> v){
	vector<ll> w(v);
	reverse(w.begin(), w.end());
	for(int i=1; i<=n; ++i) w[i] = l - w[i];
	for(int i=1; i<=n; ++i){
		v[i] += v[i-1];
		w[i] += w[i-1];
	}
//	for(int i=0; i<n+2; ++i)
//		cout << v[i] << " " << w[i] << "\n";
	ll res = v[n] - v[n-1];
	for(int i=1; i<=n-1; ++i){
		if((n - i + 1) % 2 == 0){
			int k = (n - i + 1) / 2;
			res = max(res, w[k-1]*2+(v[i+k-1]-v[i-1])*2+w[k]-w[k-1]);
		}else{
			int k = (n - i) / 2;
			res = max(res, w[k]*2+(v[i+k-1]-v[i-1])*2+v[i+k]-v[i+k-1]);
		}
//		cout << i << " " << res << "\n";
	}
	return res;
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> l >> n;
	x.resize(n+2, 0);
	for(int i=1; i<=n; ++i) cin >> x[i];
	ans = solve(x);
	reverse(x.begin(), x.end());
	for(int i=1; i<=n; ++i) x[i] = l - x[i];
	ans = max(ans, solve(x));
	cout << ans << "\n";
}

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

int main()
{
  ll n, k; cin>>n>>k;
  map<ll, ll> mp;
  rep(i, n) {
    ll a,b; cin>>a>>b;
    mp[a] += b;
  }
  for (auto v:mp) {
    if (k <= v.second) {
      cout << v.first << endl;
      return 0;
    }
    k -= v.second;
  }

  return 0;
}

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

using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int sum = A + B + C;
  
  int max = A;
  if (max < B) max = B;
  if (max < C) max = C;
  
  if ((max * 3 - sum) % 2) {
    cout << ((max +1) * 3 - sum) / 2 << endl;
  } else { 
    cout << (max * 3 - sum) / 2 << endl;
  }
    
  
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0181

"""
import sys
from sys import stdin
input = stdin.readline


def Cond(m, n, mid, books):
    if max(books) > mid:
        return False

    rem = mid
    while books:
        while rem >= books[0]:
            rem -= books[0]
            books = books[1:]
            if len(books) == 0:
                break
        rem = mid
        m -= 1

    if m >= 0:
        return True
    else:
        return False


def solve(m, n, books):
    ub = 1500000
    lb = 0
    min_width = float('inf')

    for i in range(50):
        mid = (ub + lb) // 2
        if Cond(m, n, mid, books):
            min_width = min(min_width, mid)
            ub = mid
        else:
            lb = mid

    return min_width



def main(args):
    while True:
        m, n = map(int, input().split())
        if m == 0 and n == 0:
            break
        books = [int(input()) for _ in range(n)]
        result = solve(m, n, books)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7700
import java.util.*;
import java.util.Arrays;
import java.util.Collections;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    int notUse = sc.nextInt();
    List<Integer> target = new ArrayList<Integer>();
    
    while(sc.hasNext()){
      target.add(sc.nextInt());
    }
    Collections.sort(target , Collections.reverseOrder());
    
    int Alice = 0;
    int Bob = 0;
    int count = 0;
    
    for(int i : target){
      if(count % 2 == 0){
      Alice += target.get(count);
      count++;
      
      }else{
      Bob += target.get(count);
      count++;
  }
}
    System.out.println(Alice - Bob);  
  }
}

Measured memory_bytes: 23380
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long sum = 1;
		for(int i = 1;i <= n;i++){
			sum *= (long)i;
		}
		System.out.println(sum);
	}
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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; }


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

    int ans = a-1;
    if( a <= b ) cout << ans+1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{
	auto tokens = my_readln().split();
	auto N = tokens[0].to!ulong;
	double[] p;
	foreach (token; my_readln.split)
	{
		p ~= token.to!double;
	}

	double[][] dp;
	dp.length = N + 10;
	foreach (ref e; dp) e.length = N + 10;
	dp[0][0] = 1.0 - p[0];
	dp[0][1] = p[0];
	foreach (i; 1..N)
	{
		auto q     = 1.0 - p[i];
		dp[i][0]   = dp[i-1][0] * q;
		dp[i][i+1] = dp[i-1][i] * p[i];
		foreach (j; 1..i+1)
		{
			dp[i][j] = dp[i-1][j] * q + dp[i-1][j-1] * p[i];
		}
	}

	double ans = 0.0;
	foreach (i; (N+1)/2..N+1)
	{
		ans += dp[N-1][i];
	}

	writefln("%.10f", ans);
	stdout.flush();
}

Measured memory_bytes: 74364
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>

using namespace std;

typedef pair<int,int> PII;
#define MP make_pair

int N;
vector<int> C;
vector< vector<PII> > graph(1000);

int dfs(int parent, int to){
  int ret = 0;

  for(auto& e:graph[to]){
	if(e.first == parent) continue;

	if(C[e.first] != 0){
	  ret += e.second;
	}
	else{
	  ret += min(e.second, dfs(to, e.first));
	}
  }

  return ret;
}

int main(){
  cin >> N;
  C.assign(N, 0);
  for(int i=1;i<N;++i)
	cin >> C[i];

  for(int i=0;i<N-1;++i){
	int u, v, c;
	cin >> u >> v >> c;
	graph[u].push_back(MP(v,c));
	graph[v].push_back(MP(u,c));
  }

  int ret = 0;
  ret += dfs(0, 0);

  cout << ret << endl;

  return 0;
}

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

using namespace std ;

const int MAX = 2010 ;

char arr[MAX][MAX] ;
int L[MAX][MAX] , R[MAX][MAX] , U[MAX][MAX] , D[MAX][MAX] ;
int n , m ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m ;
	for(int i = 0 ; i < n ; ++i)
	{
		for(int j = 0 ; j < m ; ++j)
		{
			cin>>arr[i][j] ;
			L[i][j] = R[i][j] = U[i][j] = D[i][j] = 0 ;
		}
	}
	for(int i = 0 ; i < n ; ++i)
	{
		int cnt = 0 ;
		for(int j = 0 ; j < m ; ++j)
		{
			if(arr[i][j] == '#')
			{
				cnt = 0 ;
				continue ;
			}
			L[i][j] = cnt ;
			cnt++ ;
		}
		cnt = 0 ;
		for(int j = m-1 ; j >= 0 ; --j)
		{
			if(arr[i][j] == '#')
			{
				cnt = 0 ;
				continue ;
			}
			R[i][j] = cnt ;
			cnt++ ;
		}
	}
	for(int j = 0 ; j < m ; ++j)
	{
		int cnt = 0 ;
		for(int i = 0 ; i < n ; ++i)
		{
			if(arr[i][j] == '#')
			{
				cnt = 0 ;
				continue ;
			}
			U[i][j] = cnt ;
			cnt++ ;
		}
		cnt = 0 ;
		for(int i = n-1 ; i >= 0 ; --i)
		{
			if(arr[i][j] == '#')
			{
				cnt = 0 ;
				continue ;
			}
			D[i][j] = cnt ;
			cnt++ ;
		}
	}
	int ans = 0 ;
	for(int i = 0 ; i < n ; ++i)
	{
		for(int j = 0 ; j < m ; ++j)
		{
			ans = max(ans , L[i][j] + R[i][j] + U[i][j] + D[i][j] + 1) ;
		}
	}
	return cout<<ans<<"\n" , 0 ;
}		

Measured memory_bytes: 67328
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int N;
double H[3005];
double dp[3005][3005];
double solve(int idx,int head){
    if(idx>=N){
        int tail = N - head;
        if(head>tail)return 1;
        return 0;
    }
    if(dp[idx][head]!=-1)return dp[idx][head];
    double res = H[idx]*solve(idx+1,head+1) + (1-H[idx])*solve(idx+1,head);
    return dp[idx][head] = res;
}
int main ()
{
    for(int i=0;i<3005;i++)
    for(int j=0;j<3005;j++)dp[i][j]=-1;
    cin >>N;

    for(int i=0;i<N;i++){
            cin >> H[i];
    }
    cout<<fixed<<setprecision(20);
    cout<<solve(0,0);
    return 0;
}


Measured memory_bytes: 71040
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int N, M;
const int MAX_N = 100000 + 1;
const int MAX_M = MAX_N;
vint H(MAX_N), A(MAX_M), B(MAX_M);
vvint graph(MAX_N);
bool ok(int i)
{
    int tmp = H[i];
    for (auto &&j : graph[i])
    {
        if (tmp <= H[j])
            return false;
    }
    return true;
}
int main()
{

    cin >> N >> M;

    for (size_t i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    for (size_t i = 0; i < M; i++)
    {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        graph[A[i]].push_back(B[i]);
        graph[B[i]].push_back(A[i]);
    }
    int ans = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (ok(i))
            ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 9460
#include<bits/stdc++.h>
using namespace std;
    int main(){
        int A, B;
            cin >> A >> B;
                int S, D, P;
                S = A + B; D = A - B; P = A * B;
                    if(S > D){
                        if(S > P){
                            cout << S << endl;
                        }else{
                            cout << P << endl;
                        }
                    }else{
                        if(D > P){
                            cout << D << endl;
                        }else{
                            if(P > S){
                                cout << P << endl;
                            }else{
                                cout << S << endl;
                            }
                        }
                    }
    
    return 0;}

Measured memory_bytes: 256
n = int(input())
H = [list(map(int, input().split())) for _ in range(n)]
dp = [[0] * 3 for _ in range(n)]
dp[0] = H[0]
for i in range(1, n):
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + H[i][0]
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + H[i][1]
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + H[i][2]
print(max(dp[n - 1]))

Measured memory_bytes: 47384
#include <iostream>

using namespace std;

int main()
{
  long long N, M;
  cin >> N >> M;
  
  long long ans = 0;
  if(2*N > M) {
    cout << M/2 <<endl;
    return 0;
  }
  ans += N;
  M -= N*2;
  ans += M/4;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
string A;
ll p[30], ans = 0;
int main() {
	cin >> A;
	for (ll i = 0; i < A.length(); i ++) {
		p[A[i] - 'a'] ++;
	}
	ans = (A.length() - 1) * A.length() / 2;
	for (ll i = 0; i < 26; i ++) {
		ans -= (p[i] - 1) * p[i] / 2;
	}
	cout << ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

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

        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];

        if (n % 3 != 0) {
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(sc.next());
                if (a[i] != 0) {
                    System.out.println("No");
                    return;
                }
            }
            System.out.println("Yes");
        } else {
            HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();

            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(sc.next());
                if (hm.get(a[i]) == null) {
                    hm.put(a[i], 1);
                } else {
                    hm.put(a[i], hm.get(a[i]) + 1);
                }
            }

            if (hm.size() == 1) {
                if (hm.containsKey(0)) {
                    System.out.println("Yes");
                } else {
                    System.out.println("No");
                }
            } else if (hm.size() == 2) {
                for (Map.Entry<Integer, Integer> entry : hm.entrySet()) {
                    if (entry.getKey() == 0) {
                        if (entry.getValue() != n / 3) {
                            System.out.println("No");
                            return;
                        }
                    } else {
                        if (entry.getValue() != 2 * n / 3) {
                            System.out.println("No");
                            return;
                        }
                    }
                }
                System.out.println("Yes");
            } else if (hm.size() == 3) {
                for (Map.Entry<Integer, Integer> entry : hm.entrySet()) {
                    if (entry.getValue() != n / 3) {
                        System.out.println("No");
                        return;
                    }
                }
                int xor = 0;
                for (Map.Entry<Integer, Integer> entry : hm.entrySet()) {
                    xor = xor ^ entry.getKey();
                }
                if (xor == 0) {
                    System.out.println("Yes");
                } else {
                    System.out.println("No");
                }
            } else {
                System.out.println("No");
            }
        }

        sc.close();
    }
}

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

vector <vector <pair <int, int>>> adj;
vector <long long> d;
vector <bool> mark;

void dfs(int v, int p = -1, int w = 0){
	mark[v] = true;
	if (p == -1)
		d[v] = 0;
	else
		d[v] = d[p] + w;
	for (auto u: adj[v]){
		if (!(mark[u.first]))
			dfs(u.first, v, u.second);
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	adj.resize(n);
	d.resize(n);
	mark.resize(n);
	for (int i = 0; i < n - 1; i ++){
		int v, u, w;
		cin >> v >> u >> w;
		v --;
		u --;
		adj[v].push_back(make_pair(u, w));
		adj[u].push_back(make_pair(v, w));
	}
	dfs(0);
	for (int i = 0; i < n; i++){
		if (d[i] % 2)
			cout << "1\n";
		else
			cout << "0\n";
	}
}

Measured memory_bytes: 8576
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <set>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long ll;

#define forn(i, n) for(int i = 0; i < (int)(n);++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define fi first
#define se second
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vb vector<bool>
#define vvi vector<vi>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()


void fastik() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

//ifstream &cin
void solve(){

}

int main() {
    fastik();
    //ifstream cin("input.txt");
    /*ll t=1;cin>>t;
    while(t--){
       solve();
    }*/
    ll n;cin >>n;
    double ans = 0;
    double x;
    cout << setprecision(16) << fixed;
    string u;
    forn(i,n){
        cin >>x>>u;
        if(u[0] == 'J'){
            ans += x;
        }else{
            ans += 380000.0 * x;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
	int a, b;
	bool ff = false;
	
	while ((std::cin >> a >> b) && (a || b)) {
		if (ff) {
			std::cout << std::endl;
		} else {
			ff = true;
		}
		bool f = true;
		for (int y = a; y <= b; ++y) {
			if ((!(y % 4) && (y % 100)) || !(y % 400)) {
				std::cout << y << std::endl;
				f = false;
			}
		}
		if (f) std::cout << "NA" << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    int H[21];
    
    cin>>N;
    rep(i,N) cin>>H[i];
    
    int cnt=0, h=0;
    rep(i,N){
        if(H[i]>=h){
            cnt++;
            h=H[i];
        }
    }
    cout1(cnt)
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a; i<=b; ++i)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using vl=vector<ll>;
using vp=vector<pll>;
const ll INF=1e18;


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t;
    cin>>t;
    cout<<!t;
    return 0;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
char B[100005],n;
int r=0;
int main()
{
	scanf("%s",B);
	for(int i=0;i<strlen(B);i++)
	{
		if(i==0)n=B[i];
		else if(B[i]!=n)
		{
			n=B[i];
			r++;
		}
	}
	printf("%d\n",r);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
	int n, k, a;
	cin >> n >> k;
	map<int, int> kind;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (kind.count(a)) {
			kind[a]++;
		} else {
			kind.emplace(a, 1);
		}
	}
	vector<int> cnt;
	for (auto x : kind)
		cnt.push_back(x.second);
	sort(cnt.begin(), cnt.end());
	int ans = 0;
	for (int i = 0; i < (int) cnt.size() - k; i++)
		ans += cnt[i];
	cout << ans << endl;
}

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

int main() {
	int n, m = 0;

	cin >> n;

	for(int i = 0; i < 4; i++){
		if(n % 10 == 2)
			m++;
		n /= 10;
	}

	cout << m << endl;

	return 0;
}

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

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

ll n;
vector<ll> a, stk;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    a.assign(n, 0);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    stk.pb(a[0]);
    for(int i = 0; i < n; ++i){
        if((sz(stk) & 1) && a[i] <= stk.back()){
            stk.pop_back(); stk.pb(a[i]);
        }
        else if((sz(stk) & 1) && a[i] > stk.back()){
            stk.pb(a[i]);
        }
        else if(a[i] >= stk.back()){
            stk.pop_back(); stk.pb(a[i]);
        }
        else{
            stk.pb(a[i]);
        }
    }
    if(sz(stk) & 1) stk.pop_back();
    ll stocks = 0, extra = 1000;
    for(int i = 0; i < sz(stk); ++i){
        // cout << stk[i] << " ";
        if(i & 1){
            extra += stocks * stk[i];
            stocks = 0;
        }
        else{
            stocks += extra/stk[i];
            extra %= stk[i];
        }
    }
    // cout << "\n";
    cout << extra;
    return 0;
}

Measured memory_bytes: 3656
import copy

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

max_v_per_w = [0] * (W+1)
for i in range(N):
    w, v = wv[i]
    tmp = copy.deepcopy(max_v_per_w)
    for j in range(w, W+1):
        max_v_per_w[j] = max(tmp[j], tmp[j-w]+v)
        
print(max(max_v_per_w))



Measured memory_bytes: 201692
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;

    double ans;
    if (n % 2 == 0) {
        ans = 0.5;
    }
    else {
        int numOfEven = n / 2;
        ans = (numOfEven + 1) / (double)n;
    }

    cout << ans << endl;

    return 0;
}

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

typedef long long ll;

int main()
{
    int h, w;
    string ans = "Yes";
    cin >> h >> w;
    char s[52][52];

    forx(i,1, h+1){
            forx(j,1, w+1){
                 cin >>s[i][j];
            }
    }

    forx(i, 1, h + 1){
         forx(j, 1, w + 1){
              if (s[i][j] == '#' && s[i][j - 1] != '#' && s[i - 1][j] != '#' && s[i][j + 1] != '#' && s[i + 1][j] != '#')
         ans = "No";
           }
     }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

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

    string check = "";
    int i;

    for(i = s.length() - 1; i >= 0; i --)
    {
    	check += s[i];

    	if(check == "maerd")
    		check = "";
    	else if(check == "remaerd")
    		check = "";
    	else if(check == "esare")
    		check = "";
    	else if(check == "resare")
    		check = "";
    }

    if(check == "")
    	cout << "YES" << endl;
    else
    	cout << "NO" << endl;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

vector<int> nodes[100000];
bool visited[100000] = {};

void dfs(int p, int s){
    visited[s] = true;
    rep(i, nodes[s].size()){
        int to = nodes[s][i];
        if(to == p) continue;
        if(!visited[to]){
            dfs(s, to);
        }
    }
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin >> N >> M;
    rep(i, M){
        int x, y, z; cin >> x >> y >> z;
        nodes[x-1].push_back(y-1);
        nodes[y-1].push_back(x-1);
    }
    int ans = 0;
    rep(i, N){
        if(!visited[i]){
            dfs(-1, i);
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    ll n;
    cin >> n;
    ll k,q;
    cin >> k >> q;
    vector<ll> vec(n);
    rep(i,n) vec[i] = k-q;
    rep(i,q){
        ll a;
        cin >> a;
        vec[a-1] += 1;
    }
    rep(i,n){
        if(vec[i]>0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 1408
#A
s = input()
k = int(input())
s_sum = 0

s_f = 1
s_l = 1


if s[0] == s[-1]:
    for i in range(len(s)):
        if i != 0:
            if s[i] == s[i-1]:
                s_f += 1
            else:
                break
                
    
    for i in range(len(s)-1 , -1, -1):
        if i != len(s)-1:
            if s[i] == s[i+1]:
                s_l += 1
            else:
                break
                
    
                
                
    if s_f == len(s):
        print((k * len(s)) // 2)
        
    else:
        n = 1
        is_not_first = False
        for i in range(len(s)):
            if i != 0:
                if s[i] == s[i-1]:
                    n += 1
                else:
                    if not is_not_first:
                        is_not_first = True
                        n = 1
                    else:
                        if n != 1:
                            if n % 2 == 0:
                                s_sum += (n / 2)
                            else:
                                s_sum += ((n - 1)/ 2)
                            n = 1

        x1 = (s_f // 2 + s_l // 2) + s_sum * k
        x2 = ((s_f + s_l)//2) * (k-1)
        print(int(x1 + x2))
        
else:   
    n = 1
    for i in range(len(s)):
        if i != 0:
            if s[i] == s[i-1]:
                n += 1
            else:
                if n != 1:
                    if n % 2 == 0:
                        s_sum += (n / 2)
                    else:
                        s_sum += ((n - 1)/ 2)
                    n = 1
                    

        if i == (len(s) - 1):
            if n != 1:
                if n % 2 == 0:
                    s_sum += (n / 2)
                else:
                    s_sum += ((n - 1)/ 2)
                    

    print(int(s_sum * k))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define vll vector<ll>
#define sz size()
#define pb emplace_back
#define mp make_pair
#define MOD 1000000007
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL))
const int N = 100005;

int main()
{
	ll n;
	cin>>n;
	ll a[n+1];
	for(ll i=0;i<n;i++)
	cin>>a[i];
	ll l=0,r=0;
	for(ll i=0;i<n;i++)
	l=l+a[i];
	ll ans=1e18,diff;
	for(ll i=0;i<n;i++)
	{
		r=r+a[i];
		l=l-a[i];
		diff=abs(l-r);
		ans=min(ans,diff);
	}
	cout<<ans;
}

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

int main(){
    unsigned long long int a,b;
    cin >> a >> b;
    unsigned long long int sum = a+b;
    if(sum%2!=0)
        cout << "IMPOSSIBLE" << endl;
    else
        cout << sum/2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n, m, t=0, i, d=1;

	scanf("%d %d", &n, &m);

	t = 1900 * m + 100 * (n - m);
	for(i = 1; i <= m; i++){
        d *= 2;
	}

    printf("%d\n", t * d); 
    
    return 0;
}



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

int main() {
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  bool ok = true;
  for (int i = 0; i < N; i++) {
    if (A.at(i) % 2 == 1) continue;
    if (A.at(i) % 3 == 0) continue;
    if (A.at(i) % 5 == 0) continue;
    ok = false;
  }
  if (ok) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e7+5;
bool p[maxn];
int p1[maxn],cnt=0,top;
ll a,b;
ll n,st[20];

void init(int n){
    for(int i=2;i<=n;i++){
        if(!p[i])p1[++cnt]=i;
        for(int j=1;j<=cnt&&p1[j]*i<=n;j++){
            p[p1[j]*i]=1;
            if(i%p1[j]==0)break;
        }
    }
}
ll mysqrt(ll x){
	ll l=1,r=maxn;
	while(l<r){
		ll mid=(l+r)>>1;
		if(mid*mid<x)l=mid+1;
		else r=mid;
	}
	return l;
}

void f(ll x){
    top=1;
    while(x>1){
     int k=mysqrt(x);
     bool f=0;
     for(int i=1;p1[i]<=k;i++){
        int tmp=0;
        while(x%p1[i]==0){
            x/=p1[i];tmp++;
        }
        if(tmp){
            st[++top]=tmp;f=1;
        }
     }

     if(!f){
        st[++top]=1;x/=x;
     }

    }
}
ll gcd(ll a,ll b){
    return b==0?a:gcd(b,a%b);
}
int main(){
    init(2e6);
    cin>>a>>b;

    ll g = gcd(a,b);


    f(g);

    printf("%d\n",top);

    return 0;
}



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

int main() {
  char base; cin >> base;
  
  if(base == 'A') cout << 'T' << endl;
  if(base == 'T') cout << 'A' << endl;
  if(base == 'C') cout << 'G' << endl;
  if(base == 'G') cout << 'C' << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong s, w;

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

    if (w >= s) {
        cout << "unsafe" << endl;
    }
    else {
        cout << "safe" << endl;
    }

    return 0;
}


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

#define int long long

// #include "debug.cpp"

#define inf 999999999999999

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, i, j;
	cin >> n;
	vector<pair<int, int>> arr(n, pair<int, int>(0, 0));

	for(i=0; i<n; i++){
		cin >> arr[i].first >> arr[i].second;
	}

	int a = -inf, b = -inf, c = -inf, d = -inf;
	pair<int, int> pta, ptb, ptc, ptd;

	for(i=0; i<n; i++){
		if(arr[i].first + arr[i].second > a){
			a = arr[i].first + arr[i].second;
			pta = arr[i];
		}
		if(-arr[i].first + arr[i].second > b){
			b = -arr[i].first + arr[i].second;
			ptb = arr[i];
		}
		if(arr[i].first - arr[i].second > c){
			c = arr[i].first - arr[i].second;
			ptc = arr[i];
		}
		if(-arr[i].first - arr[i].second > d){
			d = -arr[i].first - arr[i].second;
			ptd = arr[i];
		}
	}

	int ans = -1;

	for(i=0; i<n; i++){
		ans = max({ans, abs(pta.first - arr[i].first) + abs(pta.second - arr[i].second)});
		ans = max({ans, abs(ptb.first - arr[i].first) + abs(ptb.second - arr[i].second)});
		ans = max({ans, abs(ptc.first - arr[i].first) + abs(ptc.second - arr[i].second)});
		ans = max({ans, abs(ptd.first - arr[i].first) + abs(ptd.second - arr[i].second)});
	}

	cout << ans << "\n";
}


Measured memory_bytes: 6332
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m, p;
  cin >> n >> m >> p;
  vector<vector<int>> rg(n);
  vector<long long> a(m), b(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
    c[i] -= p;
    rg[b[i]].push_back(a[i]);
  }
  vector<int> reachable(n);
  reachable[n - 1] = true;
  queue<int> que;
  que.push(n - 1);
  while (que.size()) {
    int cur = que.front();
    que.pop();
    for (int nbr : rg[cur]) {
      if (reachable[nbr]) continue;
      reachable[nbr] = true;
      que.push(nbr);
    }
  }
  vector<vector<long long>> edge;
  for (int i = 0; i < m; i++) {
    if (reachable[a[i]] && reachable[b[i]]) {
      edge.push_back({a[i], b[i], -c[i]});
    }
  }
  //for (auto v : edge) {
    //cerr << v[0] << " " << v[1] << " " << v[2] << endl;
  //}
  const long long inf = 1LL << 60;
  vector<long long> dist(n, inf);
  dist[0] = 0;
  for (int i = 0; i < n; i++) {
     for (auto v : edge) {
       if (dist[v[0]] != inf && dist[v[1]] > dist[v[0]] + v[2]) {
         dist[v[1]] = dist[v[0]] + v[2];
         if(i == n - 1) {
           //cerr << "here" << endl;
           cout << -1 << endl;
           return 0;
         }
       }
     }
  }
  if (dist[n - 1] == inf) cout << -1 << endl;
  else cout << max(0LL, -dist[n - 1]) << endl;
  return 0;
}

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

int main() {
  int64_t A, B, K;
  cin >> A >> B >> K;
  if (A > K){
    cout << A - K << " " << B << endl;
  }
  else if (A + B > K){
    cout << 0 << " " << A + B - K << endl;
  }
  else{
    cout << "0 0" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const ll INF=1e18;


int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if(a <= b * c){
		cout << "Yes" <<endl;
	}
	else{
		cout <<"No" <<endl;
	}
}

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

bool isInt(string str){
  try{
      int n = stoi(str);
      return true;
    }
  catch(...){
    return false;
  }
}

int main()
{
  int A, B;
  string S;
  bool res=true;
  cin >> A >> B >> S;

  string a = S.substr(0,A);
  string b = S.substr(A+1);
  //cout << a << endl;                                                          
  //cout << b<< endl;                                                           
  if(b.length()!=B) res=false;
  if(!isInt(a)) res = false;
  if(S[A]!='-') res = false;
  if(!isInt(b)) res = false;

  if(res) cout << "Yes"  << endl;
  else cout << "No"  << endl;
}

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

int main() {
  int k;
  string s;
  cin >> k >> s;
  
  int cnt = 0;
  for(int i = 0; i < s.size(); i++) cnt++;
  
  if(cnt <= k) {
    cout << s << endl;
    return 0;
  }
  for(int j = 0; j < s.size(); j++) {
    if(j < k) {
      cout << s.at(j);
    }
  }
  cout << "..." << endl;
}

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

int main(){
    int ans=0,sum=0;
    int n;
    string s;
    cin >>n>>s;

    for (int i = 1; i < n; i++){
        if((s[i-1]=='X' && s[i]=='O')||(s[i-1]=='O' && s[i]=='X')){
            ans++;
            i++;
        }
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}



Measured memory_bytes: 3292
#include <cstdio>

int main()
{
  int a, b;
  bool first = true;
  while (~scanf("%d %d", &a, &b)) {
    if ((a|b) == 0)
      break;

    if (!first)
      puts("");

    bool found = false;
    for (int i = a; i <= b; ++i) {
      if (i % 4 == 0 && (i % 100 != 0 || i % 400 == 0)) {
	printf("%d\n", i);
	found = true;
      }
    }

    if (!found)
      puts("NA");
    first = false;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int const MAX_N = 500000;
int const MAX_Q = 20000;
int bit[26][MAX_N + 1];
int n;
string s;
int q;
vector<int> ans;

int sum(int i, int j){
    int s = 0;
    int idx = j;
    while (i > 0){
        s += bit[idx][i];
        i -= i & -i;
    }
    return s;
}

void add(int i, int x, char t){
    int idx = t - 'a';
    while (i <= n){
        bit[idx][i] += x;
        i += i & -i;
    }
}

int main(){
    cin >> n >> s >> q;
    rep(i, s.size()){
        add(i + 1, 1, s[i]);
    }
    rep(i, q) {
        int a;
        cin >> a;
        if (a == 1){
            int i_num;
            char c;
            cin >> i_num >> c;
            i_num--;
            add(i_num + 1, -1, s[i_num]);
            s[i_num] = c;
            add(i_num + 1, 1, s[i_num]);
        }else{
            int l, r;
            cin >> l >> r;
            int ans1 = 0;
            rep(i, 26){
                if (sum(r, i) - sum(l-1, i) > 0){
                    ans1++;;
                }
            }
            ans.push_back(ans1);
        }
    }
    rep(i, ans.size()){
        cout << ans[i] << endl;
    }
}


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

const int DIM = 2e5 + 5;

int oki[DIM];
vector<int> edg[DIM];

void dfs( int x ) {
    oki[x] = 1;
    
    for( int y : edg[x] ) {
        if( oki[y] == 0 )
            dfs( y );
    }
    
    return;
}

int main( void ) {
    
    int n, m;
    cin >> n >> m;
    
    for( int i = 1; i <= n; i ++ ) {
        int s;
        cin >> s;
        
        for( int j = 1; j <= s; j ++ ) {
            int x;
            cin >> x;
            
            edg[i].push_back( x + n );
            edg[x + n].push_back( i );
        }
    }
    
    dfs( 1 );
    if( accumulate( oki + 1, oki + n + 1, 0 ) == n )
        cout << "YES\n";
    else
        cout << "NO\n";
    
    return 0;
}


Measured memory_bytes: 8960
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
///////////////////////////////////////

int main() {
	int N, M; cin >> N >> M;
	int k[11];
	int s[11][11];
	int p[11];
	for (int i = 0; i < M; ++i) {
		cin >> k[i];
		for (int j = 0; j < k[i]; ++j) {
			cin >> s[i][j];
		}
	}
	for (int i = 0; i < M; ++i) {
		cin >> p[i];
	}
	int ans = 0;
	for (int bit = 0; bit < (1 << N); ++bit) {
		bool can = true;
		for (int i = 0; i < M; ++i) {
			int count = 0;
			for (int j = 0; j < k[i]; ++j) {
				if (bit&(1 << s[i][j]-1)) {
					count++;
				}
			}
			if (count % 2 != p[i]) {
				can = false;
				break;
			}
 		}
		if (can) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define INF 99999
using namespace std;

int G[110][110] = {};

int prim(int n)
{
    int mini[110];
    int used[110];

    //init
    for(int i = 0;i < n;i++){
        mini[i] = INF;
        used[i] = 0;
    }
    mini[0] = 0;
    int ans = 0;

    while(true)
    {
        int v = -1;
        for(int i = 0;i < n;i++){
            if(!used[i] && (v == -1 || mini[i] < mini[v])) v = i;
        }
        if(v == -1) break;
        //ans = -1;

        used[v] = 1;
        ans += mini[v];
        //cout << ans << endl;

        for(int i = 0;i < n;i++){
            mini[i] = min(mini[i], G[v][i]);
        }
    }
    return ans;
}

int main()
{
    int n;
    cin >> n;

    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            int cost;
            cin >> cost;
            if(cost == -1) G[i][j] = INF;
            else G[i][j] = cost;
        }
    }

    cout << prim(n) << endl;
    return 0;
}


Measured memory_bytes: 3136