akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <stack>
#include <cmath>
#include <string>
#include <deque>
#include <map>
#include <iomanip>
#include <math.h>
#include <cstdlib>
#include <stdlib.h>
#include <set>
#include <unordered_set>
#include <cassert>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forn1(i, n) for (int i = 1; i <= n; ++i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll p = 997;
const ll base = 1e9 + 7;
const ll MAXN = 5e5;
const ll INF = 1e9;
const ll MOD = 1e9;
const double PII = 3.14159265358979323846264338327950288419716939937510;
const double Epsilon = 1.19209e-9;
const ld fi = 1.6180339887498948482;
const ll one = 2147483647;
const ll two = 1e9 + 7;
void print_vector(vector<int> & a) {
	forn(i, (int)a.size()) {
		cout << a[i] << " ";
	}
	cout << "\n";
}
void read_vector(vector<ll> & a, ll n) {
	ll h;
	forn(i, n) {
		cin >> h;
		a.pb(h);
	}
}
bool check_four(int a){
  int sum = 0;
  while(a){
    sum += a % 10;
    a /= 10;
  }
  return sum % 4 == 0;
}
void upd_max(int & a, int b){
  a = max(a, b);
}
void upd_min(int & a, int b){
  a = min(a, b);
}
//#define DEBUG
int main(){
	FastIO;
	#ifdef DEBUG
		freopen("input.txt", "r", stdin);
	#endif // DEBUG
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(a * b, c) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
	string s,t;
	cin>>s>>t;int c=0;
	for(int i=0;i<s.length();i++){
		if(s[i]!=t[i]) c++;
	}
	cout<<c<<'\n';
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);	
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif 
	int T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3772
#include <iostream>
using namespace std;
int main() {
    
    int n,q;
    string s;
    cin >> n >> q >> s;
    int cum[100001];
    int c=0;
    cum[0]=0;
    for (int i=1;i<n;i++) {
        if(s[i-1]=='A' && s[i]=='C') c++;
        cum[i]=c;
    }
    int l,r;
    for (int i=0;i<q;i++) {
        cin >> l >> r;
        cout << (cum[r-1] - cum[l-1]) << "\n";
    }
    return 0;
}


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

int main(){
	int N;
	cin >> N;
	string tmp;
	rep(i,N) cin >> tmp[i];
	ll p = stoi(tmp);
	rep(i,N) cin >> tmp[i];
	ll q = stoi(tmp);
	
	int v[N];
	int totN = 1;
	rep(i,N) {
		v[i] = i+1;
		totN *= i+1;
	}

	int k=0;
	ll ps[totN];
	do {
		string s="";
		for (int x : v) s += to_string(x);
		ps[k] = stoi(s);
		k++;
	}while (next_permutation(v,v+N));

	int a, b;
	rep(i,totN) {
		if (ps[i] == p) a = i;
		if (ps[i] == q) b = i;
	}	

	cout << abs(a-b) << endl;

	return 0;
}


Measured memory_bytes: 4012
h, w, k = map(int, input().split())
board = [str(input()) for _ in range(h)]
ans = 0
black = 0
for i in board:
    black += i.count('#')
for i in range(2 ** h):
    for j in range(2 ** w):
        r_of_h = []
        for m in range(h):
            if ((i >> m) & 1):
                r_of_h.append(m)
        r_of_w = [] 
        for n in range(w):
            if ((j >> n) & 1):
                r_of_w.append(n)
        cnt = 0
        for H in r_of_h:
            for W in r_of_w:
                if board[H][W] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1       
print(ans)

Measured memory_bytes: 9156
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
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; }
ll n, a, b, c;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> a >> b >> c;
    string ans = "";
    vector<string>s;
    s.resize(n);
    rep(i,n)cin>>s[i];
    s.push_back("AAA");
    rep(i, n)
    {
        if (s[i] == "AB")
        {
            if (a <= b&&!(b==1&&s[i+1]=="BC"&&c==0))
            {
                a++;
                b--;
                ans += 'A';
            }
            else
            {
                a--;
                b++;
                ans += 'B';
            }
        }
        else if (s[i] == "AC")
        {
            if (a <= c &&!(c == 1 && s[i + 1] == "BC" && b == 0))
            {
                a++;
                c--;
                ans += 'A';
            }
            else
            {
                a--;
                c++;
                ans += 'C';
            }
        }
        else
        {
            if (c <= b &&!(b == 1 && s[i + 1] == "AB" && a == 0))
            {
                c++;
                b--;
                ans += 'C';
            }
            else
            {
                c--;
                b++;
                ans += 'B';
            }
        }
        if (a < 0 || b < 0 || c < 0)
            return no, 0;
    }
    yes;
    rep(i, ans.size())
    {
        cout << ans[i] << "\n";
    }
}


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

using namespace std;

int main()
{   
    int TripCost;
    while (cin >> TripCost) {
        if (TripCost == 0) break;
        
        int TripSum = 0;
        pair<bool, int> DataBase(false, 0);
        bool is_judge = true;
         
        
        for (int i = 0; i < 12; ++i) {
            int data1, data2;

            cin >> data1 >> data2;
            
            TripSum += data1 - data2;

            
            
            if (TripSum >= TripCost && is_judge) {
                DataBase.first = true;
                DataBase.second = i + 1;
                is_judge = false;
            } 
        }
        
        if (DataBase.first) {
            cout << DataBase.second << endl;
        } else {
            cout << "NA" << endl;}
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int n;
int a[55];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++ i) scanf("%d", &a[i]);
	int mx = -1e9, mxn;
	int mn = 1e9, mnn;
	for (int i = 0; i < n; ++ i) {
		if (a[i] > mx) mx = a[i], mxn = i;
		if (a[i] < mn) mn = a[i], mnn = i;
	}
	if (mx <= 0) {
		printf("%d\n", n - 1);
		for (int i = n - 1; i; -- i) {
			printf("%d %d\n", i + 1, i);
		}
		return 0;
	}
	if (mn >= 0) {
		printf("%d\n", n - 1);
		for (int i = 0; i + 1 < n; ++ i) {
			printf("%d %d\n", i + 1, i + 2);
		}
		return 0;
	}
	if (mx + mn >= 0) {
		printf("%d\n", 2 * n - 2);
		for (int i = 0; i < n; ++ i) if (i != mxn) {
			printf("%d %d\n", mxn + 1, i + 1);
		}
		for (int i = 0; i + 1 < n; ++ i) {
			printf("%d %d\n", i + 1, i + 2);
		}
	} else {
		printf("%d\n", 2 * n - 2);
		for (int i = 0; i < n; ++ i) if (i != mnn) {
			printf("%d %d\n", mnn + 1, i + 1);
		}
		for (int i = n - 1; i; -- i) {
			printf("%d %d\n", i + 1, i);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 200
void push(int);
int pop(void);
int c[N];
int num=0;

int main(){
  char s[N];
  int op;
  while(scanf("%s",s)!=EOF){
  switch (s[0]) {
    case '+':
    push(pop()+pop());
    break;
    case '-':
    op=pop();
    push(pop()-op);
    break;
    case '*':
    push(pop()*pop());
    break;
    default:
    push(atoi(s));
    break;
  }
}
printf("%d\n",pop());
  return 0;
}
void push(int x) {
  num++;
  c[num]=x;
}
int pop(void){
  num--;
  return c[num+1];
}



Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <ctype.h>

int main() 
{
    char str;

    std::cin >> str;
    if (isupper(str)) {
        std::cout << "A" << std::endl;
    }
    else
    {
        std::cout << "a" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define bash push_back
#define alles(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,-1,1,-1,1};
const int INF=1 << 30;
bool inside(int x,int y,int w,int h){
  return (x>=0 && y>=0 && x<w && y<h);}
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vit;
typedef map<string,int> mstit;
typedef priority_queue<int> pqit;





int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  string str;
  cin >>str;
  int a=0,siz=str.length();
  int b=0,w=0,bl=0,wh=0; 
  iFOR( i,1,siz){
    if(str[i-1]!=str[i]) {
      if(str[i]=='B') b++;else w++;
      a++;
    }
    if(str[siz-i]!=str[siz-i+1]){
      if(str[i]=='B') bl++;else wh++;
      b++; 
    }
  }
  cout <<a fin;

  return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main(){
    int N,K;
    cin >> N >> K;
    vector<int>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int l = 0,r = INF;
    while(l+1 < r) {
        int mid = (l+r)/2;
        int cnt = 0;
        bool ok = true;
        for(int i = 0; i < N; i++) {
            cnt += max(0LL,(A[i]+mid-1)/mid-1);
            if(A[i]%mid > 0) {
                ok = false;
            }
        }
        if(cnt <= K) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    bool ok = true;
    if(l != 0) {
        for(int i = 0; i < N; i++) {
            if(A[i]%l) {
                ok = false;
            }
         }
    }
    if(!ok || l == 0) {
        cout << l+1 << endl;
    }
    else {
        cout << l << endl;
    }
}

Measured memory_bytes: 4792
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
    ll n,t;
    cin >> n >> t;

    ll a[n];
    for(int i = 0; i < n; i++)
        scanf("%lld",&a[i]);

    ll mn = a[0];
    ll p = 0, mp = 0;
    ll c = 1; // ?!=0

    for(int i = 1; i < n; i++)
    {
        if(a[i] <  mn)   mn = a[i];
        if(a[i] >= mn)   p = a[i] - mn;

        if(p > mp)             mp = p,c = 1;
        else if(p == mp)   c++;
    }

    cout << c << endl;

    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll n;
    cin>>n;
    for(ll i=1; i<=MAX; i++)
    {
        ll cur=(i*(i+1))/2ll;
        if(cur>=n)
        {
            cout<<i<<endl;
            return 0;
        }
    }


    return 0;
}


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

int main()
{
	int t;
	cin>>t;
	double x,sum=0;
	while(t--){
		string s;
		cin>>x>>s;
		if(s=="JPY")sum+=x;
		else sum+=x*380000.0;
	}
	printf("%0.8f",sum);
	return 0;
}


Measured memory_bytes: 256
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict
import bisect

# N, P = [int(x) for x in input().split()]

N = int(input())
A = []

for i in range(N):
    a = int(input())
    A.append(a)

isAllEven = True

for a in A:
    if a % 2 == 1:
        isAllEven = False

if isAllEven == True:
    print("second")
else:
    print("first")


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

using namespace std;

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

    int n;
    int count = 0;
    cin >> n;
    vector<int> edges(n);
    for (int i = 0; i < n; ++i) {
        cin >> edges.at(i);
    }
    sort(edges.begin(), edges.end());
    for (int j = 0; j < n; ++j) {
        for (int i = j + 1; i < n; ++i) {
            for (int k = i + 1; k < n; ++k) {
                if (edges.at(i) + edges.at(j) > edges.at(k)) {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 384
//Utkarsh.25dec
#include <bits/stdc++.h>
#define ll long long int 
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n;
    cin>>n;
    vl v;
    ll highest=0;
    ll pos=0;
    rep(i,n)
    {
        ll c;
        cin>>c;
        v.pb(c);
        if(highest<c)
        {
            highest=c;
            pos=i;
        }
    }
    ll shighest=0;;
    v.erase(v.begin()+pos);
    rep(i,n-1)
    {
        ll c=v[i];
        if(shighest<c)
        {
            shighest=c;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(pos==i)
        {
            cout<<shighest<<'\n';
        }
        else
            cout<<highest<<'\n';
    }
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
}

Measured memory_bytes: 15088
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

//#define int ll

typedef int64_t ll;
//static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) signed((a).size())
#define LEN(a) signed((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")
#define YesNo(x) puts((x)?"Yes":"No")

int main(){
    set<int> S;
    int N;
    cin >> N;
    REP(i,N){
        int tmp;
        scanf("%d",&tmp);
        S.insert(tmp);
    }
    printf("%d\n",int(S.size()));
}


Measured memory_bytes: 256
//start of jonathanirvings' template v3.0.3 (BETA)

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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
}

//end of jonathanirvings' template v3.0.3 (BETA)

long long a[3];

int main()
{
  scanf("%lld %lld %lld",&a[0],&a[1],&a[2]);
  if (a[0] % 2 == 0 || a[1] % 2 == 0 || a[2] % 2 == 0)
  {
    puts("0");
    return 0;
  }
  sort(a,a+3);
  printf("%lld\n",a[0]*a[1]);
  return 0;
}










Measured memory_bytes: 256
import sys

if __name__ == "__main__":
    line1 = sys.stdin.readline().strip()
    param1 = line1.split(" ")
    n = int(param1[0])
    k = int(param1[1])

    d = []
    A = set()

    for i in range(k):
        d_i = int(sys.stdin.readline().strip())
        A_i = [int(a) for a in sys.stdin.readline().strip().split(" ")]

        for a_i in A_i:
            A.add(a_i)
    
    print(len(set([i+1 for i in range(n)]) - A))





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

bool judge(bool AC, bool BD){
    if(AC && BD)return true;
    else return false;
}
 
int main(void){
    int N, A, B, C, D;
    string S;
    cin>>N>>A>>B>>C>>D>>S;
 
    bool flagAC = true;
    bool flagBD = true;
    if(C<B){
        for(int i=A-1; i<C-1; i++){
            if(S[i]=='#' && S[i+1]=='#'){
                flagAC = false;
                break;
            }
        }
 
        for(int i=B-1; i<D-1; i++){
            if(S[i]=='#' && S[i+1]=='#'){
                flagBD = false;
                break;
            }    
        }
        if(judge(flagAC, flagBD))cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }else if(C<D){
        for(int i=B-1; i<D-1; i++){
            if(S[i]=='#' && S[i+1]=='#'){
                flagBD = false;
                break;
            }    
        }
 
        for(int i=A-1; i<C-1; i++){
            if(S[i]=='#' && S[i+1]=='#'){
                flagAC = false;
                break;
            }
        }
        if(judge(flagAC, flagBD))cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }else{
        for(int i=B-1; i<D; i++){
            if(S[i-1]=='.' && S[i]=='.' && S[i+1]=='.'){
                bool flagmentAC = true;
                bool flagmentBD = true;
                for(int j=i+1; j<C-1; j++){
                    if(S[i]=='#' && S[i+1]=='#'){
                        flagmentAC = false;
                        break;
                    }
                }
 
                for(int i=A-1; i<D-1; i++){
                    if(S[i]=='#' && S[i+1]=='#'){
                        flagmentBD = false;
                        break;
                    }    
                }
                if(flagmentAC && flagmentBD){
                    flagAC = true;
                    flagBD = true;
                    goto label;
                }else{
                    flagAC = false;
                    flagBD = false;
                }
            }else{
                flagAC = false;
                flagBD = false;
            }
        }
label:
        if(judge(flagAC, flagBD))cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	int max = 0;
	for(int i = 0; i < n; i++){
		int count = 0;
		for(int j = 0; j < m; j++){
			int tmp;
			cin >> tmp;
			count += tmp;
		}
		if(max < count) max = count;
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 1160
init = input()

words = [
  'dream',
  'dreamer',
  'erase',
  'eraser'
]

def reverseWord(str):
  return str[::-1]

def elimTheWord(str):
  for word in reversed_words:
    if str.find(word) == 0:
      str = str[len(word):]
  return str

reversed_words = list(map(reverseWord, words))

# main
target = reverseWord(init)

while True:
  pivot = elimTheWord(target)
  if pivot == '':
    print('YES')
    break
  if pivot == target:
    print('NO')
    break
  target = pivot

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

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

using namespace std;

int main(){
  ll n;
  cin>>n;
  
  vector<vector<pair<int, int>>> graph(n+1);
  
  rep(i, n-1){
    ll u,v,w;
    cin>>u>>v>>w;
    
    graph[u].emplace_back(v, w);
    graph[v].emplace_back(u, w);
  }
  
  queue<ll> q;
  q.push(1);
  
  vector<ll> results(n+1, -1);
  results[1]=0;
  
  while( !q.empty() ){
    ll c = q.front();
    q.pop();
    
    rep(i, graph[c].size()){
      ll to = graph[c][i].first;
      ll cost = graph[c][i].second;
      
      if(results[to]==-1){
        q.push(to);
        if((results[c]+cost)%2==0){
          results[to]=0;
        }else{
          results[to]=1;
        }
      }else{
        continue;
      }
    }
  }
  
  rep(i, n){
    cout<<results[i+1]<<endl;
  }
  
  return 0;
}

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

int GCD(int a, int b)
{
    int c = (a < b)? a : b;
    for (int i = 1; i <= c; ++i) {
        int d = c / i;
        if ( a % d + b % d == 0)
            return d;
    }
    return 1;
}

int LCM(int a, int b)
{
    int c = (a < b)? b : a;
    for (int i = 1; c * i <= 2000000000; ++i) {
        int d = c * i;
        if (d % a + d % b == 0)
            return d;
    }
    return -1;
}

int main(void)
{
    int a, b;
    while (cin >> a >> b)
        cout << GCD(a, b) << " " << LCM(a, b) << endl;
    return 0;
}







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

using namespace std;

int main() {
	int h, w, a, b;
	scanf("%d %d %d %d", &h, &w, &a, &b);

	printf("%d", h * w - a * w - b * h + min(a, b) * max(a, b));

	return 0;
}

Measured memory_bytes: 256
n,m,d = gets.split.map &:to_i

one = 2 * d
if one * 2 > n
    one = (n - d) * 2
    two = 0
else
    two = n - one
end

a = one + two * 2

if d == 0
    a = two
end

puts a.to_f / (n * n) * (m - 1)


Measured memory_bytes: 1788
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int f(int n){
	return ((n%2)?3*n+1:n/2);
}

int main() {
	int s,ans = 1; cin >> s;
	map<int,int> mp;
	mp[s] = 1;
	while(mp[s]==1){
		s = f(s);
		mp[s]++;
		ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using namespace __gnu_pbds;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using pl = pair<ll, ll>;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll t, d, m, n, k;

ll a, b, c;
vector<ll> v;

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

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> n >> k;

  n %= k;

  cout << min(n, abs(n-k)) << endl;
}



Measured memory_bytes: 256
n, m = input().split()
n, m = int(n), int(m)

a = input().split()
a = [int(a) for a in a]

sum_a = sum(a)

a_can_choose = [True if a >= sum_a / (4 * m) else False for a in a]

print("Yes" if m <= sum(a_can_choose) else "No")

Measured memory_bytes: 38736
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a)-1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a)-1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<< C <<endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define FORE(a,b) for(auto &&a:b)

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF+7;
const LL LLINF = 1e18;

int N, L, Q;
VL x;
VLL nxt;

int main(void) {
    cin >> N;
    x = VL(N);
    REP (i, N) scanf("%lld", &x[i]);
    cin >> L >> Q;
    nxt = VLL(21, VL(N, LLINF));
    //nxt[i][j] = j番目のホテルから2^i日以内に到達出来る最も右のホテル番号
    REP (i, N) {
        nxt[0][i] = upper_bound(x.begin()+i, x.end(), x[i]+L)-x.begin()-1;
    }
    REP (i, 20) REP(j, N) {
        nxt[i+1][j] = nxt[i][nxt[i][j]];
    }
    REP (_, Q) {
        int a, b;
        scanf("%d%d", &a, &b);
        a--; b--;
        if(a > b) swap(a, b);
        int now = a;
        int day = 0;
        RREP (i, 21) {
            if(nxt[i][now] < b) {
                now = nxt[i][now];
                day += 1<<i;
            }
        }
        cout << day+1 << endl;
    }
}


Measured memory_bytes: 18304
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using Int = long long;
int main()
{
    int N, x; cin >> N >> x;
    vector<Int> A(N); for (auto& x : A) cin >> x;
    Int ans = 0;
    for (int i = 1; i < N; i++) {
        Int t = A[i-1] + A[i] - x;
        if (t > 0) {
            ans += t;
            A[i] = max((Int)0, A[i] - t);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
# debug
debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if debugFlag

# util functions
def myabs( x )
  if x > 0
    return x
  else
    return -x
  end
end

def my_search( t, blist, resnum )
  costs = []
  vals = []

  (2**blist.size).times do |i|
    next if i == 0
    
    tmp_bamb = 0
    tmp_cmps = 0    
    blist.size.times do |j|
      tmp_bamb += blist[j]*i[j]
      tmp_cmps += i[j]
    end
    if blist.size - tmp_cmps >= resnum - 1
      costs << [tmp_bamb, i]
      vals << (myabs( tmp_bamb - t ) + (tmp_cmps - 1)*10)
    end
  end
  mp = vals.min
  c = costs[vals.index(vals.min)]

  blist.size.times do |j|
    blist[j] = nil if c[1][j] == 1
  end
  blist.compact!

  return mp
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
target_list = []
blist       = []
inputs.size.times do |i|
  if i == 0
    target_list = inputs[i][1..-1]
  else
    blist << inputs[i][0]
  end
end

if debugFlag
  p target_list
  p blist
end

mps = []
blistc = blist.clone
p "pat0" if debugFlag
mp = 0
mp += my_search( target_list[0], blistc, 3 )
mp += my_search( target_list[1], blistc, 2 )
mp += my_search( target_list[2], blistc, 1 )
mps << mp

blistc = blist.clone
p "pat1" if debugFlag
mp = 0
mp += my_search( target_list[0], blistc, 3 )
mp += my_search( target_list[2], blistc, 2 )
mp += my_search( target_list[1], blistc, 1 )
mps << mp

blistc = blist.clone
p "pat2" if debugFlag
mp = 0
mp += my_search( target_list[1], blistc, 3 )
mp += my_search( target_list[0], blistc, 2 )
mp += my_search( target_list[2], blistc, 1 )
mps << mp

blistc = blist.clone
p "pat3" if debugFlag
mp = 0
mp += my_search( target_list[1], blistc, 3 )
mp += my_search( target_list[2], blistc, 2 )
mp += my_search( target_list[0], blistc, 1 )
mps << mp

blistc = blist.clone
p "pat4" if debugFlag
mp = 0
mp += my_search( target_list[2], blistc, 3 )
mp += my_search( target_list[0], blistc, 2 )
mp += my_search( target_list[1], blistc, 1 )
mps << mp

blistc = blist.clone
p "pat5" if debugFlag
mp = 0
mp += my_search( target_list[2], blistc, 3 )
mp += my_search( target_list[1], blistc, 2 )
mp += my_search( target_list[0], blistc, 1 )
mps << mp

p mps if debugFlag
puts mps.min


Measured memory_bytes: 1788
/**************************************
*Coded By: BadduCoder (Sumit Badsara) *
***************************************/
#include<bits/stdc++.h>
using namespace std;

//All the Loops and defines required
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define ff first
#define ss second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

//All the declarations using typedef

typedef long long int ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef map<int,int> MII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int l;

int main()
{
    _cin;
    ll n,m;
    char ch;
    cin>>n>>m;
    ll grid[n][m];

    REP(i,n)
    {
        REP(j,m)
        {
            cin>>ch;
            if(ch=='.')
                grid[i][j] = 0;
            else
                grid[i][j] = -1;
        }
    }
    if(grid[0][0]==0)
        grid[0][0] = 1;

    FOR(i,1,n,1)
    {
        if(grid[i][0]!=-1)
        {
            if(grid[i-1][0]!=-1 && grid[i-1][0]!=0)
                grid[i][0] = 1; 
            else
                grid[i][0] = 0;
        }
    }

    FOR(j,1,m,1)
    {
        if(grid[0][j]!=-1)
        {
            if(grid[0][j-1]!=-1 && grid[0][j-1]!=0)
                grid[0][j] = 1;
            else
                grid[0][j] = 0;
        }
    }

    FOR(i,1,n,1)
    {
        FOR(j,1,m,1)
        {
            if(grid[i][j]!=-1)
            {
                if(grid[i-1][j]!=-1 && grid[i-1][j]!=0)
                    grid[i][j]+=grid[i-1][j];
                if(grid[i][j-1]!=-1 && grid[i][j-1]!=0)
                    grid[i][j]+=grid[i][j-1];
                grid[i][j] %= MOD;
            }
        }
    }

    // REP(i,n)
    // {
    //     REP(j,m)
    //         cout<<grid[i][j]<<" ";
    //     cout<<"\n";
    // }

    cout<<grid[n-1][m-1]%MOD;
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)

int main() { 
  int n,a;cin>>n>>a;
  cout << n*n-a << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <sstream>
#include <map>
using namespace std;

int main() {
	string a;
	int L;
	while(cin >> a >> L) {
		int mn, mx;
		int cnt = 0;
		map<int,int> s;
		if(a == "0" && L == 0) break;
		while(s.find(atoi(a.c_str())) == s.end()) {
			stringstream sstr;
			s[atoi(a.c_str())] = cnt++;
			while(a.size() < L)
				a += "0";
			sort(a.begin(), a.end());
			mn = atoi(a.c_str());
			sort(a.rbegin(), a.rend());
			mx = atoi(a.c_str());
			sstr << mx - mn;
			sstr >> a;
		}
		cout << s[atoi(a.c_str())] << " " << a
			<< " " << cnt - s[atoi(a.c_str())] << endl;
	}
}

Measured memory_bytes: 1256
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;

struct edge {
	int to, cost;
};
const int INF = 1 << 25;
int cost1[100][100];
int cost2[100][100];
int N, M;

void dfs(int r, int v, int sum, int d) {
	if(d == 2) {
		cost2[r][v] = min(cost2[r][v], sum);
		return;
	}

	for(int i = 0; i < N; i++) {
		if(cost1[v][i] != INF) {
			dfs(r, i, sum + cost1[v][i], d + 1);
		}
	}
}

int dist[100][2];

struct S {
	int v, used, d;
	bool operator < (const S s) const {
		return d > s.d;
	}
};

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

	while(cin >> N >> M, N) {
		fill((int*)begin(cost1), (int*)end(cost1), INF);
		fill((int*)begin(cost2), (int*)end(cost2), INF);
		for(int i = 0; i < M; i++) {
			int a, b, c;
			cin >> a >> b >> c;
			a--, b--;
			cost1[a][b] = cost1[b][a] = c;
		}

		for(int i = 0; i < N; i++) {
			dfs(i, i, 0, 0);
		}

		fill((int*)begin(dist), (int*)end(dist), INF);
		dist[0][0] = 0;
		priority_queue<S> q;
		q.push({ 0, 0, 0 });
		while(q.size()) {
			int v = q.top().v, used = q.top().used, d = q.top().d;
			q.pop();
			if(dist[v][used] < d) continue;
			for(int i = 0; i < N; i++) {
				if(!used && cost2[v][i] != INF && dist[i][1] > d) {
					dist[i][1] = d;
					q.push({ i, 1, d });
				}
				if(cost1[v][i] != INF && dist[i][used] > d + cost1[v][i]) {
					dist[i][used] = d + cost1[v][i];
					q.push({ i, used, d + cost1[v][i] });
				}
			}
		}

		cout << min(dist[N - 1][0], dist[N - 1][1]) << endl;
	}
}

Measured memory_bytes: 3172
import java.util.*;

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[n][2];
		for(int i = 0; i < n; i++){
			a[i][0] = sc.nextInt();
			a[i][1] = sc.nextInt();
		}
		Arrays.sort(a,(c,b) -> Integer.compare(c[0],b[0]));
		long ans = 0;
		int ansb = 0;
		int i = 0;
		while(ansb != m){
			if(a[i][1]+ansb >= m){
				ans += (long)a[i][0]*(m-ansb);
				ansb = m;
			}else{
				ansb += a[i][1];
				ans += (long)a[i][0]*a[i][1];
				i++;
			}
		}
		System.out.print(ans);
	}
}


Measured memory_bytes: 92244
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int[] antenna = new int[5];

		for (int i = 0; i < 5; i++) {
			antenna[i] = sc.nextInt();
		}

		int k = sc.nextInt();

		if (antenna[4] - antenna[0] > k) {
			System.out.println(":(");
		} else {
			System.out.println("Yay!");
		}
	}

}

Measured memory_bytes: 23892
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;

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

	bool operator < (const edge& x) const {//コストの順番にソート出来る。今回は不要。
		return cost < x.cost;
	}
};

bool Bellman_Ford(int start,int E,int V,vector<edge> Edge,vector<ll> &d) {//V:頂点数 E:辺数 
	fill(d.begin(), d.end(), LONGINF);
	d[start] = 0;
	vector<bool> t(V,false);

	for (int i = 0; i < V - 1; i++) {
		for (int j = 0; j < E; j++) {
			edge e = Edge[j];
			if (d[e.from] == LONGINF) { continue; }
			if (d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
			}
		}
	}

	for (int i = 0; i < V; i++) {
		for (int j = 0; j < E; j++) {
			edge e = Edge[j];
			if (d[e.from] == LONGINF) { continue; }
			if (d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				t[e.to] = true;
			}
			if (t[e.from]) {
				t[e.to] = true;
			}
		}
	}
	if (t[V - 1]) {
		return false;
	}
	return true;
}

int main() {
	int n, m, p; cin >> n >> m >> p;
	vector<vector<int>> g(n);
	vector<edge> e(m);
	
	for (int i = 0; i < m; i++) {
		int a, b, c; cin >> a >> b >> c;
		c -= p;
		a--; b--; c = c * (-1);
		g[a].emplace_back(b);
		e[i].from = a;
		e[i].to = b;
		e[i].cost = c;
	}
	vector<ll> d(n);
	if (Bellman_Ford(0, m, n, e, d)) {//閉路検出(無限ループでinf)なし
		cout << max((ll)0,-1*d[n - 1]) << endl;
	}
	else {//閉路検出した
		cout << "-1" << endl;
	}

	return 0;
}

Measured memory_bytes: 640
/**
 *    author        : Saurav Paul 
 *    created       : August 07, 2020 12:55 PM
 *    Problem Name  : F - LCS
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/dp/tasks/dp_f
 *    @genarated by : ai-virtual-assistant
**/

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

int main(){
    ios_base::sync_with_stdio(false);

    string s , t;
    cin >> s >> t;
    int ss = s.size() , st = t.size() ;

    vector<vector<int>> dp(ss+1,vector<int>(st+1)) ;

    for(int i = 0 ; i < ss ; i++){
        for(int j = 0 ; j < st ; j++){
            if(s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            }
            else{
                dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]) ;
            }
        }
    }

    string ans = "" ;
    for(int i = ss , j = st ; i > 0 && j > 0 ; ){
        int x = dp[i-1][j] ;
        int y = dp[i][j-1] ;
        int curr = dp[i][j] ;
        
        if(curr == x){
            i-- ;
        }
        else if(curr == y){
            j -- ;
        }
        else {
            i -- ;
            j -- ;
            ans += s[i] ;
        }

    }
    reverse(ans.begin(),ans.end()) ;
    cout << ans << endl ;

    return 0 ;
}


Measured memory_bytes: 38564
// Aizu 0230: Ninja Climbing
// 2017.9.10 bal4u@uu

#include <stdio.h>
#include <string.h>

#define QMAX 1000
typedef struct { int a, h, c; } Q;
Q que[QMAX+3]; int top, end;

int w[2][103];
char visited[2][103];

int main()
{
	int n, i, j, h, c, j2, h2;
	int ans;

	while (scanf("%d", &n) && n) {
		for (j = 0; j < 2; j++) for (i = 0; i < n; i++) scanf("%d", w[j]+i);
		w[0][n] = w[1][n] = 0;
		memset(visited, 0, sizeof(visited));
		h = 0; if (w[0][0] == 1) { while (w[0][h] == 1) h++; h--; }
		que[0].a = 0, que[0].h = h, que[0].c = 0;
		h = 0; if (w[1][0] == 1) { while (w[1][h] == 1) h++; h--; }
		que[1].a = 1, que[1].h = h, que[1].c = 0;
		ans = -1; top = 0, end = 2;
		while (top < end) {
			j = que[top].a, h = que[top].h, c = que[top].c, top++;
			if (h == n-1) { ans = c; break; }
			for (j2 = !j, i = 0; i <= 2; i++) {
				if ((h2 = h + i) >= n) continue;
				if      (w[j2][h2] == 1) { while (w[j2][h2] == 1) h2++; h2--; }
				else if (w[j2][h2] == 2) while (w[j2][h2] == 2) h2--;
				if (visited[j2][h2]) continue;
				visited[j2][h2] = 1;
				que[end].a = j2, que[end].h = h2, que[end].c = c+1, end++;
			}
		}
		printf(ans < 0 ? "NA\n" : "%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static readonly int MAX = 10000;
        static readonly int sqrt = 100;

        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            var memo = Enumerable.Range(0, MAX + 1).ToArray();
            memo[0] = memo[1] = -1;

            for (int i = 2; i <= sqrt; i++)
            {
                if (memo[i] == -1) continue;

                for (int j = i + i; j <= MAX; j += i)
                {
                    memo[j] = -1;
                }
            }

            var primes = memo.Where(a => a != -1).ToArray();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                int idx = UpperBound(primes, n) - 1;

                for (int i = idx; i > 0; i--)
                {
                    int p = primes[i - 1];
                    int q = primes[i];

                    if (q - p == 2)
                    {
                        sb.AppendLine(p + " " + q);
                        break;
                    }
                }
            }
            Console.Write(sb);
        }

        static int UpperBound(int[] arr, int value)
        {
            int low = 0;
            int high = arr.Length;
            int mid;

            while (low < high)
            {
                mid = ((high - low) >> 1) + low;

                if (arr[mid] <= value) low = mid + 1;
                else high = mid;
            }
            return low;
        }
    }
}

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

typedef long long LL;

const int N=200000;

int n;
struct side{
  int y,next;
}e[N*2+9];
int lin[N+9],cs;

void Ins(int x,int y){e[++cs].y=y;e[cs].next=lin[x];lin[x]=cs;}
void Ins2(int x,int y){Ins(x,y);Ins(y,x);}

void into(){
  scanf("%d",&n);
  for (int i=1;i<n;++i){
	int x,y;
	scanf("%d%d",&x,&y);
	Ins2(x,y);
  }
}

int a[3][N+9],ca[3];

void Get_a(){
  for (int i=1;i<=n;++i) a[i%3][++ca[i%3]]=i;
}

int d[2][N+9],cd[2];

void Dfs_d(int k,int fa,int dep){
  d[dep&1][++cd[dep&1]]=k;
  for (int i=lin[k];i;i=e[i].next)
	if (e[i].y^fa) Dfs_d(e[i].y,k,dep+1);
}

int ans[N+9];

void Get_ans(){
  if (cd[0]>cd[1]) swap(d[0],d[1]),swap(cd[0],cd[1]);
  if (ca[1]<=cd[0])
	for (int i=1;i<=cd[0];++i) ans[d[0][i]]=ca[1]?a[1][ca[1]--]:a[0][ca[0]--];
  else
	for (int i=1;i<=cd[0];++i) ans[d[0][i]]=a[0][ca[0]--];
  for (int i=1;i<=cd[1];++i) ans[d[1][i]]=ca[0]?a[0][ca[0]--]:ca[1]?a[1][ca[1]--]:a[2][ca[2]--];
}

void work(){
  Get_a();
  Dfs_d(1,0,1);
  Get_ans();
}

void outo(){
  for (int i=1;i<=n;++i)
	printf("%d ",ans[i]);
  puts("");
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 15676
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    string n;
    cin >> n;
    for (int i = 0; i < n.length(); i++) {
        if (n[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

typedef long long int ll;
int main(){
    int N;
    cin >> N;
    vector<int> B(N-1);
    for(int i = 0;i < N-1;i++)cin >> B[i];
    int A[N];
    A[0] = B[0];
    for(int i = 1;i < N-1;i++){
        A[i] = min(B[i-1],B[i]);
    }
    A[N-1] = B[N-2];
    int ans = 0;
    for(int i = 0;i < N;i++){
        ans += A[i];
    }
    cout << ans << endl;
}

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

using namespace std;

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

  vector<string> ans;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= k && i + j <= s.size(); j++) {
      ans.push_back(s.substr(i, j));
    }
  }
  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());
  cout << ans[k - 1] << endl;
}

Measured memory_bytes: 1660