akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
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() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)

#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define SWAP(x, y) do { int z = y; y = x; x = z; } while (0)
int main(void)
{
    int n,i,j,tl,hl,k;
    int flg,tp,hp,len;
    string t,h;
    tp=hp=k=0;
    cin>>n;
    REP(i,n) {
        cin>>t>>h;
        k=0;
        if(t[k]>h[k]) {tp+=3;}
        else if(h[k]>t[k]) {hp+=3;}
        else {
            flg=0;
            len=max((int)t.length(),(int)h.length());
            for(j=1;j<len;j++) {
                if(t[j]>h[j]||'\0'==h[j]) {tp+=3; flg++; break;}
                if(h[j]>t[j]||'\0'==t[j]) {hp+=3; flg++; break;}
            }
            if(0==flg) {tp++; hp++;}
        }
    }
    cout<<tp<<' '<<hp<<endl;
}



Measured memory_bytes: 3160
# -*- coding: utf-8 -*-
n, k = map(int, input().split(" "))

total_prob = 0
for i in range(1, n+1):
    for j in range(0, 10**4):
        if i * 2**j >= k:
            total_prob += 0.5 ** j / n
            break
print(total_prob) 

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
 
using namespace std;
int N, M;
vector<int> A;

int main()
{
  int i;
  int a, sum=0;

  cin >> N >> M;

  for (i=0; i<M; i++) {
    cin >> a;
    sum += a;
  }

  if (N<sum)
    printf("-1\n");
  else
    printf("%d\n", N - sum);

  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <numeric>
#include <utility>

using namespace std;

int e_gcd(int a, int b)         //C++17だとgcdでは競合するため
{
    if (b > a) swap(a, b);
    if (a % b == 0)
    {
        return b;
    }else
    {
        return (e_gcd(b, a % b));
    }
    
}

long long lcm(long long a, long long b)
{
    return (a * b) / e_gcd(a, b);
}


int main(int argc, char const *argv[])
{
    long long A, B;
    int C, D;
    cin >> A >> B >> C >> D;

    long long mC, mD, lcmCD, mlcmCD;
    lcmCD = lcm((long long)C, (long long)D);
    mC = B / C - (A - 1) / C;
    mD = B / D - (A - 1) / D;
    mlcmCD = B / lcmCD - (A - 1) / lcmCD;
    long long sum = mC + mD - mlcmCD;

    cout << (B - A + 1) - sum << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sb = sum(b)

for i in range(n):
    for j in range(i, i+2):
        t = a[j] - b[i]
        if t >= 0:
            a[j] = t
            b[i] = 0
        else:
            a[j] = 0
            b[i] = abs(t)

print(sb if sb - sum(b) == 0 else sb - sum(b))

Measured memory_bytes: 18468
#include <iostream>
using namespace std;
#define MAX_N 200001
int n, k;
int a[MAX_N];

int b[MAX_N];
int c[MAX_N];
int d[MAX_N];
int deq[MAX_N];
void solve() {
  int s = 0, t = 0;  //デックの先頭と末尾

  for (int i = 0; i < n; i++) {
    //デックにiを追加
    while (s < t && a[deq[t - 1]] >= a[i]) t--;
    deq[t++] = i;

    if (i - k + 1 >= 0) {
      b[i - k + 1] = a[deq[s]];

      if (deq[s] == i - k + 1) {
        //デックの先頭を取り出す
        s++;
      }
    }
  }
}

void solve2() {
  int s = 0, t = 0;  //デックの先頭と末尾

  for (int i = 0; i < n; i++) {
    //デックにiを追加
    while (s < t && a[deq[t - 1]] <= a[i]) t--;
    deq[t++] = i;

    if (i - k + 1 >= 0) {
      c[i - k + 1] = a[deq[s]];

      if (deq[s] == i - k + 1) {
        //デックの先頭を取り出す
        s++;
      }
    }
  }
}

int main() {
  int ans = 0, flag = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  solve();
  solve2();
  d[0] = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] > a[i - 1]) {
      d[i] = d[i - 1] + 1;
    } else {
      d[i] = 1;
    }
  }
  ans = 1;
  for (int i = 1; i <= n - k; i++) {
    ans++;
    if (a[i - 1] < b[i] && c[i] == a[i + k - 1] || flag && d[i + k - 1] >= k) {
      ans--;
    }
    if (d[i + k - 1] >= k) {
      flag = 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4096
h,w,k = map(int,input().split())
S = [input() for _ in range(h)]
ans = [[0]*w for _ in range(h)]
flag = ['#' in S[i] for i in range(h)]
upcnt = 0
last = 0
now = 0
for i in range(h):
    if flag[i]:
        for j in range(w):
            if S[i][j] == '#':
                now += 1
                if last == 0:
                    for l in range(j):
                        ans[i][l] = now
                        if upcnt >= 1:
                            for m in range(i):
                                ans[m][l] = now
                    last = 1
            ans[i][j] = now
            if upcnt >= 1:
                for m in range(i):
                    ans[m][j] = now
            # if S[i][j] == '#':
                # now += 1
        upcnt = -1
        last = 0
    elif upcnt >= 0:
        upcnt += 1
    else:
        for j in range(w):
            ans[i][j] = ans[i-1][j]
for i in range(h):
    print(' '.join(str(i) for i in ans[i]))


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

int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    //cout << a << b << c << k<< endl;
    int count = 0;
    while(a>=b){
        b *= 2;
        count ++;
        //cout << b << " " << count << endl;
    }

    while(b>=c){
        c *= 2;
        count ++;
        //cout << c << " " << count << endl;
    }
    if(count <= k){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define float long double
typedef vector<int> vi;
#define pb push_back
int dp[100][100001];


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    int N = 100001;
	int n,w;
	cin >> n >> w;
	w++;
	vector<vector<int>> pack;
	for(int i = 0 ; i < n ; i++){
        int wt,vl;
        cin >> wt >> vl;
        vector<int> temp ;
        temp.pb(vl); temp.pb(wt);
        pack.pb(temp);
	}
	for(int i = 0 ; i<w;i++ ){
        if(i>=pack[0][1]) dp[0][i] = pack[0][0];
	}
	for(int i = 1 ; i < n ; i++){
        for(int j = 0 ; j < w ; j++){
            int wt = pack[i][1];
            int vl = pack[i][0];
            if(j<wt) dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(vl + dp[i-1][j-wt],dp[i-1][j]);
        }
	}
	int ans = INT_MIN;
	for(int i = 0 ; i < w ; i++){
        ans = max(ans,dp[n-1][i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;

llong gcd(llong a, llong b)
{
    if (a<b) swap(a, b);

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

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

int main(void) {
  llong A, B;

  cin >> A >> B;

  cout << lcm(A, B) << endl;

  return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
template <typename T, typename U>ostream &operator<<(ostream &out, const pair<T, U> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>void print(const ContainerType<ValueType, Args...> &c){for (const auto &v : c)cout << v << ' ';cout << '\n';} void print(){cout<<'\n';}
template <typename T, typename... Args>void print(T a, Args... args){cout << a << " ";print(args...);}
lli llipower(lli x, lli y, lli p = LLONG_MAX){lli res = 1;x = x % p;while (y > 0){if (y & 1)res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}

//8====================================D
int main(){
    int x,y;
    cin>>x>>y;
    if(y%2==0 && (y/2-x)>=0 && (2*x-y/2)>=0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

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

bool dp1[8005][16005],dp2[8005][16005];

signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif    

    string a;
    cin>>a;
    int l,r;
    cin>>l>>r;
    int n=a.length();
    vector<int>x,y;
    int dis=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]=='F')
            dis++;
        else
        {
            if(x.size()==y.size())
            {
                x.push_back(dis);
                dis=0;
            }
            else
            {
                y.push_back(dis);
                dis=0;
            }
        }
    }
    if(a[n-1]!='T')
    {
        if(x.size()==y.size())
        {
            x.push_back(dis);
        }
        else
        {
            y.push_back(dis);
        }
    }
    int lim=8000;
    dp1[0][lim]=1;
    dp2[0][lim]=1;
    int sz=x.size();
    for(int i=0;i<sz;i++)
    {
        int tt=x[i];
        for(int j=0;j<=2*lim;j++)
        {
            if(j+tt<=2*lim && i>0)
               dp1[i+1][j]|=dp1[i][j+tt];
            if(j-tt>=0)
                dp1[i+1][j]|=dp1[i][j-tt];
        }
    }

    int z=0;
    z+=dp1[sz][lim+l];
    sz=y.size();
    for(int i=0;i<sz;i++)
    {
        int tt=y[i];
        for(int j=0;j<=2*lim;j++)
        {
            if(j+tt<=2*lim)
               dp2[i+1][j]|=dp2[i][j+tt];
            if(j-tt>=0)
                dp2[i+1][j]|=dp2[i][j-tt];
        }
    }

    z+=dp2[sz][lim+r];
    if(z==2)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    



}

Measured memory_bytes: 127604
#include<stdio.h>
#include<ctype.h>
#include<string.h>

int main(){
  int count=0,i;
  char text[1002],w[12],end[]="END_OF_TEXT";
  
  scanf("%s",w);
   for(i=0;i<strlen(w);i++)
      w[i] = tolower(w[i]);
  
  
  while(1){
    scanf("%s",text);
    if(strcmp(text,end)==0) break;
    for(i=0;i<strlen(text);i++)
      text[i] = tolower(text[i]);
    if(strcmp(text,w)==0) count++;
  }
  printf("%d\n",count);
  return 0;
}

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

using namespace std;
set<int> v[100009];
vector<int> s[100009],e[100009];
int n,c;
int main()
{
    cin>>n>>c;
    for(int i=1;i<=n;i++)
    {
        int x,y,ct;
        cin>>x>>y>>ct;
        s[ct].push_back(x);
        e[ct].push_back(y);
        for(int j=x;j<=y;j++)
            v[j].insert(ct);
    }
    int ans=0;
    for(int i=0;i<100005;i++)
    {
        if(v[i].size()==0)continue;
        ans=max((int)ans,(int)v[i].size());
    }
    cout<<ans;
}


Measured memory_bytes: 151168
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define mp make_pair
#define P pair
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)
#define cbuf(buf, init) memset(buf, init, sizeof(buf))
#define modp(x, y) (((y) + (x) % (y)) % (y))
#define divd(x, y) (static_cast<double>(x) / static_cast<double>(y))

ll N, A, B;

int main()
{
    cin >> N >> A >> B;
    cout << min(N * A, B) << endl;
}


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

int n;
map<P,int> m;
int x[100000], y[100000], w[100000];

int main(){
	scanf("%d",&n);
	rep(i,n){
		scanf("%d%d%d",x+i,y+i,w+i);
		m[P(x[i],y[i])] = w[i];
	}
	int ans = 0;
	rep(i,n){
		ans = max(ans,m[P(x[i],y[i])]+m[P(x[i]+1,y[i])]+m[P(x[i],y[i]+1)]+m[P(x[i]+1,y[i]+1)]);
		ans = max(ans,m[P(x[i],y[i])]+m[P(x[i]-1,y[i])]+m[P(x[i],y[i]+1)]+m[P(x[i]-1,y[i]+1)]);
		ans = max(ans,m[P(x[i],y[i])]+m[P(x[i]+1,y[i])]+m[P(x[i],y[i]-1)]+m[P(x[i]+1,y[i]-1)]);
		ans = max(ans,m[P(x[i],y[i])]+m[P(x[i]-1,y[i])]+m[P(x[i],y[i]-1)]+m[P(x[i]-1,y[i]-1)]);
	}
	cout << ans << " / 1" << endl;
}

Measured memory_bytes: 58636
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}

int main(){
    int r, g;
    cin >> r >> g;

    int ans = g * 2 - r;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    vec<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));
    if(A[0] == 0) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    for(auto e:A){
        if((ll)1e18/e < ans){
            cout << -1 << endl;
            return 0;
        }
        ans*=e;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3980
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;

int n, k;
vector<int> a;

bool isNeed(int id) {
	vector<vector<bool>> dp(n+1, vector<bool>(k,false));
	dp[0][0] = true;
	for (int i = 0;i < n;i++) {
		
		for (int j = k-1; j >=0;j--) {
			
			dp[i + 1][j] = dp[i][j];
			
			if (i != id && dp[i][j] == true && a[i] + j <k) {
				dp[i + 1][a[i] + j] = true;
				
			}

			
		}
	}

	for (int i = max(k-a[id],0); i < k;i++) {
		//cout << id <<" " << i << " " << dp[n][i] << endl;
		if (dp[n][i]) {
			
			return true;
			
		}
		
	}
	return false;
}

int main() {
	
	cin >> n >> k;
	a=vector<int>(n);
	for (int i = 0; i < n;i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end());

	if (isNeed(0)) {
		cout << 0 << endl;
	}
	else if (!isNeed(n - 1)) {
		cout << n << endl;
	}
	else {
		int r = 0;
		int l = n - 1;
		int mid = (r + l) / 2;
		while (r != mid) {
			if (isNeed(mid)) {
				l = mid;
			}
			else {
				r = mid;
			}

			mid = (r + l) / 2;
			//cout << mid << endl;
		}



		cout << l << endl;
	}
	
}





Measured memory_bytes: 3588
package main

import (
	"fmt"
)

func main() {
	var N, X, l, w int
	fmt.Scan(&N, &X)
	cnt := 1
	for i := 1; i <= N; i++ {
		fmt.Scan(&l)
		w += l
		if w > X {
			break
		}
		cnt++
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
def main():
    s = input()
    a = {'ABC', 'ARC'}
    a.discard(s)

    print(a.pop())


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9024
N, K = gets.split.map(&:to_i)
hs = gets.split.map(&:to_i)

dp = Array.new(N)
dp[0] = 0

(1...N).each do |i|
  min = Float::INFINITY

  1.upto(K) do |j|
    idx = i - j

    break if idx < 0

    m = dp[idx] + (hs[i] - hs[idx]).abs

    min = m if m < min

    break if m == dp[idx]
  end

  dp[i] = min
end

puts dp.last


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

int main() {
	// your code goes here
	string s;cin>>s;
	int n=s.size();
	if(s[n-1]=='3') cout<<"bon";
	else if(s[n-1]=='1'||s[n-1]=='6'||s[n-1]=='0'||s[n-1]=='8') cout<<"pon";
	else cout<<"hon";
	return 0;
}


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

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

    for(int i = 0; i < n; i++){
        string x = s.substr(0,i);
        string y = s.substr(i,n-i);
        bool a[26] = {}, b[26] = {};
        for(int j = 0; j < x.size(); j++){
            a[(int)x[j]-(int)'a'] = 1;
        }
        for(int j = 0; j < y.size(); j++){
            b[(int)y[j]-(int)'a'] = 1;
        }
        int count = 0;
        for(int j = 0; j < 26; j++){
            if(a[j] == 1 && b[j] == 1){
                count++;
            }
        }
        ans = max(ans,count);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define cost first
#define from second.first
#define to second.second
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

int main(void){
	ll h,hd,w,wd,i,a,b,c,ans;
	cin >> h >> w;
	if(!((h*w)%3)){
		cout << 0 << endl;
		return 0;
	}
	ans = min(h,w);
	for(i=1ll; i<h; ++i){
		a = w * i;
		hd = h - i;
		b = hd * (w/2);
		c = hd * (w - (w/2));
		ans = min(ans,max(a,c)-min(a,b));
	}
	for(i=1ll; i<w; ++i){
		a = h * i;
		wd = w - i;
		b = wd * (h/2);
		c = wd * (h - (h/2));
		ans = min(ans,max(a,c)-min(a,b));
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(int argc, char* argv[]) {

  	int n;
  	cin >> n;
  
	vector<int> var(n);
  	vector<int> car(n);
  	for (int i=0; i<n; i++) {
    	cin >> var[i];
    }
  	for (int i=0; i<n; i++) {
      	cin >> car[i];
    }

  	int max = 0;
  	for (int i=0; i<n; i++) {
      	int v = var[i] - car[i];
    	if ( v > 0 ) {
          max += v;
        }
    }
  
  	cout << max << endl;
	return 0;
}

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

using namespace std;

int main(){
#ifdef CIN
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif

	int a, b, c;

	cin >> a >> b >> c;

	if (a < b && b < c) cout << "Yes" << endl;
	else cout << "No" << endl;



	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

struct edge{
  ll from,to,cost;
};

ll n,m,p;
ll inf=1e15;
vector<edge> g;
vector<ll> d2(5010,inf);
vector<bool> negative(5010);

void shortest_path(ll s){
  d2[s]=0;
  rep(j,n-1){
    //bool update=false;
    rep(i,m){
      edge e=g[i];
      if(d2[e.from]!=inf && d2[e.to]>d2[e.from]+e.cost){
        d2[e.to]=d2[e.from]+e.cost;
        //update=true;
      }
    }
    //if(!update) break;
  }
}

void find_negative_loop(){
	//memset(D,0,sizeof(D));
	for(int i=1;i<=n;i++) negative[i] = false;
	for(int i=1;i<=n;i++){
		for(int j=0;j<m;j++){
			edge e=g[j];
			if(d2[e.to]!=inf && d2[e.to] > d2[e.from] + e.cost){
				d2[e.to] = d2[e.from] + e.cost;
				negative[e.to] = true;
			}
			if(negative[e.from]) negative[e.to] = true;
		}
	}
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m>>p;
    rep(i,m){
      ll a,b,c;
      cin>>a>>b>>c;
      g.push_back({a,b,p-c});
    }
    shortest_path(1);
    ll ans=max(-d2[n],0ll);
    find_negative_loop();
    if(negative[n]) cout<<-1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<stdio.h>
    int main(void)
    {
      char s[4];
      int i,j;
      int count=0;
      scanf ("%s",&s);
      for(i=0;i<4;i++){
        for (j=0;j<4;j++){
          if(s[i]==s[j]){
            count++;
          }
        }
      }
      if (count != 8){
        printf("No\n");
      }
      else{
        printf("Yes\n");
      }
      return 0;
    }

Measured memory_bytes: 128
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;


int main() {
	vector<string>sts;
	int H,W;cin>>H>>W;
	for (int i = 0; i < H; ++i) {
		string st;cin>>st;
		sts.push_back(st);
	}
	vector<vector<int>>dp(H,vector<int>(W,1e9));
	dp[0][0]=sts[0][0]-'0';
	for (int h = 0; h < H; ++h) {
		for (int w = 0; w < W; ++w) {
			if (h != H - 1) {
				dp[h+1][w]=min(dp[h+1][w],dp[h][w]+sts[h+1][w]-'0');
			}
			if (w != W - 1) {
				dp[h][w+1]=min(dp[h][w+1],dp[h][w]+sts[h][w+1]-'0');
			}
		}
	}
	cout<<dp[H-1][W-1]<<endl;
	return 0;
} 

Measured memory_bytes: 3236
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N =sc.nextLong();
		Map<Long,Long>  map= new HashMap();
		for (long i=0;i<N;i++) {
			long a = sc.nextLong();
			Long count = map.get(a);
			if (count ==null) {
				map.put(a, 1l);
			} else {
				map.put(a, count+1);
			}
		}
		Set<Long> set = map.keySet();
		Object[] array = set.toArray();
		Arrays.sort(array);
		int i=array.length-1;
		long x=0;
		long y=0;
		for (;i>=0;i--) {
			Long count= (Long)map.get(array[i]);
			if (count >=4) {
				System.out.println((Long)array[i]*(Long)array[i]);
				return;
			} else if (count >=2) {
				x = (Long)array[i];
				i--;
				break;
			}
		}
		for (;i>=0;i--) {
			Long count= map.get(array[i]);
			if (count >=2) {
				y = (Long)array[i];
				break;
			}
		}
		System.out.println(x*y);
	}
}

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

using namespace std;

int main(void)
{
    int a, b, c, k; cin >> a >> b >> c >> k;
    int maior_a = 0;
    int maior_b = 0;
    int maior_c = 0;
    int total = 1;
    if(a > b and a > c)
        maior_a = a;
    else if(b > a and b > c)
        maior_b = b;
    else if (c > a and c > b)
        maior_c = c;
    else
    {
        for(int i = 0; i < k; ++i)
            a *= 2;

        total = a + b + c;
    }
    

    if(maior_a)
    {
        for(int i = 0; i < k; ++i)
            maior_a *= 2;

        total = maior_a + b + c;
        
    }
    else if(maior_b)
    {
        for(int i = 0; i < k; ++i)
            maior_b *= 2;

        total = maior_b + a + c;
    }
    else if(maior_c)
    {
        for(int i = 0; i < k; ++i)
            maior_c *= 2;

        total = maior_c + a + b;
    }
    
    cout << total << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
input_line = [input() for i in range(1)]
W = list(map(int, input_line[0].split()))

D = []
for T in range(1,N):
    S1 = sum(W[:T])
    S2 = sum(W[T:])
    D.append(abs(S1 - S2))
print(min(D))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <queue>
#define REP(i, n) for (ll i = 1; i <= n; i++)
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ll long long
#define ld long double
using namespace std;

ll Sum = 0;
string S;

ll addByString(string keep_S)
{

    string k = keep_S;
    ll sum = 0;
    ll count = 0;
    rep(i, keep_S.size())
    {
        if (keep_S.at(i) == '+')
        {
            sum += stoll(k.erase(i - count)); //+より前を取得
            // cout << "erase:" << k << endl;
            count += k.size() + 1; //取得した部分のサイズぶんたす
            k = keep_S;            //kをもとにもどす
            k = k.substr(count);   //取得した部分をのぞく
            // cout << "substr:" << k << endl;
        }
        if (i == keep_S.size() - 1)
        {
            sum += stoll(k);
        }
    }
    return sum;
}

ll Calc(string S, string c, int Size_S)
{
    ll sum = 0;
    int count = 0;
    int cutSize = c.size();
    string Cut_first = c;
    string keep_S = S;

    //cout << "cut:" << c << endl;

    vector<int> keep(0);
    //cut = 1 0 1 1 //S = 1 2 3 4 5
    rep(i, cutSize)
    {
        if (c.at(i) == '1')
        {

            if (i + 1 + count < keep_S.size())
            {
                keep_S.insert(i + 1 + count, "+");
            }
            count++;
        }
    }
    sum = addByString(keep_S);
    //cout << keep_S << endl;

    return sum;
}

int main()
{

    //1〇2〇5   2^(n-1) max 512通り
    cin >> S;
    int Size_S = S.size();

    for (int tmp = 0; tmp < (1 << (Size_S - 1)); tmp++)
    {
        bitset<9> bs(tmp); //整数tmpを9個のbit列で表す
        string cut = bs.to_string().substr(10 - Size_S);
        //cout << bs << endl;
        Sum += Calc(S, cut, Size_S);
    }
    cout << Sum << endl;
}


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

int main(void)
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	if (A <= C && C <= B) {
		if (A <= D && D <= B) {
			cout << D - C << endl;
		}
		else {
			cout << B - C << endl;
		}
	}
	else if(C <= A && A <= D) {
		if (A <= D && D <= B) {
			cout << D - A << endl;
		}
		else {
			cout << B - A << endl;
		}
	}
	else {
		cout << "0" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define N 501001
#define MAX 2001
#define inf 1e18
#define eps 1e-10
using namespace std;
typedef long long ll;
typedef double db;
const ll mod=1000000007;
inline void read(re ll &ret)
{
    ret=0;re bool pd=false;re char c=getchar();
    while(!isdigit(c)){pd|=c=='-';c=getchar();}
    while(isdigit(c)){ret=(ret<<1)+(ret<<3)+(c&15);c=getchar();}
    ret=pd?-ret:ret;
    return;
}
ll n,x,y,z,dp[41][N],ans,state,maxn;
signed main()
{
    read(n);
    read(x);
    read(y);
    read(z);
    ans=1;
    state=((1<<x+y+z-1)|(1<<y+z-1)|(1<<z-1));
    maxn=(1<<x+y+z)-1;
    dp[0][0]=1;
    for(re int i=1;i<=n;i++)
    {
        ans*=10,ans%=mod;
        for(re int s=0;s<=maxn;s++)
        {
            if(!dp[i-1][s])
                continue;
            for(re int j=1;j<=10;j++)
            {
                re ll now=(s<<j)|(1<<j-1);
                now&=maxn;
                if((now&state)!=state)
                    dp[i][now]=(dp[i][now]+dp[i-1][s])%mod;
                
            }
        }
    }
    for(re int s=0;s<=maxn;s++)
        ans=(ans-dp[n][s]+mod)%mod;
    printf("%lld\n",ans);
    #ifdef WIN32
    system("pause");
    #endif WIN32
    exit(0);
}

Measured memory_bytes: 41148
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]

ans = -10 ** 10
for b in range(1, 2 ** 10):
    bin_str = format(b, '010b')
    p = 0
    for i in range(N):
        c = 0
        for j in range(10):
            c += F[i][j] * int(bin_str[j])
        p += P[i][c]
    ans = max(ans, p)
print(ans)


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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define spc printf(" ")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007
#define FI freopen("input.txt","r",stdin)
#define FO freopen("output.txt","w",stdout)
#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

using namespace std;

int main (){
	ll n, sum;
	sl(n);
	pf("%lld\n", n*n);
	return 0;
}

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

int main() {
  string s;
  int ans=0,cnt=0;
  cin>>s;
  for(int i=0;i<s.size();i++) {
    if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T') cnt++;
    else {
      ans=max(ans,cnt);
      cnt=0;
    }
  }
  ans=max(ans,cnt);
  cout<<ans<<endl;
}


Measured memory_bytes: 3592
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
    n = ni()

    for i in range(1, n+1):
        if int(i*1.08) == n:
            print(i)
            return
    print(":(")

if __name__ == '__main__':
  main()


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

int main() {
    int n;cin>>n;
    int a[26];
    memset(a,0,sizeof(a));
    string s;cin>>s;
    int m = s.size();
    rep(i,m)++a[s[i]-'a'];
    
    rep(i,n-1){
        int b[26];
        memset(b,0,sizeof(b));
        string t;cin>>t;
        int m2=t.size();
        rep(j,m2)++b[t[j]-'a'];
        
        rep(k,26)a[k]=min(a[k],b[k]);
    }
    rep(i,26){
      string ans = "a";
      ans[0]+=i;
        rep(j,a[i])cout<<ans;
    }
    cout<<endl;
	return 0;
}

Measured memory_bytes: 3588
import itertools
n,k=map(int,input().split())

d=[]
a=[]

for i in range(k):
  p=int(input())
  d.append(p)
  q=list(map(int,input().split()))
  a.append(q)

c=list(itertools.chain.from_iterable(a))
c.sort()

c_set=set(c)
c=list(c_set)

print(n-len(c))

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

int main() {
	int a=0,b=0,c=0,i=0,x=0;
	cin >>a>>b>>c;
	for (i=a; i<=b; i++){
		if (c%i==0) x++;
	}
	cout <<x<<endl;
	return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
   int a, b, C;
   double S, L, h, d;
   cin >> a >> b >> C;

   d = (acos(-1.0)*C)/180.0;
   S = a*b*sin(d)/2.0;
   L = a+b+sqrt(a*a + b*b - 2*a*b*cos(d));
   h = b*sin(d);

   printf("%lf\n%lf\n%lf\n", S, L, h);

  return 0;
 }


Measured memory_bytes: 3500
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[M];
		int count = 0;

		for (int i = 0; i < N; i++) {
			int K = sc.nextInt();
			for (int j = 0; j < K; j++) {
				int a = sc.nextInt();
				A[a - 1]++;
			}

		}

		for (int i = 0; i < M; i++) {
			if (A[i] == N) {
				count++;
			}
		}
		System.out.println(count);
		sc.close();
	}
}


Measured memory_bytes: 23892
# include <algorithm>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <string>
# include <vector>

typedef long long ll;
using namespace std;

const ll mod = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    ll c[n + 1][k + 1];
    for (int i = 0; i <= n; i++) fill(c[i], c[i] + k + 1, 0);
    c[0][0] = 1;

    // combination
    for (int i = 1; i <= n; i++) {
        for (int l = 0; l <= k; l++) {
            if (l > i) break;
            if (l == 0 || l == i) {
                c[i][l] = 1;
                continue;
            }
            c[i][l] = c[i - 1][l - 1] + c[i - 1][l];
            c[i][l] %= mod;
        }
    }
    for (int i = 1; i <= k; i++) {
        ll ans = c[n - k + 1][i] % mod * c[k - 1][i - 1] % mod;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 31488
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
//#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a,int b){
    if(b==0) return a;
    return saidaikouyakusuu(b,a%b);
}
int saisyoukoubaisuu(int a,int b){
    return a*b/saidaikouyakusuu(a,b);
}
int n,m,cnt=INF,aa[220000],ans=0,o,x,y;
pair<string,int> pp[220000];
string s,sa[220000];
char c,ca[100][100];
queue<int> que;
signed main(){
    cin>>n>>m>>o>>x>>y;
    o*=2;
    rep(i,max(x,y)+1){
        cnt=min(cnt,i*o+max(0,x-i)*n+max(y-i,0)*m);
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 19104
MOD = 10 ** 9 + 7
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))


dp = [[0] * (M + 1) for _ in range(N + 1)]
dp[0][0] = 1
sm = [[0] * (M + 1) for _ in range(N + 1)]

for i in range(1, N + 1):
    for j in range(1, M + 1):
        if S[i - 1] == T[j - 1]:
            dp[i][j] = (sm[i - 1][j - 1] + 1) % MOD
        else:
            dp[i][j] = 0
        sm[i][j] = (sm[i - 1][j] + sm[i][j - 1] - sm[i - 1][j - 1] + dp[i][j]) % MOD

print(sm[N][M] + 1)


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

bool CanGo(int y, int x, int R, int C) {
	return y >= 0 && y < R&& x >= 0 && x < C;
}

int ToBlock(vector<vector<char>>& Map, int y1, int x1, int y2, int x2) {
	return Map[y1][x1] == '.' && Map[y2][x2] == '#' ? -1 : 0;
}

int TraceMaze(priority_queue<vector<int>>& Queue, int gy, int gx, vector<vector<char>>& Map) {
	vector<int> nowstate = Queue.top();
	Queue.pop();
	int R = Map.size();
	int C = Map[0].size();
	int step = nowstate[0];
	int ny = nowstate[1];
	int nx = nowstate[2];

	if (ny == gy && nx == gx) return -step;

	if (Map[ny][nx]=='#' || Map[ny][nx]=='.') {
		if (CanGo(ny + 1, nx, R, C))Queue.push({ step + ToBlock(Map,ny,nx,ny + 1,nx), ny + 1, nx });
		if (CanGo(ny, nx + 1, R, C))Queue.push({ step + ToBlock(Map,ny,nx,ny,nx + 1), ny , nx + 1 });
		Map[ny][nx] = ' ';
	}
	return -1;
}

int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>> Map(H, vector<char>(W, 0));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> Map[i][j];
		}
	}
	int step = Map[0][0] == '#' ? -1 : 0;
	priority_queue<vector<int>> Queue;
	Queue.push({ step, 0, 0 });
	int ans = -1;
	while (!Queue.empty() && ans < 0) ans = TraceMaze(Queue, H - 1, W - 1, Map);
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream> // cin, cout を利用
using namespace std;
 
#include <iostream> // cin, cout を利用
using namespace std;
 
int main() {
    int N, X, T;
    cin >> N >> X >> T;

    int times = (N + X - 1) / X;
    int ans = T * times;

    cout << ans << endl;

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M,A;
    cin >> N >> M >> A;
    while(N){
        vector<tuple<int,int,int> > V(M);
        rep(i,0,M){
            int a,b,c;
            cin >> a >> b >> c;
            V[i] = tie(a,b,c);
        }
        sort(V.rbegin(), V.rend());
        rep(i,0,M){
            int a = get<1>(V[i]), b = get<2>(V[i]);
            if(A == a || A == b){
                A = (A == a) ? b : a;
            }
        }
        cout << A << endl;
        cin >> N >> M >> A;
    }
}


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

int main() {
    int n;
    int m;
 
   cin >> n >> m;
  
   if(n > m){
     cout << n-1 << endl;
   }else{
     cout << n << endl;
   }
  
 
  
  return 0;
}

Measured memory_bytes: 256
c={
    'S':[0]*13,
    'H':[0]*13,
    'C':[0]*13,
    'D':[0]*13
}
n=int(input())
for i in range(n):
    s,num=input().split()
    c[s][int(num)-1]=1
for i in["S","H","C","D"]:
    for j in range(13):
        if c[i][j]==0:
            print(i,j+1)



Measured memory_bytes: 5600
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

int main()
{
ll int a,b,c,d;
cin>>a>>b>>c>>d;
ll int max1 = max((ll)(a*c),(ll)(a*d));
ll int max2 = max((ll)(b*c),(ll)(b*d));
ll int max3 = max(max1,max2);
cout<<max3;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
int main()
{
    long long A, B, C, D, E, N;
    std::cin >> N >> A >> B >> C >> D >> E;

    long long ans = std::max({(N+A-1)/A, (N+B-1)/B, (N+C-1)/C, (N+D-1)/D, (N+E-1)/E});
    std::cout << (ans+4) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

using Graph = vector<vector<int>>;
int main()
{
  int l, r, d;
  cin >> l >> r >> d;
  int ans = 0;
  for (int i = l; i <= r; ++i)
  {
    if (i % d == 0)
      ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3576
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

int main() {
  int n; cin >> n;
  vector<int> A(n);
  loop(i,0,n) cin >> A[i];
  
  int max_ = 0;
  loop(i,0,n-1) {
    loop(j,i+1,n) {
      int d = abs(A[i]-A[j]);
      if (max_ < d) max_ = d;
    }
  }
  cout << max_ << endl;
  return 0;
}


Measured memory_bytes: 3552
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll =long long;
using namespace std;
using graph=vector<vector<int>>;
using field=vector<string>;
using p =pair<int,int>;
const ll mod=1000000007;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

int main(){
    string s;
    cin>>s;
    int len=s.size();
    ll ans=0;
    rep(i,pow(2,len-1)){
        ll tmp=0;
        rep(j,len-1){
            ll num=s[j]-'0';
            tmp+=num;
            if((i>>j)&1){
                ans+=tmp;
                tmp=0;
            }else{
                tmp*=10;
            }
        }
        ans+=tmp;
        ans+=s[len-1]-'0';
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4072
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int x = sc.nextInt();
        int y = sc.nextInt();
        sc.close();

        ArrayList h = new ArrayList<Integer>();
        ArrayList w = new ArrayList<Integer>();

        char pc = 'F';
        int cont = 0;
        boolean dir = true;        // t:x, f:y
        for(int i=0; i<s.length(); i++){
            if(s.charAt(i) == 'F'){
                if(pc == 'F'){
                    cont++;
                }else{
                    if(cont%2 != 0) dir = !dir;
                    cont = 1;
                    pc = 'F';
                }
            }else{
                if(pc == 'F'){
                    if(dir){
                        w.add(cont);
                    }else{
                        h.add(cont);
                    }
                    cont = 1;
                    pc = 'T';
                }else{
                    cont++;
                }
            }
        }
        if(pc == 'F'){
            if(dir){
                w.add(cont);
            }else{
                h.add(cont);
            }
        }
        if(s.charAt(0) == 'F'){
            x -= (int)w.remove(0);
        }
        if(canReach(Math.abs(x), w) && canReach(Math.abs(y), h)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }

    public static boolean canReach(int len, ArrayList<Integer> move){
        int sum = 0;
        for (int oneMove : move) {
            sum += oneMove;
        }
        if(((sum-len) % 2 != 0) || sum < len) return false;
        int target = (sum - len) / 2;
        boolean[][] dp = new boolean[move.size()+1][target+1];
        for(int i=0; i<move.size()+1; i++){
            for(int j=0; j<target+1; j++){
                dp[i][j] = j == 0 ? true : false;
            }
        }
        for(int i=0; i<move.size(); i++){
            for(int j=0; j<target+1; j++){
                if(j >= move.get(i)){
                    if(dp[i][j] || dp[i][j-move.get(i)]) dp[i+1][j] = true;
                }else{
                    dp[i+1][j] = dp[i][j];
                }
            }
        }
        return dp[move.size()][target];
    }
}

Measured memory_bytes: 25428
import java.util.Scanner;
import java.util.stream.IntStream;

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

        int A = sc.nextInt();
        int B = sc.nextInt();

        System.out.println(solve(A, B));

        sc.close();
    }

    static int solve(int A, int B) {
        return IntStream.of(A * 2 - 1, B * 2 - 1, A + B).max().getAsInt();
    }
}

Measured memory_bytes: 35832
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(void){
	char in[10],o[10];
	int i,l,max,min,ans,n,c,f;
	
	scanf("%d",&n);
	
	for(;n>0;n--){
		scanf("%s",in);
		
		c=0;
		for(f=0;f<=9;f++){
			for(l=0;l<8;l++){
				if(c==8)break;
				if(in[l]==57-f){
					o[c]=in[l];
					c++;
				}
			}
		}
		
		max=atoi(o);
		
		//printf("max=%8d\n",atoi(o));
		
		for(i=0;i<8;i++)in[i]=o[7-i];
		
		min=atoi(in);
		
		//printf("min=%8d\n",atoi(in));
		
		ans=max-min;
		
		printf("%d\n",ans);
		
	}
	
	
	
	
	return 0;
}

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

const ll INF = 1e18;
ll dp[100005][3];

int main() {
  int n;
  cin >> n;
  vector<ll> A(n);
  rep(i, n) cin >> A[i];
  ll ans = -INF;
  if (n%2 == 0) {
    for (int i = 0; i < n/2; ++i) {
      dp[i+1][0] += dp[i][0] + A[i*2];
      dp[i+1][1] += dp[i][1] + A[i*2+1];
    }
    rep(i, n/2+1) ans = max(ans, dp[i][0]+dp[n/2][1]-dp[i][1]);
  } else {
    rep(i, n/2+1) rep(j, 3) dp[i][j] = -INF;
    rep(i, 3) dp[1][i] = A[i];
    for (int i = 1; i < n/2; ++i) {
      dp[i+1][0] = dp[i][0] + A[i*2];
      dp[i+1][1] = max(dp[i][0] + A[i*2+1], dp[i][1] + A[i*2+1]);
      rep(j, 3) dp[i+1][2] = max(dp[i+1][2], dp[i][j] + A[i*2+2]);
    }
    rep(i, 3) ans = max(ans, dp[n/2][i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7212
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define ALL(x) (x).begin(),(x).end()
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
using P=pair<int,int>;

signed _main(){
  int N; cin >> N;
  string ans="";
  while(N!=0){
    if(N%26==0){
      ans+='z';
      N-=26;
    }
    else{
      ans+='a'+N%26-1;
      N-=N%26;
    }
    N/=26;
  }
  reverse(ALL(ans));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

#include <random>
vector<int> edg[100003];
bool used[100003];
int deg[100003];
vector<int> ans;
random_device rnd;
mt19937 mt(rnd());

bool func(int start, int pos) {
	for (int i = 0; i < (int)edg[pos].size(); ++i) --deg[edg[pos][i]];

	if (deg[start] == 0 && deg[pos] == 0) {
		ans.push_back(pos);
		return true;
	}
	used[pos] = true;
	for (int i = 0; i < (int)edg[pos].size(); ++i) {
		if (used[edg[pos][i]]) continue;
		if (func(start, edg[pos][i])) {
			ans.push_back(pos);
			return true;
		}
	}
	used[pos] = false;
	for (int i = 0; i < (int)edg[pos].size(); ++i) ++deg[edg[pos][i]];
	return false;
}

int main() {
	int n, m; cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int a, b; cin >> a >> b;
		--a; --b;
		edg[a].push_back(b);
		edg[b].push_back(a);
		++deg[a]; ++deg[b];
	}
	set<int> s;
	int pos;
	do {
		do {
			pos = mt() % n;
		} while (s.count(pos));
		s.insert(pos);
	} while (!func(pos, pos));
	cout << ans.size() << endl;
	for (int i = ans.size() - 1; i >= 0; --i) cout << ans[i] + 1 << (i == 0 ? "\n" : " ");
	return 0;
}


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

using namespace std;

int main(void){
	int N;
	cin >> N;
	char s[N],t[N];
	cin>>s>>t;
	int i;
	for(i = 0; i < N; i++){
		cout<<s[i]<<t[i];
	}
	cout<<endl;
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pii pair<int, int>
#define fr(n) for (int i = 0; i < n; i++)
#define fr1(n) for (int i = 1; i <= n; i++)
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    if ((b - a) & 1) cout << "Borys";
    else cout << "Alice";
}


Measured memory_bytes: 256
import numpy as np
N, M = map(int, input().split())
a = []
for i in range(M):
    a.append([int(j) for j in input().split()])

num = np.ones((N+1,))
red = np.zeros((N+1,))
red[1] = 1

for i in range(M):
    if red[a[i][0]] == 1:
        red[a[i][1]] = 1
    num[a[i][0]] -= 1
    num[a[i][1]] += 1
    if num[a[i][0]] == 0:
        red[a[i][0]] = 0

print(np.sum(red == 1))

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

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

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

#define MAX 1400

// Gはgridで0 or 1
int dp[MAX][MAX], G[MAX][MAX];

int getLargestSquare(int H, int W) {
  int maxWidth = 0;
  rep(i, 0, H) {
    rep(j, 0, W) {
      dp[i][j] = (G[i][j] + 1) % 2;
      maxWidth |= dp[i][j];
    }
  }

  rep(i, 1, H) {
    rep(j, 1, W) {
      if (G[i][j]) {
        dp[i][j] = 0;
      } else {
        dp[i][j] = min(dp[i - 1][j - 1], min(dp[i-1][j], dp[i][j-1])) + 1;
        maxWidth = max(maxWidth, dp[i][j]);
      }
    }
  }

  return maxWidth * maxWidth;
};

int main() {
  int H, W;
  cin >> H >> W;

  rep(i, 0, H) {
    rep(j, 0, W) {
      scanf("%d", &G[i][j]);
    }
  }

  int ans = getLargestSquare(H, W);

  cout << ans << endl;
};



Measured memory_bytes: 18456