akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args){
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();

        String N = sc.nextToken();
        int ans = 0;

        if (N.equals("MON")){
          ans = 6;
        }else if(N.equals("TUE")){
          ans = 5;
        }else if(N.equals("WED")){
          ans = 4;
        }else if(N.equals("THU")){
          ans = 3;
        }else if(N.equals("FRI")){
          ans = 2;
        }else if(N.equals("SAT")){
          ans = 1;
        }else {
          ans = 7;
        }

        out.println(ans);
        out.flush();
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

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

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

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

        int[] nextIntArray(int N) {
            int a[] = new int[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextInt();
            }

            return a;
        }

        long[] nextLongArray(int N) {
            long a[] = new long[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextLong();
            }

            return a;
        }

        double[] nextDoubleArray(int N) {
            double a[] = new double[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextDouble();
            }

            return a;
        }

        String[] nextTokenArray(int N) {
            String a[] = new String[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextToken();
            }

            return a;
        }
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define lc "\n"
#define fast_io ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0)
#define ll long long int



int main()
{
    fast_io;
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(), a.end());
    vector<bool> dp(k+1);
    for(int i = 1; i <= k; i++)
    {
        for(int j = 0; a[j] <= i && j < a.size(); j++)
        {
            if(a[j] == i)
            {
                dp[i] = true;
                break;
            }
            if(dp[i - a[j]] == false)
            {
                dp[i] = true;
                break;
            }
        }
    }
    if(dp[k])
        cout << "First";
    else
        cout << "Second";
    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
int H,W;
bool ok = false;
const int max_n = 100;
char s[max_n][max_n];
void dfs(int x, int y,int cnt){
  s[x][y] = '.';
  for(int i=0 ; i<4 ; i++){
    int nx = x + dx[i], ny = y + dy[i];
    if(nx>=0 && ny >=0 && nx < H && ny < W && s[nx][ny] == '#'){
      if(cnt == 0){
        ok = true;
      }
      dfs(nx, ny, cnt+1);
    }
  }
}
void solve(){
  for(int i=0 ; i<H ; i++){
    for(int j=0 ; j<W ; j++){
      if(s[i][j]=='#'){
        dfs(i,j,0);
        if(!ok){
          cout << "No" << endl;
          return ;
        }
        ok = false;
      }
    }
  }
  cout << "Yes" << endl;
}

int main(){
  cin >> H >> W;
   for(int i=0 ; i<H ; i++){
     for(int j=0 ; j<W ; j++){
       cin >> s[i][j];
     }
   }
   solve();
   return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)



int main(){

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt	
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	 #endif

    FAST
	//PRECISE

ll d,t,s;
cin>>d>>t>>s;
if(s*t>=d)cout<<"Yes";
else cout<<"No";


return 0;
 }

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

const ll mod=1e9+7;
ll pow_mod(ll a, ll n)
{
    if(n == 0) return 1;
    ll x = pow_mod(a, n/2);
    ll ans = x * x % mod;
    if(n % 2 == 1) ans = ans *a % mod;
    return ans%mod;
}

ll C(ll n,ll m) {
    if(n < m) return 0;
    ll res = 1;
    for(ll i=1; i<=m; i++) {
        ll a = (n+i-m)%mod;
        ll b = i%mod;
        res = res*(a*pow_mod(b,mod-2)%mod)%mod;
    }
    return res;
}

ll Lucas(ll n,ll m) {
    if(m == 0) return 1;
    return C(n%mod, m%mod) * Lucas(n/mod,m/mod)%mod;
}

ll n,a,b;
int main(){
    cin>>n>>a>>b;
    ll ans=pow_mod(2,n)-Lucas(n,a)-Lucas(n,b)-1;
   while(ans<0) {
        ans+=mod;
    }
    cout<<ans%mod;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(998244353)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
	int n,m; ll l; cin>>n>>m>>l;
	ll d[n+5][n+5], c[n+5][n+5];
	rep(i,n)rep(j,n) d[i][j]=LINF;
	rep(i,n) d[i][i]=0LL;

	rep(i,m){
		int a,b; ll cost; cin>>a>>b>>cost; a--; b--;
		d[a][b]=cost; d[b][a]=cost;
	}

	rep(k,n)rep(i,n)rep(j,n) chmin(d[i][j],d[i][k]+d[k][j]);

	rep(i,n){
		rep(j,n){
			if(d[i][j]<=l) c[i][j]=1LL;
			else c[i][j]=LINF;
		}
	}
	rep(i,n) c[i][i]=0LL;

	rep(k,n)rep(i,n)rep(j,n) chmin(c[i][j],c[i][k]+c[k][j]);

	int q; cin>>q;
	rep(i,q){
		int s,t; cin>>s>>t; s--; t--;
		if(c[s][t]>=n+5) cout<<-1<<endl;
		else cout<<c[s][t]-1<<endl;
	}



	return 0;
}


Measured memory_bytes: 2048
n = int(input())
h = list(map(int, input().split()))

ans = 0
while True:
    l, r, = -1, n
    num = -1
    for i in range(n):
        if l == -1:
            if h[i] > 0:
                l = i
                num = h[i]
        else:
            if h[i] == 0:
                r = i
                break
            else:
                num = min(num, h[i])
    if l == -1:
        break

    for i in range(l, r):
        h[i] -= num
    ans += num

print(ans)

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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int n, l;
    cin >> n >> l;

    int sum = 0;
    int n0 = INF;
    for (int i = 1; i <= n; i++)
    {
        int tmp = l + i - 1;
        sum += tmp;
        if (abs(tmp) < abs(n0))
            n0 = tmp;
        // cout << n0 << endl;
    }
    cout << sum - n0 << endl;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

int target, sum;
string num;
vector<int> part;
bool rejected;

int stoi(string s) {
	istringstream is(s);
	int res;
	is >> res;
	return res;	
}

void solve(vector<int>& seq, int idx = 0) {
	if(idx == (int)num.size()) {
		int tmp = 0;
		for(int i = 0; i < (int)seq.size(); ++i)
			tmp += seq[i];

		if(tmp <= target) {
			if(tmp > sum) {
				rejected = false;
				sum = tmp;
				part = seq;
			}
			else if(tmp == sum) {
				rejected = true;
			}
		}
		return;
	}

	seq.push_back(num[idx] - '0');
	solve(seq, idx + 1);
	seq.pop_back();

	for(int i = idx + 1; i < (int)num.size(); ++i) {
		seq.push_back(stoi(num.substr(idx, i - idx + 1)));
		solve(seq, i + 1);
		seq.pop_back();
	}
}

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

	while(cin >> target >> num, target) {
		part.clear();
		rejected = false;
		sum = -1;
		vector<int> tmp;
		solve(tmp);
		if(rejected)
			cout << "rejected" << endl;

		else if(sum == -1)
			cout << "error" << endl;

		else {
			cout << sum << " ";
			for(int i = 0; i < (int)part.size(); ++i)
				cout << part[i] << (i + 1 == (int)part.size() ? "\n" : " ");
		}
	}

	return EXIT_SUCCESS;
}

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

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

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

//ここから

void solve(){
  int n;
  cin>>n;
  vector<ll>x(n);
  rep(i,n)cin>>x[i];
  ll ans=1e10;
  rep(i,100){
    ll sum=0;
    rep(j,n){
      sum+=(i+1-x[j])*(i+1-x[j]);
    }
    chmin(ans,sum);
  }
  cout<<ans;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int cnt=0;
    for(int i=1; s[i]; i++){
        if(s[i-1] == s[i]){
            s[i] = s[i]=='0' ? '1' : '0';
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 512
H, W = map(int, input().split())

#縦に3分割する場合
d1 = (H + 2) // 3 * W - H // 3 * W
#横に3分割する場合
d2 = (W + 2) // 3 * H - W // 3 * H
#縦に2分割，残りを横に2分割する場合
d3 = 10**18
for i in range(W + 1):
    d = max(H * i, (H + 1) // 2 * (W - i), H // 2 * (W - i)) - min(H * i, (H + 1) // 2 * (W - i), H // 2 * (W - i))
    d3 = min(d3, d)
#横に2分割，残りを縦に2分割する場合
d4 = 10**18
for i in range(H + 1):
    d = max(W * i, (W + 1) // 2 * (H - i), W // 2 * (H - i)) - min(W * i, (W + 1) // 2 * (H - i), W // 2 * (H - i))
    d3 = min(d3, d)
    
print(min(d1, d2, d3, d4))

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef ONLINE_JUDGE
const int N = 1e6+50;
#else
const int N = 567;
#endif




int main() {
	int a, b;
	scanf("%d%d",&a,&b);
	if (a>0) return puts("Positive"),0;
	if (b>=0) return puts("Zero"),0;
	puts(b-a&1?"Positive":"Negative");
}








Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <array>
#include <queue>
#include <set>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

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

    vector<int> W(N);
    int sum = 0;
    REP(i, N)
    {
        cin >> W[i];
        sum += W[i];
    }
    
    int abs_min = int(1e9);
    for (int T=0; T < W.size(); T++)
    {
        int S1=0;
        for (int i=0; i < T; i++)
        {
            S1 += W[i];
        }
        int S2 = sum - S1;
        abs_min = min(abs_min, abs(S1 - S2));
    }

    cout << abs_min << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;

int main() {
	int n, k;
	cin >> n >> k;
	V<int> b(n, 0);
	rep(i, k) {
		int d;
		cin >> d;
		rep(j, d) {
			int idx;
			cin >> idx;
			++b[idx-1];
		}
	}
	int cnt = 0;
	rep(i, n) {
		if (b[i] <= 0) ++cnt;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3596
# include <cstdio>
# include <cstring>
# include <iostream>
# define R register int
# define ll long long

using namespace std;

const int maxn=100005;
int n;
int a[maxn],m,l,r,mid,ans,c[maxn],t[maxn<<1];

void ins (int x) { for (R i=x;i<=2*n+2;i+=(i&(-i))) t[i]++; }
int ask (int x) { int ans=0; for (R i=x;i;i-=(i&(-i))) ans+=t[i]; return ans; }

bool check (int ans)
{
    ll cnt=0;
    memset(t,0,sizeof(t));
    for (R i=1;i<=n;++i)
        if(a[i]<=ans) c[i]=c[i-1]+1;
        else c[i]=c[i-1]-1;
    ins(n+1);
    for (R i=1;i<=n;++i)
    {
        cnt+=ask(c[i]+n);
        ins(c[i]+n+1);
    }
    ll b=1LL*n*(n+1)/2;
    b/=2;
    return cnt>=b+1;
}

int main()
{
    scanf("%d",&n);
    for (R i=1;i<=n;++i)
        scanf("%d",&a[i]),m=max(m,a[i]);
    l=0,r=m,ans=m;
    while(l<=r)
    {
        mid=(l+r)>>1;
        if(check(mid))
            ans=min(ans,mid),r=mid-1;
        else
            l=mid+1;
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;

int main() {
    int N;
    cin >> N;
    set<string> s;
    string tmp;
    for(int i=0; i<N; ++i) {
        cin >> tmp;
        s.insert(tmp);
    }
    cout << s.size() << endl;

    return 0;
}


Measured memory_bytes: 19188
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(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;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
    long long a,b;
    cin>>a>>b;
    if(a==b){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
}



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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  set<char> s;
  for (char x : S) s.insert(x);
  for (char i = 'a'; i <= 'z'; i++) {
    if(*begin(s) != i) {
      cout << i << endl;
      return 0;
    }
    s.erase(i);
  }
  cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

struct edge {
  ll to, cost;
  edge(ll to, ll cost) : to(to), cost(cost) {}
};

int V, E, P;
vector<vector<edge>> G;
vector<ll> dist;

/* 負閉路があるとtrueを返す。O(EV) */
/* 負の辺があっても計算できる */
bool bellman_ford(int s, vector<ll>& dist, int iter) {  // sは開始頂点
  dist[s] = 0;  // 開始点の距離は0
  for (int i = 0; i < iter; i++) {
    for (int v = 0; v < V; v++) {
      for (int k = 0; k < G[v].size(); k++) {
        edge e = G[v][k];
        if (dist[v] != LINF && dist[e.to] > dist[v] + e.cost) {
          dist[e.to] = dist[v] + e.cost;
        }
      }
    }
  }
}

void dfs(int now, vector<vector<edge>>& G, vector<bool>& reach) {
  reach[now] = true;
  for (auto edge : G[now]) {
    ll next = edge.to;
    if (reach[next])
      continue;
    dfs(next, G, reach);
  }
}

int main() {
  cin >> V >> E >> P;

  vector<vector<edge>> Gf(V);
  vector<bool> reachf(V, false);
  vector<vector<edge>> Gb(V);
  vector<bool> reachb(V, false);

  for (int i = 0; i < E; i++) {
    ll from, to, cost;
    cin >> from >> to >> cost;
    from--;
    to--;
    Gf[from].push_back(edge(to, P - cost));
    Gb[to].push_back(edge(from, P - cost));
  }

  dfs(0, Gf, reachf);
  dfs(V - 1, Gb, reachb);

  vector<bool> use(V);
  rep(i, V) {
    use[i] = (reachf[i] && reachb[i]);
  }

  G = vector<vector<edge>>(V);

  rep(i, V) {
    if (!use[i])
      continue;
    for (auto ed : Gf[i]) {
      if (use[ed.to]) {
        G[i].pb(edge(ed.to, ed.cost));
      }
    }
  }

  vector<ll> dist1(V, LINF);
  bellman_ford(0, dist1, V);

  vector<ll> dist2(V, LINF);
  bellman_ford(0, dist2, 2 * V);

  bool ok = true;
  rep(i, V) {
    if (dist1[i] != dist2[i])
      ok = false;
  }

  if (ok) {
    cout << max(0LL, -dist1[V - 1]) << endl;
  } else {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 896
while True:
    n = int(input())
    
    if n == 0:
        break
    
    ans = []
    cnt = 0
    for i in range(1, n//2+2):
        p = i
        for j in range(i+1, n//2+2):
            p += j
            if p == n:
                cnt += 1
            elif p > n:
                break
    ans.append(cnt)
    print(*ans)


Measured memory_bytes: 5596
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long 
#define ll long long 
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair 
#define INF 1000000000
#define MOD 1000000007 

using namespace std;

const int maxn=1e5+5;

int n,deg[maxn];
vector<int>G[maxn];




int main()
{
	scanf("%d",&n);
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
		deg[x]++;deg[y]++;	
	}
	
	int mx=0;
	for(int i=0;i<n;i++)if(deg[i]>mx)mx=deg[i];
	
	if(mx<=2)
	{
		printf("%d\n",1);
		return 0;
	}	
	
	queue<int>qu;
	for(int i=0;i<n;i++)if(deg[i]==1)qu.push(i);
	
	while (!qu.empty())
	{
		int u=qu.front();qu.pop();
		for(int i=0;i<G[u].size();i++)if(deg[G[u][i]]!=1)
		{
			if(deg[G[u][i]]==2)deg[G[u][i]]=1,qu.push(G[u][i]);
			break;
		}
	}
	
	int res=0;
	
	for(int i=0;i<n;i++)if(deg[i]>1)
	{
		int ans=0;
		for(int j=0;j<G[i].size();j++)if(deg[G[i][j]]==1)ans++;
		res+=max(0,ans-1);
	}
	
	printf("%d\n",res);


	return 0;	
} 


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

int main()
{
  int a[4];
  cin >> a[0] >> a[1] >> a[2] >> a[3];

  sort(a, a + 4);
  bool f = (a[0] == a[1]) && (a[2] == a[3]);

  cout << (f ? "yes" : "no") << endl;
}

Measured memory_bytes: 3124
#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 ans = 0;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != t[i]) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  double a, b;
  int ar = 0, al = 0, br = 0, bl = 0, cr = 0, cl = 0, dr = 0, dl = 0;
  while(cin >> a >> b) {
    if(a >= 1.1) al++;
    else if(a >= 0.6) bl++;
    else if(a >= 0.2) cl++;
    else dl++;
    if(b >= 1.1) ar++;
    else if(b >= 0.6) br++;
    else if(b >= 0.2) cr++;
    else dr++;
  }

  cout << al << " " << ar << endl;
  cout << bl << " " << br << endl;
  cout << cl << " " << cr << endl;
  cout << dl << " " << dr << endl;

}

Measured memory_bytes: 3164
#include <cstdio>
using namespace std;

int main(){
	double x[4], y[4];
	double vx, vy, v1x, v1y, v2x, v2y;
	double s, t;
	bool convex;
	
	while((scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3])) != EOF){
		convex = true;
		for(int i = 0; i < 4; i++){
			vx = x[i] - x[(i + 1) % 4];
			vy = y[i] - y[(i + 1) % 4];
			v1x = x[(i + 2) % 4] - x[(i + 1) % 4];
			v1y = y[(i + 2) % 4] - y[(i + 1) % 4];
			v2x = x[(i + 3) % 4] - x[(i + 1) % 4];
			v2y = y[(i + 3) % 4] - y[(i + 1) % 4];
			
			s = (double)(vx*v2y - vy*v2x) / (v1x*v2y - v1y*v2x);
			t = (double)(vx*v1y - vy*v1x) / (v2x*v1y - v2y*v1x);
			if(0 <= s && s <= 1 && 0 <= t && t <= 1){
				convex = false;
				printf("NO\n");
				break;
			}
		}
		if(convex){
			printf("YES\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 1036
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    String[] hs = sc.nextLine().split(" ");
    int[] h = new int[n];
    for (int i = 0; i < n; i++) h[i] = Integer.parseInt(hs[i]);
    sc.close();
    int max = 0;
    int count = 0;
    for (int i = 1; i < n; i++) {
      count = h[i] <= h[i - 1] ? count + 1 : 0;
      max = Math.max(max, count);
    }
    System.out.println(max);
  }
}


Measured memory_bytes: 48984
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B) {
		cout << C << endl;

	}
	if (B == C) {
		cout << A << endl;

	}
	if (A == C) {
		cout << B << endl;
	}
	return 0;
}



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

using namespace std;

#define BUG (cout << "Sehen Sie mich!" << endl)

int main()
{
        int n, a, b;
        int res = 0;
        cin >> n >> a >> b;

        for (int i = 1; i <= n; i++) {
                int sum = 0;
                int tmp = i;
                while (tmp != 0) {
                        sum += tmp % 10;
                        tmp /= 10;
                }
                if (sum >= a && sum <= b)
                        res += i;
        }
        cout << res << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define M 400004
#define N 100002
int S,T,a[N],b[M],c[M],e[N],f[N],g[N],h[N],l,n,o[N],p[N],q[N],r,t,x;bool d[M];
inline void add(int u,int v){b[++t]=a[u],c[a[u]=t]=v,d[t]=true,b[++t]=a[v],c[a[v]=t]=u;}
inline bool bfs()
{
    for(memset(h+1,-1,T<<2),q[l=0]=S,r=1;l<r;)
		for(int u=q[l++],i=a[u];i;i=b[i])
			if(d[i]&&h[c[i]]<0)h[q[r++]=c[i]]=h[u]+1;
    return h[T]>=0;
}
bool dfs(int u)
{
    if(u==T)return true;
    for(int&i=e[u];i;i=b[i])if(d[i]&&h[c[i]]==h[u]+1&&dfs(c[i]))return d[i]=false,d[i^1]=true;
    return false;
}
int i,j;
int main()
{
    scanf("%d",&n),t=1,x=n;
    for(i=0;i<n;i++)scanf("%d",o+i);
    for(i=0;i<n;i++)scanf("%d",p+i);
    for(i=0;i<n;i++) if(o[i]!=i&&!f[i]) for(j=i,T++;!f[j];j=o[j])f[j]=T;
    for(i=0;i<n;i++) if(p[i]!=i&&!g[i]) for(j=i,T++;!g[j];j=p[j])g[j]=T;
    for(i=0,T++;i<n;i++)
	    if(o[i]==i&&p[i]==i)x--;
	    else if(o[i]==i)add(g[i],T);
	    else if(p[i]==i)add(S,f[i]);
	    else if(o[i]!=p[i])add(g[i],f[i]);
	    else add(f[i],g[i]),add(g[i],f[i]);
    while(bfs())for(memcpy(e,a,T+1<<2);dfs(S);)x--;
    printf("%d\n",x);
}


Measured memory_bytes: 7168
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		int a[] = fs.nextIntArray(n);
		
		//先頭マイナスの場合
		long ans = Long.MAX_VALUE/3;
		long sum = 0;
		long cnt = 0;
		for(int i=0;i<n;i++) {
			if(i%2==0) {
				if(sum + a[i]>=0) {
					cnt += ((sum + a[i])+1);
					sum = -1;
				}
				else {
					sum += a[i];
				}
			}
			else {
				if(sum + a[i]<=0) {
					cnt += (-(sum + a[i]) + 1);
					sum = 1;
				}
				else {
					sum += a[i];
				}
			}
		}
		
		ans = Math.min(ans, cnt);
		
		cnt = 0;
		sum = 0;
		for(int i=0;i<n;i++) {
			if(i%2==1) {
				if(sum + a[i]>=0) {
					cnt += ((sum + a[i])+1);
					sum = -1;
				}
				else {
					sum += a[i];
				}
			}
			else {
				if(sum + a[i]<=0) {
					cnt += (-(sum + a[i]) + 1);
					sum = 1;
				}
				else {
					sum += a[i];
				}
			}
		}
		
		ans = Math.min(ans, cnt);
		System.out.println(ans);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

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

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

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

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 35548
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define ll long long int
#define lim 100010
#define mod 1e9+7
#define INF 1e9
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define ABS(x) ((x)>0?(x):-(x))
int compare(const void *a,const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int N,A,B,C,D;
	scanf("%d%d%d%d%d",&N,&A,&B,&C,&D);
	char S[200001];
	scanf("%s",S);
	bool ans = true;
	for(int i=A;i<D;i++){
		if(S[i]=='#' && S[i+1]=='#'){
			ans = false;
			break;
		}
	}
	if(C>D && ans){
		ans = false;
		B--;D--;
		for(int i=B;i<=D;i++){
			if(S[i]=='.' && S[i+1]=='.' && S[i-1]=='.'){
				ans = true;
				break;
			}
		}
	}
	
	
	printf("%s",ans?"Yes":"No");
	return 0;
}

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

using namespace std;

int const NMAX = 6;
char v[1 + NMAX][1 + NMAX];

int k, n, m;

bool kExact(int l, int c){
  int ans = 0;
  for(int i = 1;i <= n;i++){
    int cl = c;
    for(int j = 1;j <= m;j++){
      if(v[i][j] == '#' && !(l % 2 == 1 || cl % 2 == 1)){
        ans++;
      }
      cl /= 2;
    }
    l /= 2;
  }
  return (ans == k);
}

int main() {

  int ans = 0, tCol, tLin;
  cin >> n >> m >> k;
  for(int i = 1;i <= n;i++){
    for(int j = 1;j <= m;j++){
      cin >> v[i][j];
    }
  }
  tLin = 1 << n;
  tCol = 1 << m;
  for(int i = 0;i < tLin;i++){
    for(int j = 0;j < tCol;j++){
      if(kExact(i, j) == true){
        ans++;
      }
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<ll, ll>;
template<class T> inline bool chmax(T& a, T b) {if (a < b){a = b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b) {if (a > b){a = b;return 1;}return 0;}
const long long LLINF = 1LL << 60;
using namespace std;

ll dp[50];

int main()
{
    int n;
    while (cin >> n and n)
    {
        fill(dp, dp+n, 0);

        dp[0] = dp[1] = dp[2] = 1;
        for (int i=0; i<n; ++i)
        {
            dp[i+1] += dp[i];
            dp[i+2] += dp[i];
            dp[i+3] += dp[i];
        }

        dp[n-1] = dp[n-1]/10 + bool(dp[n-1]%10);
        cout << dp[n-1]/365 + bool(dp[n-1]%365) << endl;
    }
}



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

using namespace std;

typedef long long ll;
typedef long double ld;

vector <int> rec(int a, int b, int mask, int n) {
    if (n == 1) {
        return {a, b};
    } else {
        int id = 31 - __builtin_clz(a ^ b);
        //cout << a << ' ' << b << ' ' << (a & ~(1 << id)) << ' ' << (b & ~(1 << id)) << endl;
        int bt = (a >> id) & 1;
        mask |= (1 << id);
        int i;
        for (i = 0; ;++i) {
            if (!(mask & (1 << i))) {
                break;
            }
        }
        vector <int> f = rec(a & ~(1 << id), (a & ~(1 << id)) ^ (1 << i), mask, n - 1);
        vector <int> s = rec((a & ~(1 << id)) ^ (1 << i), b & ~(1 << id), mask, n - 1);
        vector <int> res;
        if (bt) {
            for (int x : f) res.push_back(x | (1 << id));
            for (int x : s) res.push_back(x);
        } else {
            for (int x : f) res.push_back(x);
            for (int x : s) res.push_back(x | (1 << id));
        }
        return res;
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n, a, b;
    cin >> n >> a >> b;
    if (__builtin_popcount(a ^ b) % 2 == 0) {
        cout << "NO\n";
        return 0;
    }
    cout << "YES\n";
    for (int x : rec(a, b, 0, n)) {
        cout << x << ' ';
    }
}

Measured memory_bytes: 1756
s;a;b;main(t){
    scanf("%d%d",&a,&b);
    t=b;
    while(t)t/=10,a*=10;
    a+=b;    
    
    if( pow( (int)sqrt((double)a) ,2)==(double)a   )
        printf("Yes\n");
    else
        printf("No\n");
    
}

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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < (int)k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

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

    string n;
    cin >> n;
    (n[1] == '9' || n[0] == '9') ? cout << "Yes" : cout << "No";
    cout << "\n";
    return 0;
}

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

int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    if(s[i]=='7'){
        puts("Yes");return 0;
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
	int i,j,k,m,n;
	cin>>n;
	for(register int i=1;i<=9;i++){
		if(n%i==0){
			if(n/i>=1 && n/i<=9){cout<<"Yes"<<endl;return 0;}
		}
	}
	cout<<"No"<<endl;
	return 0;		
}


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

int main()
{
	string S;
	cin >> S;
	int N = S.size();
	int ans = 0;
	for (int i = 0; i < N / 2; ++i)
		if (S[i] != S[N - i - 1])
			++ans;
	cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
    string s,t;
    int sum = 0;
    cin >> s;
    cin >> t;
    rep(i,s.size()) {
        if (s[i] == t[i]) {
            sum += 1;
        }
    }
    cout << sum << "\n";
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;

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

    for (int i = X - K + 1; i <= K + X - 1; i++) {
        cout << i;
        if (i != K + X - 1) {
            cout << ' ';
        } else {
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define N 500055
#define int ll
using namespace std;
inline char gc(){
	
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,ans,a[N],vis[N],vis2[N],tot,tot2;
pa z[N],z2[N];
signed main(){
	n=read();
	F(i,1,n) a[i]=read();
	F(i,1,n/2){
		vis[a[i*2-1]]++;
		vis2[a[i*2]]++;
	}
	F(i,1,100000){
		if (vis[i]) z[++tot]=mp(vis[i],i);
		if (vis2[i]) z2[++tot2]=mp(vis2[i],i);
	}
	sort(z+1,z+tot+1);sort(z2+1,z2+tot2+1);ans=n;
	D(i,tot,1){
		if (z[i].se!=z2[tot2].se) ans=min(ans,n-z[i].fi-z2[tot2].fi);
		else ans=min(ans,n-z[i].fi-z2[tot2-1].fi);
	}
	wrn(ans);
	return 0;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define ll long long
#define N 101
#define V 100010
using namespace std;

ll n,w,v,x;

int main()
{
    cin>>n>>w;
    ll its[n][2];
    FOR(i,0,n) cin>>its[i][0]>>its[i][1],v+=its[i][1];

    ll inf,dp[n+1][v+1];
    inf=1e14;
    FOR(i,0,n+1) FOR(j,0,v+1) dp[i][j]=inf;

    dp[0][0]=0;
    FOR(i,0,n)
    {
        FOR(j,0,v+1)
        {
            dp[i+1][j]=dp[i][j];
            if(its[i][1]<=j) dp[i+1][j]=min(dp[i+1][j],dp[i][j-its[i][1]]+its[i][0]);
        }
    }
    for(x=v;x>0;x--) if(dp[n][x]<=w) break;
    cout<<x<<'\n';

    return 0;
}

Measured memory_bytes: 79104
def bubble_sort(a, n)
  swap_count = 0
  exists_counter = true
  while exists_counter
    exists_counter = false
    (n - 1).downto(1).each {|j|
      k = j - 1
      if a[j] < a[k]
        tmp = a[j]
        a[j] = a[k]
        a[k] = tmp
        swap_count += 1
        exists_counter = true
      end
    }
  end
  return a, swap_count
end

n = gets.to_i
a, swap_count = bubble_sort gets.split(" ").map(&:to_i), n
puts a.join(" ")
puts swap_count

Measured memory_bytes: 8624
#include <algorithm>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N;
  double X;
  while (cin >> N >> X) {
    vector<double> x(N);
    for (int i = 0; i < N; i++) cin >> x[i];
    reverse(x.begin(), x.end());
    vector<double> sum(N + 1);
    sum[0] = 0;
    for (int i = 0; i < N; i++) sum[i + 1] = sum[i] + x[i];
    double res = 1ll << 60;
    for (int K = 1; K <= N; K++) {
      double cost = (N + K) * X;
      cost += sum[K] * 5;
      for (int i = K; i < N; i += K) {
        double coef = 2 * ((i - K) / K + 2) + 1;
        cost += coef * (sum[min(N, i + K)] - sum[i]);
      }
      res = min(res, cost);
    }
    cout << (ll)res << endl;
  }
  return 0;
}


Measured memory_bytes: 3328
n = gets.to_i
arr = gets.chomp.split.map(&:to_i)
str, max = "", 0
arr.each{|x|
    str << "(" *  (x - max) if x > max
    str << ")"
    max = x if max < x
}
arr_in, arr_out, count = [], [], 0
str.each_char{|c|
    case c
    when '('
        count += 1
        arr_in << count
    when ')'
        arr_out << arr_in.pop
    end
}
puts arr == arr_out ? str : ":("


Measured memory_bytes: 15384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin >> k;
  if(k%2==0){
    cout << -1;
  }else{
    long long num = 0;
    int cnt = 0;
    while(num < k){
        num *= 10;
        num += 7;
        cnt++;
    }
    if(num >= k){
        num %= k;
    }
    while(num > 0 && cnt <= 1000000){
        num %= k;
        if(num == 0){
            break;
        }
        num *= 10;
        num += 7;
        cnt++;
    }
    cout << (num == 0 ? cnt : -1) << endl;
  }
}


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

using namespace std;

int
main(void){
	vector<int> vec(3);
	for(int i = 0; i < 3; i++) cin >> vec[i];
	sort(vec.begin(), vec.end());
	int ans = 0;
	if(vec[0]%2 == vec[1]%2){
		ans += (vec[1] - vec[0])/2;
	}
	else{
		ans += (vec[1] + 1 - vec[0])/2 + 1;
		vec[1]++;
		vec[2]++;
	}
	ans += (vec[2] - vec[1]);
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using G=vector<vector<int>>;
const ll MOD=2019ll;

ll RS(ll x,ll y,ll mod){
    if(y==0) return 1;
    else if(y&1){
        return x*RS(x,y-1,mod)%mod;
    }
    else{
        ll p=RS(x,y/2,mod);
        return p*p%mod;
    }
}
int main(){
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    vector<ll> res(200050);
    res[0]=0ll;
    int n=s.size();
    rp(i,n){
        ll num=s.at(i)-'0';
        if(i==0){
            res.at(1)=num;
            continue;
        }
        res.at(i+1)=res.at(i)+num*RS(10ll,(ll)i,MOD);
        res.at(i+1)%=MOD;
    }
    auto ite=res.begin();
    sort(ite,ite+n+1);
    ll ctr=1ll;
    ll sum=0ll;
    rp(i,n+1){
        if(res[i]==res[i+1]){
            ctr++;
        }
        else{
            sum+=(ctr-1)*ctr/2ll;
            ctr=1ll;
        }
    }
    sum+=(ctr-1)*ctr/2ll;
    cout << sum <<endl;
    return 0;
}

Measured memory_bytes: 5244
#include<iostream>
int main(){
  int i,j,h,w;
  while(1){
    std::cin >> h >> w;
    if(h == 0 && w == 0) return 0;
    for(i=0; i<h; i++){
      for(j=0; j<w; j++){
        bool flag = (i == 0 || i == h - 1 ) || ( j == 0 || j == w - 1);
        std::cout << (flag ? "#" : ".");
      }
      std::cout << std::endl;
    }
    std::cout << std::endl;
  }
}

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <map>
#include <utility>
#include<math.h>
#include <iomanip>
#include<vector>
#define ll long long
#define ull unsigned long long
#include<numeric>
#include <map>
using namespace std;



int main()
{
    std::ios::sync_with_stdio(false);
    int n;cin>>n;
    string s;cin>>s;
    int maxD=0;
    int m=0;
    for(int i=0;i<s.size();i++){
        m=m+(s[i]=='I');
        m=m-(s[i]=='D');
        maxD=max(m,maxD);
    }
    cout<<maxD<<endl;
    return 0;
}


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

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    
    vector<vector<int>> a(n, vector<int>(3));
    for (int i = 0; i < n; i++) {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    
    int w0 = 0, h0 = 0; //左下の点
    for (int i = 0; i < n; i++) {
        if (a[i][2] == 1 and a[i][0] > w0) {
            w0 = a[i][0];
        }
        else if (a[i][2] == 2 and a[i][0] < w) {
            w = a[i][0];
        }
        else if (a[i][2] == 3 and a[i][1] > h0) {
            h0 = a[i][1];
        }
        else if (a[i][2] == 4 and a[i][1] < h) {
            h = a[i][1];
        }
    }
    
    if (h < h0 or w < w0) cout << 0 << endl;
    else cout << (h-h0)*(w-w0) << endl;
}


Measured memory_bytes: 256
n = int(input())
# 答え用の配列を準備しておく
ans = [0 for i in range(n+1)]
for x in range(1,int(n**0.5+1)):
    for y in range(1,int(n**0.5+1)):
        for z in range(1,int(n**0.5+1)):
            res = x**2+y**2+z**2+x*y+y*z+x*z
            # resの値がn以下ならカウントする
            if res<=n:
                ans[res] += 1
for i in range(1,n+1):
    print(ans[i])

Measured memory_bytes: 9504
#include <iostream>
#include <cstring>
#include <cstdio>

#include <cmath>
using namespace std;
typedef long long ll;
int n;

ll ans1,ans2;
int main(){
    ans1=1;
    ans2=1;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        ll a,b;
        ll t1=1,t2=1,t=1;
        scanf("%lld%lld", &a, &b);
        
        if(ans1>a){
            t1=ans1/a;
            if(ans1%a!=0) t1++;

        }
        
        if(ans2>b){
            t2=ans2/b;
            if(ans2%b!=0) t2++;
        }
        t=max(t1,t2);
        ans1=a*t;
        ans2=b*t;
    }

    printf("%lld\n",ans1+ans2);
    // getchar();
    // getchar();

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long int

typedef struct{
	int p;
	ll y;
	int idx;
	int id;
}data;

int compare(const void *a, const void *b){
	return (((data*)a)->y - ((data*)b)->y);
}

int comp2(const void *a, const void *b){
	return (((data*)a)->idx - ((data*)b)->idx);
}

int main(void){
	int n,m,i,tmp[100001]={0};
	scanf("%d %d",&n,&m);
	data city[m];
	for(i=0;i<m;i++){
		scanf("%d %lld",&city[i].p,&city[i].y);
		city[i].idx=i;
	}
	qsort(city, m, sizeof(data), compare);
	for(i=0;i<m;i++){
		++tmp[city[i].p-1];
		city[i].id=tmp[city[i].p-1];
	}
	qsort(city,m,sizeof(data),comp2);
	for(i=0;i<m;i++){
		printf("%06d%06d\n",city[i].p,city[i].id);
	}
	
	return 0;
}

Measured memory_bytes: 6504
#define alphanso                  \
	ios_base::sync_with_stdio(0); \
	cin.tie(NULL)
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
int main()
{
	alphanso;
	string s;
	cin >> s;
	ull cnt_b = 0, i, ans = 0;
	for (i = 0; i < s.size(); i++)
	{
		if (s[i] == 'B')
			cnt_b++;
		else
			ans += cnt_b;
	}
	cout << ans;
	return 0;
}

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

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

    int n;
    cin>>n;

    vector<int> a(n),b(n);
    for(int i=0;i<n;i++)cin>>a[i];

    b=a;

    sort(a.begin(),a.end(),greater<int>());

    for(int i=0;i<n;i++)
    {
        cout<<(b[i]==a[0]?a[1]:a[0])<<"\n";
    }

    return 0;
}


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

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

  // ここにプログラムを追記
  int A, cnt, min = 100000000;
  for(int i=0; i<N; i++) {
    cin >> A;
    cnt = 0;
    while(A > 0) {
      if(A%2==1) {
        break;
      }
      cnt++;
      A /= 2;
    }
    if(min > cnt && A%2==1) {
      min = cnt;
    }
  }
  cout << min << endl;
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N);
    unordered_map<unsigned long, unsigned long> m;
    unsigned long ans{0};
    for(auto& i : A){
        cin >> i;
        ans += m[i]++;
    }
    for(const auto& i : A)cout << ans - m[i] + 1 << endl;
    return 0;
}

Measured memory_bytes: 9928