akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 104;
int dp[MAXN][MAXN];

void solve(){
    string s; cin>>s;
    int n = sz(s);

    s = '{' + s;

    int st = 1,en = (n-1)/2;

    bool flag = true;
    while(st <= en){
        if(s[st] == s[en]){
            st++,en--;
        }else {
            flag = false; break;
        }
    }

    st = (n+3+1)/2,en = n;
    while(st <= en){
        if(s[st] == s[en]){
            st++,en--;
        }else {
            flag = false; break;
        }
    }


    st = 1,en = n;
    while(st <= en){
        if(s[st] == s[en]){
            st++,en--;
        }else {
            flag = false; break;
        }
    }

    if(flag) cout<<"Yes\n";
    else cout<<"No\n";
}

signed main(){

   FastRead;    


    int t = 1; 
    // cin>>t; 
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 256
import itertools


def main():
    n = int(input())
    p = tuple(map(int, input().split()))
    q = tuple(map(int, input().split()))
    l = [i for i in range(1, n + 1)]
    mp = {}
    for v in itertools.permutations(l, n):
        mp[v] = len(mp)
    print(abs(mp[p] - mp[q]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10344
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
typedef map<int, vector<int>> Graph;
typedef map<int, map<int, int>> WGraph;
typedef pair<int, int> Edge;

map<Edge, bool> mp;
map<int, int> back;
vector<int> dijkstra(int v, WGraph &g, int r)
{
    vector<int> cost(v, 1 << 30);
    cost[r] = 0;
    priority_queue<pair<int, int>> pq;

    pq.push({0, r});

    while (!pq.empty())
    {
        //cerr << "-------------------------------" << endl;
        auto t = pq.top();
        pq.pop();
        //cerr << t.second << "," << t.first << endl;
        if (cost[t.second] < -t.first)
        {
            continue;
        }
        for (auto x : g[t.second])
        {
            if (cost[x.first] > cost[t.second] + g[t.second][x.first])
            {
                cost[x.first] = cost[t.second] + g[t.second][x.first];
                //cerr << "update cost[" << x.first << "] with " << cost[x.first] << endl;
                back[x.first] = t.second;
                pq.push({-cost[x.first], x.first});
            }
        }
    }
    return cost;
}

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    WGraph g;
    rep(i, n)
    {
        int k;
        cin >> k >> k;
        rep(j, k)
        {
            int v, c;
            cin >> v >> c;
            g[i][v] = c;
        }
    }
    auto cost = dijkstra(n, g, 0);
    rep(i, n)
    {
        cout << i << " " << cost[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3324
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 1000001;
const int MOD =  998244353;
const int INV2 = (MOD+1)/2;

     signed main(){
       
        int n,m;
        cin>>n>>m;
        if(n%2){
          for(int i=1;i<=m;i++){
            cout<<i<<' '<<n+1-i<<endl;
          }
        }else{
          for(int i=1;i<=min(m,n/4);i++){
            cout<<i<<' '<<n+1-i<<endl;
          }
          for(int i=n/4 +1;i<=m;i++){
            cout<<i<<' '<<n-i<<endl;
          }
        }
        





}


        


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int data = sc.nextInt();
		for(int i=0; i<data; i++){
			String mcxi_1 = sc.next();
			String mcxi_2 = sc.next();

			int a = Main.numeral_system(mcxi_1);
			int b = Main.numeral_system(mcxi_2);

			String str = Main.changeMCXI(a+b);	

			System.out.println(str);
		}
	}

	static int numeral_system(String mcxi){
		int num = 0;
		int coefficient = 1;
		for(int i=0; i<mcxi.length(); i++){
			char temp = mcxi.charAt(i);
			if(temp>'0'&&temp<='9'){
				coefficient = temp - '0';
			}else if(temp == 'm'){
				num += coefficient*1000;
				coefficient = 1;
			}else if(temp == 'c'){
				num += coefficient*100;
				coefficient = 1;
			}else if(temp == 'x'){
				num += coefficient*10;
				coefficient = 1;
			}else{
				num += coefficient;
			}
		}
		return num;
	}

	static String changeMCXI(int num){
		String str = "";
		int coefficient, n = 1000;
		for(int i=0; i<4; i++){
			coefficient = num/n;
			if(coefficient!=0){
				if(coefficient!=1) str += String.valueOf(coefficient);
				switch(i){
					case 0:
						str += "m";
						break;
					case 1:
						str += "c";
						break;
					case 2:
						str += "x";
						break;
					case 3:
						str += "i";
				}
			}
			num -= coefficient*n;
			n /= 10;
		}
		return str;
	}
}

Measured memory_bytes: 37540
if __name__ == '__main__':
    n = int(input())
    b = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]

    sum = 0
    for i in range(n):
        if b[i] >= a[i]:
            sum = sum + a[i]
        else:
            a[i] = a[i]-b[i]
            sum = sum+b[i]
            if b[i+1]>=a[i]:
                sum = sum +a[i]
                b[i+1] = b[i+1] -a[i]
            else:
                sum = sum + b[i+1]
                b[i+1] = 0
    print(sum)

Measured memory_bytes: 18624
k =int(input())
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[k-1])

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

#define N 100005

char s[N];

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    scanf("%s", s + 1);
    int cnt = 0;
    int n = strlen(s + 1);
    for (int i = 1; i <= n; ++i)
        if (s[i] == 'o')
            ++cnt;
    for (int i = n + 1; i <= 15; ++i)++cnt;
    if (cnt >= 8)
        puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 256
def solve(left, right):
    if right - left >= 2019:
        return 0
    l_mod = left % 2019
    r_mod = right % 2019
    if r_mod < l_mod:
        return 0
    ans = 2019
    for i in range(l_mod, r_mod + 1):
        for j in range(i + 1, r_mod + 1):
            ans = min(ans, i * j % 2019)
    return ans


if __name__ == '__main__':
    L, R = map(int, input().split())
    print(solve(L, R))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  ll s = 0;
  rep(i, n) {
    cin >> a[i];
    s += a[i];
  }
  vector<int> x(n);
  x[0] = s;
  for (int i = 1; i < n; i += 2) {
    x[0] -= 2*a[i];
  }
  rrep(i, n) x[i] = 2*a[i-1] - x[i-1];
  rep(i, n) {
    printf("%d%c", x[i], i==n-1?'\n':' ');
  }
}



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

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

    vector<int> X(N);
    rep(i, N) cin >> X.at(i);

    int ans = 0;
    int sum_x = 0;

    rep(i, N)
    {
        sum_x += X.at(i);
        ans += pow(X.at(i), 2);
    }

    int tmp = ans;
    for (int i = 0; i < 100; i++)
    {
        tmp -= 2 * sum_x - N * (2 * i + 1);
        ans = min(tmp, ans);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, cnt = 0, inp;
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> inp;
        if(inp != i)
            cnt++;
    }
    cout << (cnt <= 2 ? "YES" : "NO") << endl;



    return 0;
}


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

using namespace std;

int main(int argc, char *argv[]) {
	int N, K;
	cin >> N >> K;

	vector<int> l(N);
	for (int i = 0; i < N; i++) cin >> l[i];

	sort(begin(l), end(l), greater<int>());

	int ans = 0;
	for (int i = 0; i < K; i++) ans += l[i];

	cout << ans << endl;
	return 0;
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

int n;
int ans = 0;
int num[101] = {0};
int main() {
	scanf("%d",&n);
    vector<int>d(n);
    rep(i,0,n) cin >> d[i];

    set<int>value;
    rep(i,0,n) value.insert(d[i]);
    rep(i,1,101){
        if(num[i] != 0){
            ans++;
        }
    }
    cout << value.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxi = 2e5+1;
long long h[maxi], v[maxi], tree[4*maxi];

void update(int node, long long val, int cur, int st, int end){
    if(st==end){
        if (st==node)
            tree[cur] = val;
        return;
    }
    if (node<st || node> end)
        return;
    int mid = (st+end)/2;
    update(node, val, 2*cur, st, mid);
    update(node, val, 2*cur+1, mid+1, end);
    tree[cur] = max(tree[2*cur], tree[2*cur+1]);
}

long long query(int l, int r, int cur, int st, int end){
    if (r<st || l>end)
        return INT_MIN;
    if (l<=st && end<=r)
        return tree[cur];
    int mid = (st+end)/2;
    return max(query(l, r, 2*cur, st, mid), query(l, r, 2*cur+1, mid+1, end));
}


int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int n;
    cin >> n;
    for (int i=1; i<=n; i++)
        cin >> h[i];
    for (int i=1; i<=n; i++)
        cin >> v[i];
    vector<vector<long long>> pq;
    for (int i=1; i<=n; i++){
        pq.push_back({h[i], v[i], i});
    }
    sort(pq.begin(), pq.end());
    for (auto &i: pq){
        long long cur = query(1, i[2], 1, 1, n);
        update(i[2], cur+i[1], 1, 1, n);
    }
    cout << query(1, n, 1, 1, n) << "\n" ;
}

Measured memory_bytes: 21468
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll x, y;
  cin >> x >> y;
  if(abs(x+y) <= 1){
    cout << "Brown" << endl;
  }else{
    if(abs(x-y) <= 1){
      cout << "Brown" << endl;
    }else{
      cout << "Alice" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
n,W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
bag = [0 for _ in range(W+1)]
for w,v in a:
  for i in range(min(w,W+1),W+1)[::-1]:
    bag[i] = max(bag[i], bag[i-w] + v)
print(bag[W])  

Measured memory_bytes: 45040
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
point = 0

for i in range(N):
    point += B[A[i]-1]
    if i>0 and A[i]-1 == A[i-1]:
        point += C[A[i-1]-1]
print(point)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(k,n) for(int i=k;i<(n);i++)
#define REP(n) for(int i=0;i<(n);i++)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)


int main() {
  int n;
  cin>>n;
  for(int i=1;i<10;i++){
    if(n%i==0&&n/i<10){
      cout<<"Yes";
      return 0;
    }
  }
  cout<<"No";
}

Measured memory_bytes: 256
/**
*    author:  yuya1234
*    created: 08.07.2020 17:16:43
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define ALL(v) (s).begin(), (s).end()
#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

  int n;
  cin>>n;

  vector<int> v;
  int sum=0,tmp,ans=0;

  REP(i,n)
  {
    cin>>tmp;
    if(tmp%10==0)sum+=tmp;
    else v.emplace_back(tmp);
    ans+=tmp;
  }

  v.emplace_back(0);
  SORT(v);

  bool flg=false;
  REP(i,SZ(v))
  {
    ans-=v[i];
    if(ans%10!=0)
    {
      flg=true;
      break;
    }
    
  }

  if(flg)cout<<ans<<endl;
  else cout<<0<<endl;

  return 0;
}

Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var abck = Input.arL;
        WriteLine(abck[3] % 2 == 0 ? abck[0] - abck[1] : abck[1] - abck[0]);
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< class T >
struct CumulativeSum {
  vector< T > data;

  CumulativeSum(int sz) : data(sz, 0) {};

  void add(int k, T x) {
    data[k] += x;
  }

  void build() {
    for(int i = 1; i < data.size(); i++) {
      data[i] += data[i - 1];
    }
  }

  T query(int k) {
    if(k < 0) return (0);
    return (data[min(k, (int) data.size() - 1)]);
  }
};



// やめます

int main() {
  int N, Q;
  cin >> N >> Q;
  CumulativeSum< int > sum(N);
  string S;
  cin >> S;
  for(int i = 0; i + 1 < S.size(); i++) {
    sum.add(i, S[i] == 'A' && S[i + 1] == 'C');
  }
  sum.build();
  while(Q--) {
    int x, y;
    cin >> x >> y;
    --x;
    cout << max(0, sum.query(y - 2) - sum.query(x - 1)) << endl;
  }
}





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

using namespace std;
const int MAXN = 1e5+3;
string s;
int x[MAXN], n, flag;
//1 is sheep
//0 is lang

bool dfs() {
    for(int i = 1; i <= n; i++) {
        if(s[i] == 'o') {
            if (x[i]) x[i+1] = x[i-1];
            else x[i+1] = 1-x[i-1];
        } else {
            if(x[i]) x[i+1] = 1-x[i-1];
            else x[i+1] = x[i-1];
        }
    }
    if(x[n] == x[0] && x[n+1] == x[1]) return true;
    else return false;

}

int main() {
    cin >> n >> s;
    s[n] = s[0], s[n+1] = s[1];
    for(int S = 0; S <= 1; S++) {
        for(int W = 0; W <= 1; W++) {
            x[0] = S, x[1] = W;
            if(dfs()) {
                for(int i = 0; i < n; i++)
                    if(x[i]) printf("S");
                    else printf("W");
                printf("\n");
                exit(0);
            }
        }
    }
    printf("-1\n");
    return 0;
}


Measured memory_bytes: 896
#!/usr/bin/env python3

A, B, N = map(int, input().split())

f1 = 0
f2 = 0
if N >=B:
    f1 = int(A*(B-1)/B)
    f2 = A*int((B-1)/B)
else:
    f1 = int(A*N/B)
    f2 = A*int(N/B)

ans = f1-f2
print(ans)


Measured memory_bytes: 9184
#include <stdio.h>
#define max 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 1000000000

int n, m[max][max];
int totalweight;

void prim();

int main(){

  int i, j, data;
  
  scanf("%d", &n);
  //与えられた情報を格納
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      
      scanf("%d", &data);
      
      if(data == -1) m[i][j]= INFTY;
      else m[i][j]=data;
    }
  }
  
  prim();
  
  //print
  printf("%d\n", totalweight);  

  return 0;
}
void prim(){
  int u, minv; //u...現在の頂点の場所 minv...最小の重みので行ける頂点の番号
  int d[max], parent[max], color[max];
  int v;
  int i;

  //初期設定
  for(i=0; i<n; i++){
    d[i]=INFTY;
    parent[i]= -1;//-1なら親に関して何も述べられていない状態
    color[i]=WHITE;
  }

  d[0]=0;

  while(1){

    minv=INFTY;//最小の重みで行ける頂点がない場合INFTY
    u= -1;

    for(i=0; i<n; i++){
      if( d[i]<minv && color[i]!=BLACK){
	//初回...重みがある時　2回目以降...前の頂点までの重みと比べて小さい時
	//&& まだ調べ終わってない時
	
	u=i; //今の頂点はiだよ
	minv=d[i];
      }
    }

    if(u == -1) break;
    color[u]= BLACK;

    for(v=0; v<n; v++){
      if(color[v] != BLACK && m[u][v] != INFTY){

	if( m[u][v]< d[v]){
	  d[v]=m[u][v];
	  parent[v]=u;
	  color[v]=GRAY;
	}
      }
    }
    //ここで一旦d[0]~[4], p[0]~[4], color[0]~[4]に値が入る
  }//whileへ戻る

  //whileを出ると最終的なparet[i]の親の関係図が完成した
  totalweight=0;
  for(i=0; i<n; i++){
    if(parent[i] != -1) totalweight += m[i][parent[i]];
  }

}
    
	    
     
	
	
	
    
    

  
    
  



Measured memory_bytes: 2108
from collections import Counter
import numpy as np

N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for i in range(M)]

A_cnt = list(Counter(A).items())
for i in range(len(A_cnt)):
  BC.append([A_cnt[i][1], A_cnt[i][0]])
BC.sort(key=lambda x: x[1], reverse=True) # [n_cards, val_cards]

n_cards = 0
ans = 0
idx = 0
while True:
  if n_cards < N:
    if n_cards + BC[idx][0] < N:
      n_cards += BC[idx][0]
      ans += BC[idx][0] * BC[idx][1]
      idx += 1
    else:
      ans += (N - n_cards) * BC[idx][1]
      break
  else:
    #print('koko ni ha konai hazu')
    break
    
print(ans)

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int l = a + b;
  int r = c + d;

  if (l > r) {
    cout << "Left" << endl;
  }
  else if (l == r) {
    cout << "Balanced" << endl;
  }
  else {
  	cout << "Right" << endl;
  }
}

Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

struct Query {
  int t, A, B;
};
const int N = 2e5 + 10;
int64 c[N], d[N];

void add(int64 c[], int x, int64 y) {
  for (; x < N; x += x & -x) {
    c[x] += y;
  }
}

int64 query(int64 c[], int x) {
  int64 ret = 0;
  for (; x; x -= x & -x) {
    ret += c[x];
  }
  return ret;
}

int main() {
  int m;
  scanf("%d", &m);
  vector<Query> b(m);
  vector<int> a;
  for (int i = 0; i < m; ++i) {
    scanf("%d", &b[i].t);
    if (b[i].t == 1) {
      scanf("%d%d", &b[i].A, &b[i].B);
      a.push_back(b[i].A);
    }
  }
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  int n = a.size();
  // trace(n);
  for (int i = 0; i < m; ++i) {
    if (b[i].t == 1) {
      int k = lower_bound(a.begin(), a.end(), b[i].A) - a.begin() + 2;
      add(c, 1, -1);
      add(c, k, 2);
      add(d, 1, b[i].A + b[i].B);
      add(d, k, -2LL * b[i].A);
    } else {
      int low = 1, high = n + 1;
      while (low != high) {
        int mid = (low + high) / 2;
        // trace(mid, query(c, mid));
        if (query(c, mid) < 0) {
          low = mid + 1;
        } else {
          high = mid;
        }
      }
      int x = a[high - 2];
      int64 slope = query(c, high);
      int64 bias = query(d, high);
      // trace(x, slope, bias);
      printf("%d %lld\n", x, x * slope + bias);
    }
  }
  return 0;
}


Measured memory_bytes: 7032
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
	int A,B,C,D;
	while(~scanf("%d %d %d %d",&A,&B,&C,&D))
	{
		if(A+B>C+D)
			printf("Left\n");
		else if(A+B<C+D)
			printf("Right\n");
		else
			printf("Balanced\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
struct Node{int parent, left, right;};

struct Node T[10000];
int n, D[10000], H[10000];

void Depth(int u,int d){
  if(u == -1) return;
  D[u] = d;
  Depth(T[u].left, d+1);
  Depth(T[u].right, d+1);
}

int Height(int u){
  int h1 =0;
  int h2 = 0;
  if(T[u].left != -1){
    h1 = Height(T[u].left)+1;
  }
  if(T[u].right != -1){
    h2 = Height(T[u].right) + 1;
  }
  return H[u] = (h1 > h2 ? h1 : h2);
}

int Sibling(int u){
  if(T[u].parent == -1) {
    return -1;
  }
  if(T[T[u].parent].left != u && T[T[u].parent].left != -1){
    return T[T[u].parent].left;
  }
  if(T[T[u].parent].right != u && T[T[u].parent].right != -1){
     return T[T[u].parent].right;
  }
  return  -1;
}

int main(){
  int v,l,r,root=0,i;
  scanf("%d", &n);
  for (i =0;i< n;i++){
    T[i].parent = -1;
  }
  for (i = 0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left = l;
    T[v].right =r;
    if(l != -1) T[l].parent = v;
    if (r != -1) T[r].parent =v;
  }
  for ( i = 0;i<n; i++){
    if(T[i].parent == -1) root = i;
  }

  Depth(root,0);
  Height(root);
  int d;
  for (i = 0;i<n;i++){
    printf("node %d: ",i);
    printf("parent = %d, ",T[i].parent);
    printf("sibling = %d, ",Sibling(i));
    d = 0;
    if(T[i].left != -1) d ++;
    if(T[i].right != -1) d++;
    printf("degree = %d, ",d);
    printf("depth = %d, ",D[i]);
    printf("height = %d, ",H[i]);

    if(T[i].parent == -1){
      printf("root\n");
    }
    else if(T[i].left == -1 && T[i].right == -1){
      printf("leaf\n");
    }
    else {
      printf("internal node\n");
    }
  }
  return 0;
  
}
     
    

Measured memory_bytes: 624
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
const int INF = 1e9;
const int MOD = 1e9+7;

ll fact(ll n)
{
    if(n < 2) return 1;
    return (n * fact(n-1)) % MOD;
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    ll N; cin >> N;
    vl A(N); REP(i, N) cin >> A[i];
    sort(ALL(A));
    ll sum = 0, c = 0;
    REP(i, N)
    {
        if(sum*2 < A[i]) c = 1;
        else c++;
        sum += A[i];
    }
    cout << c << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back

using namespace std;
using ll=long long;
// using ll=int;

const ll mod = (ll)(1e9+7);

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;


int main(){

    /*
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("myoutput.txt", "w", stdout);
    #endif
    */

    fast;
    ll t = 1;
    // cin >> t;
    while(t--){
        string s; cin >> s;
        for(auto i : s){
            if(i == '7') {
                cout << "Yes" << endl;
                return 0;
            }
        }

        cout << "No" << endl;
        
    }
    // cerr << (double)clock()/CLOCKS_PER_SEC << endl;
    return 0;
}

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

vector<vector<int> > v;
vector<int> d,f,visited;
int cnt = 0;

void dfs(int node, vector<vector<int> > &graph)
{
  //cout << node+1 << " " << cnt+1 << "\n";
  d[node] = cnt;
  cnt++;
  visited[node] = 1;
  for(int i = 0; i<v[node].size(); i++)
  {
    if(visited[v[node][i]] == 1) continue;
    dfs(v[node][i], v);
  }
  //visited[node] = 0;
  //cout << node+1 << " " << cnt+1 << "\n";
  f[node] = cnt;
  cnt++;
}

int main()
{
  int n; cin>>n;
  d.resize(n, 0);
  f.resize(n, 0);
  visited.resize(n, 0);
  v.resize(n);
  for(int i=0; i<n; i++)
  {
    int id, u; cin>>id>>u;
    id--;
    v[i].resize(u);
    for(int j=0; j<u; j++)
    {
      int l; cin>>l;
      l--;
      v[id][j] = l;
    }
  }
  for(int i = 0; i < n; i++)
  {
    if (visited[i]) continue;
    else dfs(i, v);
  }
  for(int i = 0; i<n; i++)
  {
    cout << i+1 << " " << d[i] + 1 << " " << f[i] + 1 << "\n";
  }
  return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define err(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

using namespace std;

typedef long long ll;

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	puts(abs(x - a) < abs(x - b) ? "A" : "B");
	return 0;
}

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

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int main(){
    vector<int> prime;
    vector<int> v;
    v.push_back(2);
    for(int i=3;i<100000;i+=2){
        v.push_back(i);
    }

    while(!v.empty()){
        int min=v[0];
        prime.push_back(min);
        auto rm=std::remove_if(v.begin(),v.end(),[min](int x)->bool{return x%min==0;});
        v.erase(rm,v.end());
    }

    vector<int> like(prime.begin(),prime.end());
    auto rm=std::remove_if(like.begin(),like.end(),[&prime](int x)->bool{
            return !std::binary_search(prime.begin(),prime.end(),(x+1)/2);
            });
    like.erase(rm,like.end());

    int q;
    cin >> q;

    for(int i=0;i<q;i++){
        int l,r;
        cin >> l >> r;
        auto low=std::lower_bound(like.begin(),like.end(),l);
        auto upp=std::upper_bound(low,like.end(),r);
        cout << (upp-low) << endl;
    }
    return 0;
}



Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,k,ctn = 0;
	cin >> n >> k;
	if (k == 0 ){
		ctn = n * n ;
	} else {
		for (long long i=k;i<=n;i++){
			ctn += n/i * (i - k);
			if(n%i-k >= 0) ctn += n%i+1-k;
		}
	}
	cout << ctn << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<vector>
#include<math.h>
#include<string>

typedef long long ll;
typedef unsigned short int unsi;
typedef unsigned int uni;
typedef unsigned long int unli;

using namespace std;

unsi gojoho(unsi A, unsi B) {
	unsi R = 1;
	if (A > B) {
		while (R!=0) {
			R = A % B;
			A = B;
			B = R;
		}
		return A;
	} else {
		while (R != 0) {
			R = B % A;
			B = A;
			A = R;
		}
		return B;
	}
}

uni gojoho(uni A, uni B) {
	uni R = 1;
	if (A > B) {
		while (R != 0) {
			R = A % B;
			A = B;
			B = R;
		}
		return A;
	} else {
		while (R != 0) {
			R = B % A;
			B = A;
			A = R;
		}
		return B;
	}
}

unli gojoho(unli A, unli B) {
	unli R = 1;
	if (A > B) {
		while (R != 0) {
			R = A % B;
			A = B;
			B = R;
		}
		return A;
	} else {
		while (R != 0) {
			R = B % A;
			B = A;
			A = R;
		}
		return B;
	}
}

int gojoho(int A, int B) {
	int R = 1;
	if (A > B) {
		while (R != 0) {
			R = A % B;
			A = B;
			B = R;
		}
		return A;
	} else {
		while (R != 0) {
			R = B % A;
			B = A;
			A = R;
		}
		return B;
	}
}



int main(){
	int r;
	int D;
	int x;

	scanf("%d%d%d", &r, &D, &x);
	
	for (int i = 1; i <= 10; i++) {
		x = r * x - D;
		printf("%d\n", x);
	}

}

Measured memory_bytes: 128
#include <stdio.h>

int n, k;

int w[128];
int v[128];

int d[128][128][1024];

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d%d", &w[i], &v[i]);
	}

	int C = w[1] - 1;
	for (int i = 1; i <= n; i++) {
		w[i] -= C;
	}

	for (int i = 0; i < 128; i++) {
		for (int k = 0; k < 128; k++) {
			for (int j = 0; j < 1024; j++) {
				d[k][i][j] = -1000000000;
			}
		}
	}

	d[0][0][0] = 0;

	int M = 512;
	int mx = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int h = 0; h < M; h++) {
				if (d[i][j][h] < d[i - 1][j][h]) d[i][j][h] = d[i - 1][j][h];

				if (d[i][j + 1][h + w[i]] < d[i - 1][j][h] + v[i] && ((j + 1) * C + (h + w[i])) <= k) {
					d[i][j + 1][h + w[i]] = d[i - 1][j][h] + v[i];
					
					if (mx < d[i][j + 1][h + w[i]]) {
						//printf("%d %d %d  %d\n", i, j + 1, h + w[i], w[i]);
						mx = d[i][j + 1][h + w[i]];
					}
				}
			}
		}
	}
	printf("%d\n", mx);
	return 0;
}

Measured memory_bytes: 65664
#include<iostream>
using namespace std;
int main()
{
  int a,b,c,x,y,moneyAB=0,money=0,moneyABC=0;
  cin >> a >> b >> c >> x >> y;
  money+= a*x + b*y;
  if(x>y)
  {
    moneyAB = 2*y*c + (x-y)*a;
    moneyABC = 2*x*c;
  }
  else
  {
    moneyAB = 2*x*c + (y-x)*b;
    moneyABC = 2*y*c;
  }
  
  if(money>moneyAB)
    if(moneyAB<moneyABC)
      cout<<moneyAB;
    else
      cout<<moneyABC;
  else
  if(money<moneyABC)
    cout<<money;
  else
    cout<<moneyABC;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>


int main()
{
    int A,B,C;
    while(scanf("%d%d%d",&A,&B,&C)!=EOF){
    if(C<=A+B)
        printf("%d\n",B+C);
    else
        printf("%d\n",A+B*2+1);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using plpii = std::pair<long long, std::pair<int, int>>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

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

	int n;
	cin >> n;
	ll* a = new ll[n];
	rep(i, n) cin >> a[i];

	int minus = 0;
	ll sum = 0, minA = _MOD;
	rep(i, n) {
		if (a[i] < 0) ++minus;
		sum += abs(a[i]);
		minA = min(minA, abs(a[i]));
	}

	if (minus & 1) {
		cout << sum - minA * 2 << "\n";
	}
	else {
		cout << sum << "\n";
	}

	return 0;
}



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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

int main(void) {
    string ss;
    cin >> ss;

    int n;
    n = ss.size();

    for(int i=0;i<n;i++) {
        if(ss.at(i)!=ss.at(n-1-i)) {
            cout << "No" << endl;
            return 0;
        }
    }

    int m = (n-1)/2;
    for(int i=0;i<m;i++) {
        if(ss.at(i)!=ss.at(m-1-i)) {
            cout << "No" << endl;
            return 0;
        }
    }

    int l = (n+3)/2;
    for(int i=l-1;i<n;i++) {
        if(ss.at(i)!=ss.at(n-i+l-2)) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
q, h, s, d = map(int, input().split())
n = int(input())

l1, l2 = min(q*4, h*2, s), min(q*8, h*4, s*2, d)
if n % 2 == 0:
    print(l2 * (n//2))
else:
    print(l2 * (n//2) + l1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define MOD 1000000007LL
signed main(){
    string s; cin >> s;
    auto memo = vectors(s.size() + 1, 10,13,-1LL);
    vector<int>base(s.size() + 1,0LL);
    base[s.size()] = 1;
    
    for(int i = (int)s.size() - 1; i >= 0; --i)
        base[i] = (9 * base[i + 1] + base[i + 1]) % 13;
    for(int i = 0; i < 13; ++i)
        for(int j = 0; j < 10; ++j)
            memo[s.size()][j][i] = (i == j ? 1 : 0);
    
    function<int(int,int,int)>solver = [&](int digit,int num,int cmod){
        if( memo[digit][num][cmod] != -1LL) return memo[digit][num][cmod];
        memo[digit][num][cmod] = 0;
        int temp =  ( base[digit] * num ) % 13;
        int nmod =  (cmod - temp <= 0 ? cmod - temp + 13 : cmod - temp) % 13;
        int nidx = digit;
        if(s[nidx] == '?'){
            for(int i = 0; i < 10; ++i){
                memo[digit][num][cmod] += solver(digit + 1, i, nmod);
                memo[digit][num][cmod] %= MOD;
            }
        } else {
            memo[digit][num][cmod] += solver(digit + 1,s[nidx] - '0',nmod);
            memo[digit][num][cmod] %= MOD;
        }
        return memo[digit][num][cmod];
    };
    int ans = 0;
    if(s.front() == '?'){
        for(int i = 0; i < 10; ++i)
            ans += solver(1,i,5), ans %= MOD;
    } else {
        ans += solver(1,s.front() - '0',5);
    }
    cout << (ans % MOD) << endl;
}


Measured memory_bytes: 155000
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(void){
	int N;
	cin>>N;
	int dig = 1000000000;
	int S = 0,work=N;
	rep(i,9){
		S += work/dig;
		work -= (work/dig)*dig;
		dig /= 10;
	}
	S += work;
	if(S == 0){
		cout<<"No"<<endl;
		return 0;
	}
	if((N/S)*S == N)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

//ここから

//頂点fromから頂点toへのcost
struct edge{
  ll from,to,cost;
  edge (ll from,ll to,ll cost):from(from),to(to),cost(cost){}
};

vector<ll>d;//最短距離

void bellman_ford(vector<edge> &es,int V,int s){//es:頂点,costという要素からなる、辺についての配列、V:頂点数,s:スタート地点
    d.resize(V+1,INF);
    ll cnt=0;
    d[s]=0;
    bool upgrade=true;
    while(upgrade){
      ++cnt;
      if(cnt>V){
        for(int i=0;i<V;i++){
		      for(auto &e:es){
			      if(d[e.to]!=INF && d[e.to] > d[e.from] + e.cost)d[e.to] = -INF;
		      }
	      }
        return;
      }
      upgrade=false;//フラグ
    //それぞれの頂点につき1回ずつしか通らないため、V-1回しかループは実行されない(V回目があるときは負の辺を含む)
        for(auto &e:es){//esの変更が反映される
            if(d[e.from]==INF)continue;
            if(d[e.to]>d[e.from]+e.cost){
            d[e.to]=d[e.from]+e.cost;
            upgrade=true;
            }
        }
    }
}

using P=pair<ll,ll>;
void solve(){
  int n,m;
  cin>>n>>m;
  vector<edge>es;
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    es.eb(a,b,-c);
  }
  bellman_ford(es,n,0);
  if(d[n-1]==-INF)cout<<"inf";
  else cout<<-d[n-1]<<endl;
}

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


Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		List<String> list = new ArrayList<String>();
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == 'B') {
					if(list.size() > 0) {
						list.remove(list.size() - 1);
					}
			}else {
				list.add(String.valueOf(s.charAt(i)));
			}
		}
		StringBuilder sb = new StringBuilder();
		for(String t : list) {
			sb.append(t);
		}
		System.out.println(sb.toString());
	}
}

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

using namespace std ;

int main () {
    long long n , k,l,i=0,a[5]={} ;
    string s ;

    cin >> n ;

    while (n){
        a[i++]=n%10 ;
        n=n/10 ;
   //     cout << i-1 << "="<<a[i-1] <<endl ;

    }
    k=a[1]*10+a[0] ;
    l=a[2]+a[3]*10 ;
//    cout << k <<" " << l;

    if (k>0 and k<13 and l>0 and l<13)
        cout << "AMBIGUOUS\n";
    else if (k>0 and k<13)
        cout << "YYMM\n" ;
    else if (l>0 and l<13)
        cout << "MMYY\n" ;
    else
        cout << "NA\n" ;

    return 0 ;
}


Measured memory_bytes: 256
class Queue(object):

    def __init__(self, l):
        self._queue = l
        self._n = len(l)
        self._head = 0
        self._tail = 0

    def pop_left(self):
        if self._head == self._n:
            self._head = 0
        ret = self._queue[self._head][::]
        self._head += 1

        return ret

    def push_right(self, x):
        if self._tail == self._n:
            self._tail = 0
        self._queue[self._tail] = x
        self._tail += 1

if __name__ == '__main__':
    n, q = [int(x) for x in raw_input().split()]
    ps_list = []
    for _ in range(n):
        raw = raw_input().split()
        ps_list.append([raw[0], int(raw[1])])

    queue = Queue(ps_list)

    n_end_process = 0
    acc_time = 0
    while n_end_process < n:
        h = queue.pop_left()
        if h[1] <= q:
            n_end_process += 1
            acc_time += h[1]
            print "{} {}".format(h[0], acc_time)
        else:
            h[1] -= q
            acc_time += q
            queue.push_right(h)

Measured memory_bytes: 15496
use std::io::*;
use std::str::FromStr;

fn parse_line<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn parse_line_vec<T: FromStr>() -> Vec<T> {
    let line = parse_line::<String>();
    line.split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn println<T: ToString>(s: T) {
    println!("{}", s.to_string());
}

// ------------------------------------------------------------------------

fn main() {
    let _n = parse_line::<usize>();
    let p = parse_line_vec::<usize>();

    println(
        if p.into_iter()
            .enumerate()
            .filter(|&(i, n)| i + 1 != n)
            .nth(2)
            .is_some()
        {
            "NO"
        } else {
            "YES"
        },
    );
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
using namespace std;
const int maxn = 200010;
int dp[2][2030];
char str[maxn];
int main(){
    cin>>str;
    int len = strlen(str);
    memset(dp, 0, sizeof(dp));
    long long ans = 0;
    bool which = 0;
    dp[which][(str[0]-'0')%2019]++;
    for(int i=1; i<len; i++){
        int now = str[i]-'0';
        memset(dp[!which], 0, sizeof(dp[!which]));
        for(int j=0; j<2019; j++){
            dp[!which][( j*10 + now )%2019] = dp[which][j];
        }
        dp[!which][now]++;
        ans += dp[!which][0];
        which = !which;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3732
l,r = map(int,input().split())

if r-l >= 2019:
    ans = 0
else:
    ans = 2018
    for i in range(r-l):
        for j in range(i+1,r-l+1):
            mod = ((l+i)*(l+j))%2019
            if ans > mod:
                ans = mod

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
using namespace std;
void print_str(char str[], int s, int e);
int main() {
    // insert code here...
    char str[13];
    fgets(str, 13, stdin);
    print_str(str, 0, 3);
    printf(" ");
    print_str(str, 4, 11);
    printf("\n");
    return 0;
}
void print_str(char str[], int s, int e)
{
    for (int i = s; i<=e; i++)
        printf("%c", str[i]);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

typedef long long ll;
//typedef pair<ll, ll> P;

//static const ll MOD = 1000000007;
//static const ll INF = 100000000;

int main() {
    // input
    string N;
    cin >> N;

    // process
    for (int i = 0; i < 3; i++) {
        if (N[i] == '7') {
            cout << "Yes";
            return 0;
        }
    }

    cout << "No";
    return 0;
}

Measured memory_bytes: 3028
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)

int main(){
    int N, A;
    cin >> N >> A;
    vector<i64> X(N);
    rep(i, N) cin >> X[i];

    vector<vector<vector<i64>>> dp(N+1,vector<vector<i64>>(N+1, vector<i64>(2501, 0)));
    dp[0][0][0] = 1;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= N; j++){
            for(int a = 0; a < 2501; a++){
                dp[i][j][a] += dp[i-1][j][a];
                if(a - X[i-1] < 0 || j < 1) continue;
                dp[i][j][a] += dp[i-1][j-1][a - X[i-1]];
            }
        }
    }

    i64 ans = 0;
    for(int j = 1; j <= N; j++) ans += dp[N][j][j*A];
    cout << ans << endl;
}

// dp[i][j][a] := カードをi枚目まで見て,j枚選んだ時の和がaになる選び方の数

Measured memory_bytes: 52224