akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-3
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
const ll mod = 1e9 + 9;
const db pi = acos(-1.0);
const ll maxn = 5e5+10;
vector<int > a;
signed main(){
    ll n = 0;
    cin >> n;
    string s = "";
    while (n)
    {
        s += char((--n)%26 + 'a');
        n /= 26;
    }
    for(int i = s.size()-1; i>=0;i--){
        cout << s[i];
    }
}

Measured memory_bytes: 3636
import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);
        String b = sc.next();

        switch (b) {
            case "A":
                System.out.println("T");
                break;
            case "T":
                System.out.println("A");
                break;
            case "C":
                System.out.println("G");
                break;
            case "G":
                System.out.println("C");
                break;
        }
     }

}

Measured memory_bytes: 21716
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(void) {
	int N, L;
	scanf("%d %d", &N, &L);
	vector<int> apple(N);
	int ans = 0;
	int minimun = 1000;
	int eatApple;
	for (int i = 1; i < N + 1; i++) {
		int taste = L + i - 1;
		ans += taste;
		if (minimun > abs(taste)) {
			minimun = abs(taste);
			eatApple = taste;
		}
		// printf("%d\n", eatApple);
	}
	ans -= eatApple;
	printf("%d", ans);
	return 0;
}


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

int main(){
    int N;
    cin >> N;
    int alice = 0;
    int kirito = 0;
    vector<int>vec(N); 
    for(int i = 0; i < N; i++){
    cin >>vec[i];
    }
    sort(vec.begin(), vec.end()); 
    reverse(vec.begin(), vec.end()); 
    for(int i = 0; i < N; i++){
    if(i%2 == 0){
      alice+=vec[i];
    }
    else{
      kirito+=vec[i];
    }
    }
    cout << alice - kirito <<endl;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

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

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n,m,a;
    cin >> n >> m;
    vll d(n+1);
    rep(i,n+1) d[i]=0;
    rep(i,m){
        cin >> a;
        d[a]=-1;
    }
    d[n]=1;
    if(d[n-1]!=-1) d[n-1]=1;
    for(ll i=n-2;i>=0;i--){
        if(d[i]==-1) continue;
        if(d[i+1]!=-1) d[i]+=d[i+1];
        d[i]%=1000000007;
        if(d[i+2]!=-1) d[i]+=d[i+2];
        d[i]%=1000000007;
    }
    cout << d[0] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
	using namespace std;
	#define mp make_pair
	#define ll long long
	#define pb push_back
	#define mp make_pair
	#define M LONG_LONG_MAX
	#define IM INT_MAX
	#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int32_t main()
    {
		IOS;
		ll n,m,i,j,k;
        string s;
        cin>>s;
        if(s.length()==4)
        {
            char c,d;
            ll x=0,y=0;
            for(i=0;i<s.length();i++)
            {
                if(!i)
                {c=s.at(i);
                ++x;
                    continue;
                }
                if(s.at(i)==c)
                ++x;
                else if(s.at(i)!=c&&!y)
                {
                    d=s.at(i);
                    ++y;
                }
                else if(s.at(i)==d)
                ++y;
                else
                {
                    cout<<"No";
                    return 0;
                }
            }
            if(x==2&&y==2)
            {
                cout<<"Yes";
            }
            else
            cout<<"No";
        }
        else
        cout<<"No";
	}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
 
int main() {
    int cach;
    int n, x;
    while (true){
        cach = 0;
        cin >> n >> x;
        if (n == 0 && x == 0) break; 
        for (int i = 1; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = j + 1; k <= n; k++) {
                    if (i + j + k == x) cach++;
                }
            }
        }
        cout << cach << endl;
    }
    return 0;
}

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

int main(){
  int s;
  cin >> s;
  int count = 4;
  if (s == 1 or s == 2){
    cout << 4 << endl;
  }
  else{
    while (true){
      if (s == 4){
        cout << count << endl;
        return 0;
      }
      else{
        if (s % 2 == 0){
          s /= 2;
        }
        else{
          s = s * 3 + 1;
        }
        count += 1;
      }
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <limits.h>
using namespace std;
int dist[100][100]; //距離,道がないところはINF
int mincost[100];
bool used[100];
int n; //頂点数
//prim法
int prim(){
	for(int i=0;i<n;i++) mincost[i]=INT_MAX, used[i]=false;
	int res=0; mincost[0]=0;
	while(1){
		int v=-1;
		for(int u=0;u<n;u++) if(!used[u] && (v==-1 || mincost[u]<mincost[v])) v=u;
		if(v==-1) break;
		used[v]=true;
		res+=mincost[v];
		//距離の更新
		for(int u=0;u<n;u++) mincost[u]=min(mincost[u],dist[v][u]);
	}
	return res;
}
int main() {
	int m;
	while(1){
		cin >> n ; if(!n) break;
		cin >> m ;
		for(int i=0;i<100;i++) for(int j=0;j<100;j++) dist[i][j]=INT_MAX;
		for(int i=0;i<m;i++){
			int st,fin,DIST; scanf("%d,%d,%d",&st,&fin,&DIST);
			dist[st][fin]=dist[fin][st]=DIST/100;
		}
		cout << prim()-(n-1) << '\n';
	}
}

Measured memory_bytes: 1284
def gcd(numbers):
    numbers.sort()
    a = numbers[1]
    b = numbers[0]
    ans = b
    while True:
        q, mod = divmod(a, b)
        if mod == 0:
            break
        a = b
        b = mod
        ans = mod
    return ans

K = int(input())
numbers = []

for i in range(K, 0, -1):
    for j in range(i, 0, -1):
        for k in range(j, 0, -1):
            numbers.append([i, j, k])

gcd_sum = 0
for number in numbers:
    dup = len(set(number))
    a, b, c = number
    if dup == 1:
        gcd_sum += gcd([gcd([a, b]), c])
    elif dup == 2:
        gcd_sum += gcd([gcd([a, b]), c]) * 3
    else:
        gcd_sum += gcd([gcd([a, b]), c]) * 6

print(gcd_sum)


Measured memory_bytes: 225048
# アリ１からNまでの前後関係は不変。つまり、アリ１からNまでの順番は保たれる。
# アリの最終座標の昇順リストを用意して、アリ１からNに対応させればよい。

n,l,t=map(int,input().split())
x=[]
w=[]
ans=[]

crash=0
for i in range(n):
    xx,ww=map(int,input().split())
    x.append(xx); w.append(ww)
    if w[i]==1: anss=(x[i]+t)%l
    else: anss=(x[i]-t+l)%l
    ans.append(anss)
    if i!=0 and w[i] != w[0]:
        if w[0] == 1: crash += (t-((x[i]-x[0])/2)) // (l/2) + 1
        else: crash += (t-(l-(x[i]-x[0]))/2) // (l/2) + 1

# あり１の現在のゼッケン番号num0
if w[0]==1: num0 =int(crash)%n
else: num0 =int(-crash)%n
# あり１の現在地点に対応する昇順リストの番号num
nowplace = ans[0]
ans.sort()
num = ans.index(nowplace)
if w[0]==1 and ans.count(nowplace)==2: num += 1 # ２つ該当する場合の処理
# numがnum0の位置であるように調整したい
gap = num0-num
for i in range(n):
    i = (i-gap)%n
    print(ans[i])



Measured memory_bytes: 12888
let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  Array.to_list as_
  |> (fun (h :: t) ->
    List.fold_left (fun (acc, a, dir) a' ->
      if dir = 0 || compare a a' = dir then (acc, a', compare a a')
      else if compare a a' = 0 then (acc, a', dir)
      else (1 + acc, a', 0)) (1, h, 0) t)
  |> (fun (acc, _, _) -> acc)
  |> Printf.printf "%d\n"


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  printf("%.12lf\n", ((N+1)/2)/(double)N);
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int ar[100000];
int max(int a,int b){return a>b?a:b;}
int main(){
	int n,k;
	int i,j;
	while(1){
	int ans=0;
	scanf("%d %d",&n,&k);
	if(n==0)return 0;
	for(i=0;i<n;i++)scanf("%d",&ar[i]);
	int res=0;
	for(i=0;i<k;i++)res+=ar[i];
	ans=max(ans,res);
	for(i=k;i<n;i++){
		res+=ar[i];
		res-=ar[i-k];
		ans=max(ans,res);
	}
	printf("%d\n",ans);
	}
}

Measured memory_bytes: 1416
N = int(input())

odd = list()

count_list = list()
count = 0

for a in range(1, N+1):
    if a % 2 != 0:
        odd.append(a)

l = len(odd)

for a in range(0, l):
    for b in range(1, odd[a]+1):
        if odd[a] % b == 0:
            count += 1
    count_list.append(count)
    count = 0

print(len(list(filter(lambda x: x == 8, count_list))))


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound


struct UF {
    static const int N = 410 * 410;//書き換え!
    int par[N];
    int b[N];
    int w[N];

    UF() {
        rep(i, N) {
            par[i] = i;
        }
    }

    void color(int x, bool black) {
        if (black)b[x] = 1;
        else w[x] = 1;
    }

    void init() {
        rep(i, N) {
            par[i] = i;
        }
    }

    int root(int x) {
        if (par[x] == x)return x;
        return par[x] = root(par[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y)return;
        par[x] = y;
        b[y] += b[x];
        w[y] += w[x];
    }

    bool isRoot(int x) {
        return par[x] == x;
    }
};

UF uf;
string S[410];
int H, W;

signed main() {
    cin >> H >> W;
    rep(i, H) {
        cin >> S[i];
        rep(j, W) {
            uf.color(i * W + j, S[i][j] == '#');
        }
    }
    rep(i, H) {
        rep(j, W - 1) {
            if (S[i][j] != S[i][j + 1]) {
                uf.unite(i * W + j, i * W + j + 1);
            }
        }
    }

    rep(i, H - 1) {
        rep(j, W) {
            if (S[i][j] != S[i + 1][j]) {
                uf.unite(i * W + j, (i + 1) * W + j);
            }
        }
    }

    int ans = 0;
    rep(i, W * H) {
        if (uf.isRoot(i)) {
            ans += uf.b[i] * uf.w[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

priority_queue<ll,vector<ll>,greater<ll>> lnum;

void build(string s, int i)
{
    if(i == 0)
    {
        ll tmp = stoll(s);
        lnum.push(tmp);
        return;
    }
    char last = s.back();
    if(last - '0' > 0)
    {
        string next_1 = s;
        next_1.push_back(last - 1);
        build(next_1,i-1);
    }  
    string next_2 = s;
    next_2.push_back(last); 
    build(next_2,i - 1);
    if('9' - last > 0)
    {
        string next_3 = s;
        next_3.push_back(last + 1);
        build(next_3,i-1);
    }
    return;
}

void solve()
{
    int k; cin >> k;
    rep(i, 10)reps(j, 9)
    {
        char c = char('0'+ j);
        string first(1, c);
        build(first,i);
    }
    int cnt = 0;
    while(true)
    {
        cnt++;
        if(cnt == k)
        {
            cout << lnum.top() << endl;
            return;
        }
        lnum.pop();
    }
    return;
}

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


Measured memory_bytes: 2420
// Problem: A - Takoyaki
// Contest: AtCoder - AtCoder Beginner Contest 176
// URL: https://atcoder.jp/contests/abc176/tasks/abc176_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>inline void read(T &FF){
	T RR=1;FF=0;char CH=getchar();
	for(;!isdigit(CH);CH=getchar())if(CH=='-')RR=-1;
	for(;isdigit(CH);CH=getchar())FF=(FF<<1)+(FF<<3)+(CH^48);
	FF*=RR;
}
int main(){
	int n,x,t;read(n);read(t);read(x);
	if(n%t==0)cout<<n/t*x;
	else cout<<(n/t+1)*x;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <class T>
using ordered_set =
       tree <T,null_type,less <T>,rb_tree_tag,tree_order_statistics_node_update> ;
///find_by_order()
///order_of_key()

template <class T,class U>
void maximize(T &x,U y){
    if(x < y)x=y;
}
template <class T,class U>
void minimize(T &x,U y){
    if(x > y)x=y;
}
template <class T>
T Abs(T x){
    return (x < (T)0 ? -x : x);
}
template <class T>
T safe_sqrt(T x){
    return sqrt(max(x,(T)0));
}
template <class T,class U,class V>
T addmod(T x,U k,V MOD){
    return ((x+k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T submod(T x,U k,V MOD){
    return ((x-k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T mul(T x,U y,V MOD){
    return ( (x % MOD) * (y % MOD) ) % MOD;
}

#define ll long long
#define pll pair <ll,ll>
#define pii pair <int,int>
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define emp emplace_back
#define MASK(i) ((1LL)<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)((c).size())
#define fn "test"    ///FILE_NAME_HERE

/*------------------------------------------END_OF_TEMPLATE------------------------------------------*/

namespace task{

	const int maxValues = 1e5;
	int f[102][maxValues + 2];
	int n,W;
	int w[102],v[102];

    void solve(){
    	cin>>n>>W;
    	int sumValues = 0;
    	for(int i = 1;i <= n;++i){
    		cin>>w[i]>>v[i];
    		sumValues += v[i];
    	}
    	for(int i = 0;i <= n;++i){
    		for(int j = 0;j <= sumValues;++j){
    			f[i][j] = -1;
    		}
    	}
    	f[0][0] = W;
    	for(int i = 1;i <= n;++i){
    		for(int j = 0;j <= sumValues;++j){
    			f[i][j] = f[i - 1][j];
    			if(j - v[i] >= 0 and f[i - 1][j - v[i]] - w[i] >= 0){
    				maximize(f[i][j],f[i - 1][j - v[i]] - w[i]);
    			}
    		}
    	}
    	for(int j = sumValues;j >= 0;--j){
    		if(~f[n][j]){
    			cout<<j,exit(0);
    		}
    	}
    }
}

int main(void){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    task::solve();
}


Measured memory_bytes: 39680
i[100012],d[100012],s,w,n,a,x,y;
main()
{
  for(w=scanf("%d",&n);a++<n;d[y]++)
      scanf("%d%d",&x,&y),i[x]++;
  for(a=2;a<=n+1;w-=d[a++])
    {
      w+=i[a];
      w>=a?s=a-1:0;
    }
  printf("%d\n",s);
  exit(0);
}

Measured memory_bytes: 1140
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    a = ii()
    for i in range(1,10):
        for j in range(1,10):
            if a == i*j:
                print('Yes')
                exit()
    print('No')

main()


Measured memory_bytes: 22532
import itertools

N, A, B, C = map(int, input().split())
l = [0] * N
for i in range(N):
  l[i] = int(input())
mplist = []
for r in itertools.product([0, 1, 2, 3], repeat = N):
  mp = 0
  use = 0
  le = [0] * 4
  for i in range(N):
    le[r[i]] += l[i]
    if r[i] >= 1:
      use += 1
  if le[1] == 0 or le[2] == 0 or le[3] == 0:
    continue
  mp = (use - 3) * 10 + abs(le[1] - A) + abs(le[2] - B) + abs(le[3] - C)
  mplist.append(mp)
print(min(mplist))

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

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

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N;
    cin >> N;
    ll A[N];
    rep(i,N) {
        cin >> A[i];
    }
    ll ans = 0;
    ll now = 0;
    rep(i,N) {
        if (i==0) {
            now = A[i];
        }
        else {
            if (A[i]<now) {
                ans += now-A[i];
            }
            else {
                now = A[i];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5156
abcd = list(input())
a,b,c,d = map(int, abcd)

res = ""

if a + b + c + d == 7:
    res = str(a)+"+"+str(b)+"+"+str(c)+"+"+str(d)+"=7"
elif a + b + c - d == 7:
    res = str(a)+"+"+str(b)+"+"+str(c)+"-"+str(d)+"=7"
elif a + b - c + d == 7:
    res = str(a)+"+"+str(b)+"-"+str(c)+"+"+str(d)+"=7"
elif a + b - c - d == 7:
    res = str(a)+"+"+str(b)+"-"+str(c)+"-"+str(d)+"=7"
elif a +- b + c + d == 7:
    res = str(a)+"-"+str(b)+"+"+str(c)+"+"+str(d)+"=7"
elif a - b + c - d == 7:
    res = str(a)+"-"+str(b)+"+"+str(c)+"-"+str(d)+"=7"
elif a - b - c + d == 7:
    res = str(a)+"-"+str(b)+"-"+str(c)+"+"+str(d)+"=7"
elif a - b - c - d == 7:
    res = str(a)+"-"+str(b)+"-"+str(c)+"-"+str(d)+"=7"

print(res)




Measured memory_bytes: 3064
#include<iostream>
#include<sstream>
#include<cmath>
using namespace std;

int main(){
string S;
cin>>S;
int N=S.size();
for(int i=0;i<N;i++){
	if(islower(S[i])){
		continue;
	}
	else{
		cout<<"No";
		return 0;
	}
}
if(N==6 && S[2]==S[3] && S[4]==S[5]){
	cout<<"Yes";
}
else{
	cout<<"No";
}
}


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

int main() {

    int n;
    cin >> n;
    map<string, int> mp;
    rep(i,n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for (auto p : mp) mx = max(mx, p.second);
    for (auto p : mp) {
        if (p.second == mx) cout << p.first << endl;
    }
    return 0;
}

Measured memory_bytes: 19192
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

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

  ll n;
  cin >> n;
  vll as(n);

  rep(i, n) cin >> as[i];

  vvll dp(n, vll(n + 1));
  rep(i, n) dp[i][i] = 0;
  repLRE(h, 1, n) {
    rep(l, n) {
      ll r = l + h;
      if (r > n) break;
      ll ban = (n - r + l) & 1;  // 0:sente, 1:gote
      if (ban) {
        dp[l][r] = dp[l][r - 1] - as[r - 1];
        if (l + 1 < n) chmin(dp[l][r], dp[l + 1][r] - as[l]);
      } else {
        dp[l][r] = dp[l][r - 1] + as[r - 1];
        if (l + 1 < n) chmax(dp[l][r], dp[l + 1][r] + as[l]);
      }
    }
  }

  cout << dp[0][n] << endl;

  return 0;
}


Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c,A,B,C,x,y,z;
main(){
  cin>>n;
  for(;cin>>a>>b>>c,x=A,y=B,z=C,n--;A=a+max(y,z),B=b+max(x,z),C=c+max(x,y));
  cout<<max({A,B,C});
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n,t,a;
cin >> n >> t >> a;
int h[n];
int ans;
REP(i,n) cin >> h[i];
double temp;
double temp_min=INF;
REP(i,n) {
  temp = abs(a-t+h[i]*0.006);
  if(temp_min>temp) {
    temp_min = temp;
    ans = i+1;
  }
}
cout << ans <<endl;
return 0;
}


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

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

const ll MOD = 1e9+7;

// Combinationの使い方
// vector<vector<ll>> v(N+1, vector<ll>(N+1, 0));
// comb(v);
void comb(vector<vector<ll>> &v){
    for(int i = 0; i < v.size(); i++){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(int k = 1; k < v.size(); k++){
        for(int j = 1; j < k; j++){
            v[k][j] = (v[k-1][j-1] + v[k-1][j]);
            //余りを求める問題は毎回計算ごとにやる
            // v[k][j] = (v[k-1][j-1] + v[k-1][j]) % MOD;
        }
    }
}

// Union Find
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

// 1 << 3 : int "3" change to bit "100"
// rep(pattern, 1 << N) if (pattern & (1 << x)) cnt++

int main(){
    int N;
    cin >> N;
    vector<ll> A(201,0);
    rep(i,N) cin >> A[i];

    int cnt = 0;
    bool flag = true;
    while(flag){
        cnt++;
        rep(i,N){
            if(A[i]%2==0) A[i] = A[i]/2;
            else{
                cnt--;
                flag = false;
                break;
            } 
        }
    }
    
    cout << cnt << endl;
   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

int main(){
 ll n,m ;cin>>n>>m ;
 ll ans=1 ;
 for( ll i=1; i*i<=m;i++){
   if(m%i==0){
     ll j= m/i ;
     if(j>=n) chmax(ans,i) ;
     if(i>=n) chmax(ans,j) ;
   }
 }
   cout<<ans<<endl ;
  return 0;
  }

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int n, m;

struct edge{
	int to;
	int cost;
};

vector<vector<edge>> graph(100100);
int val[100100];
bool visited[100100];

bool dfs( int prev, int target, int k ){
	// cout << "prev: " << prev << ", target: " << target << ", k: " << k << endl;
	if( prev == -1 && visited[target] ) return true;
	if( prev != -1 && visited[prev] && visited[target] ){
		// cout << "valprev: " << val[prev] << ", valtarget: " << val[target] << ", k: " << k << endl;
		if( val[target] == k ){
			return true;
		} else {
			return false;
		}
	}
	val[target] = k;
	visited[target] = true;
	for( auto t : graph[target] ){
		if( !dfs( target, t.to, val[target]+t.cost ) ){
			return false;
		}
	}
	return true;
}


int main(){
	cin >> n >> m;
	for( int i = 0; i < m; ++i ){
		int x, y, d; cin >> x >> y >> d;
		--x; --y;
		edge temp;
		temp.to = y;
		temp.cost = d;
		graph[x].push_back(temp);
		temp.to = x;
		temp.cost = -d;
		graph[y].push_back(temp);
	}
	for( int i = 0; i < n; ++i ){
		// cout << "when i = " << i << endl;
		if( !dfs( -1, i, 0 ) ){	
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 998244353

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll n, m, k;
    cin >> n >> m >> k;
    vector<string> arr(n);
    REP(i, 0, n)
        cin >> arr[i];
    vvi dp(n+1, vi(m+1, 0));
    REP(i, 0, n) {
        REP(j, 0, m) {
            dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1] - dp[i][j];
            if (arr[i][j] == '1')
                dp[i+1][j+1] += 1;
        }
    }
    ll ans = LLONG_MAX;
    REP(i, (1ll << (n-1)), (1ll << n)) {
        bitset<11> msk(i);
        ll tmp = msk.count() - 1, t = 0, q = 0;
        REP(j, 1, m+1) {
            ll p = 0, c = 0;
            REP(x, 0, n) {
                if (msk[x] == 1) {
                    if (dp[x+1][j] - dp[p][j] - dp[x+1][q] + dp[p][q] > k)
                        c = 1;
                    p = x+1;
                }
            }
            if (c) {
                tmp++;
                if (j == q+1) {
                    tmp = -1;
                    break;
                }
                q = j-1;
            }
        }
        if (tmp >= 0)
            ans = min(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define DATA_SIZE 4

int calc(int num1, int num2, string op){
	if(op == " + "){
		return num1 + num2;
	}else if(op == " - "){
		return num1 - num2;
	}else if(op == " * "){
		return num1 * num2;
	}
	return (1 << 24); // ??§????????°
}

void search(int a[3]){
	
	string op[3] = {" + ", " - ", " * "};
	sort(a, a + DATA_SIZE);
	
	do{
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				for(int k = 0; k < 3; k++){
					if(calc(calc(calc(a[0], a[1], op[i]), a[2], op[j]), a[3], op[k]) == 10){
						cout << "(((" << a[0] << op[i] << a[1] << ")" << op[j] << a[2] << ")" << op[k] << a[3] << ")" << endl;
						return;
					}
					if(calc(calc(a[0], calc(a[1], a[2], op[i]), op[j]), a[3], op[k]) == 10){
						cout << "((" << a[0] << op[j] << "(" << a[1] << op[i] << a[2] << "))" << op[k] << a[3] << ")" << endl;
						return;
					}
					if(calc(a[0], calc(calc(a[1], a[2], op[i]), a[3], op[j]), op[k]) == 10){
						cout << "(" << a[0] << op[k] << "((" << a[1] << op[i] << a[2] << ")" << op[j] << a[3] << "))" << endl;
						return;
					}
					if(calc(a[0], calc(a[1], calc(a[2], a[3], op[i]), op[j]), op[k]) == 10){
						cout << "(" << a[0] << op[k] << "(" << a[1] << op[j] << "(" << a[2] << op[i] << a[3] << ")))" << endl;
						return;
					}
					if(calc(calc(a[0], a[1], op[i]), calc(a[2], a[3], op[j]), op[k]) == 10){
						cout << "((" << a[0] << op[i] << a[1] << ")" << op[k] << "(" << a[2] << op[j] << a[3] << "))" << endl;
						return;
					}
				}
			}
		}
	}while(next_permutation(a, a + DATA_SIZE));
	cout << "0" << endl;
	return;
}

int main(){
	int a[DATA_SIZE];
	while(true){
		
		bool flag = true;
		
		for(int i = 0; i < DATA_SIZE; i++){
			cin >> a[i];
			if(a[i] != 0){
				flag = false;
			}
		}
		if(flag){
			break;
		}
		
		search(a);
	}
	
	
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
//freopen("transmitters.in","r",stdin);
using namespace std;

void fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
/*long long mn=1e9;
void lucky (long long a, long long c,int b)
{
    if(a > 1e11)
    return ;
    if(a>=b&&c==0)
    mn=min(mn,a);
    
    lucky (a*10+7,c-1,b);
    lucky (a*10+4,c+1,b);
    
}*/
long long toint(string s){
	long long a = 0, c = 1;;
	for (int i = 0; i<s.size(); i++){
		a += (s[s.size() - i - 1] - '0')*c;
		// cout<<a<<endl;
		c *= 10;
	}
	return a;
}
int prime(int x)
{
int c=0;
 if(x==1)
 {
    return 0;
    
 }
 else
 {
  for(int j=2; j*j<=x;j++ ) 
  {
   if(x%j==0) 
   {
    c++;
     } 
   }

     if(c==0) 
      return 1;
    
    return 0;
     }
}
int brr[50];
int main()
{

  fast();

   long long n,m,c=0,x=0,y=0,t,h,z;
   string s;
   cin>>n;
   if(n==25)
   cout<<"Christmas"<<endl;
   if(n==24)
   cout<<"Christmas Eve"<<endl;
   if(n==23)
   cout<<"Christmas Eve Eve"<<endl;
   if(n==22)
   cout<<"Christmas Eve Eve Eve"<<endl;
//	system("pause");
	//cout << "-1" << endl;
	//  transform(x.begin(), x.end(), x.begin(), ::tolower); 

	return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
ll INF = 1000000007;
using Graph = vector<vector<ll>>;

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する

bool cmp(pair<ll,ll> a, pair<ll,ll> b){
    return a.second < b.second;
}

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

    vector<pair<ll,ll>> vec(m);

    rep(i,m){
        ll a, b;
        cin >> a >> b;
        vec.at(i) = make_pair(a,b);
    }

    sort(all(vec), cmp);

    vector<ll> div;

    rep(i,m){

        if(div.size() == 0){
            div.pb(vec.at(i).second);
            continue;
        }

        ll flag = 0;

        rep(j, div.size()){
            if(vec.at(i).first < div.at(j) && vec.at(i).second >= div.at(j)){
                flag = 1;
                break;
            }
        }

        if(flag == 0){
            div.pb(vec.at(i).second);
        }


    }

    cout << div.size() << endl;

}


Measured memory_bytes: 1792
use proconio::{fastout, input};
use std::cmp::Reverse;

#[fastout]
fn main() {
    input! {
        n: usize,
        m: i32,
        mut a: [i32; n],
    }

    a.sort_by_key(|k| Reverse(*k));
    let a_m = a.iter().skip(m as usize - 1).next().unwrap();
    let sum: i32 = a.iter().sum();

    let ans = if a_m * m * 4 >= sum { "Yes" } else { "No" };

    println!("{}", ans);
}


Measured memory_bytes: 2168
/*⠄⢰⣧⣼⣯⠄⣸⣠⣶⣶⣦⣾⠄⠄⠄⠄⡀⠄⢀⣿⣿⠄⠄⠄⢸⡇⠄⠄
⠄⠄⠄⣾⣿⠿⠿⠶⠿⢿⣿⣿⣿⣿⣦⣤⣄⢀⡅⢠⣾⣛⡉⠄⠄⠄⠸⢀⣿⠄
⠄⠄⢀⡋⣡⣴⣶⣶⡀⠄⠄⠙⢿⣿⣿⣿⣿⣿⣴⣿⣿⣿⢃⣤⣄⣀⣥⣿⣿⠄
⠄⠄⢸⣇⠻⣿⣿⣿⣧⣀⢀⣠⡌⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠿⣿⣿⣿⠄
⠄⢀⢸⣿⣷⣤⣤⣤⣬⣙⣛⢿⣿⣿⣿⣿⣿⣿⡿⣿⣿⡍⠄⠄⢀⣤⣄⠉⠋⣰
⠄⣼⣖⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⢇⣿⣿⡷⠶⠶⢿⣿⣿⠇⢀⣤
⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⣿⣿⣿⣿⣿⣿⣷⣶⣥⣴⣿⡗
⢀⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠄
⢸⣿⣦⣌⣛⣻⣿⣿⣧⠙⠛⠛⡭⠅⠒⠦⠭⣭⡻⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠄
⠘⣿⣿⣿⣿⣿⣿⣿⣿⡆⠄⠄⠄⠄⠄⠄⠄⠄⠹⠈⢋⣽⣿⣿⣿⣿⣵⣾⠃⠄
⠄⠘⣿⣿⣿⣿⣿⣿⣿⣿⠄⣴⣿⣶⣄⠄⣴⣶⠄⢀⣾⣿⣿⣿⣿⣿⣿⠃⠄⠄
⠄⠄⠈⠻⣿⣿⣿⣿⣿⣿⡄⢻⣿⣿⣿⠄⣿⣿⡀⣾⣿⣿⣿⣿⣛⠛⠁⠄⠄⠄
⠄⠄⠄⠄⠈⠛⢿⣿⣿⣿⠁⠞⢿⣿⣿⡄⢿⣿⡇⣸⣿⣿⠿⠛⠁⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠉⠻⣿⣿⣾⣦⡙⠻⣷⣾⣿⠃⠿⠋⠁⠄⠄⠄⠄⠄⢀⣠⣴
⣿⣿⣿⣶⣶⣮⣥⣒⠲⢮⣝⡿⣿⣿⡆⣿⡿⠃⠄⠄⠄⠄⠄⠄⠄⣠⣴⣿*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

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

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,k;
int arr[200005];
int cnt[1000005];

bool dd[1000005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	rep(x,0,n){
		cin>>arr[x];
		cnt[arr[x]]++;
	}
	
	sort(arr,arr+n);
	
	int ans=0;
	rep(x,0,n){
		if (cnt[arr[x]]==1 && !dd[arr[x]]) ans++;
		
		if (!dd[arr[x]]) for (int y=arr[x];y<1000005;y+=arr[x]){
			dd[y]=true;
		}
	}
	
	cout<<ans<<endl;

}


Measured memory_bytes: 9280
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n ;
    cin >> n;
    int a = n % 10;
    if(a == 2 or a == 4 or a == 5 or a ==7 or a == 9) cout << "hon";
    else if( a == 0 or a == 1 or a == 6 or a == 8) cout << "pon";
    else cout << "bon";
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int total;
  cin >> total;
  vector<char> color(total);
  //金平糖の数だけ入れる
  for(int i=0; i<total; i++){
    cin >> color.at(i);
  }
  auto itr = find(color.begin(), color.end(), 'Y');
  if(itr != color.end()){
    cout << "Four";
  } else{
    cout << "Three";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define MAXSIZE 60
using namespace std;
const int N = 1e6 + 5;
const ll mo = 1e10 +7;
const int M = 100+50;
const int mod = 100;
int main(){
	int n;
	string s;
	int k;
	cin>>n>>s>>k;
	for(int i=0;i<s.length();i++)
		if(s[i]==s[k-1])
			cout<<s[i];
		else
			cout<<"*";
	cout<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  ll cnt=0;
  FOR(i,1,n+1){
    ll x=i;
    ll num=0;
    while(x!=0){
      num+=x%10;
      x/=10;
    }
    if(a<=num&&num<=b){
      cnt+=i;
    }
  }
  cout << cnt << endl;
}


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

const long long INF = 1LL << 60;

int main() {
    int N, M, P;
    std::cin >> N >> M >> P;

    std::vector<int> A(M), B(M), C(M);
    for (int i = 0; i < M; i++) {
        std::cin >> A[i] >> B[i] >> C[i];
        A[i]--;
        B[i]--;
        C[i] = P - C[i];
    }

    std::vector<long long> dist(N, INF);
    dist[0] = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = 0; j < M; j++) {
            if (dist[A[j]] != INF && dist[A[j]] + C[j] < dist[B[j]])
                dist[B[j]] = dist[A[j]] + C[j];
        }
    }

    for (int i = 0; i < N - 1; i++) {
        for (int j = 0; j < M; j++) {
            if (dist[A[j]] != INF && dist[A[j]] + C[j] < dist[B[j]])
                dist[B[j]] = -INF;
        }
    }

    if (dist[N - 1] == -INF)
        std::cout << -1 << "\n";
    else
        std::cout << std::max(0LL, -dist[N - 1]) << "\n";
}

Measured memory_bytes: 384
N = int(input())
g = [[] for i in [0]*(N+1)]

for i in range(1,N+1):
    S = input()
    for j in range(1,i+1):
        if S[j-1] == '1':
            g[i].append(j)
            g[j].append(i)

def max_len(g,v):
    visited = [False]*(N+1)
    l = 1
    ls = [v]
    pre_v = []
    while(ls):
        new_ls = []
        for cv in ls:
            for nv in g[cv]:
                if visited[nv] and not nv in pre_v:
                    return -1
                if not visited[nv] and not nv in new_ls:
                    new_ls.append(nv)
            visited[cv] = True
        if new_ls:
            l += 1
        pre_v = ls
        ls = new_ls
    return l

m = -1 
for i in range(1,N+1):
    m = max(m,max_len(g,i))
print(m)







Measured memory_bytes: 41712
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>

using namespace std;
#define REP(i,m,n) for(int i=m;i<n;++i)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

int main() {
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	REP(i, 0, a) {
		if (s[i] < '0' || '9' < s[i]) {
			printf("No\n");
			return 0;
		}
	}
	if (s[a] != '-') {
		printf("No\n");
		return 0;
	}
	REP(i, a + 1, a + b + 1) {
		if (s[i] < '0' || '9' < s[i]) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 4e3 + 5;
int n,sum[N][256];
long long ans;
char s[N];
int main() {
	cin >> n >> s+1;
	for(int i = 1;i <= n;++i) {
		sum[i]['R'] = sum[i-1]['R'];
		sum[i]['G'] = sum[i-1]['G'];
		sum[i]['B'] = sum[i-1]['B'];
		++sum[i][s[i]];
	}
	for(int i = 1;i < n;++i)
		for(int j = i+1;j < n;++j)
			if(s[i] != s[j]) {
				char c;
				int k = j + (j-i);
				if(s[i] == 'R' && s[j] == 'G') c = 'B';
				if(s[i] == 'G' && s[j] == 'R') c = 'B';
				if(s[i] == 'R' && s[j] == 'B') c = 'G';
				if(s[i] == 'B' && s[j] == 'R') c = 'G';
				if(s[i] == 'B' && s[j] == 'G') c = 'R';
				if(s[i] == 'G' && s[j] == 'B') c = 'R';
				ans += sum[n][c] - sum[j][c];
				if(k <= n && s[k] == c) --ans;
			}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7584
# -*- coding: utf-8 -*-
N, M = map(int, input().split(' '))

ret = 1
for i in range(1, int(M**0.5)+1):
    if M % i == 0 and i * N <= M:
        ret = max(ret, i)

        j = M//i
        if M % j == 0 and j * N <= M:
            ret = max(ret, j)

        # exit()
print(ret)




Measured memory_bytes: 39024
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////



int main() {

	ll X;
	cin >> X;

	ll k = 0;
	ll c = 0;
	while (k < X) {
		c++;
		k += c;
	}

	cout << c;
	system("PAUSE");
}


Measured memory_bytes: 504
#include <stdio.h>
int main(void)
{
	int k,a[101],n,m,s=0,ss;
	scanf("%d",&k);
	for(n=0;n<k;n++)
	{
		scanf("%d",&a[n]);
	}
	for(;;)
	{
		ss=0;
		for(m=0;m<k;m++)
		{
			if(a[m]>=s)
			{
				ss++;
			}
		}
		if(ss<s)
		{
			break;
		}
		s++;
	}
	printf("%d\n",s-1);
	return 0;
}

Measured memory_bytes: 2760
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

struct S{
  int A[9][9];
};

int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int h, w, c, p[9][9], colcnt, ans;
bool visit[9][9];

void paint(int bfcolor, int x, int y,int color, int tp[9][9]){
  visit[y][x] = true;
  bfcolor = tp[y][x];
  tp[y][x] = color;
  REP(k,0,4){
    int posx = x + dx[k];
    int posy = y + dy[k];
    if(!CH(posx,0,w) || !CH(posy,0,h)) continue;
    if(tp[posy][posx] != bfcolor || visit[posy][posx]) continue;
    paint(bfcolor, posx, posy, color, tp);
  }
  return ;
}

void check(int x, int y, int color, struct S s){
  visit[y][x] = true;
  colcnt++;
  REP(k,0,4){
    int posx = x + dx[k];
    int posy = y + dy[k];
    if(!CH(posx,0,w) || !CH(posy,0,h)) continue;
    if(s.A[posy][posx] != color || visit[posy][posx]) continue;
    check(posx, posy, color, s);
  }
  return ;
}

void dfs(int k, int turn, struct S s){

  //??????
  int tp[9][9];
  REP(i,0,h)REP(j,0,w) tp[i][j] = s.A[i][j];  //??????????????§??????????????¨???????????????
  REP(i,0,h)REP(j,0,w) visit[i][j] = false;
  paint(s.A[0][0],0,0,k,tp);
  REP(i,0,h)REP(j,0,w) s.A[i][j] = tp[i][j]; //??????????????????????????????

  //??????????????????????????§???????????????
  //int maxpanel = 0;
  REP(i,0,h)REP(j,0,w){
    colcnt = 0;
    if(s.A[i][j]==c){
      REP(ii,0,h)REP(jj,0,w) visit[ii][jj] = false;
      check(j,i,c,s);
    }
    //maxpanel = max(maxpanel, colcnt);
    ans = max(ans, colcnt);
  }
  //ans = max(ans, maxpanel);

  if(turn == 5){
    return;
  }


  REP(kk,1,7){ //??????????????????????????????
    int bcol = s.A[0][0];
    dfs(kk,turn + 1,s);
  }

  return;
}

int main() {

while(1){
    cin>>h>>w>>c;
    if(h==0 && w==0 && c==0) break;
    REP(i,0,h)REP(j,0,w) cin>>p[i][j];

    ans = 0;
    S sc;
    REP(i,0,h)REP(j,0,w) sc.A[i][j] = p[i][j];

    REP(k,1,7) dfs(k,1,sc);

    cout<<ans<<endl;
  }

  return 0;
}

Measured memory_bytes: 3084
#include <stdio.h>

int main(){
	int n,i;
	int max = 0;
	int min = 0;
	scanf("%d",&n);
	int a[n];
	for(i = 0;i < n;i++){
		scanf("%d",&a[n]);
	if(max < a[n])
		max = a[n];
	if(min == 0)
		min = a[n];
	if(a[n] < min)
		min = a[n];
	}
	printf("%d",max - min);
	return 0;
}

Measured memory_bytes: 128
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
    }
    if n % 2 == 1 {
        println!("0");
        return;
    }
    let mut result = 0;
    let mut d = 5;
    while d < n {
        result += (n / 2) / d;
        d *= 5;
    }
    println!("{}", result);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
const int mm=1e6;
ll d[mm];
ll mod=1e9+7;
int main()
{
	ll n,m,i,j;
   string s;
   cin>>s;
   for(i=0;i<s.size();i++)
   cout<<'x';
   
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF (1<<30)
#define LINF (1ll<<60ll)
#define MOD 1000000007
#define pb(a) push_back(a)
#define _overload4(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload4(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)
#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))
#define d(a) cerr<<#a<<":"<<a<<endl
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl


int main(){
    int n;
    int m=0;
    int sum=0;
    cin>>n;
    int p;
    REP(i,n){
        cin>>p;
        chmax(m,p);
        sum+=p;
    }
    sum-=m/2;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 764