akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n & 1) {
        No();
    }else{
        if(s.substr(0, n/2) == s.substr(n/2, n/2)) Yes();
        else No();
    }
}

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

int main(){
    int n; cin >> n;
    int n2=0,n4=0,nodd=0,n1=0;
    bool can = true;
    for(int ix=0;ix<n;ix++){
        ll a; cin >> a;
        if(a%4==0) n4++;
        else if(a%2==0) n2++;
        //else if(a==1) n1++;
        else nodd++;
    }
    if(n4+1<nodd) can = false;
    else if(n4+1-nodd<(n2%2)) can = false;
    
    cout << (can ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
n=int(input())
a = [int(input()) for _ in range(n)]
a.sort()
for i in range(n):
    if sum(a)%10 == 0:
        if a[i]%10 == 0:
            continue
        else:
            a[i]=0
    else:
        print(sum(a))
        exit(0)
print(0)

Measured memory_bytes: 9164
#!/usr/bin/env python3
import sys

input = sys.stdin.readline


def ST():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


x = I()
if x == 1:
    print(0)
else:
    print(1)


Measured memory_bytes: 9096
fn main() {
    proconio::input! {
        n: usize,
        a: [usize; n],
    }
    let mut dp = vec![0;n+1];
    let mut b: Vec<_> = (0..n).collect();
    b.sort_by_key(|k| a[*k]);
    for (m,k) in b.into_iter().enumerate() {
        let f = |i| a[k]*if i>k {i-k} else {k-i};
        for i in 0..n-m {
            dp[i]=std::cmp::max(dp[i]+f(i+m),dp[i+1]+f(i));
        }
    }
    println!("{}",dp[0]);
}

Measured memory_bytes: 2232
#なぜこれが通らないのか分からない
from collections import Counter
N = int(input())
v = list(map(int, input().split()))

odd = v[0::2]
even = v[1::2]

o = Counter(odd).most_common(2)
e = Counter(even).most_common(2)

o.append((0,0))
e.append((0,0))

if o[0][0]==e[0][0]:
    print(min(N-o[0][1]-e[1][1], N-o[1][1]-e[0][1]))
else:
    print(N-o[0][1]-e[0][1])

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, W, A, B;
bool ans[1005][1005];

int main(){
  cin >> H >> W >> A >> B;

  for (int i = 0; i < B; i++){
    for (int j = 0; j < W; j++){
      if (j < A) cout << 0;
      else cout << 1;
    }
    cout << endl;
  }
  
  for (int i = B; i < H; i++){
    for (int j = 0; j < W; j++){
      if (j < A) cout << 1;
      else cout << 0;
    }
    cout << endl;
  }

  return 0;
}


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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

map<ll, ll> mp;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int a,b,c,d,e,k;cin>>a>>b>>c>>d>>e>>k;
  if(e-a>k)cout<<":("<<endl;
  else cout<<"Yay!"<<endl;

  return 0;
}


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

using namespace std;

int main(){

    int n,maxV=0;
    cin>>n;
    
    string s1;

    map<string,int>m1;
    //vector<string>sv;

    for (int i = 0; i < n; i++)
    {
        cin>>s1;
        m1[s1]++;
        maxV = max(m1[s1],maxV);
    
    }

    for (auto i = m1.begin(); i != m1.end(); i++)
    {
        if ((*i).second == maxV)
        {
            cout<<(*i).first<<endl;
        }
        
    }
    


}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
#define sz 200005
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;

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

    int x,y;
    x = (s[0]-'0')*10+(s[1]-'0');
    y = (s[2]-'0')*10+(s[3]-'0');

    if((x && x<13 && y<13) && (y && y<13 && x<13 )) cout<<"AMBIGUOUS"<<endl;
    else if(x && x<13) cout<<"MMYY"<<endl;
    else if(y && y<13) cout<<"YYMM"<<endl;
    else cout<<"NA"<<endl;

    return 0;
}





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

int main(){
    ll a,v,b,w,t; cin >> a >> v >> b >> w >> t;
    if(v <= w) cout << "NO" << endl;
    else {
        if(abs(a-b) > t * (v-w)) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
}

Measured memory_bytes: 3676
import heapq

n, m = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
heapq.heapify(A)
for _ in range(m):
    max_price = -heapq.heappop(A) // 2
    heapq.heappush(A, -max_price)
total = -sum(A)
print(total)


Measured memory_bytes: 20404
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
const int MAXN = 100005;
const int mod = 998244353;

int main(){
	int n, k;
	cin >> n >> k;
	if(k == 0){
		cout << 1ll * n * n << endl;
		return 0;
	}
	lint ret = 0;
	for(int i=1; i<=n; i++){
		int mok = n / i;
		ret += mok * max(0, i - k);
		ret += max(n % i - k + 1, 0);
	}
	cout << ret << endl;
}


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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

    int a, b;
    cin >> a >> b;
    string A = string(b, a + '0'), B = string(a, b + '0');
    cout << min(A, B) << endl;
}

Measured memory_bytes: 256
// std = C++14
#include <iostream> // cin, cout, endl, ...
using namespace std;

class card {
public:
    char moji;
    int num, id; 
};
// IDを追加
//   ref: https://onlinejudge.u-aizu.ac.jp/solutions/problem/ALDS1_6_C/review/970351/dohatsu/C++

int partition(card* C, int p, int r) {
    const int x = C[r].num;
    int i = p - 1;
    for (int j = p; j <= r - 1; j++)
        if (C[j].num <= x) {
            i++;
            swap(C[i], C[j]);
        }
    swap(C[i + 1], C[r]);
    return i + 1;
}

void quick_sort(int n, card* C, int p, int r) {
    if (p < r) {
        const int q = partition(C, p, r);
        quick_sort(n, C, p, q - 1);
        quick_sort(n, C, q + 1, r);
    }
}

bool is_stable(int n, card* C) {
    for (int i = 1; i <= n - 1; i++)
        if (C[i].num == C[i - 1].num && C[i].id < C[i - 1].id)
            return false;
    return true;
}

int main() {
    int n; cin >> n;
    card Cards[n];
    for (int i = 0; i < n; i++) {
        cin >> Cards[i].moji >> Cards[i].num;
        Cards[i].id = i;
    }

    quick_sort(n, Cards, 0, n - 1);

    if (is_stable(n, Cards))
        cout << "Stable" << endl;
    else
        cout << "Not stable" << endl;
    for (int i = 0; i < n; i++)
        cout << Cards[i].moji << ' ' << Cards[i].num << endl;
}


Measured memory_bytes: 4196
#include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define FAST ios_base::sync_with_stdio(false);cin.tie(0);
    const double EPS = 1e-9;
    const double PI = acos(-1);
    const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
    //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
    //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
    const int dx[] = {0 , 1 , 0 , -1};
    const int dy[] = {1 , 0 , -1 , 0};
    //#define MOD         1000000007LL
    #define MAX         1000005
    const ll MOD = 1000000000 + 7;
    int arr[MAX] , n ;
    int fact[MAX];
    
    bool pairwise()
    {
        
        for(int i = 0 ; i < n ; i++)
        {
            int x = arr[i];
            for(int j = 1 ; j * j <= x ; j++)
            {
                if(x % j == 0)
                {
                    fact[j]++;
                    if(j > 1 && fact[j] >= 2)return false;
                    if(x / j != j)
                    {
                        fact[x / j]++;
                        if(fact[x / j] >= 2)return false;
                    }
                }
            }
        }
        
        return true;
    }
    
    bool setwise()
    {
        int ans = arr[0];
        
        for(int i = 1 ; i < n ; i++)
        {
            ans = __gcd(ans , arr[i]);
            
        }
        if(ans != 1)return false;
        return true;
    }
    
    int main()
    {
        FAST
        int t;
        t = 1;

        while(t--)
        {
           
           cin >> n;
           
           for(int i = 0 ;  i < n ; i++)cin >> arr[i];
        
           if(pairwise())cout << "pairwise coprime\n";
           else if(setwise())cout << "setwise coprime\n";
           else cout << "not coprime\n";
        }
    }



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

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

if(N==1||N==2||N==3||N==5||N==7|N==13||N==15||N==17||N==19||N==23||N==29||N==31){
cout<<1<<endl;
return 0;

}
if(N==4||N==6||N==9||N==10||N==14|N==21||N==22||N==25||N==26){
cout<<2<<endl;
return 0;

}

if(N==28||N==30){
cout<<4<<endl;
return 0;

}

if(N==8||N==12||N==18||N==20||N==27){
cout<<5<<endl;
return 0;

}

if(N==16){
cout<<14<<endl;
return 0;
}
if(N==24){
cout<<15<<endl;
return 0;

}

if(N==32){
cout<<51<<endl;
return 0;

}

}


Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)

	sc.Scan()
	s := sc.Text()

	ss := make([]rune, len(s))

	for i, v := range s {
		ss[i] = v
	}

	sc.Scan()
	p := sc.Text()

	pp := make([]rune, len(p))

	for i, v := range p {
		pp[i] = v
	}

	same := false
	for si, sv := range ss {
		if sv == pp[0] {
			same = true
			for pi, pv := range pp {
				sl := si + pi
				if len(ss)-1 < sl {
					sl = sl - len(ss)
				}
				if ss[sl] != pv {
					same = false
					break
				}
			}
			if same {
				break
			} else {
				continue
			}
		}
	}

	if same {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}



Measured memory_bytes: 1112
N, T = list(map(int, input().split()))
ct = [list(map(int, input().split())) for i in range(N)]

minimum = 1001
for cni in ct:
    if cni[1] <= T:
        minimum = min(cni[0], minimum)

answer = minimum if minimum < 1001 else 'TLE'

print(answer)


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

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

	// 幸福じゃない人たちを見る
	// 右向きの人達, 左向きの人たち
	int left = 0, right = 0;
	if(S[0] == 'L') left++;
	if(S[N-1] == 'R') right++;
	for(int i=0;i<N-1;i++) {
		if(S[i] == 'R' and S[i+1] == 'L') {
			right++;
			left++;
		}
	}
	if(left == right) {
		cout << N - ((left + right) - min(2 * K, left+right-1)) << endl;
	} else {
		int minval = min(left, right);
		cout << N - ((left+right) - 2 * min(minval, K)) << endl;
	}
}

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

int main() {
  int n;
  cin >> n;
  while (n > 1000) {
    n = n - 1000;
  }

  cout << 1000 - n << endl;
  return 0;
}

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


int main() {
  int N;
  cin>>N;
  vector<long> a(N);
  for(int i=0;i<N;i++) cin>>a[i];

  sort(a.begin(),a.end());
  //reverse(a.begin(),a.begin());
  vector<long> c(N);
  c[N/2]=a[0];

  int j=0,k=0;
  for(int i=0;i<N/2;i++){
    if(i%2==0){
      c[N/2-i-1]=a[N-1-j];
      c[N/2+i+1]=a[N-1-j-1];
      j+=2;
    }
    else{
      c[N/2-i-1]=a[k+1];
      c[N/2+i+1]=a[k+2];
      k+=2;
    }
  }
  long ans1=0;
  for(int i=0;i<N-1;i++) ans1+=abs(c[i+1]-c[i]);

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

  //vector<long> c(N);
  c[N/2]=a[0];

  j=0,k=0;
  for(int i=0;i<N/2;i++){
    if(i%2==0){
      c[N/2-i-1]=a[N-1-j];
      c[N/2+i+1]=a[N-1-j-1];
      j+=2;
    }
    else{
      c[N/2-i-1]=a[k+1];
      c[N/2+i+1]=a[k+2];
      k+=2;
    }
  }
  long ans2=0;
  for(int i=0;i<N-1;i++) ans2+=abs(c[i+1]-c[i]);

  cout<<max(ans1,ans2)<<endl;
  }


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

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

    if(a == 'H' && b == 'H')
    	cout << "H" << endl;
    else if(a == 'D' && b == 'D')
    	cout << "H" << endl;
    else
    	cout << "D" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

typedef string Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}


int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, m, st, go;
	int aaaa = 0;
	while (cin >> n >> m >> st >> go, n)
	{

		Graph tg(n), r(n);
		REP(i, m)
		{
			int a, b; string s; cin >> a >> b >> s;
			add_edge(tg, a, b, s);
			add_edge(r, b, a, s);
		}
		set<int> use;
		use.insert(go);
		queue<int> que;
		que.push(go);
		while (!que.empty())
		{
			int v = que.front();
			que.pop();
			for (auto e : r[v])
			{
				int u = e.to;
				if (use.count(u) > 0) continue;
				use.insert(u);
				que.push(u);
			}
		}
		if (use.count(st) == 0)
		{
			cout << "NO" << endl;
			continue;
		}
		Graph g(m * 10 + n);
		int tmp = n;
		REP(v, n)
		{
			if (use.count(v) == 0) continue;
			for (auto e : tg[v])
			{
				int src = v, dst = tmp;
				int u = e.to;
				string s = e.cost;
				tmp += s.size() - 1;
				if (use.count(u) == 0) continue;
				REP(i, s.size() - 1)
				{
					add_edge(g, src, dst, string{ s[i] });
					src = dst; dst++;
				}
				add_edge(g, src, u, string{ s.back() });
			}
		}

		REP(i, g.size())
		{
			sort(ALL(g[i]));
		}

		bool ok = false;
		set<pii> vis;
		map<int, string> mp;
		queue<pair<int, string>> que2;
		que2.emplace(st, "");
		while (!que2.empty())
		{
			int v = que2.front().first;
			string tmp = que2.front().second;
			que2.pop();
			if (mp[tmp.size()] < tmp) continue;
			if (v == go)
			{
				ok = true;
				cout << tmp << endl;
				break;
			}
			if (tmp.size() > 2500) break;
			if (vis.count(pii(v, tmp.size())) == 1) continue;
			vis.emplace(v, tmp.size());


			string c = g[v][0].cost;
			for (auto e : g[v])
			{
				if (e.cost != c) break;
				string nx = tmp + c;
				if (mp.count(nx.size()) == 0) mp[nx.size()] = nx;
				else chmin(mp[nx.size()], nx);
				que2.emplace(e.to, nx);
			}
		}
		if (!ok) cout << "NO" << endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  
  int c = 0;
  for (int i = 1; i <= n; i++) {
    int v;
    cin >> v;
    if (i % 2 == 1 && v % 2 == 1) {
      c++;
    }
  }
  cout << c << endl;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int n;
	cin >> n;
	vector<int> w(n);
	rep(i, n)cin>>w[i];

	vector<int> b(n+1);
	b[0] = 0;
	rep(i,n){
		b[i+1] = b[i] + w[i];
	}
	
	ll ans = 10001010;
	ll sum = b[n];
	rep(i,n+1){
	 	chmin(ans, abs(b[i] - (sum - b[i])) );
	}
	cout << ans << endl;
}


Measured memory_bytes: 3588
import Data.List

main = print . solve . map read . drop 1 . words =<< getContents

solve :: [Int] -> Int
solve xs =
    let s = sort xs
        t = sum s
    in  if mod t 10 /= 0 then t
        else (-) t . head $ (filter (\x -> mod x 10 /= 0) s) ++ [t]


Measured memory_bytes: 1020
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        if ((n + 1) / 2 >= k) {
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
    }

}


Measured memory_bytes: 22608
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

int dp[5005][5005];

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

	dp[0][0] = 1;
	FOR (j,1,n+1) {
		REP (i,j+1) {
			if (i == 0) {
				dp[i][j] = dp[1][j-1] + dp[0][j-1];
			} else {
				dp[i][j] = dp[i+1][j-1] + 2 * dp[i-1][j-1];
			}
			dp[i][j] %= mod;
		}
	}
	int ans = dp[s.size()][n];
	REP (i,s.size()) {
		if (ans%2==0) {
			ans /= 2;
		} else {
			ans = (mod + ans) / 2;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 196864
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        string[] s = Console.ReadLine().Split();
        Console.WriteLine(s[0].ToUpper()[0].ToString()+ s[1].ToUpper()[0].ToString()+ s[2].ToUpper()[0].ToString());
    }
}

Measured memory_bytes: 11092
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[][] a = new long[n][3];
        for(int i=0; i<n; i++){
            a[i][0] = sc.nextLong();
            a[i][1] = sc.nextLong();
            a[i][2] = (a[i][0] + a[i][1]);
        }

        Arrays.sort(a, (aa, ab) -> Long.compare(aa[2], ab[2]));

        long ma = 0;
        long mb = 0;
        int posl = 0;
        int posr = n-1;

        for(int i=0; i<n; i++){
            if(i % 2 == 0){
                ma += a[n-i-1][0];
            }else{
                mb += a[n-i-1][1];
            }
        }

        System.out.println(ma - mb);

    }
}

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

typedef long long ll;
typedef long double ld;
// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// use merge(all(vec1), all(vec2), vec3.begin()) to merge 2 vectors, use vec3.resize(vec1.size() + vec2.size()) first
// ll pos = partition_point(all(vec), pred) - vec.begin(); bool pred(ll a){return a<3};
// print number in binary -> cout << bitset<20>(n);
#define inf 9e18+1


int n;
int ar[502][502];
bool dead[502][502];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

void dfs(int y,int x){
	int z=ar[y][x]+!dead[y][x];
	for(int i=0;i<4;++i){
		int y1=y+dy[i];
		int x1=x+dx[i];
		if(ar[y1][x1]>z){
			ar[y1][x1]=z;
			dfs(y1,x1);
		}
	}
}

int main(){
	cin>>n;
	for(int i=0;i<n+2;++i)
		ar[n+1][i]=ar[i][n+1]=ar[0][i]=ar[i][0]=-10;
	for(int i=1;i<n+1;++i)
		for(int j=1;j<n+1;++j)
			ar[i][j]=min({i-1,j-1,n-i,n-j});
	ll res=0;
	for(int i=0;i<n*n;++i){
	//	for(int i=0;i<n+2;++i,cout<<endl)
	//		for(int j=0;j<n+2;++j)
	//			cout<<ar[i][j]<<" ";
	// cout<<res<<endl;	
		int viewer;cin>>viewer;
		--viewer;
		int y=viewer/n+1;
		int x=viewer%n+1;
		res+=ar[y][x];
		dead[y][x]=true;
		dfs(y,x);
	}
	cout<<res<<endl;
}


Measured memory_bytes: 19824
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, N;  string S, A;
  cin >> K >> S;
  N = S.size();
  if(N <= K){
  cout << S << endl;
  }
  else{
    for(int i = 0; i < K;i++){
    A = A + S.at(i);
    }
    A = A + "...";
  }     
  cout << A << endl;
}

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
int main(){
	int N;
	int A[200000];
	int max=0;
	long long total = 0LL;
	cin >> N;
	for (int a = 0;a < N;a++)
		cin >> A[a];
	max = A[0];
	for (int i = 1;i < N;i++) {
		if (max < A[i])
			max = A[i];
		
		total += max - A[i];
	}
	cout << total;
 
}

Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
ll n,k;
ll a[20];
ll ans=1000000000000000000;
int main(void){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int bit=0;bit<(1<<n);bit++){
        int c=0;
        for(int i=0;i<n;i++){
            if((1<<i)&bit) c++;
        }
        if(c>=k){
            ll m=0;
            ll C=0;
            for(int i=0;i<n;i++){
                if((1<<i)&bit){
                    if(m<a[i]){
                        m=a[i];
                    }else{
                        C+=(m-a[i]+1);
                        m++;
                    }
                }else{
                    m=max(m,a[i]);
                }
            }
            ans=min(ans,C);
        }
    }
    cout<<ans<<endl;
    
}


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


long comb[51][51] = {0};
int N, P;
long A[51] = {0};

void combination(int n){
    for (int i = 0; i <= n; ++i){
        comb[i][0] = 1;
        comb[i][i] = 1;
    }
    for(int i = 2; i <= n; ++i){
        for(int j = 1; j < i; ++j){
            comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
        }
    }
}

void solve(){
    combination(N);
    int cnt_even = 0;
    int cnt_odd = 0;
    for(int i = 0; i < N; ++i){
        if(A[i] % 2 == 0) cnt_even++;
        else cnt_odd++;
    }
    combination(N);
    long total_even = 0;
    long total_odd = 0;
    if(P == 0){
        for(int i = 1; i <= cnt_even; ++i){
            total_even += comb[cnt_even][i];
        }
        for(int i = 2; i <= cnt_odd; i+=2){
            total_odd += comb[cnt_odd][i];
        }    
        cout << 1 + total_odd + total_even + total_even * total_odd << "\n";
        return ;
    }else{
        for(int i = 1; i <= cnt_even; ++i){
            total_even += comb[cnt_even][i];
        }
        for(int i = 1; i <= cnt_odd; i += 2){
            total_odd += comb[cnt_odd][i];
        }
        cout << (total_even + 1) * total_odd << "\n";
        return ;
    }
}


int main(){
    cin >> N >> P;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
  int cards[4][13] = {0}; //持ってると１
  int i, j, n, tempInt;
  char tempChar[2];

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%s %d", tempChar, &tempInt);

    switch (tempChar[0]) {
      case 'S':
        cards[0][tempInt - 1] = 1;
        break;
      case 'H':
        cards[1][tempInt - 1] = 1;
        break;
      case 'C':
        cards[2][tempInt - 1] = 1;
        break;
      case 'D':
        cards[3][tempInt - 1] = 1;
        break;
    }
  }

  for (i = 0; i < 4; i++) {
    for (j = 0; j < 13; j++) {
      if (cards[i][j] == 0) {
        switch (i) {
          case 0:
            printf("S ");
            break;
          case 1:
            printf("H ");
            break;
          case 2:
            printf("C ");
            break;
          case 3:
            printf("D ");
            break;
        }
        printf("%d\n", j + 1);
      }

    }
  }
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int N;
  cin >> N;
  vector<int> a(N), b(N), c(N);
  for (int i=0; i<N; i++){
    cin >> a.at(i) >> b.at(i) >> c.at(i);
  }
  
  vector<int> dp0(N), dp1(N), dp2(N);
  dp0.at(0)=a.at(0);
  dp1.at(0)=b.at(0);
  dp2.at(0)=c.at(0);
  for (int i=1; i<N; i++){
  	dp0.at(i)=max(dp1.at(i-1)+a.at(i),dp2.at(i-1)+a.at(i));
    dp1.at(i)=max(dp0.at(i-1)+b.at(i),dp2.at(i-1)+b.at(i));
    dp2.at(i)=max(dp0.at(i-1)+c.at(i),dp1.at(i-1)+c.at(i));
  }
  
  cout << max({dp0.at(N-1),dp1.at(N-1),dp2.at(N-1)})<<endl;
  
}

Measured memory_bytes: 2560
def resolve():
    n=int(input())
    A=[int(i) for i in input().split()]
    B=[A[0]]+[A[i+1]-A[i] for i in range(n-1)]+[-A[n-1]]
    abssum=sum(abs(b) for b in B)
    for i in range(n):
        print(abssum-abs(B[i])-abs(B[i+1])+abs(B[i]+B[i+1]))
resolve()

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

int n;
long k,a[200010],f[200010];
bool bi_se(long x);

int main(void){
  int i;
  long x,l=0,r=1e18;
  cin >> n >> k;
  for (i=0;i<n;i++) cin >> a[i];
  for (i=0;i<n;i++) cin >> f[i];
  sort(a,a+n);
  sort(f,f+n,greater<long>());
  while (r-l>1){
    x=(l+r)/2;
    if (bi_se(x)) r=x;
    else l=x;
  }
  if (bi_se(l)) cout << l << endl;
  else cout << r << endl;
  return 0;
}

bool bi_se(long x){
  int i;
  long u=k,m;
  bool dn[200010]={false};
  for (i=0;i<n;i++){
    m=x/f[i];
    if (a[i]-m>u) break;
    if (a[i]>m) u-=a[i]-m;
  }
  return i==n;
}

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

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

    int x=a*p;
    int y=b+max(0,p-c)*d;

    cout<<min(x,y)<<endl;
    return 0;
}

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

int main(){
    int N, x, count = 0;
    long long sum = 0;
    cin >> N >> x;
    int a[100];
    for(int i=0;i<N;i++){
        cin >> a[i];
        sum += a[i];
    }
    if(x == sum){
        cout << N << endl;
    }else if(x > sum){  //お菓子過多
        cout << N - 1 << endl;
    }else{  //お菓子不足
        sort(a, a + N);
        for(int i=0;i<N;i++){
            x -= a[i];
            if(x < 0)
                break;
            count++;
        }
        cout << count << endl;
    }    
    return 0;
}

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

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

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

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

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

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

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

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

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

ll n, k;
vector<vl> a(51);
std::vector<vl> identity;

vector<vl> mul(vector<vl> a, vector<vl> b){
    ll n = a.size();
    vector<vl> ans(n);
    for(ll i=0; i<n; i++){
        for(ll j=0; j<n; j++){
            ll res = 0;
            for(ll k=0; k<n; k++){
                res = (res%mod + (a[i][k]%mod*b[k][j]%mod)%mod)%mod;
            } 
            ans[i].pb(res);
        }
    }
    ret ans;
}


vector<vl> bin_exp(vector<vl> a, ll k){

    if(k==0) ret identity;
    std::vector<vl> temp = bin_exp(a, k/2);
    if(k&1){
        return mul(mul(temp, temp), a);
    }
    else return mul(temp, temp);
}

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

    ll n, k;
    cin>>n>>k;
    for(ll i=0; i<n; i++){
        vl v;
        loop(j,0,n){
            if(i==j) v.pb(1);
            else v.pb(0);
        }
        identity.pb(v);
    }
    loop(i,0,n){
        loop(j,0,n){
            ll x;
            cin>>x;
            a[i].pb(x);
        }
    }

    vector<vl> op = bin_exp(a, k);

    ll fin_ans = 0;
    for(ll i=0; i<n; i++){
        for(ll j=0; j<n; j++){
            fin_ans = (fin_ans%mod + op[i][j]%mod)%mod;
        }
    }
    print(fin_ans);
        
    
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

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


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int N,i,c=0;
    scanf("%d",&N);
    int arr[N];
    for(i=0;i<N;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=0;i<N;i++)
    {
        if(i%2==0)
        {
            if(arr[i]%2!=0)
                c++;
        }
    }
    printf("%d\n",c);

    return 0;
}


Measured memory_bytes: 1724
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

setrecursionlimit(10**6)

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

n, m = reads()

d = dict()
edges = [[] for _ in range(n)]

for i in range(m):
  u, v, s = reads()
  u, v = u-1, v-1
  edges[u].append((s, v))
  edges[v].append((s, u))

def quit(x):
  print(x)
  exit()

cond = [[None] * n for _ in range(2)]
cond[0][0] = 0

INF = 10**16

visited = [False] * n

def walk(x):
  if visited[x]:
    return
  visited[x] = True
  for s, y in edges[x]:
    for sig in range(2):
      if cond[sig][x] is not None:
        p = cond[sig][x]
        if cond[1-sig][y] is None or cond[1-sig][y] == s - p:
          cond[1-sig][y] = s - p
        else:
          quit(0)
    walk(y)

walk(0)

for i in range(n):
  if cond[0][i] is not None and cond[1][i] is not None:
    x = (cond[1][i] - cond[0][i]) // 2
    for i in range(n):
      if cond[0][i] is not None and cond[0][i] + x <= 0:
        quit(0)
      if cond[1][i] is not None and cond[1][i] - x <= 0:
        quit(0)
      if cond[0][i] is not None and cond[1][i] is not None and x + cond[0][i] != cond[1][i] - x:
        quit(0)
    quit(1)

pmin = min(p for p in cond[0] if p is not None)
nmin = min(p for p in cond[1] if p is not None)

print(max(0, nmin + pmin - 1))


Measured memory_bytes: 133772
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
vector<pii> edges[1000005];
int num[100005];
int p[100005];
int root(int a){
    return p[a] == a?a:(p[a]=root(p[a]));
}
void merge(int a, int b){
    a = root(a), b = root(b);
    if(a != b) p[a] = b;
}
int dp[300005];
bool vis[300005];
vector<pii> g[300005];
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i=1;i<=n;i++) p[i] = i;
    int cnt = n+1;
    for(int i=1;i<=m;i++){
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        edges[c].push_back(pii(a, b));
    }
    vis[n] = 1;
    for(int i=1;i<=1000000;i++){
        vector<int> v;
        for(int j=0;j<edges[i].size();j++){
            int a = edges[i][j].first, b = edges[i][j].second;
            v.push_back(a);
            v.push_back(b);
            merge(a, b);
        }

        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());

        for(int i=0;i<v.size();i++){
            int u = v[i];
            if(root(u) == u) num[u] = cnt++;
        }

        for(int i=0;i<v.size();i++){
            int u = v[i];
            g[u].push_back(pii(num[root(u)], 1));
            g[num[root(u)]].push_back(pii(u, 0));
            if(u == n){
                vis[u] = 1;
                vis[num[root(u)]] = 1;
            }
        }

        for(int i=0;i<v.size();i++){
            int u = v[i];
            p[u] = u;
        }
    }
    memset(dp, -1, sizeof(dp));
    queue<int> q;
    dp[1] = 0;
    q.push(1);
    while(!q.empty()){
        int u = q.front();
        q.pop();
        if(vis[u]){
            printf("%d\n", dp[u]);
            return 0;
        }
        for(int i=0;i<g[u].size();i++){
            int v = g[u][i].first, w = g[u][i].second;
            if(dp[v] == -1 || dp[v] > dp[u] + w){
                q.push(v);
                dp[v] = dp[u] + w;
            }
        }
    }
    printf("-1\n");
}

Measured memory_bytes: 50816
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int a,b,c; cin >> a >> b >> c;
    out(min(b/a,c));

    return 0;
}

Measured memory_bytes: 256
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

const LL INF = 1LL << 60;

struct Edge {
	int from;
	int to;
	int cost;
};

int main(int argc, char* argv[]) {
	int n, m, p;
	cin >> n >> m >> p;
	vector<Edge> edges;
	for (int i = 0; i < m; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		edges.push_back({ a - 1, b - 1, -(c - p) });
	}
	vector<LL> costs(n, INF);
	costs[0] = 0;
	LL ans = 0;
	for (int i = 0; i < m * 2; ++i) {
		for (int j = 0; j < m; ++j) {
			if (costs[edges[j].from] >= INF) continue;
			LL cost = costs[edges[j].from] + edges[j].cost;
			if (cost < costs[edges[j].to]) {
				costs[edges[j].to] = cost;
				if (edges[j].to == n - 1) {
					ans = max(0LL, -cost);
					if (i >= m) {
						ans = -1;
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const long long MOD = 1000000007;

typedef long long ll;

int main(void) {
  int x, a, b;
  int n;
  cin >> x >> a >> b >> n;
  rep(i, n) {
    char s[10];
    cin >> s;
    if (s[0] == 'n') x += a;
    if (s[0] == 't') x += b;
    if (s[0] == 'k') x = 0;
    if (x < 0) x = 0;
  }
  cout << x << endl;

  return 0;
}




Measured memory_bytes: 3100
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	static int n,m;
	static int a[100010],b[100010];
	scanf("%d%d",&n,&m);
	rep1(i,m){
		scanf("%d%d",&a[i],&b[i]);
	}
	
	static set<int> G[100010];
	static set<int> _G[100010];
	rep1(i,m){
		G[a[i]].insert(b[i]);
		G[b[i]].insert(a[i]);
	}
	rep1(i,n)_G[i] = G[i];
	vector<int> ret;
	ret.pb(1);
	int loc = 1;
	for(int v: _G[loc]){
		G[v].erase(loc);
	}
	while(!G[loc].empty()){
		loc = *G[loc].begin();
		ret.pb(loc);
		for(int v: _G[loc]){
			G[v].erase(loc);
		}
	}
	rev(ret);
	loc = 1;
	while(!G[loc].empty()){
		loc = *G[loc].begin();
		ret.pb(loc);
		for(int v: _G[loc]){
			G[v].erase(loc);
		}
	}
	cout << ret.size() << endl;
	rep(i,ret.size()){
		printf("%d%c",ret[i],i+1==ret.size()?'\n':' ');
	}
}

Measured memory_bytes: 30204
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
#define  st first
#define  nd second
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
 
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
 
 
#define MOD   1000000007
const int LN =19;
#define int long long
const int  MAXN = 100004;
 
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef cc_hash_table<int, int, hash<int > > ht;
 
int mu[MAXN];
int f[MAXN];
int n , k ; 
void mobius(){
     mu[1] = 1;
	 for (int i = 1; i < MAXN; i++)
		for (int j = 2*i; j < MAXN; j += i)
		{
				mu[j] -= mu[i];
		}
}
 
int modular_pow(int  base, int exponent, int modulus)
{
    int result = 1;
    while (exponent > 0)
    {
        if (exponent % 2 == 1)
            result = (result * base) % modulus;
        exponent = exponent >> 1;
        base = (base * base) % modulus;
    }
    return result;
}
int fact[MAXN];
int invf[MAXN]; 

void fun(){
  for(int i=1;i<MAXN;i++){
    for(int j=i;j<MAXN;j+=i){
        f[j]= ((f[j]+((i*mu[j/i])%MOD))%MOD + MOD)%MOD;
    }
  }
 
}
int solve(){
   int ans=0;
   for(int d=1;d<=k;d++){
    ans=(ans+((f[d]* modular_pow(k/d,n ,MOD))%MOD))%MOD;
   }
   return ans;
}
void precal(){
  fact[0] = 1 ; 
  for(int i = 1; i<MAXN ; i++){
      fact[i] = (fact[i-1]*i)%MOD;
      invf[i] = modular_pow(fact[i],MOD-2,MOD);
  }
  mobius();
  fun();
}
int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  precal();
  n = 3;
  cin>> k ;
  cout<<solve();
}
 
 

Measured memory_bytes: 6820
#include <stdio.h>
int main(void){                                                                                                           int N;                                                                                                                  int H[1000010];                                                                                                         scanf("%d",&N);                                                                                                         int i;                                                                                                                  for(i=0;i<N;i++){                                                                                                         scanf("%d",&H[i]);                                                                                                    }
  for(i=N-1;i>0;i--){
    if(H[i-1]-H[i]>=2){
      printf("No\n");
      return 0;
    }
    else if(H[i-1]-H[i]==1){
      H[i-1]--;                                                                                                             }
  }
  printf("Yes\n");
  return 0;
}

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

int main()
{
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (to_string(i).length() % 2 != 0) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////



int main(){fastio
    
    ll h,w,a,b;cin>>h>>w>>a>>b;
    ll ans[h][w];memset(ans,-1,sizeof(ans));
    rep(i,0,h-1)rep(j,0,w-1){
        if(i<=b-1)ans[i][j]*=-1;
        if(j<=a-1)ans[i][j]*=-1;
    }
    rep(i,0,h-1){
        rep(j,0,w-1){
            if(ans[i][j]==-1)ans[i][j]=0;
        }
    }
    rep(i,0,h-1){
        rep(j,0,w-1){
            cout<<ans[i][j];
        }cout<<endl;
    }
    
    return 0;
}





Measured memory_bytes: 9088