akhauriyash/Code-Regression huggingface dataset:
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif
int N, W;
vi w, v;
map<pll,ll> dp;
ll dfs(int n, ll wt) {
    if (n >= N) return 0;
    
    if (dp.count(pll(n,wt)) > 0) return dp[pll(n,wt)];

    ll ret = 0;
    if (wt+w[n] <= W) {
        ll yes = dfs(n + 1, wt + w[n]) + v[n];
        ll no = dfs(n + 1, wt);
        ret = max(yes, no);
    } else {
        ret = dfs(n + 1, wt);
    }
    
    dp[pll(n,wt)] = ret;

    return ret;
}

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

    cin >> N >> W;
    w = vi(N);
    v = vi(N);
    REP(i, N) cin >> w[i] >> v[i];

    ll ans = dfs(0, 0);

    cout << ans << endl;
    dp.clear();

    return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  string s;
  cin>>s;
  int a=0;
  int z=s.size();
  rep(i,s.size()){
    if(s[i]=='A') break;
    a++;
  }
  for(int i=s.size()-1;i>0;i--){
    if(s[i]=='Z') break;
    z--;
  }
  cout<<z-a<<endl;
}

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

int main() {
	int a, b, q;
	cin >> a >> b >> q;
	vector<long long> s(a), t(b);
	for (int i = 0; i < a; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < b; i++) {
		cin >> t[i];
	}
	vector<long long> ans;
	for (int i = 0, sl, sr, tl, tr, mid; i < q; i++) {
		long long x, ns, nt;
		cin >> x;
		ans.clear();
		sl = -1, sr = a;
		while (sr - sl > 1) {
			mid = (sl + sr) / 2;
			if (x > s[mid])
				sl = mid;
			else
				sr = mid;
		}
		tl = -1, tr = b;
		while (tr - tl > 1) {
			mid = (tl + tr) / 2;
			if (x > t[mid])
				tl = mid;
			else
				tr = mid;
		}
		if (sl > -1 && tl > -1)
			ans.emplace_back(max(x - s[sl], x - t[tl]));
		if (sr < a && tr < b)
			ans.emplace_back(max(s[sr] - x, t[tr] - x));

		if (sl < 0) {
			ns = s[sr] - x;
		} else if (sr > a - 1) {
			ns = x - s[sl];
		} else {
			ns = min(x - s[sl], s[sr] - x);
		}
		if (tl < 0) {
			nt = t[tr] - x;
		} else if (tr > b - 1) {
			nt = x - t[tl];
		} else {
			nt = min(x - t[tl], t[tr] - x);
		}
		ans.emplace_back(min(ns * 2 + nt, nt * 2 + ns));
		cout << *min_element(ans.begin(), ans.end()) << endl;
	}
}


Measured memory_bytes: 2944
N, M = [int(i) for i in raw_input().split()]
R = [tuple(int(i) for i in raw_input().split()) for i in range(N)]
R = sorted(R, key=lambda x: x[0])
money = 0
for a, b in R:
	n = min(M, b)
	M -= n
	money += n * a
print money


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

int main()
{
	int n, j = 0;
	long long a, s = 0, m = 1000000000;

	cin >> n;

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

		if (a < 0) {
			j++;
			a *= -1;
		}

		s += a;
		m = min(m, a);
	}

	if (j % 2 == 0)
		cout << s << endl;
	else
		cout << s - m * 2 << endl;

	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	int n, c, k; cin >> n >> c >> k;
	priority_queue<int> q;
	for (int i = 0; i < n; ++i) {
		int t; cin >> t;
		q.push(-t);
	}
	int res = 0;
	while (!q.empty()) {
		int depart = -q.top() + k;
		for (int i = 0; i < c && !q.empty() && -q.top() <= depart; ++i) q.pop();
		++res;
	}
	cout << res << '\n';
	return 0;
}


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

using namespace std;

int main() {
    int a, b, c, d;
    int area0, area1;

    cin >> a >> b >> c >> d;

    area0 = a * b;
    area1 = c * d;

    if (area0 > area1) cout << area0 << endl;
    else               cout << area1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    while(1){
        int z[21][21]={};
        int i,x=10,y=10,a,b,flag=0;
        char h;
        cin >> i;
        if(i==0)    break;
        while(i--){
            cin >> a >> b;
            z[b][a] = 1;
        }
        cin >> i;
        while(i--){
            cin >> h >> a;
            if(h=='N') 
                while(a--){
                    z[++y][x] = 0;
                }
            else if(h=='E')
                while(a--){
                    z[y][++x] = 0;
                }
            else if(h=='S') 
                while(a--){
                    z[--y][x] = 0;
                }
            else if(h=='W')
                while(a--){
                    z[y][--x] = 0;
                }
        }
        for(int Y=0;Y<20;Y++){
            for(int X=0;X<20;X++){
                if(z[Y][X]==1){
                    flag = 1;
                    break;
                }
            }
        }
        if(flag == 1)   cout << "No\n";
        else cout << "Yes\n";
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    int count = 1;
    for (int i = 0; i < N - 1; i++) {
        if (s.at(i) == s.at(i + 1)) {
            continue;
        }

        count++;
    }

    cout << count << endl;
}

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

vector<int> s, r, c;

void makeSet(int x){
    s.push_back(x);
    r.push_back(0);
    c.push_back(0);
}

int findSet(int x){
    int parent = s[x];
    if(x != s[x]) s[x] = findSet(s[x]);
    c[x] += c[parent];
    return s[x];
}

void relate(int x, int y, int z){
    int rootx = findSet(x);
    int rooty = findSet(y);
    if(rootx == rooty) return;
    z = z + c[x] - c[y];

    if(r[rootx] > r[rooty]){
        s[rooty] = rootx;
        c[rooty] = z;
    }else{
        s[rootx] = rooty;
        c[rootx] = -z;
        if(r[rootx] == r[rooty]){
            r[rooty] += 1;
        }
    }
}

void diff(int x, int y){
    if(findSet(x) == findSet(y)){
        cout << c[y] - c[x] << endl;
    }else{
        cout << "?" << endl;
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    for(int i = 0; i < n; i++) makeSet(i);

    int com, x, y, z;
    for(int i = 0; i < q; i++){
        cin >> com;
        if(com == 0){
            cin >> x >> y >> z;
            relate(x, y, z);
        }else{
            cin >> x >> y;
            diff(x, y);
        }
    }



    return 0;
}


Measured memory_bytes: 4316
#include "bits/stdc++.h"
using namespace std;
int main(){
    string a,b;
    cin>>a>>b;
    int n=a.size(); // 毎回sizeを計算させない(高速化)
    for(int i=0;i<n;i++){
        if(a==b){
            cout<<"Yes";
            return 0; // 終了
        }
        b=b.back()+b; // .back()は最後の要素
        b.pop_back(); // .pop_back()で最後を消去
    }
    cout<<"No"; // 1周したらNo
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxm = 111;
int m,n;
int f[maxm];
int odd;
vector<int>g;
int main()
{
    scanf("%d%d",&m,&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&f[i]);
        if(f[i]%2==1)
            odd++;
    }
    if(odd>2)
    {
        cout<<"Impossible"<<endl;
        return 0;
    }
    int now = 0;

    if(n==1)
    {
        if(f[1]-1!=0)
            g.push_back(f[1]-1);
        g.push_back(1);
    }
    else if(n==2)
    {
        if(f[1]-1!=0)
            g.push_back(f[1]-1);
        g.push_back(f[2]+1);
    }
    else
    {
        for(int i=1;i<n;i++)
        {
            if(f[i]%2==1)
            {
                now++;
                if(now==1)
                    swap(f[i],f[1]);
                else
                    swap(f[i],f[n]);
            }
        }
        if(f[1]-1!=0)g.push_back(f[1]-1);
        for(int i=2;i<n;i++)g.push_back(f[i]);
        g.push_back(f[n]+1);
    }
    for(int i=1;i<=n;i++)cout<<f[i]<<" ";cout<<endl;
    cout<<g.size()<<endl;
    for(auto && e : g)
        cout<<e<<" ";
    cout<<endl;
    return 0;
}

        



Measured memory_bytes: 256
from numpy import cumsum
N, *A = map(int, open(0).read().split())
A_dif = [abs(A[i] - A[i - 1]) if i != 0 else abs(A[i]) for i in range(N)]
cum_A = cumsum(A_dif)


for i in range(N):
    # ans=iの一つ前までの経路
    # ans+= i-1からi+1までの距離
    # ans+= i+1から最後の観光地までの経路
    # ans+= 最後の観光地から0への距離
    if i == 0:
        ans = 0
        ans += abs(A[i + 1] - 0)
        ans += (cum_A[-1] - cum_A[i + 1])
        ans += abs(A[-1])
    elif i == N - 1:
        ans = cum_A[i-1]
        ans += 0
        ans += 0
        ans += abs(A[-2])
    else:
        ans = cum_A[i-1]
        ans += abs(A[i + 1] - A[i-1])
        ans += (cum_A[-1] - cum_A[i + 1])
        ans += abs(A[-1])
    print(ans)


Measured memory_bytes: 23008
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){

  int n,a,b;
  string str;

  cin >> a >> b;
  if(a+b >=10) cout <<"error\n";
  else cout <<a+b fin;
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



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

using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

#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 all(x) x.begin(), x.end()

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

    int h, w, k;
    cin >> h >> w >> k;
    vvc a(h, vc(w));
    rep(i, h) {
        rep(j, w) {
            cin >> a[i][j];
        }
    }

    int num = 0;
    for(int i = 0; i < (1 << h); i++) {
        bitset<6> hh(i);
        for(int j = 0; j < (1 << w); j++) {
            bitset<6> ww(j);
            int che = 0;
            rep(l, h) {
                rep(m, w) {
                    if(!hh.test(l) && !ww.test(m)) {
                        if(a[l][m] == '#') {
                            che++;
                        }
                    }
                }
            }
            if(che == k) {num++;}
        }
    }

    cout << num << endl;
}

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

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;

const int INF=2000000000;
const ll LINF = 1e18+5;

int main() {
    int A, B;
    cin >> A >> B;
    if(A==1 && B==2) cout << 3 << endl;
    else if (A==1 && B==3) cout << 2 << endl;
    else if (A==2 && B==1) cout << 3 << endl;
    else if (A==2 && B==3) cout << 1 << endl;
    else if (A==3 && B==1) cout << 2 << endl;
    else if (A==3 && B==2) cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, m, c; cin >> n >> m >> c;
  vector<int> hoge(m);
  rep_i(i, m){
      cin >> hoge[i];
  }
  int ans = 0;
  int sum = 0;
  int a;
  for (int i = 0; i < n; i++){
      sum = c;
      for (int v = 0; v < m; v++){
          cin >> a;
          sum += a*hoge[v];
      }
      if(sum > 0){
          ans++;
      }
  }
  say(ans)
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
 
using namespace std;

const int WordsNum = 4;
string words[WordsNum] = { "eraser", "dreamer", "erase", "dream" };

int main()
{
    string s;
    cin >> s;
    
    int len = s.length();
    for (int i = 0; i < WordsNum; i++)
    {
        auto fd = s.rfind(words[i], len - 1);
        
        // npos は発見できなかった場合の返り値
        // len - fd == u[i].length() は文末から見つかったことを示す
        if (fd != string::npos && len - fd == words[i].length())
        {
            // サイズ分減らす
            len -= words[i].length();
            
            // for 文やり直し (ループ最後で 0 になる)
            i = -1;
            
            // 0 以下なら分解終了
            if (len <= 0)
            {
                break;
            }
        }
    }
    
    printf("%s\n", (len == 0) ? "YES" : "NO");
    
    return 0;
}

Measured memory_bytes: 512
url = "https://atcoder.jp//contests/abc073/tasks/abc073_c"

def main():
    li = {}
    n = int(input())
    for i in range(n):
        ind = int(input())
        li.setdefault(ind, 0)
        if li[ind] == 0:
            li[ind] = 1
        else:
            li[ind] = 0
    print(list(li.values()).count(1))


if __name__ == '__main__':
    main()


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

int main() {
  int N, W;
  cin >> N >> W;
  vector<ll> v(N);
  vector<ll> w(N);
  rep(i, N) cin >> w[i] >> v[i];

  vector<vector<ll>> dp(N, vector<ll>(W+1));

  for(int i=0;i<N;i++) {
    for(int j=0;j<=W;j++) {
      if(i==0) {
        if(j-w[i] >= 0) dp[0][j] = v[0];
        continue;
      }
      if(j-w[i] >= 0) dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
      else dp[i][j] = max(dp[i][j], dp[i-1][j]);
    }
  }

  ll ans = 0;
  for(int j=0;j<=W;j++) {
    ans = max(ans, dp[N-1][j]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 82460
#include <bits/stdc++.h>
using namespace std;
#define Me3za() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))
#define endl "\n"
int n,w;
int value[102];
int we[102];
long long mem[102][100002];
long long solve(int i=0,int k=0){
 if(i>=n)return 0;
 if(mem[i][k]!=-1)return mem[i][k];
 long long ch1=solve(i+1,k);
 long long ch2=0;
 if(k+we[i]<=w){
    ch2=solve(i+1,k+we[i])+value[i];
 }
 return mem[i][k]=max(ch1,ch2);
}
int main() {
Me3za();
cin>>n>>w;
for(int i=0;i<n;i++)cin>>we[i]>>value[i];
memset(mem,-1,sizeof mem);
cout<<solve();
}


Measured memory_bytes: 80000
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

#[allow(unused_macros)]
macro_rules! vec_md {
    ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vec_md ! ( $ ( $ dim ) ;* => $ init ) };
    ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vec_md ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] };
    ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] };
}

fn main() {
    input! {
        n: usize,
        a: [u64; n]
    }

    let mut dp = vec_md![None;n+1;n+1;n+1];

    let mut one = 0usize;
    let mut two = 0usize;
    let mut thr = 0usize;
    for i in 0..n {
        if a[i] == 1 {
            one += 1;
        } else if a[i] == 2 {
            two += 1;
        } else {
            thr += 1;
        }
    }

    let ret = rec(one,two,thr,n, &mut dp);
    println!("{}", ret);
}

fn rec(i: usize, j: usize, k: usize, n: usize, dp: &mut Vec<Vec<Vec<Option<f64>>>>) -> f64 {
    if let Some(src) = dp[i][j][k] {
        return src;
    }
    if (i,j,k) == (0,0,0) {
        return 0f64;
    }

    let mut ret = 0f64;
    if i > 0 {
        ret += rec(i-1, j, k, n, dp) * i as f64;
    }
    if j > 0 {
        ret += rec(i+1, j-1, k, n, dp) * j as f64;
    }
    if k > 0 {
        ret += rec(i, j+1, k-1, n, dp) * k as f64;
    }
    ret += n as f64;
    ret /= (i+j+k) as f64;
    dp[i][j][k] = Some(ret);
    ret
}

Measured memory_bytes: 469244
n=int(input())
s=input()
li=list(s)
leftWhichNeedsRight = [] # )
RightWhichNeedsLeft = [] # ()
if li[0] == "(":
    leftWhichNeedsRight.append(1)
    RightWhichNeedsLeft.append(0)
if li[0] == ")":
    leftWhichNeedsRight.append(0)
    RightWhichNeedsLeft.append(1)
for i in range(1,n):
    c = li[i]
    l = leftWhichNeedsRight[i-1]
    r = RightWhichNeedsLeft[i-1]
    if c == "(":
        RightWhichNeedsLeft.append(r)
        leftWhichNeedsRight.append(l+1)
    elif c == ")":
        if l > 0:
            RightWhichNeedsLeft.append(r)
            leftWhichNeedsRight.append(l-1)
        else:
            RightWhichNeedsLeft.append(r+1)
            leftWhichNeedsRight.append(l)
# print(RightWhichNeedsLeft)
# print(leftWhichNeedsRight)
print("("*RightWhichNeedsLeft[n-1]+s+")"*leftWhichNeedsRight[n-1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define Im using
#define Too_Stupid_To namespace
#define Solve_This_Problem std


Im Too_Stupid_To Solve_This_Problem;

string a,b;
int dp[3005][3005];
int f(int n,int m){
  if (n==0 || m==0) return 0;
  int &ret= dp[n][m];
  if (ret!=-1) return ret;
  if (a[n]==b[m]) return ret = 1 + f(n-1,m-1);
  else return ret = max(f(n-1,m), f(n,m-1));
}
int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> a >> b;
  memset(dp,-1,sizeof dp);
  string ans = "";
  a = '$' + a;
  b = '#' + b;
  f(a.size()-1,b.size()-1);
  int x=a.size()-1,y=b.size()-1;

  while(x>0 && y>0){
    if (a[x]==b[y]) {
      ans+=a[x];
      x--; y--;
    }
    else{
      if (dp[x][y-1] > dp[x-1][y]) y--;
      else x--;
    }

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

} 

Measured memory_bytes: 35840
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll MOD = 1e9+7;
/*int dfs(vector<int> &T, vector<int> &C, int i, int sum, int g, int count){
   
}*/

int main(){
  /*
  int n, i, j;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  */
  int x, hp=0;
  cin >> x;
  while(x>=5){
    if(x-500>=0){
      x -= 500;
      hp += 1000;
    }
    else if(x-5>=0){
      x -= 5;
      hp += 5;
    }
    }
    cout << hp << endl; 
}


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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

#define INF 1e9
#define MOD 1000000007
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define each(x, v) for (auto& x: (v))
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl

void solve();
void in(){} template<class T, class... U> void in(T &t, U &...u){ cin >> t; in(u...); }
int main() { cin.tie(0); ios::sync_with_stdio(0); solve(); }

void solve() {
  int N, K, Q;
  in(N, K, Q);
  vi P(N);
  vi A(Q);
  rep(i, 0, Q) {
    int ai;
    in(ai);
    P[ai-1]++;
  }
  rep(i, 0, N) {
    if (P[i] + K > Q) {
      print("Yes");
    } else {
      print("No");
    }
  }
}


Measured memory_bytes: 1408
"use strict";
    
const main = arg => {
    const N = arg.split("\n")[0];
    const K = arg.split("\n")[1];
    const X = arg.split("\n")[2];
    const Y = arg.split("\n")[3];
    
    console.log(N - K > 0 ? (X * K) + Y * (N - K) : X * N);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define min(a,b) (((a) > (b)) ? (b) : (a))
int main(void) {
    int64_t N,T;
    int64_t sum;
    int64_t tmp;
    cin >> N >> T;
    vector<int64_t> t(N);
    for(int i=0;i<N;i++) {
        cin >> t[i];        
    }

    sum = T;
    for(int i=1;i<N;i++) {
        sum += min(T,t[i] - t[i-1]);
    }

    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)

int n, m;
vector<int> a;

string memo[10010];

string larger(string a, string b) {
    if (a[0] == '-') return b;
    if (b[0] == '-') return a;
    
    if (a.size() > b.size()) {
        return a;
    } else if (a.size() < b.size()) {
        return b;
    } else {
        REP(i, a.size()) {
            if (a[i] == b[i]) continue;
            if (a[i] > b[i]) {
                return a;
            } else {
                return b;
            }
        }
    }

    return a;
}

int mnum[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

string maxnum(int res) {
    if (res==0) return "";
    if (memo[res] != "null") return memo[res];
        
    string output = "-";
    
    REP(i, a.size()) {
        if (res < mnum[a[i]]) continue;
        string ith = maxnum(res - mnum[a[i]]) + to_string(a[i]);
        output = larger(output, ith);
    }

    return memo[res] = output;
}

int main(){
    a = vector<int>();
    cin >> n >> m;

    REP(i, 10010) memo[i] = "null";

    REP(i, m) {
        int ai;
        cin >> ai;
        a.push_back(ai);
    }

    cout << maxnum(n) << endl;
}


Measured memory_bytes: 29568
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<iomanip>
#include<cmath>
#include<numeric>
#include<vector>
#include<algorithm>
#include<string>
#include<deque>
#include<stack>
#include<map>
#include<cstring>
#include<random>
#include<queue>
#include<iterator>
#include<bitset>
#include<unordered_set>
#include<set>

using namespace std;
#define ll long long
#define endl "\n"
const int dx[] = { -1 , -1 , -1 , 0 , 0 , 0 , 1 , 1 , 1 };
const int dy[] = { -1 , 0 , 1 , -1 , 0 , 1 , -1 , 0 , 1 };
const ll integer = pow(2, 32) - 1; // 4294967295
#define N 8010000
#define TC int t;cin>>t;for(int T=1;T<=t;T++)
#define mod 1000000007
#define PI acos(-1)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define clr(v, d) memset(v, d, sizeof(v)) 
void AIA() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isprime(ll n) {
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0)return 0;
	}
	return (n != 1);
}
ll gcd(ll x, ll y)
{
	return (y == 0 ? x : gcd(y, x % y));
}
ll lcm(ll x, ll y) {
	return (x * y) / gcd(x, y);
}
/*
 _____________              __                ___        ___       ___________________________     ____        ____
|             |            /\ \              |   |      |   |     |                           |    \   \      /   /
|   __________|           / /\ \             |   |      |   |     |      _____      _____     |     \   \    /   /
|  |                     / /  \ \            |   |      |   |     |     |     |    |     |    |      \   \  /   /
|  |                    / /    \ \           |   |      |   |     |     |     |    |     |    |       \   \/   /
|  |______             / /      \ \          |   |______|   |     |     |     |    |     |    |        \      /
|         |           / /        \ \         |              |     |     |     |    |     |    |         \    /
|   ______|          / /          \ \        |    ______    |     |     |     |    |     |    |          |  |
|  |                / /============\ \       |   |      |   |     |     |     |    |     |    |          |  |
|  |               / /==============\ \      |   |      |   |     |     |     |    |     |    |          |  |
|  |              / /                \ \     |   |      |   |     |     |     |    |     |    |          |  |
|  |             / /                  \ \    |   |      |   |     |     |     |    |     |    |          |  |
|__|            /_/                    \_\   |___|      |___|     |_____|     |____|     |____|          |__|

										  <<<<<<<<<<< NEVER GIVE UP !! >>>>>>>>>>>
										<<<<<<<< YOU CAN DO IT IF YOU WANT !! >>>>>>>>
										 <<<<<<<<< BELIEVE IN YOURSELF !! >>>>>>>>>
*/
int n, x, k, m, cnt = 0;
vector<int>v1, v2, v3;
int dp[100007];
int main()
{
	//cout<<fixed<<setprecision(20);
	//freopen("Input.txt.txt", "r", stdin);
	//freopen("Output.txt.txt", "w", stdout);
	AIA();
	cin >> n;
	v1.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> v1[i];
	}
	dp[1] = abs(v1[0] - v1[1]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(v1[i] - v1[i - 1]), dp[i - 2] + abs(v1[i] - v1[i - 2]));
	}
	cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 4068
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[200001];
long long kq=1e18;
long long sum[200001];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        sum[i]=sum[i-1]+a[i];
    for(int i=1;i<n;i++)
    {
        long long h=sum[i];
        long long k=sum[n]-sum[i];
        long long tt=h-min(h,k)+k-min(h,k);
        kq=min(kq,tt);
    }
    cout<<kq;
    return 0;
}


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

int main(){
    int n, m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++) {
        int num;
        scanf("%d",&num);
    }
    int ans=ceil((double)(n-1)/(m-1));
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
s=list(input())
a = int(s[0])
b= int(s[1])
c = int(s[2])
d = int(s[3])

l = [a]
l2 = []
for x in l:
    
    l2.append(x+b)
    l2.append(x-b)
l = l2
l2 = []
for x in l:
    
    l2.append(x+c)
    l2.append(x-c)
l = l2

l2 = []
for x in l:
    
    l2.append(x+d)
    l2.append(x-d)
l = l2

k = l.index(7)
if k <= 3:
    w1 = '+'
else:
    w1 = '-'

if k == 0 or k == 1 or k == 4 or k == 5:
    w2 = '+'
else:
    w2 = '-'
    
if k%2 == 0:
    w3 = '+'
else:
    w3 = '-'
    
print(s[0] + w1 + s[1] + w2 + s[2] + w3+ s[3] +'=7')

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

int main(){
    string S,T;
    int N,M;

    cin >> S >> T;
    N = S.size();
    M = 0;

    for (int i = 0; i < N;i++){
        if(S.at(i)!=T.at(i)){
            ++M;
        }
    }
    cout << M << endl;
}

Measured memory_bytes: 3924
#include <iostream>

using namespace std;

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

  int ans = 0;
  for( int i = 0; i < N; ++i )
  {
    int tmp;
    cin >> tmp;
    ans += ( tmp - 1 );
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
ans = A*X+B*Y
for Z in range(10**5+1):
    Z *= 2
    price = A*max(X-Z//2, 0)+B*max(Y-Z//2, 0)+C*Z
    ans = min(ans, price)
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const int MAX=2e5+10;
const ll INF=1e18;

string S,T;
int ls, lt;
void input(){
	cin>>S>>T;
	ls=sz(S);
	lt=sz(T);
}

ll nex[MAX][26];
ll ans=0;
void solve(){
	rep(i,ls)rep(k,26)nex[i][k]=INF;
	for(int i=2*ls-1; i>=0; i--){
		rep(k,26)nex[i%ls][k]=min(INF, nex[(i+1)%ls][k]+1);
		int Z=S[i%ls]-'a';
		nex[i%ls][Z]=0;
	}
	rep(i,lt){
		ll tmp=nex[ans%ls][T[i]-'a'];
		ans=min(ans+tmp,INF);
      	ans++;
	}
	if(ans>INF)cout<<-1<<endl;
    else cout<<ans<<endl;
}

void output(){
  rep(k,26)if(nex[0][k]!=INF){
    char Z='a'+k;
    cout<<Z<<" ";
    rep(i,ls)cout<<nex[i][k];
    cout<<endl;
  }
}

int main(){
  input();
  solve();
}

Measured memory_bytes: 20992
# -*- coding: utf-8 -*-

def main():

    count1=int(0)
    count2=int(0)

    S = input()
    
    count1=S.count('+')
    count2=S.count('-')

    count=count1-count2
    
    print(count)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
MAX = 2010
MOD = 10**9+7
fact = [0]*MAX #fact[i]: i!
inv = [0]*MAX #inv[i]: iの逆元
finv = [0]*MAX #finv[i]: i!の逆元
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
    
for i in range(2, MAX):
    fact[i] = fact[i-1]*i%MOD
    inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
    finv[i] = finv[i-1]*inv[i]%MOD

def C(n, r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD

N, K = map(int, input().split())

for i in range(1, K+1):
    ans = C(N-K+1, i)*C(K-1, i-1)%MOD
    print(ans)

Measured memory_bytes: 42736
#include <iostream>
#include <string>

class Score {
public:
	Score() :out(0), runner(0), score(0), change(false) {};
	void batter(const int &event) {
		if (event == 0) {
			++runner;
		}
		else if (event == 1) {
			score += runner + 1;
			runner = 0;
		}
		else {
			if (++out == 3) {
				if (runner > 3) {
					score += runner - 3;
				}
				std::cout << score << std::endl;
				change = true;
			}
		}
	}
	const bool in_turn() const { return !change; }
private:
	int out, runner, score;
	bool change;
};

int main() {
	int n;
	std::cin >> n;
	for (auto i = 0; i < n; ++i) {
		Score score;
		while (score.in_turn()) {
			std::string event;
			std::cin >> event;
			if (event == "HIT") {
				score.batter(0);
			}
			else if (event == "HOMERUN") {
				score.batter(1);
			}
			else {
				score.batter(2);
			}
		}
	}
}

Measured memory_bytes: 1212
/**
 * Author : RDP
 * There are no two words in the English language more harmful than "good job".
 * 1729 ;)
**/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <numeric>
using namespace std;
using ll = long long;
#define endl '\n'
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) 
{
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define FAST_IO ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
#define bp(x) __builtin_popcount(x)
#define zf(x) __builtin_clz(x)
#define zl(x) __builtin_ctz(x)
#define par(x) __bultin_parity(x)
#define all(x) (x).begin(), (x).end()
/* **************************************************************************************** */

void test_case()
{
    int n;
    cin >> n;
    vector <bool> a(n);
    for(int i = 0; i < n; i ++)
    {
        int p, q;
        cin >> p >> q;
        a[i] = (p == q);
    }

    for(int i = 0; i < n; i ++)
    {
        if(a[i])
        {
            int j = i + 1;
            while(j < n && a[j])
                j ++;
            --j;
            if(j - i + 1 >= 3)
            {
                cout << "Yes" << endl;
                return;
            }
            i = j;
        }
    }

    cout << "No" << endl;
	return ;
}
int main()
{
	FAST_IO
    test_case();
	return 0;
}



Measured memory_bytes: 3640
/* ex4_1
   moka223711 */

#include <stdio.h>

int main(void){
    // n本の木があり、1〜nの番号がついている
    // 番号iの木に監視員がつき、i-dからi+dまでの木を監視できる
    // すべての木を監視するのに必要な監視員の数の最小値を求める
    
    int n, d, ans = 0;
    scanf("%d %d", &n, &d);
    
    // 監視員はi-dからi+dまでの2d+1本の木を監視できる
    // nを2d+1で割った商を求め、余りがあったときはもう一人監視員を加える
    ans = n / (2*d + 1);
    if(n % (2*d + 1) != 0){
        ans++;
    }
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();       //月
        int d = sc.nextInt();       //日
        int d1;
        int d2;
        int seki_cnt = 0;

        for (int i = 2;i <= m;i++){ 
                //System.out.println(m.substring(i-1,i));
                for(int x = 20; x <= d;x++){
                    d1 = x / 10;
                    d2 = x % 10;
                    if (d1 * d2 == i && d2 >= 2){
                        seki_cnt ++;
                        //System.out.println(i + "/" + x);
                    }
                }               
        }
        System.out.println(seki_cnt);

        sc.close();
    }
}

Measured memory_bytes: 22868
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double rad = abs(M_PI * 2 * (h + double(m) / 60) / 12 - M_PI * 2 * double(m) / 60);
  cout << setprecision(20) << sqrt(a * a + b * b - 2 * a * b * cos(rad)) << endl;
}


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

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

  ll ans = 0;

  if (K % 2 == 0) {
    map<int, int> m;
    for (int i = 1; i <= N; i++) {
      if (m.find(i % K) == m.end())
        m.insert(make_pair(i % K, 0));
      m[i % K]++;
    }
    for (auto e : m)
      if (e.first == 0 || e.first == K / 2) {
        ll n = e.second;
        ans += n * n * n;
      }
  } else {
    ll n = N / K;
    ans += n * n * n;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
	double x,y,a,b,c,d,e,f;
	while(cin>>a>>b>>c>>d>>e>>f){
		y=(a*f-c*d)/(a*e-d*b);
		x=(c-b*y)/a;
		cout <<fixed<<setprecision(3)<<x<<" "<<y<<endl;
	}
	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int X,A;
int main(){
  cin>>X>>A;
  if(X<A) prin(0);
  else prin(10);
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

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

Measured memory_bytes: 18476
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=2e4+4;
const int M=1e7+4;
int m,n;
struct Edge {
	int v,nxt,w;
}e[M];
int head[N],etot;
int dis[N];
bool vis[N];
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
inline void smax(int &x,int y) {
	x=x<y?y:x;
}
inline void smin(int &x,int y) {
	x=x>y?y:x;
}
inline void adde(int u,int v,int w) {
//	printf("%d %d %d\n",u,v,w);
	e[++etot].nxt=head[u],e[etot].v=v,e[etot].w=w,head[u]=etot;
}
inline void build(int pos,int step,int w) {
	for (int j=pos;j<m;j+=step)
		adde(j,j+step,w);
}
struct Node {
	int id,dis;
	friend bool operator <(const Node &a,const Node &b) {
		return a.dis>b.dis;
	}
};
inline void dijkstra(int S) {
	priority_queue<Node> q;
	memset(dis,INF,sizeof(dis));
	dis[S]=0;
	q.push((Node){S,0});
	while (!q.empty()) {
		Node cur=q.top();
		q.pop();
		int p=cur.id;
		if (vis[p]) continue;
		vis[p]=true;
		for (int i=head[p];~i;i=e[i].nxt) {
			int v=e[i].v;
			if (dis[v]>dis[p]+e[i].w) {
				dis[v]=dis[p]+e[i].w;
				q.push((Node){v,dis[v]});
			}
		}
	}
}
int main() {
//	freopen("in3.txt","r",stdin);
	memset(head,-1,sizeof(head));
	m=read(),n=read();
	int mv=0;
	for (int i=1;i<=n;++i) {
		int v=read();
		int c=read();
		smax(mv,v);
		for (register int p=0;p<v;++p)
			build(p,v,c);
	}
	dijkstra(0);
	int ans=INF;
	for (int i=m;i<mv+m;++i) {
		smin(ans,dis[i]);
//		printf("%d\n",ans);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 124556
n, m = map(int, input().split())
a = []
b = []
c = []

for _ in range(m):
	INPUT = list(map(int, input().split()))
	a.append(INPUT[0])
	b.append(INPUT[1])
	c.append(-INPUT[2])

dist = [float("inf") for _ in range(n)]
dist[0] = 0

for _ in range(1, n):
	for j in range(m):
		if dist[b[j] - 1] > dist[a[j] - 1] + c[j]:
			dist[b[j] - 1] = dist[a[j] - 1] + c[j]

ans = dist[n - 1]

for j in range(m):
	if dist[b[j] - 1] > dist[a[j] - 1] + c[j]:
		dist[b[j] - 1] = dist[a[j] - 1] + c[j]

if dist[n - 1] < ans:
	print("inf")
else:
	print(-ans)

Measured memory_bytes: 45528
#include <iostream>
#include <map>

using namespace std;

const int MAX_N = 100005;
int par[MAX_N];
int rn[MAX_N];

void init(int n){
    for(int i=0; i<n; i++){
        par[i] = i;
        rn[i] = 0;
    }
}

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

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x==y) return;

    if(rn[x] < rn[y]){
        par[x] = y;
    } else{
        par[y] = x;
        if(rn[x] == rn[y]) rn[x]++;
    }
}

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

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

    int X[M], Y[M], Z[M];
    for(int i=0; i<M; i++){
        cin >> X[i] >> Y[i] >> Z[i];
        X[i]--; Y[i]--;
    }

    init(N);
    for(int i=0; i<M; i++){
        unite(X[i], Y[i]);
    }

    map<int, int> m;
    int ans = 0;
    for(int i=0; i<N; i++){
        int k = find(i);
        if(m.count(k) == 0){
            m[k] = 1;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6784
#include <iostream>
#define ABS(X) ((X)<0?-(X):(X))
#define MINABS(X,Y) (ABS(X)<ABS(Y)?(X):(Y))
using namespace std;

int main(void){
  int n,l;
  int mn, sm=0;
  
  cin >> n >> l;
  mn = ABS(l);
  for (int i=1; i<=n; i++){
    sm += (l+i-1);
    mn = MINABS(mn, l+i-1);
  }
  cout << (sm-mn) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 1000;
int N;
ll A[Nmax];

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

	ll s0=0,s1=0;
	for(int i=0; i<N; i++){
		if(A[i]<0) continue;
		if(i%2==0) s0 += A[i];
		else s1 += A[i];
	}


	ll sum=0;
	vector<int> ans;
	if(s0==0&&s1==0){
		ll imax=0;
		for(int i=0; i<N; i++){
			if(A[imax]<A[i]) imax=i;
		}
		sum = A[imax];
		for(int i=imax+1; i<N; i++){
			ans.push_back(N-i+imax+1);
		}
		for(int i=0; i<imax; i++){
			ans.push_back(1);
		}
	} else {
		int p = s0>s1?0:1;
		sum =  max(s0, s1);
		map<int, bool> use;
		int s=0;
		for(int i=0; i<N; i++){
			if(i%2==p && A[i]>0) use[i]=true;
			else use[i]=false;
		}
		for(int i=N-1; !use[i]; i--){
			ans.push_back(i+1);
			use.erase(i);
		}
		for(int i=0; !use[i]; i++){
			ans.push_back(1);
			use.erase(i);
			s=i+1;
		}
		for(int i=s+2; use.find(i)!=use.end(); i+=2){
			if(use[s]&&use[i]){
				ans.push_back(2);
			} else {
				ans.push_back(3);
			}
		}
	}

	cout << sum << endl;
	cout << ans.size() << endl;
	for(int a: ans){
		cout << a << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
# elem 前後で自分未満のものをカウント * K
N, K =  map(int, sys.stdin.readline().split())
L =  list(map(int, sys.stdin.readline().split()))

cnt = 0
for l1 in L:
    for l2 in L:
        if l1 > l2:
            cnt += 1
prev = 0
for i in range(N):
    for j in range(i, -1, -1):
        if L[i] > L[j]:
            prev += 1
if cnt == 0:
    print(0)
else:
    # print((cnt * K * K - K * (K - 1)// 2) % big_prime)
    print((cnt * K * K - cnt * K * (K -1) // 2 - prev * K) % big_prime)

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

int main() {
    int h, n;
    cin >> h >> n;
    int sum = 0;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
        sum += a.at(i);
    }
    if(sum >= h){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);

queue<int> que;

int main() {
    int N; cin >> N;
    bool ok = false;
    int n;
    if(N == 1) {
        cout << "Yes" << endl;
        cout << 2 << endl;
        cout << 1 << " " << 1<< endl;
        cout << 1 << " " << 1 << endl;
        return 0;
    }
    for(int k = 1; k <= 1000; k++) {
        que.push((k-1)*(k+4)/2+3);
        if(N == (k-1)*(k+4)/2+3) {
            ok = true;
            n = k;
        }
    }
    if(!ok) {
        cout << "No" << endl;
        return 0;
    } else cout << "Yes" << endl;
    //cout << n << endl;
    int r = 2;
    int c = 1;
    int y = 0;
    int x = 0;
    vecveci ans(n+2,veci(n+1));
    ans[0][0] = 1, ans[1][0] = 1;
    for(int i = 2; i <= N; i++) {
        if(i < que.front()) {
            ans[r][x] = i;
            ans[y][c] = i;
            x++;
            y++;
        } else if(i == que.front()) {
            ans[r][x] = i;
            ans[y][c] = i;
            r++;
            c++;
            x = 0;
            y = 0;
            que.pop();
        }
    }

    cout << n+2 << endl;
    REP(i,n+2) {
        cout << n+1 << " ";
        REP(j,n+1) cout << ans[i][j] << " ";
        cout << endl; 
    }
}


Measured memory_bytes: 3808
import queue
k = int(input())
q = queue.Queue()
cnt = 0
for i in range(1,10):
    q.put(i)
    
while cnt < k: 
    num = q.get()
    if num%10 != 0:
        q.put(num*10+num%10-1)
    q.put(num*10+num%10) 
    if num%10 != 9:
        q.put(num*10+num%10+1)
    cnt += 1
    
print(num)

Measured memory_bytes: 12452
N, C = map(int, input().split())
D = [[0 for j in range(C)] for i in range(C)]
for i in range(C):
  D[i] = [int(x) for x in input().split()]
Cxy = [[0 for j in range(C)] for i in range(3)]
for i in range(N):
  for j, c in enumerate(input().split()):
    Cxy[(i + j + 2) % 3][int(c) - 1] += 1
Change = [[[0, j] for j in range(C)] for i in range(3)]
for i in range(3):
  for j in range(C):
    for k in range(C):
      Change[i][j][0] += D[k][j] * Cxy[i][k]
for i in range(3):
  Change[i].sort()
cost = Change[0][2][0] + Change[1][2][0] + Change[2][2][0]
for i in range(3):
  for j in range(3):
    for k in range(3):
      if Change[0][i][1] != Change[1][j][1] and Change[1][j][1] != Change[2][k][1] and Change[2][k][1] != Change[0][i][1]:
        cost = min(Change[0][i][0] + Change[1][j][0] + Change[2][k][0], cost)
print(cost)

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  if((N/100) == (N%10)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
x=input().rstrip()
x10=int(x,2)
pcx=x.count("1")

plus=x10%(pcx+1)
if pcx>=2:
    minus=x10%(pcx-1)

def popcnt(x):
    cnt=1
    while x>=1:
        x%=(bin(x).count("1"))
        cnt+=1
    return cnt

for i in range(n):
    if x[i]=="0":
        amari=(plus+pow(2,n-i-1,pcx+1))%(pcx+1)
        print(popcnt(amari))
    else:
        if pcx==1:
            print(0)
        else:
            amari=(minus-pow(2,n-i-1,pcx-1))%(pcx-1)
            print(popcnt(amari))

Measured memory_bytes: 83560