akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
int N;
string s;
const int maxn = 3e5 + 10;
int wcnt[maxn],ecnt[maxn];
int main() {
    cin>>N>>s;
    for(int i = 0,j = 1; i < s.size(); i++,j++){
        wcnt[j] = (s[i] == 'W') + wcnt[j - 1];
        ecnt[j] = (s[i] == 'E') + ecnt[j - 1];
    }
    int min_turn = 0x7fffffff;
    for(int i = 1; i <= N; i++){
        if(min_turn > wcnt[i - 1] + ecnt[N] - ecnt[i]){
            min_turn = wcnt[i - 1] + ecnt[N] - ecnt[i];
        }
    }
    cout<<min_turn<<endl;
    return 0;
}

Measured memory_bytes: 3076
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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 maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    ll ans=0;
    string x; cin>>x;
    string s="i";
    s+=x;
    ll Bcnt=0;
    rep1(i,N){
        if(s[i]=='B') Bcnt++;
    }
    rep1(R,N)rep1(G,N){
        if(s[R]=='R' && s[G]=='G'){ //B探す
            ll ans1,ans2,ans3,tmp=Bcnt;
            if(abs(R-G)%2==0){
                ans1=(R+G)/2;
                if(s[ans1]=='B') tmp--;
            }
            ans2=2*R-G;
            if(1<=ans2 && ans2<=N && s[ans2]=='B') tmp--;
            ans3=2*G-R;
            if(1<=ans3 && ans3<=N && s[ans3]=='B') tmp--;
            
            ans+=tmp;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a*b==15) cout<<"*"<<endl;
    else if(a+b==15) cout<<"+"<<endl;
    else cout<<"x"<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
unsigned long long res=0;
long long n;

int main()
{
    cin >> n;
    for (long long i=1;i<=n;++i)
        if ( (i%3)!=0)
            if ((i%5)!=0)
                res+=i;
    cout << res;
    return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<pair<T, T>>& vp) {
	for (int i = 0; i < vp.size(); ++i) {
		s << "(" << vp[i].first << "," << vp[i].second << ")" << ( i+1 == vp.size() ? "" : ",\t" );
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
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...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
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);
}

//main code

int main(int argc, char const* argv[])
{
	int a,b;
	cin >> a >> b;
	if ((a*b)%2 == 1) {
		cout << "Odd" << endl;
	} else {
		cout << "Even" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;
  int r,k,t;
  int p;
  int s,d,b;
  int ans=0;
  int box[111][111];
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      box[i][j]=(1<<21);
    }
  }
  for(int i=0;i<n;i++){
    cin >> r >> k;
    for(int j=0;j<k;j++){
      cin >> t;
      box[r-1][t-1]=1;
    }
  }
  for(int z=0;z<n;z++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	box[i][j]=min(box[i][j],box[i][z]+box[z][j]);
      }
    }
  }
  cin >> p;
  for(int i=0;i<p;i++){
    cin >> s >> d >> b;
    ans=box[s-1][d-1]+1;
    if(ans<=b){
      cout << box[s-1][d-1]+1 << endl;
    }else{
      cout << "NA" << endl;
    }
  }
}

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


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, typ=int):
    return [typ(input()) for _ in range(n)]


def main():
    S = input()

    for i in range(26):
        c = chr(ord('a') + i)
        if c not in S:
            print(c)
            return

    print(None)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <stdio.h>
 
int main(void) {
	int a,b,c,d,e;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	if(a==0){printf("1");}
     else if(b==0){printf("2");}
     else if(c==0){printf("3");}
     else if(d==0){printf("4");}
     else {printf("5");}
	return 0;
}

Measured memory_bytes: 1620
// #includes {{{
#ifdef MY_DEBUG
#include "header/header.hpp"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
T inf(){
	return numeric_limits<T>::has_infinity?numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);
}

typedef pair<int,int> pii;

#ifdef MY_DEBUG
#include"debug.hpp"
#include"print.hpp"
#endif
// }}}

const string YES = "YES";
const string NO = "NO";
Int H;
Int W;
Int N;
Int s_r;
Int s_c;
string S;
string T;

void solve(){
	int up = s_r, bottom = s_r;
	REP(i,N){
		if(S[i]=='U')up--;
		else if(S[i]=='D')bottom++;
		if(up<1 or bottom>H){
			cout<<NO<<endl;
			return;
		}
		if(T[i]=='U'){
			if(bottom>1)bottom--;
		}else if(T[i]=='D'){
			if(up<H)up++;
		}
//		if(up>bottom)swap(up,bottom);
	}
	int left = s_c, right = s_c;
	REP(i,N){
		if(S[i]=='L')left--;
		else if(S[i]=='R')right++;
		if(left<1 or right>W){
			cout<<NO<<endl;
			return;
		}
		if(T[i]=='L'){
			if(right>1)right--;
		}else if(T[i]=='R'){
			if(left<W)left++;
		}
//		if(left>right)swap(left,right);
	}
	cout<<YES<<endl;
}

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

	cin >> H;
    cin >> W;
    cin >> N;
    cin >> s_r;
    cin >> s_c;
    cin >> S;
    cin >> T;
	solve();
	return 0;
}


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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

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

const int N = 1e5 + 5, D = 1e1 + 1;

bool M[N][D];
int C[N];
vector<int> G[N];

void Q(int v, int d, int c) {
	if (M[v][d]) return;
	M[v][d] = true;
	if (d == 0) {
		C[v] = c;
		return;
	}
	Q(v, d - 1, c);
	for (int u : G[v]) Q(u, d - 1, c);
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n, m; cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int v, u; cin >> v >> u;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	int q; cin >> q;
	vector< pair<int, pii> > qs;
	for (int i = 0; i < q; i++) {
		int v, d, c; cin >> v >> d >> c;
		qs.push_back(make_pair(v, make_pair(d, c)));
	}
	reverse(all(qs));
	for (pair<int, pii> x : qs) Q(x.first, x.second.first, x.second.second);
	for (int i = 1; i <= n; i++) cout << C[i] << endl;

	return 0;
}


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

int main(){
  int h,w;
  cin >> h >> w;
  vector<char> board(2500);

  for(int i=0;i<h*w;++i) cin >> board.at(i);

  vector<int> dx={1,0,-1,0,1,-1,-1,1};
  vector<int> dy={0,1,0,-1,1,1,-1,-1};

  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(board.at(i*w+j) == '#'){
        cout << board.at(i*w+j);  
        continue;
      }

      int num=0;
      for(int d=0;d<8;++d){
        int ni = i+dy.at(d);
        int nj = j+dx.at(d);
        if(ni < 0 || h <= ni) continue;
        if(nj < 0 || w <= nj) continue;
        if(board.at(ni*w+nj) == '#') num++;
      }

      board.at(i*w+j) = char(num+'0');
      cout << board.at(i*w+j);
    }
    cout << endl;
  }
}

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

int main(){
  string s;
  cin>>s;
  if(s.length()!=26){
  	for(char c='a';c<='z';c++){
    	if(s.find(c)==-1){
        	cout<<s<<(char)c<<endl;
          	return 0;
        }
    }
  }else{
  	for(int i=s.size();i>0;i--){
    	if(s[i]>s[i-1]){
          	auto p=s.substr(i);
          	sort(p.begin(),p.end());
          	for(auto c:p){
            	if(s[i-1]<c){
		        	cout<<s.substr(0,i-1)<<c<<endl;
                  	return 0;
                }
            }
        }
    }
  }
  cout<<-1<<endl;
}

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

int main() {
	std::vector<bool> isPrime(1000000, true);
	std::vector<int> numP(1000000, 0);

	isPrime[0] = false;
	isPrime[1] = false;

	for (int i = 2; i < 1000000; i++) {
		if (isPrime[i]) {
			numP[i] = numP[i - 1] + 1;
			for (int x = 2; i*x < 1000000; x++) {
				isPrime[i*x] = false;
			}
		}
		else {
			numP[i] = numP[i - 1];
		}
	}

	int input;
	while (std::cin >> input) {
		std::cout << numP[input] << std::endl;
	}
	return 0;
}

Measured memory_bytes: 6628
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   let HP = xs[0];
   let attack = xs[1];
  
   let ans = xs[0]/xs[1];
   console.log(Math.ceil(ans));


}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 19656
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	m := make(map[byte]int)
	var s string
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		m[s[0]]++
	}

	march := []byte{'M', 'A', 'R', 'C', 'H'}

	ans := 0
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			for k := j + 1; k < 5; k++ {
				ans += m[march[i]] * m[march[j]] * m[march[k]]
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		if((a*b)%2==0) {
			System.out.println("Even");
		}else {
			System.out.println("Odd");
		}
	}

}


Measured memory_bytes: 19284
#include<iostream>


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

    if(A>=13){
        std::cout<<B<<std::endl;
    }else if(A>=6){
        std::cout<<B/2<<std::endl;
    }else{
        std::cout<<0<<std::endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef long double ld;
vector<pair<ld,int>> p;
vector<ll> v;
ll a[200010],b[200010],dp[200010][40],c[200010];
int main(){
	ll i,j,n,t;
	cin >> n >> t; t++;
	for(i=0;i<n;i++){
		cin >> a[i] >> b[i];
		a[i]++; b[i]++;
		if(a[i]>=2){
			p.push_back({(ld)(a[i] - 1)/(ld)b[i],i});
		}else{
			v.push_back(b[i]);
		}
	}
	sort(p.rbegin(),p.rend());
	sort(v.begin(),v.end());
	for(i=0;i<=p.size();i++){
		for(j=0;j<40;j++){
			dp[i][j] = 100000000000;
		}
	}
	dp[0][0] = 1;
	for(i=1;i<=p.size();i++){
		for(j=0;j<40;j++){
			int k = p[i - 1].second;
			if(dp[i - 1][j]<=t) dp[i][j] = min(dp[i][j],dp[i - 1][j]);
			if(j>=1 && dp[i - 1][j - 1]<=t && a[k]*dp[i - 1][j - 1] + b[k]<=t) dp[i][j] = min(dp[i][j],a[k]*dp[i - 1][j - 1] + b[k]);
		}
	}
	ll sum = 0,ans = 0;
	int k = 0;
	for(j=39;j>=0;j--){
		while(k<v.size() && dp[p.size()][j] + sum + v[k]<=t){
			sum += v[k];
			k++;
		}
		c[j] = k;
	}
	for(j=0;j<40;j++){
		if(dp[p.size()][j]<=t){
			ans = max(ans,j + c[j]);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 74088
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include <vector>
#define ll long long int
#define ve vector<int>
#define vell vector<ll>
#define ve_pa vector<pair<ll,ll> >
#define pb push_back
#define mod 1000000007
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll a,b,c,k;cin>>a>>b>>c>>k;
if(a>k)
{
	cout<<k;
}
else if(a+b>k)
{
	cout<<a;
}
else  
{
	cout<<a-(k-a-b);
}



}

Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

bool ok(const char& s, const char& t1, const char& t2, const char& t3) {
    if ( (s == 'o' && t1 == 'W') || (s == 'x' && t1 == 'S')) return t2 != t3;
    else return t2 == t3;
}

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

    vector<string> init = {"WW", "WS", "SS", "SW"};
    string ans = "-1";

    // oox
    for (auto& t : init ) {
        for (int i=1; i<n-1; i++) {
            if ( (t[i] == 'W' && s[i] == 'o') || (t[i] == 'S' && s[i] == 'x') ) t += (t[i-1]=='W'? 'S' : 'W');
            else if ( (t[i] == 'W' && s[i] == 'x') || (t[i] == 'S' && s[i] == 'o') ) t += t[i-1];
        }
        if (ok(s[n-1], t[n-1], t[0], t[n-2]) && ok(s[0], t[0], t[n-1], t[1])){
            ans = t;
            break;
        }
    }
    cout << ans << endl;
}

/*
 * 6
 * ooxoox
 *
 * W
 *
 * 3
 * ○○×
 * WWS -> ×
 * WSW -> ×
 * SSS -> ×
 * SWW -> ×
 */

Measured memory_bytes: 832
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define infy 2e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________
const int N = five;
int dp[102][N];
int n,wt;
ll w[102];
ll v[102];
ll f(int i,int j)
{
       if(j<0){return mod;}
       if(i==-1){
              if(j!=0){return mod;}
              return 0;
       }
       if(dp[i][j] != -1){return dp[i][j];}
       return dp[i][j] = min(f(i-1,j-v[i])+w[i],f(i-1,j));
}
int main()
{
       cin>>n>>wt;
       fri(i,0,n){
              cin>>w[i]>>v[i];
       }
       memset(dp,-1,sizeof dp);
       ll ans = 0;
       fri(i,0,N-2){
              if(f(n-1,i)<=wt){
                     ans = i;
              }
       }
       cout<<ans<<endl;
}


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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

int main() {
    Int n, x;
    cin >> n >> x;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    for (Int i = 0; i < n; i++) {
        x -= a[i];
    }
    print(n + x / a[0]);
    return 0;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

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

  int n;
  cin >> n;
  rep(bit, 1<<n) {
    cout << bit << ":";
    rep(i, n) if((bit>>i)&1) cout << " " << i;
    cout << endl;
  }

  return 0;
}



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

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let a: u32 = read();
    let b: u32 = read();
    let t: u32 = read();
    println!("{}", t / a * b);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define watch(x) cout << #x << " is " << x << endl;
#define print(a, l, r) \
    for (int i = l; i < r; i++) cout << a[i] << (i == (r - 1) ? endl : " ");
const long long M = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin >> s;

    int a = 0, b = 0;
    for (auto c : s) {
        if ((c - 'A') == 0) {
            a++;
        } else if ((c - 'A') == 1) {
            b++;
        }
    }
    /*  watch(a);
    watch(b); */
    if (a == 0 || b == 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;

    s64 a;
    s64 cnt[60];
    rep (i, 60) cnt[i] = 0;
    rep (i, n)
    {
        cin >> a;
        int j = 0;
        while (a)
        {
            cnt[j++] += a & 1;
            a >>= 1;
        }
    }

    s64 pow2[61];
    pow2[0] = 1;
    rep (i, 60)
    {
        pow2[i + 1] = (pow2[i] << 1) % MOD;
    }

    s64 ans = 0;
    rep (i, 60)
    {
        ans = (ans + ((cnt[i] * (n - cnt[i]) % MOD) * pow2[i] % MOD)) % MOD;
    }

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



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

int main(){

int judge=0;
string S;
cin >> S;
for(int i=0;i<3;i++){
    if(S.at(i)==S.at(i+1)){
        judge=1;
    }
}
if(judge==1){
    cout << "Bad" << endl;
}
else{
    cout << "Good" << endl;
}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN];

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m;
	if (n==m) kill("Yes")
	kill("No")
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i<N; i++)
#define RVROOP(i, N) for(int i=N; i>=0; i--)
#define INF 1e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  int N,M; cin>>N>>M;
  if(N==1){
    cout<<"1"<<endl;
  }
  else{
    int a[N+1];
    for(int i=0; i<=N; i++){
      a[i]=0;
    }
    for(int i=0; i<M; i++){
      int A;
      cin>>A;
      a[A]=1;
    }
    ll x,y;
    x=1;
    if(a[1]==0){
      y=1;
    }
    else{
      y=0;
    }
    for(int i=2; i<N; i++){
      if(a[i]==0){
        ll z=y;
        y=(x+y)%MOD;
        x=z;
      }
      else{
        x=y;
        y=0;
      }
    }
    cout<<(x+y)%MOD<<endl;
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=b-1;i>=a;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll N,A[200007],ans[200007];
vector<vector<ll>> E(200007);

ll binaly(ll key,vector<ll>& V,vector<ll>& dp){
  ll ok=0,ng=V.size();
  while(ok<ng){
    ll mid = (ok+ng)/2;
    if(dp[mid]<key){ 
      ok = mid+1; 
    }
    else{
      ng = mid;
    }
  }
  return ok;
}

void dfs(ll key,ll mae, vector<ll>& dp,vector<ll>& V){
  V.pb(A[key]);
  ll bak,bak2;
  bak2=dp[bak=binaly(A[key],V,dp)];
  dp[bak]=A[key];
  ans[key]=lower_bound(dp.begin(), dp.end(), INF ) - dp.begin();
  rep(i,E[key].size()){
    if(E[key][i]!=mae){
      dfs(E[key][i],key,dp,V);
    }
  }
  dp[bak] = bak2;
  V.pop_back();
}

int main(){
  cin >> N;
  rep(i,N){
    cin >> A[i+1];
  }
  vector<ll> V;
  V.clear();
  vector<ll> dp(200007,INF);
  rep(i,N-1){
    ll X,Y;
    cin >> X >> Y;
    E[X].pb(Y);
    E[Y].pb(X);
  }
  dfs(1,0,dp,V);
  rep(i,N){
    cout << ans[i+1] << endl;
  }
}

Measured memory_bytes: 37532
#include<stdio.h>
int main(){
  int i,j,s,k,a=0;
  scanf("%d%d",&k,&s);
  for(i=0;i<=k;i++){
    if(s-i>=0&&s-i<=k)a+=s-i+1;
    if(s-i>k&&s-i<=2*k)a+=2*k-s+i+1;
  }
  printf("%d",a);
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static int W;
    static int H;
    static int[] P;
    static int[] Q;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        W = sc.nextInt();
        H = sc.nextInt();
        P = sc.nextIntArray(W);
        Q = sc.nextIntArray(H);
        System.out.println( solve() );
    }

    static long solve() {
        Arrays.sort(P);
        Arrays.sort(Q);

        int pi = 0;
        int qi = 0;

        long ans = 0;
        while(pi < W || qi < H) {
            if( pi == W ) {
                ans += Q[qi];
                qi++;

            } else if( qi == H ) {
                ans += P[pi];
                pi++;

            } else {
                long p = P[pi];
                long q = Q[qi];

                if( p < q ) {
                    ans += p * (H - qi + 1);
                    pi++;
                } else {
                    ans += q * (W - pi + 1);
                    qi++;
                }
            }
        }
        return ans;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;
        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }
        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }
        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}

Measured memory_bytes: 43656
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();

    if k == 1 {
        return "0".to_string();
    }

    let ans = n - k;
    return ans.to_string();
}


Measured memory_bytes: 2104
#include<cstdio>//AT3959
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int N=200010;

struct B{
	int u,id;
	bool operator<(const B&rhs)const{
		return u<rhs.u;
	}
};

B b[N];

int n,a[N],aans;

int main(){
	scanf("%d",&n);
	if(n==1){
		printf("0\n");
		return 0;
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[i].u=a[i];
		b[i].id=i;
	}
	sort(b+1,b+1+n);
	int cnt=1;
	for(int i=2;i<=n;i++){
		if(b[i].id>b[i-1].id){
			cnt++;
		}
		else{
			aans=max(cnt,aans);
			cnt=1;
		}
	}
	aans=max(cnt,aans);
	printf("%d\n",n-aans);
	return 0;
}


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

using namespace std;
using ll = long long;

#define FOR(i,m,n) for(ll i=(m); (i)<(ll)(n); ++(i))
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin,(a).end

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  ll x; cin >> x;
  ll now = 100;
  for(ll i=1; ; ++i){
    now *= 1.01;
    if(now >= x){
      cout << i << "\n";
      return 0;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();

		if(y >= r && y <= H-r && x >=r && x <= W-r){
			System.out.printf("Yes\n");
		}else{
			System.out.printf("No\n");
		}
	}
}



Measured memory_bytes: 26376
#include<stdio.h>
int main() {
	int a, b;
	char op;
	while (1) {
		scanf("%d %c %d", &a, &op, &b);
		if (op == '+') {
			printf("%d\n", a + b);
		}
		else if (op == '-') {
			printf("%d\n", a - b);
		}
		else if (op == '*') {
			printf("%d\n", a * b);
		}
		else if (op == '/') {
			printf("%d\n", a / b);
		}
		else {
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	cout << a[n - 1] - a[0] << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main() {
 int a,b,r=90;
 double x=0,y=0;
 char c;
 while(true) {
 scanf("%d%c%d",&a,&c,&b);
 if (a==0 && b==0) break;
 x+=a*cos(3.141592*r/180);
 y+=a*sin(3.141592*r/180);
 r-=b;
 }
 cout << (int)x << endl << (int)y << endl;
 return 0;
}

Measured memory_bytes: 1212
#C - *3 or /2
N = int(input())
a = list(map(int, input().split()))
tmp = 0
for i in range(N):
    for _ in range(a[i]//2):
        if a[i] % 2 == 0:
            a[i] = a[i] / 2
            tmp += 1
        else:
            break

print(tmp)

Measured memory_bytes: 4148
n,k=map(int,input().split())
count=[]
num=0
for i in range(n):
  j=0
  num=i+1
  while num<k:
    num*=2
    j+=1
  count.append(j)
ran=[]
for i in range(n):
  ran.append((1/2)**count[i])
print((1/n)*sum(ran))

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

int main(){
  int W, a, b;
  cin >> W >> a >> b;
  
  if (abs(a-b) <= W){
    cout << 0 << endl;
  }
  else if (a > b){
    cout << a - b - W << endl;
  }
  else{
    cout << b - a - W << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 1000000
#define INF 2000000000

void merge(int [], int, int, int);
void mergeso(int [], int, int);

int count=0,n;
int A[N];


int main()
{
  int i,l=0,m,r;

  scanf("%d",&n);
  r=n;
  
  for(i=0; i<n; i++) scanf("%d",&A[i]);
  
  mergeso(A,l,r);
   
  for(i=0; i<n; i++)
    {
      printf("%d",A[i]);
      if(i!=n-1)printf(" ");
    }
  printf("\n");
  printf("%d\n",count);
    

  return 0;
}

void merge(int A[], int l, int m, int r)
{
  int n1,n2,L[N],R[N],k,i,j;

  
  n1=m-l;
  n2=r-m;

  for(i=0; i<n1; i++) L[i]=A[l+i];
  L[n1]=INF;
  for(i=0; i<n2; i++) R[i]=A[m+i];
  R[n2]=INF;
  i=0;
  j=0;

  for(k=l; k<r; k++)
    {
      
      if(L[i]<=R[j])
	{
	  A[k]=L[i];
	  i++;
	  count++;
	}
      else
	{
	  A[k]=R[j];
	  j++;
	  count++;
	}
    }
  
}

void mergeso(int A[], int l, int r)
{
  int m;
  if(l+1<r)
    {
      m=(l+r)/2;
      mergeso(A,l,m);
      mergeso(A,m,r);
      merge(A,l,m,r);
    }
}
  
  



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

//ll F[101][11] = {};
//ll P[101][11] ={};
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N),B(N),C(N);
    rep(i,N)cin >> A[i];
    rep(i,N)cin >> B[i];
    rep(i,N)cin >> C[i];

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());

    ll sum = 0;
    /*ll L = -1, R = 1e12;
    while(L+1 < N){
        ll mid = (L+N)/2;
            ll b_ncan = lower_bound(B.begin(), B.end(), C[mid]) - B.begin(); 
            if(b_ncan>N){
                L = mid;
                continue;
            }else{
                R = mid;
            }
            /*rep(j,b_ncan){
                ll a_ncan = lower_bound(A.begin(), A.end(), B[j]) - A.begin();
                if(a_ncan>N){
                    continue;
                } 
                sum += a_ncan;
            }
        
    }*/
    rep(i,N){
        ll c_ncan = N - (upper_bound(C.begin(), C.end(), B[i]) - C.begin()); 
        if(c_ncan>N){
            continue;
        }
        
        ll a_ncan = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        if(a_ncan>N){
            continue;
        } 
            sum += a_ncan*c_ncan;
        
    }
    cout << sum << endl;
}

Measured memory_bytes: 2560
// Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

// Type
template <typename T> using P = pair<T, T>;
using ll = long long;
using ull = unsigned long long;

// Constants
const ll INF = 1e18;
const ll MOD = 1000000007;


// 辺
template <typename T>
struct Edge {
  int to;
  T cost;
  Edge(int to, T cost) : to(to), cost(cost) {}
};

// ノード
template <typename T>
struct Node {
  vector< Edge<T> > edges;
  Node() {}
  void addEdge(int to, T cost) {
    edges.push_back(Edge<T>(to, cost));
  }
};

// グラフ
template <typename T>
class Graph {
  private:
    int nodeN;
    vector< Node<T> > graph;
  public:
    Graph(int nodeN) {
      this->nodeN = nodeN;
      for(int i = 0; i < nodeN; i++) {
        graph.push_back(Node<T>());
      }
    }
    /**
      辺を追加する
      */
    void addEdge(int from, int to, T cost) {
      graph[from].addEdge(to, cost);
    }
    /**
      ベルマンフォード法
      計算量: O(|V|・|E|)
      */
    vector<T> bellmanFord(int s) {
      // 距離情報初期化
      vector<T> d(this->nodeN, -INF);
      d[s] = 0;

      // 全ての辺に対して、nodeN回更新を掛ける
      for(int i = 0; i < this->nodeN; i++) {
        for(int j = 0; j < this->nodeN; j++) {
          for(Edge<T> edge : this->graph[j].edges) {
            if(d[edge.to] < d[j] + edge.cost) {
              d[edge.to] = d[j] + edge.cost;
              // 負閉路検出
              // nodeN回目のループで、目的地Nへのルートが更新されるなら負閉路
              if(i == this->nodeN-1 && edge.to == this->nodeN-1) {
                d[this->nodeN-1] = -INF;
                return d;
              }
            }
          }
        }
      }
      return d;
    }
    /**
      getter
      */
    int getNodeN() {
      return this->nodeN;
    }
};

int main() {
  // 入力
  int N, M;
  cin >> N >> M;
  Graph<ll> graph = Graph<ll>(N);
  for(int i = 0; i < M; i++) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--; b--;
    graph.addEdge(a, b, c);
  }

  vector<ll> d = graph.bellmanFord(0);

  if(d[N-1] != -INF) {
    cout << d[N-1] << endl;
  } else {
    cout << "inf" << endl;
  }

  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void){
    int N,M;
    int correct = 0, pena = 0;
    int X[100000+1] = {0};

    int P;
    char S,S2;

    scanf("%d %d ",&N,&M);
    // printf("%d %d \n",N,M);
    
    for (int i = 0; i < M; i++){
        scanf("%d %c%c",&P,&S,&S2);
        // printf("%d %c\n",P,S);
        if(S=='W'){
            if(X[P] == -1){
                continue;
            }else{
                X[P]++;
            }
        }else if(S=='A'){
            if(X[P] == -1){
                continue;
            }else{
                pena += X[P];
                correct++;
                X[P] = -1;
            }
        }else{
            printf("???");
        }
    }

    printf("%d %d",correct,pena);

    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
#define MAXN 500100
int n, m, cnt[MAXN], a[MAXN], dp[MAXN], flag[MAXN], cnt2;
struct node
{
	int v;
	node *next;
}pool[2*MAXN], *h[MAXN];
void addedge(int u, int v)
{
	node *p = &pool[++cnt2], *q = &pool[++cnt2];
	p->v = v; p->next = h[u]; h[u] = p;
	q->v = u; q->next = h[v]; h[v] = q;
}
queue<int> Q;
void bfs()
{
	Q.push(1);
	int u, v;
	while(!Q.empty())
	{
		u = Q.front();
		Q.pop();
		flag[u] = 0;
		for(node *p = h[u]; p; p = p->next)
		{
			if(dp[p->v] == 0 || cnt[p->v] > cnt[u] + 1)
			{
				dp[p->v] = u;
				cnt[p->v] = cnt[u] + 1;
				if(flag[p->v] == 0) Q.push(p->v), flag[p->v] = 1;
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	int u, v;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		addedge(u, v);
	}
	dp[1] = 1;
	bfs();
	for(int i=2;i<=n;i++)
		if(dp[i] == 0)
		{
			printf("No\n");
			return 0;
		}
	printf("Yes\n");
	for(int i=2;i<=n;i++) printf("%d\n",dp[i]);
	
	return 0;
}

Measured memory_bytes: 12096
#include <bits/stdc++.h>
using namespace std;
signed main(){
	long long a,b,z,s;
  	cin>>a>>b;
  	if(b > a)
      swap(a,b);
  	s=a*b;
  	z=a%b;
  	while(z){
      a=b;
		b=z;
      z=a%b;
    }
  	cout<<s/b<<endl;
	return(0);
}

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

#define int long long

int32_t main(){
	int n;
	cin >> n;
	int a[n] ;
	for(int i = 0 ; i < n ; i++) cin >> a[i] ;
	int ans = 0 ;
	int mx = 0 ;
	for(int i = 0 ; i < n ; i++){
		mx = max(mx , a[i]) ;
		ans += mx - a[i] ;
	}
	cout << ans ;
	return 0 ;
}



Measured memory_bytes: 5076
def calc_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

n = int(input())
cnt = 0
for i in range(1, n + 1, 2):
    if len(calc_divisors(i)) == 8:
        cnt += 1
print(cnt)

Measured memory_bytes: 3188
List=[list(map(int,input().split())) for i in range(3)]
newlist=[]
new = [x-y for (x,y) in zip(List[0],List[1])]
new2 = [x-y for (x,y) in zip(List[2],List[1])]
if new[0]==new[1] and new[1]==new[2]:
    pass
else:
    print('No')
    exit()
if new2[0]==new2[1] and new2[1]==new2[2]:
    pass
else:
    print('No')
    exit()
    
if List[0][0]-List[0][1]==List[1][0]-List[1][1] and List[2][0]-List[2][1]==List[1][0]-List[1][1]:
    pass
else:
    print('No')
    exit()
if List[0][0]-List[0][2]==List[1][0]-List[1][2] and List[2][0]-List[2][2]==List[1][0]-List[1][2]:
    pass
else:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 9236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
char s[maxn];
char w[maxn];
int num[maxn];
vector<int>ss[maxn];
vector<int>::iterator it;
int main()
{
    scanf("%s%s",s,w);
    int len1=strlen(s);
    int len2=strlen(w);
    for(int i=0;i<len1;i++)
        num[s[i]]++,
        ss[s[i]].push_back(i);
    for(int i=0;i<len2;i++)
    {
        if(num[w[i]]==0)
        {
            puts("-1");
            return 0;
        }
    }
    int d=0,index=-1;
    for(int i=0;i<len2;i++)
    {
         it=upper_bound(ss[w[i]].begin(),ss[w[i]].end(),index);
         if(it==ss[w[i]].end())
         {
             d++;
             index=ss[w[i]][0];
         }
         else
         {
             index=*it;
         }
    }
    printf("%lld",(ll)d*len1+index+1);

}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int A, B;
    cin >> A >> B;
    int ans = 0;
    for (double i=1; i <= 10000; i++) {
        if (int(i * 0.08) == A && int(i * 0.10) == B) {
            ans = int(i);
            break;
        }
    }

    if (ans == 0) {
        cout << "-1" << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
ll n,a[101010];
pair<ll,ll> b[101010];
vector<ll> v,t;
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	fo(i,0,n){
		cin>>a[i];
		if(a[i]>0)v.pb(a[i]);
		else t.pb(a[i]);
	}
	if(!v.size()){
		sort(all(t));
		ll x=t[t.size()-1];
		fo(i,1,t.size())x-=t[t.size()-i-1];
		cout<<x<<endl;
		x=t[t.size()-1];
		fo(i,1,t.size()){
			cout<<x<<" "<<t[t.size()-i-1]<<endl;
			x-=t[t.size()-i-1];
		}
		return 0;
	}if(!t.size()){
		sort(all(v));
		ll x=-v[0];
		fo(i,1,v.size())x+=v[i];
		cout<<x<<endl;
		x=v[0];
		fo(i,1,v.size()-1){
			cout<<x<<" "<<v[i]<<endl;
			x-=v[i];
		}
		cout<<v[v.size()-1]<<" "<<x<<endl;
		return 0;
	}
	ll x=0;
	fo(i,0,n)x+=abs(a[i]);
	cout<<x<<endl;
	x=t[0];
	fo(i,0,v.size()-1){
		cout<<x<<" "<<v[i]<<endl;
		x-=v[i];
	}
	cout<<v[v.size()-1]<<" "<<x<<endl;
	x=v[v.size()-1]-x;
	fo(i,1,t.size()){
		cout<<x<<" "<<t[i]<<endl;
		x-=t[i];
	}
	return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define MAX_V 105
using namespace std;
int V; //????????°
vector<int> G[MAX_V]; //??°???????????£??\??????????????¨???
vector<int> rG[MAX_V];//?????????????????????????????°??????
vector<int> vs;       //??°?????????????????????
bool used[MAX_V];     //?????§???????????????
int cmp[MAX_V];       //?±????????????£?????????????????????????????????

void add_edge(int from,int to){
  G[from].push_back(to);
  rG[to].push_back(from);
}

void dfs(int v){
  used[v]=true;
  for(int i=0;i<G[v].size();i++)if(!used[G[v][i]])dfs(G[v][i]);
  vs.push_back(v);
}

void rdfs(int v,int k){
  used[v]=true;
  cmp[v]=k;
  for(int i=0;i<rG[v].size();i++) if(!used[rG[v][i]])rdfs(rG[v][i],k);
}

int scc(){
  memset(used,0,sizeof(used));
  vs.clear();
  for(int v=0;v<V;v++) if(!used[v]) dfs(v);  
  memset(used,0,sizeof(used));
  int k=0;
  for(int i=vs.size()-1;i>=0;i--)if(!used[vs[i]]) rdfs(vs[i],k++);
  return k;
}

int n,m,to;
double p[MAX_V],ans[MAX_V];

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    V=n;
    for(int i=0;i<n;i++){
      cin>>p[i]>>m;
      for(int j=0;j<m;j++){
	cin>>to; to--;
	add_edge(i,to);
      }
    }
    int node=scc();
    for(int i=0;i<node;i++)ans[i]=1;
    for(int i=0;i<n;i++)
      ans[cmp[i]]*=p[i];
    for(int i=0;i<node;i++)
      ans[i]=1-ans[i];
    for(int i=0;i<n;i++)
      for(int j=0;j<G[i].size();j++){
	to=G[i][j];
	if(cmp[i]!=cmp[to])ans[cmp[to]]=-1;
      }
    double P=1;
    for(int i=0;i<node;i++)
      if(ans[i]!=-1)P*=ans[i];
    printf("%.9f\n",P);
    for(int i=0;i<n;i++){
      G[i].clear();
      rG[i].clear();
    }
  }
  return 0;
}

Measured memory_bytes: 3264