akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

#define MOD 1000000007

bool is_valid(ll n)
{
  return (n % 3 == 0) || (n % 5 == 0);
}

int main()
{
  ll n;
  cin >> n;
  vector<ll> as = {};
  ll a;
  for (auto i = 0; i < n; i++)
  {
    cin >> a;
    as.push_back(a);
  }

  for (auto a : as)
  {
    if (a % 2 == 0)
    {
      if (is_valid(a))
      {
        continue;
      }
      else
      {
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }

  cout << "APPROVED" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
#define Endl endl
const int INF=100000000;
int main(){
	ll a,b;
	cin>>a>>b;
	if(a%b==0){
		cout<<-1<<endl;
	}
	else{
		cout<<a<<endl;
	}
	return 0;
}

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

struct ModInt {
    using M = ModInt;

    static vector<M> fact, finv;
    static long long MOD;
    long long v;

    // normalize: [-MOD, MOD**2] -> [0, MOD)
    ModInt(const long long _v = 0) : v((_v < 0) ? _v % MOD + MOD : _v % MOD) {}

    M operator+(const M& x) const { return M(v + x.v); }
    M operator-(const M& x) const { return M(v - x.v); }
    M operator*(const M& x) const { return M(v * x.v); }
    M operator/(const M& x) const { return M(v * x.inv().v); }
    M& operator+=(const M& x) { return *this = *this + x; }
    M& operator-=(const M& x) { return *this = *this - x; }
    M& operator*=(const M& x) { return *this = *this * x; }
    M& operator/=(const M& x) { return *this = *this / x; }
    bool operator==(const M& x) const { return v == x.v; }
    bool operator!=(const M& x) const { return v != x.v; }
    friend istream& operator>>(istream& input, M& x) {
        return input >> x.v, x = M(x), input;
    }
    friend ostream& operator<<(ostream& output, const M& x) {
        return output << x.v;
    }
    inline M pow(long long n) const {
        M x(v), res(1);
        while (n) {
            if (n & 1) res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }
    inline M inv() const { return this->pow(MOD - 2); }
    static void build(int n) {
        fact.assign(n + 1, 1);
        for (int i = 1; i < n + 1; i++) fact[i] = fact[i - 1] * M(i);
        finv.assign(n + 1, fact[n].inv());
        for (int i = n; i > 0; i--) finv[i - 1] = finv[i] * M(i);
    }
    static M comb(int n, int k) {
        if (n < k || k < 0) return M(0);
        return fact[n] * finv[n - k] * finv[k];
    }
    static M extgcd(int a, int b, int& x, int& y) {
        M d(a);
        if (b) {
            d = extgcd(b, a % b, y, x);
            y -= (a / b) * x;
        } else {
            x = 1;
            y = 0;
        }
        return d;
    }
};
vector<ModInt> ModInt::fact = vector<ModInt>();
vector<ModInt> ModInt::finv = vector<ModInt>();
long long ModInt::MOD = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    map<P, int> mp;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        if (a | b) {
            ll g = abs(__gcd(a, b));
            a /= g;
            b /= g;
        }
        mp[P(a, b)]++;
    }
    map<P, int> c = mp;
    int z = c[P(0, 0)];
    c[P(0, 0)] = 0;
    ModInt ans = 1;
    for (auto&& p : mp) {
        ll a, b;
        tie(a, b) = p.first;
        int x = c[P(a, b)] + c[P(-a, -b)];
        c[P(a, b)] = c[P(-a, -b)] = 0;
        int y = c[P(-b, a)] + c[P(b, -a)];
        c[P(-b, a)] = c[P(b, -a)] = 0;
        ans *= ModInt(2).pow(x) + ModInt(2).pow(y) - 1;
    }
    cout << ans + z - 1 << endl;
}

Measured memory_bytes: 66028
// Sky's the limit :)
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    //int t = 1; cin >> t; while(t--)
    {
        int n;
        cin >> n;
        cout << (n + 1) / 2;
        
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int cnt[26];
int main()
{
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) cnt[S[i] - 'A']++;
	int ans = 0;
	for (int i = 0; i < 26; i++) {
		if (cnt[i] == 2) {
			ans++;
		}
	}
	if (ans == 2)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc134/tasks/abc134_e

//multisetの注意点：
//ある値iをmultisetから削除したい時、erase(i)をすると
//multisetにiが複数入っている時これが全部削除対象になる
//一個だけ削除したい時は
//削除したい要素のイテレータをeraseの引数にしておく必要がある

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[100000];
 
LL ans = 0;

void solve(){
	//数をグループに分類、グループの数を回答とする
	multiset<LL> group_max;//各グループに格納されている数のうち最大値
	group_max.insert(A[0]);
	for(int i=1;i<N;i++){
		auto iter = group_max.lower_bound(A[i]);
		if(iter==group_max.begin()){
			group_max.insert(A[i]);
			continue;
		}
		iter--;
		if(*iter<A[i]){
			group_max.erase(iter);
			group_max.insert(A[i]);
		}else{
			group_max.insert(A[i]);
		}
	}
	ans = (LL)group_max.size();
}

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

Measured memory_bytes: 5760
n = int(input())
a = [int(i) for i in input().split()]
x = [0] * n

suma = sum(a)
for i in range(1, n, 2):
  suma -= 2*a[i]
x[0] = suma
for i in range(1, n):
  x[i] = 2*a[i-1] -x[i-1]
  
print(*x)

Measured memory_bytes: 64484
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

bool isPrime(ll n){
    if (n <= 1){
        return false;
    }
    for(int i = 2; i*i <= n; ++i){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}

int main(void)
{
    cin.sync_with_stdio(false);
    int X;
    cin >> X;

    while(1) {
        if (isPrime(X)) {
            cout << X << endl;
            return 0;
        }
        X++;
    }

    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main ()
{

 char s[110][110],t[110];
 int n,i,j,k,l;
 while(scanf("%d%d\n",&n,&l)!=EOF)
 {

for(i=0;i<n;i++)
   cin>>s[i];
for(i=0;i<n-1;i++)
{
  k=i;
 for(j=i+1;j<n;j++)
 if(strcmp(s[j],s[k])<0)k=j;
 strcpy(t,s[i]); strcpy(s[i],s[k]); strcpy(s[k],t);
}
for(i=0;i<n;i++)
cout<<s[i];
printf("\n");
}
return 0;
}

Measured memory_bytes: 256
N=int(input())
L=[]
for _ in range(N):
  a,b=map(str,input().split())
  L.append([a, int(b)])
X=str(input())

count=0
know=0
for i in range(N):
  if know==1:
    count+=L[i][1]
  elif L[i][0]==X:
    know=1
    
print(count)

Measured memory_bytes: 3064
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val k = readLong()
    var modK = 7 % k
    var ans = 1L
    val table = BooleanArray(k.toInt() + 1)

    while (true) {
        if (modK == 0L) {
            break
        }

        if (table[modK.toInt()]) {
            out.println(-1)
            return
        }
        table[modK.toInt()] = true

        modK = (modK * (10 % k)) % k
        modK = (modK + (7 % k)) % k
        ans++
    }

    out.println(ans)
}


fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 35136
void main()
{
    long n = rdElem;
    long[] a = rdRow;

    a.sort!"a < b";
    if (!a[0])
    {
        writeln(0);
        return;
    }

    long lim = 10L^^18;
    long num = 1;
    foreach (x; a)
    {
        if (lim < x)
        {
            writeln(-1);
            return;
        }
        lim /= x;
        num *= x;
    }

    writeln(num <= 10L^^18 ? num : -1);
}

enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

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

int sorted(vector<int> a){
  int size = a.size();
  for(int i=0; i<size-1 ; ++i){
    if(a.at(i) > a.at(i+1)){
      return 1;
    }
  }
  return 0;
}

int main(){
  int n, x=0;
  cin >> n;
  vector<int> a(n);

  for(int i= 0; i<n; ++i){
    cin >> a.at(i);
  }

  if(sorted(a)==0){x=1;}//初めから昇順

  for(int i = 0; i<n-1 ; ++i){
    for(int j=i+1 ; j<n ; ++j){
      swap(a.at(i), a.at(j));
      if(sorted(a)==0){ x=1; break;}
      swap(a.at(i), a.at(j));
    }
  }
  if(x==1){cout << "YES" << endl;}
  else{cout << "NO" << endl;}


}


Measured memory_bytes: 256
import sys
def main():
    n=int(input())
    s=input()
    MOD=10**9+7
    perm=1
    for i in range(1,n+1):
        perm=perm*i%MOD
    ans=1
    dp=[-1]*(2*n)

    dp[0]=1#L
    for i in range(1,2*n):
        if s[i]==s[i-1]:
            dp[i]=1-dp[i-1]
        else:
            dp[i]=dp[i-1]
    if s[0]=='W' or s[-1]=='W' or sum(dp)!=n:
        print(0)
        sys.exit()
    #print(dp)
    count=0
    for i in range(2*n):
        if dp[i]==1:
            count+=1
        else:
            ans*=count
            ans%=MOD
            count-=1
    print(ans*perm%MOD)

if __name__ == '__main__':
    main()


Measured memory_bytes: 41840
# -*- coding: utf-8 -*-
H,W = map(int, input().split())

ret = 10**9
for h in range(1,H):
    w = W//2
    s1 = h*W
    s2 = (H-h)*w
    s3 = (H-h)*(W-w)
    ret = min(ret, max(s1,s2,s3)-min(s1,s2,s3))

    hh = (H-h)//2
    s1 = h*W
    s2 = hh*W
    s3 = (H-h-hh)*W
    ret = min(ret, max(s1,s2,s3)-min(s1,s2,s3))

for w in range(1,W):
    h = H//2
    s1 = w*H
    s2 = (W-w)*h
    s3 = (W-w)*(H-h)
    ret = min(ret, max(s1,s2,s3)-min(s1,s2,s3))

    ww = (W-w)//2
    s1 = w*H
    s2 = ww*H
    s3 = (W-w-ww)*H
    ret = min(ret, max(s1,s2,s3)-min(s1,s2,s3))

print(ret)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(){
  long long a = 0;
  cin >> a;
  long long kazu = 0;
  kazu = 1;
  long long kotae = 0;
  while(a != 0){
    kotae += kazu;
    a /= 2;
    kazu *= 2;
  }
  cout << kotae << endl;
  return 0;
}

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

// true -> 壊れている, false -> 壊れていない
bool a[110000];

long long dp[110000];

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

		for (int i=0; i<110000; ++i) a[i] = false;
		for (int i=0; i<M; ++i) {
			int bad;
			cin >> bad;
			a[bad] = true;
		}

		// 初期化
		for (int i=0; i<110000; ++i) dp[i] = 0;

		// 初期条件
		dp[0] = 1;

		// ループ
		for (int i=1; i<=N; i++) {
			if (a[i] == true) continue;
			if (a[i-1] == false) dp[i] += dp[i-1];
			if (i > 1) {
				if (a[i-2] == false) dp[i] += dp[i-2];
			}

			dp[i] %= 1000000007;
		}

		cout << dp[N] << endl;
		return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <numeric>
using namespace std;
#define mod (long)(100000)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> count(M, 0);
    for(int i = 0; i < N; i++){
        int K;
        cin >> K;
        for(int j = 0; j < K; j++){
            int A;
            cin >> A;
            count[A - 1]++;
        }
    }
    cout << character_count(count, N) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
typedef pair<int, int> Pr;

int n, m, start;
vector<Pr> g[1000];
int dist[1000];

int solve()
{
	for (int i = 0; i < n; i++){
		dist[i] = INF;
	}
	dist[start] = 0;
	
	int k = 0;
	while (k < n){
		bool update = false;
		for (int i = 0; i < n; i++){
			if (dist[i] == INF) continue;
			for (int j = 0; j < g[i].size(); j++){
				int from = i;
				int to = g[i][j].first;
				int cost = g[i][j].second;
				if (dist[to] > dist[from] + cost){
					dist[to] = dist[from] + cost;
					update = true;
				}
			}
		}
		if (!update) break;
		k++;
	}
	
	if (k == n) return -1;
	return 1;
}

int main()
{
	scanf("%d %d %d", &n, &m, &start);
	
	for (int i = 0; i < m; i++){
		int s, t, d;
		scanf("%d %d %d", &s, &t, &d);
		
		g[s].push_back(Pr(t, d));
	}
	
	if (solve() == -1){
		puts("NEGATIVE CYCLE");
	}
	else {
		for (int i = 0; i < n; i++){
			if (dist[i] == INF) puts("INF");
			else printf("%d\n", dist[i]);
		}
	}
}

Measured memory_bytes: 1252
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<math.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define N (1000000000+7)
#define INF (ll)1e16
typedef long long ll;

ll sum[200000]={0};

int main(void){
    ll n,k,i=0,ans=0;
    string s;
    cin>>n>>k;
    cin>>s;
    vector<ll>a,sum;
    if(s[i]=='0')a.push_back(0);
    for(;i<s.length();){
        ll j=i;
        while(true){
            if(i==s.length()){
                a.push_back(i-j);
                break;
            }
            if(s[j]==s[i])i++;
            else{
                a.push_back(i-j);
                break;
            }
        }
    }
    if(s[s.length()]=='0')a.push_back(0);
    for(i=0;i<(ll)a.size();i++){
        ll num=num+a[i];
        sum.push_back(num);
    }
    for(ll i=0;i<(ll)a.size();i+=2){
        if((ll)a.size()>2*k+i){
           ans=max(ans,sum[2*k+i]-sum[i]+a[i]);
        }
        else{
            ans=max(ans,sum[(ll)sum.size()-1]-sum[i]+a[i]);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2676
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
#define MV 5000
struct edge{int to,cost; };
vector <edge> G[MV];
int V,E;
ll d[MV+1];
bool bellmanford(int s){
	rep(i,V){
		d[i]=INFl;
	}
	d[s] = 0;
	int c = 0;
	//bool upd = false;
	bool goalupd=false;//出発点から目的地までの経路での負の閉路の存在判定
	while(true){
		//upd = false;
		goalupd = false;
		for(int i = 0;i < V;i++){
			for(int j = 0;j < G[i].size();j++){
				edge e = G[i][j];
				if(d[i] != INFl && d[e.to] > d[i] + e.cost){
					//printf("c:%d i:%d to:%d oldcost:%lld newcost:%lld\n",c,i,e.to,d[e.to],d[i] + e.cost);
					d[e.to] = d[i] + e.cost;
					//upd = true;
					if(e.to==V-1) goalupd=true;
				}
			}
		}
		if(c>=V-1&& goalupd) return true;
		if(c == 2*V-1) return false;
		c++;
	}
}
int main(){
	int P,A[5001],B[5001],C[5001];
	scan(V>>E>>P);
	rep(i,E){
		scan(A[i]>>B[i]>>C[i]);
		edge e;
		e.to=B[i]-1;
		e.cost=-C[i]+P;
		G[A[i]-1].push_back(e);
	}
	bool flag=bellmanford(0);
	if(flag) prin(-1);
	else{
		prin(max(0LL,-d[V-1]));
	}
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
long long a[10005][102][2];
long long n,d,mod=1000000007;
string s;
long long ff(int i,int cnt,int tight){
if(i==n && cnt==0) return(1);
if(i==n) return(0);
if(a[i][cnt][tight] !=-1) return(a[i][cnt][tight]);
int end;
if(tight==0) end=9;
if(tight==1) end=s[i]-'0';
long long ans=0;
for(int j=0;j<=end;j++){
if(!tight){ans=ans+ff(i+1,(cnt+j)%d,tight);}
else{
if(j !=end) {ans=ans+ff(i+1,(cnt+j)%d,0);}
else {ans=ans+ff(i+1,(cnt+j)%d,1);}
}
}ans=ans%mod;
a[i][cnt][tight]=ans;
return(ans);
}
int main(){
long long ans;
int t,i;
memset(a,-1,sizeof(a));
cin>>s;n=s.size();cin>>d;
ans=(ff(0,0,1)-1+mod)%mod;
cout<<ans<<endl;

}

Measured memory_bytes: 20384
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
vector<int> z_algorithm(const string &S) {
    vector<int> ans(S.size());
    int from = 0, to = 0;
    for (int i = 1; i < S.size(); i++) {
        int k = min(ans[i - from] + i, to);
        k = max(i, k);
        while (k < S.size()) {
            if (S[k - i] != S[k]) break;
            k++;
        }
        ans[i] = k - i;
        if (to < k) {
            from = i, to = k;
        }
    }
    ans[0] = S.size();
    return ans;
}
int main() {
    string W; cin >> W;
    if (all_of(begin(W), end(W), [&](char c) { return c == W[0]; })) {
        cout << W.size() << "\n1\n";
    } else {
        auto f = [](const string &S) {
            vector<bool> ans(S.size(), true);
            auto Z = z_algorithm(S);
            for (int i = 1; i < S.size(); i++) {
                for (int j = i + i - 1; j < S.size() && j < i + Z[i]; j += i) {
                    ans[j] = false;
                }
            }
            return ans;
        };
        auto A = f(W);
        reverse(begin(W), end(W));
        auto B = f(W);
        reverse(begin(B), end(B));
        if (A[W.size() - 1]) {
            cout << 1 << '\n' << 1 << '\n';
        } else {
            int ans = 0;
            for (int i = 0; i < A.size() - 1; i++) {
                ans += (A[i] && B[i + 1]);
            }
            cout << 2 << '\n' << ans << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 2844
public class Main {
  private static void solve() {
    int n = ni();
    int m = ni();
    System.out.println(n == m ? "Yes" : "No");
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,a[100005];
	long long ans[100005];
	memset(a,0,sizeof(a));
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int k;
		cin>>k;
		a[k]=1;
	}
	if(a[1])
	{
		ans[1]=0;
	}
	else
	{
		ans[1]=1;
	}
	ans[0]=1;
	for(int i=2;i<=n;i++)
	{
		ans[i]=(ans[i-1]+ans[i-2])%1000000007;
		 if(a[i]==1)ans[i]=0;
	} 
	long long num=ans[n]%1000000007;
	cout<<num;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main()
{
    float a,b,c,d,e,f;
    float x=0,y=0;
    while(scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f)!=EOF)
    {
        x=(c*e-b*f)/(a*e-b*d);
        y=(a*f-c*d)/(a*e-b*d);
        if(x==-0.000000)
            x=0.000000;
        if(y==-0.000000)
            y=0.000000;
        printf("%.3f %.3f\n",x,y);
    }
}



Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int ans=0,i,n,k,j;
	cin>>n>>k;
	n-=2;
	if(n>=11)
	{
		ans+=n/11*5;
		n%=11;
	}
	for (i=1;i<=5;i++)
		for (j=1;j<=n;j++)
			if((63*j+9*i+9)%11==k)
				ans++;
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define int long long
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,dp[li][4];
int cev;
string s;
vector<int> v[li];

inline int add(int x,int y){
	if(x+y>=mod)return x+y-mod;
	return x+y;
}

inline int mul(int x,int y){
	return (x%mod)*(y%mod)%mod;
}

inline void dfs(int node,int ata){
	int cevv=1;
	int cevv1=1;
	for(int i=0;i<(int)v[node].size();i++){
		int go=v[node][i];
		if(go==ata)continue;
		dfs(go,node);
		cevv=mul(cevv,(dp[go][0]+dp[go][1]));
		cevv1=mul(cevv1,(dp[go][0]));
	}
	if(v[node].size()==1 && v[node][0]==ata){dp[node][1]=1;dp[node][0]=1;}
	else{dp[node][0]=cevv;dp[node][1]=cevv1;}
}

main(void){
	scanf("%lld",&n);
	if(n==1){printf("2\n");return 0;}
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%lld %lld",&x,&y);
		v[x].pb(y);
		v[y].pb(x);
	}
	dfs(1,0);
	printf("%lld\n",add(dp[1][1],dp[1][0]));
	return 0;
}


Measured memory_bytes: 24960
n = int(input())
A = list(map(int,input().split()))
oddr = [0]*(n+1)
oddl = [0]*(n+1)
ever = [0]*(n+1)
evel = [0]*(n+1)
#r:右への和 l左への和
for i in range(1,n+1):
    oddr[i] = oddr[i-1]
    ever[i] = ever[i-1]
    if i%2==1:
        oddr[i]+=A[i-1]
    else:
        ever[i]+=A[i-1]

for i in range(1,n+1):
    oddl[i] = oddl[i-1]
    evel[i] = evel[i-1]
    if i%2==1:
        oddl[i]+=A[-i]
    else:
        evel[i]+=A[-i]

ans = [0]*n
sa = sum(A)
for i in range(1,n+1):
    idxl = (n+1-i)
    if i%2==0:
        ans[i-1] = sa - 2*((oddr[-1] - oddr[i]) + (evel[-1] - evel[idxl]))
    else:
        ans[i-1] = sa -2*( (ever[-1] - ever[i]) + (oddl[-1] - oddl[idxl]))

print(*ans)


Measured memory_bytes: 24780
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if (x == 3 || x == 5 || x ==7) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 27092
#include<stdio.h>

int main()
{
	int a,b;
	scanf("%d %d",&a, &b);
	char str[a+b+2];
	scanf("%s",str);
	int i;
	int flag=1;
	for (i=0;i<=a+b;i++)
	{
		if (i==a)
			continue;
		else
		{
			if (str[i]>=48 && str[i]<=(57))
				flag=1;
			else{
				flag=0;
				break;
			}
		}
	}
	if (str[a]!='-')
		flag=0;
	if (flag==0)
		printf("No\n");
	else
		printf("Yes\n");
	
	return 0;
}

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

int main() {
  uint64_t n, m, q;
  std::cin >> n >> m >> q;
  std::vector<uint64_t> r(n, 0);
  std::vector<uint64_t> sum(n, 0);
  std::vector<std::vector<uint64_t>> over(n, std::vector<uint64_t>(n, 0));

  for (uint64_t i = 0; i < m; i++) {
    int li, ri;
    std::cin >> li >> ri;
    r[ri - 1]++;

    for (int j = li + 1; j <= ri; j++) {
      over[j - 1][ri - 1]++;
    }
  }

  sum[0] = r[0];
  for (uint64_t i = 1; i < n; i++) {
    sum[i] = sum[i - 1] + r[i];
  }

  std::vector<std::vector<uint64_t>> over_sum(n, std::vector<uint64_t>(n, 0));
  for (uint64_t i = 0; i < n; i++) {
    over_sum[i][0] = over[i][0];
  }
  for (uint64_t i = 0; i < n; i++) {
    for (uint64_t j = 1; j < n; j++) {
      over_sum[i][j] = over_sum[i][j - 1] + over[i][j];
    }
  }
  for (uint64_t i = 0; i < q; i++) {
    int p, q;
    std::cin >> p >> q;
    uint64_t sum_p;
    if (p == 1) {
      sum_p = 0;
    } else {
      sum_p = sum[p - 2];
    }
    std::cout << sum[q - 1] - sum_p - over_sum[p - 1][q - 1] << std::endl;
  }

  return 0;
}

Measured memory_bytes: 4864
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
ans = 0

for i in range(N):
    A = list(map(int, input().split()))
    tmp = C
    for i, j in zip(A, B):
        tmp += i * j
    if tmp > 0:
        ans += 1
print(ans)

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

using namespace std;

#define ll long long
#define endl "\n"
#define rep(i, n) for(__typeof(n) i = 0; i < n; i++)
#define per(i, n) for(__typeof(n) i = n - 1; i >= 0; i--)
#define loop(i, a, b) for(__typeof(a) i = a; i <= b; i++)
#define set(a, val) memset(a, val, sizeof(a))
#define f first
#define s second
#define all(x) x.begin(), x.end()

const int mod = 1000000007;


int main()
{
    string s;
    cin >> s;
    stack<char> st;
    int cnt = 0, sz = s.size();
    rep(i, (int)s.size())
    {
        if(s[i] == '0')
        {
            if(!st.empty() &&st.top() == '1' )
                cnt++, st.pop();
            else
                st.push('0');
        }
        else
        {
            if(!st.empty() &&st.top() == '0' )
                cnt++, st.pop();
            else
                st.push('1');
        }
    }
    cout << sz - st.size() << endl;
}


Measured memory_bytes: 512
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        N: i32,
        a: [i32; N],
    }

    let mut sum = 0;
    for (i, num) in a.iter().enumerate() {
        if i % 2 == 0 && num % 2 == 1 {
            sum += 1;
        }
    }

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


Measured memory_bytes: 2172
import java.io.*;
import java.util.StringTokenizer;

public class Main {
  private static PrintWriter out;

  public static void main(String[] args) {
    Main main = new Main();
    Runtime.getRuntime().addShutdownHook(new Thread(() -> out.close()));
    try {
      main.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void run(String[] arguments) throws Exception {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));

    String N = sc.next();
    String ans = "No";
    if (N.contains("7")){
      ans="Yes";
    }
    out.println(ans);
    out.close();
  }

  /*          
   * Form: http://codeforces.com/blog/entry/7018
   */
  private class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[] TT = new int[K+1];
		int[] La = new int[K+1];
		int[] Lv = new int[K+1];
		int[] Ra = new int[K+1];
		int[] Rv = new int[K+1];
		
		for(int i=1;i<=K;i++){
			TT[i] = R[i - 1];
		}
		
		La[0] = 0;
		Lv[0] = 0;
		Ra[0] = X;
		Rv[0] = X;
		for(int i=1;i<=K;i++){
			int lose = TT[i] - TT[i-1];
			int l = Lv[i-1] - lose;
			La[i] = La[i-1];
			if(l <= 0) La[i] += (-l);
			Lv[i] = X - Math.Max(0, l);
			
			int r = Rv[i-1] - lose;
			Ra[i] = Ra[i-1];
			if(r <= 0) Ra[i] -= (-r);
			Rv[i] = X - Math.Max(0, r);
			
		}
		
//		Console.WriteLine(String.Join("\t",La));
//		Console.WriteLine(String.Join("\t",Lv));
//		Console.WriteLine(String.Join("\t",Ra));
//		Console.WriteLine(String.Join("\t",Rv));
		
		int[] ans = new int[Q];
		for(int q=0;q<Q;q++){
			int t = T[q];
			int a = A[q];
			
			int l = 0;
			int r = K + 1;
			while(r - l > 1){
				int c = (l + r) / 2;
				if(TT[c] <= t){
					l = c;
				} else {
					r = c;
				}
			}
			
			int iniTime = l;
			int lose = t - TT[iniTime];
			
			int iniValue = 0;
			if(Lv[iniTime] == Rv[iniTime]){
				iniValue = Lv[iniTime];
			} else {
				if(a <= La[iniTime]){
					iniValue = Lv[iniTime];
				} else if(a >= Ra[iniTime]){
					iniValue = Rv[iniTime];
				} else {
					if(Lv[iniTime] < Rv[iniTime]){
						iniValue = Lv[iniTime] + (a - La[iniTime]);
					} else {
						iniValue = Lv[iniTime] - (a - La[iniTime]);
					}
				}
			}
			
			ans[q] = iniTime % 2 == 0 ? Math.Max(0, iniValue - lose) : Math.Max(0, X -Math.Max(0, iniValue - lose));
		}
		
		
		Console.WriteLine(String.Join("\n",ans));
	}
	int X;
	int K;
	int[] R;
	int Q;
	int[] T;
	int[] A;
	
	
	public Sol(){
		X = ri();
		K = ri();
		R = ria();
		Q = ri();
		T = new int[Q];
		A = new int[Q];
		for(int i=0;i<Q;i++){
			var d = ria();
			T[i] = d[0]; A[i] = d[1];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

long long N, K;

vector<long long> solve(long long n, long long p) {
	vector<long long>L, res;
	L.push_back(1);
	for (int i = 1; i <= n; i++) L.push_back(L[L.size() - 1] * K + 1);
	for (int i = n - 1; i >= 0; i--) {
		if (p == 1) return res;
		p--;
		int cnt = 0;
		while (p > L[i]) { p -= L[i]; cnt++; }
		res.push_back(cnt + 1);
	}
	return res;
}

int main() {
	cin >> K >> N;
	if (K % 2 == 0) {
		cout << K / 2;
		for (int i = 2; i <= N; i++) cout << " " << K;
		cout << endl;
	}
	else {
		vector<long long>vec, L;
		
		long long BB = (1LL << 42);

		L.push_back(1);
		for (int i = 1; i <= N - 1; i++) {
			L.push_back(L[L.size() - 1] * K + 1);
			if (L[L.size() - 1] >= BB) L[L.size() - 1] = BB;
		}
		L.push_back(L[L.size() - 1] * K); if (L[L.size() - 1] >= BB) L[L.size() - 1] = BB;
		reverse(L.begin(), L.end());

		long long A = 0; if (N % 2 == 1) A = 1;

		for (int i = 1; i <= N; i++) {
			if (L[i - 1] >= BB) { vec.push_back((K + 1) / 2); if (i >= 2) A--; continue; }

			long long V = (L[i - 1] + A) / 2; if (i == 1) V++;
			vector<long long>E = solve(N - vec.size(), V);
			for (int j = 0; j < E.size(); j++) vec.push_back(E[j]);
			break;
		}
		for (int i = 0; i < vec.size(); i++) {
			if (i) cout << " "; cout << vec[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 11628
h, w, m = map(int, input().split())
h_cnt = [0 for i in range(h)]
w_cnt = [0 for i in range(w)]
bomb = set()

for i in range(m):
    _h, _w = map(int, input().split())
    h_cnt[_h-1] += 1
    w_cnt[_w-1] += 1
    bomb.add(((_h-1),(_w-1))) #爆破対象の位置を判断

h_max = max(h_cnt)
w_max = max(w_cnt)

max_h = []
max_w = []

for i in range(h):
    if h_cnt[i] == h_max:
        max_h.append(i)

for i in range(w):
    if w_cnt[i] == w_max:
        max_w.append(i)

flg = True

for i in max_h:
    for j in max_w:
        if (i,j) not in bomb:
            flg = False
            break
print(h_max+w_max-1 if flg else h_max+w_max)

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  int a,b,c;

  while(cin >> a >> b >> c,a||b||c){
    int d1 = 2*a,d2 = 2*a;
    int u1 = b,u2 = b;
    int tmp = b*b - 4*a*c;

    bool f = false;
    for(int i=0;i*i<=tmp;i++)
      if(i*i==tmp){
	tmp = i;
	f = true;
      }
    
    if(!f){
      cout << "Impossible\n";
      continue;
    }

    u1 += tmp;
    u2 -= tmp;
    
    tmp = gcd(u1,d1);
    u1 /= tmp; d1/= tmp;
    tmp = gcd(u2,d2);
    u2 /= tmp; d2/= tmp;
    
    if(d1<0){u1*=-1; d1*=-1;}
    if(d2<0){u2*=-1; d2*=-1;}

    if(d1<d2 || (d1==d2 && u1<u2)){swap(u1,u2); swap(d1,d2);}
    
    cout << d1 << " " << u1 << " " << d2 << " " << u2 << endl;
  }
}

Measured memory_bytes: 0
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

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

int main() {
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;
	cout << min(N, K) * X + max(0, N - K) * Y << endl;
}


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

int main()
{
    int A,B;
    cin>>A>>B;

    if((A==1&&B!=1)||(A>B&&(A!=1&&B!=1)))
        cout<<"Alice"<<endl;
    else if((B==1&&A!=1)||(B>A&&(A!=1&&B!=1)))
        cout<<"Bob"<<endl;
    else if(A==B)
        cout<<"Draw"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 101

//static const int MAX = 500;
static const int INFTY = (1<<21);

int main(){
  int n, i, j;
  //
  int u,v,c,k,M[N][N],p[N],cos[N],visit[N],key;
  //

  //---template bubun
  scanf("%d", &n);
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }
  //--------------
  
  for (i=0;i<n;i++) {
    cos[i]=INFTY;
    if (i==0){
      cos[i]=0;
    }
    p[i]=-1;
    visit[i]=0;
  }

  //----a01.c + alpha
  while(1) {
    key = INFTY;
    u = -1;
    for (i=0;i<n;i++){
      if (key>cos[i] && visit[i]==0) {
	u = i;
	key = cos[i];
      }
    }

    if (u==-1){
      break;
    } else {
      visit[u] = 1;
      for (j=0;j<n;j++){
	if (cos[j]>cos[u]+M[u][j] && visit[j]==0){ //
	  p[j]=u;                                  //
	  cos[j]=cos[u]+M[u][j];                   //
	}                                          //
      }
    }
  }

  //cost wo shimese
  for (i=0;i<n;i++){
    printf("%d %d\n", i, cos[i]);
  }
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define vll vector<ll>
#define pb push_back
using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {x++;}
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> inline T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> inline T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> inline T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}
template<class T> inline T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> inline T sum(vector<T>v){return reduce(all(v),0LL);}

// Template ends here

vector<vll> dp(100100, vll(3, 0));

void solve(ll N, vector<ll> a, vector<ll> b, vector<ll> c){
    dp.at(0).at(0) = a.at(0);
    dp.at(0).at(1) = b.at(0);
    dp.at(0).at(2) = c.at(0);

    rep2(i, 1, N - 1) {
        dp.at(i).at(0) += a.at(i);
        dp.at(i).at(1) += b.at(i);
        dp.at(i).at(2) += c.at(i);

        rep(j, 3) {
            dp.at(i).at(j) += max(dp.at(i - 1).at((j + 1) % 3), dp.at(i - 1).at((j + 2) % 3));
        }
    }

    cout << max({ dp.at(N - 1).at(0), dp.at(N - 1).at(1), dp.at(N - 1).at(2) }) << endl;
}

int main() {
    ll N;
    ignore_ret(scanf("%lld",&N));
    vector<ll> a(N);
    vector<ll> b(N);
    vector<ll> c(N);
    for(int i = 0 ; i < N ; i++){
        ignore_ret(scanf("%lld",&a[i]));
        ignore_ret(scanf("%lld",&b[i]));
        ignore_ret(scanf("%lld",&c[i]));
    }
    solve(N, move(a), move(b), move(c));
    return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
 
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); ++(i))
#define ALL(s) (s).begin(),(s).end()
#define EACH(i,s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl
 
template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T> ostream& operator<<(ostream &s, set<T> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<*it;}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}
 
template<class T> bool chmax(T& a, T b) { if (a < b) {a = b; return 1;} return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) {a = b; return 1;} return 0; }
 
 
 
const long long INF = 1LL<<59;
const int MAX = 4010;
 
int N;
long long w[MAX];
long long sum[MAX];
long long dp[MAX][MAX];
int kdp[MAX][MAX];
 
int main() {
    while (cin >> N) {
        for (int i = 0; i < N; ++i) cin >> w[i];
         
        sum[0] = 0;
        for (int i = 0; i < N; ++i) sum[i+1] = sum[i] + w[i];
        for (int i = 0; i < MAX; ++i) for (int j = i; j < MAX; ++j) { dp[i][j] = INF; }
        for (int i = 0; i < MAX; ++i) { dp[i][i+1] = w[i]; kdp[i][i+1] = i; }
         
        for (int b = 2; b <= N; ++b) {
            for (int i = 0; i+b <= N; ++i) {
                int j = i + b;
 
                for (int k = kdp[i][j-1]; k <= kdp[i+1][j]; ++k) {
                    if (chmin(dp[i][j], dp[i][k] + dp[k][j] + sum[j] - sum[i])) 
                        kdp[i][j] = k;
                }
            }
        }
 
    cout << dp[0][N] - sum[N] << endl;
    }
     
    return 0;
}

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

using namespace std;

using i64 = long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


signed main(){
    int n;
    string s;
    cin >> n >> s;
    if(n % 2 == 0 && s.substr(0, n >> 1) == s.substr(n >> 1))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256