akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 1e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, w;

ll dp[105][MAXN];


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

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n>>w;

    for(int i = 1; i <= n; i++){
        ll we, v;
        cin>>we>>v;
        for(int l = 0; l <= w; l++){
            dp[i][l] = max(dp[i - 1][l], (l >= we ? dp[i - 1][l - we] + v : 0));
        }
    }
    ll ans = 0;
    for(int l = 0; l <= w; l++){
        ans = max(ans, dp[n][l]);
    }
    cout<<ans<<endl;

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Measured memory_bytes: 79360
#include<iostream>
#include<bits/stdc++.h>
#include<climits>
#include<math.h>

#define forn(e,n,s) for(int i = e; i < n;i += s)
#define forr(e,n,s) for(int i = e; i >= n; i -= s)
#define PI 3.14159265358979323846264338327950L

using namespace std;

int MOD = 1e9+7;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout<<fixed;
  cout<<setprecision(20);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
}

int main(){
    go(); 

    // code here
    int n;cin>>n;
    vector<int> dp(n+1,0);
    dp[0] = 1;
    for(int i = 1; i <= n;i++){
        for(int j = 3; j <= n; j++){
            if(i-j>=0) dp[i] = ( dp[i]%MOD + (dp[i-j])%MOD)%MOD;
            dp[i] %= MOD;
        }
    }
    cout<<dp[n];
}










Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,a,b) for(ll i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<< endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, W, H, x, y);
  cout << (double)(W * H) / 2 << " ";

  if (x * 2 == W && y * 2 == H) {
    print(1);
  } else {
    print(0);
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a, b;
  
  scanf("%d%d", &a, &b);
  if(a > b){
    printf("a > b\n");
  }
  else if(a < b){
    printf("a < b\n");
  }
  else{
    printf("a == b\n");
  }
  
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  int a, max_a = 0, min_a = 1000;
  rep(i,n) {
    cin >> a;
    if (a > max_a) max_a = a;
    if (a < min_a) min_a = a;
  }
  cout << max_a - min_a << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  string S;
  cin >> S;
  int s = S.size();
  vector<int> t(s);
  long x = 0, ans = 0;
  for (int i = 0; i < s; i++) {
    if (S.at(i) == 'B') x++;
    t.at(i) = x;
  }
  for (int i = 0; i < s; i++) {
    if (S.at(i) == 'W') ans += t.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1412
/*
 * Created by: Son Dinh
 */ 
#include<bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sqr(x) (x)*(x)
#define sz(X) (int)(X).size()
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

const int mod=1e9+7;

int a,p;
int main(){
    scanf("%d %d", &a, &p);
    printf("%d", (3 * a + p) / 2);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    string s; cin >> s;
    if (s[0] != 'A')
    {
        cout << "WA\n";
        return 0;
    }
    int cntC = 0;
    for (int i = 3-1; i < s.size()-1; i++)
    {
        if (s[i] == 'C')
        {
            cntC++;
        }
    }
    if (cntC != 1)
    {
        cout << "WA\n";
        return 0;
    }
    int cntCAP = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (65 <= s[i] && s[i] <= 90)
        {
            cntCAP++;
        }
    }
    if (cntCAP != 2) {
        cout << "WA\n";
        return 0;
    }
    cout << "AC\n";    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,k;cin>>n>>k;
    vin p(n);rep(i,n)cin>>p[i];
    vll c(n);rep(i,n)cin>>c[i];
    int tmp,res,t;ll circle,ans=-INF,tokuten,lap;
    rep2(i,1,n+1){
        vin num(n+1,inf);
        vll score(n+2);
        tmp=i;res=0;
        while(1){
            if(num[tmp]!=inf){
                t=res-num[tmp];
                score[res]=score[res-1]+c[tmp-1];
                circle=score[res]-score[num[tmp]];
                break;
            }
            num[tmp]=res;
            if(res>0)score[res]=score[res-1]+c[tmp-1];
            //else score[res]=c[tmp-1];
            res++;
            tmp=p[tmp-1];
        }
        if(k<res)rep2(j,1,k+1)ans=max(ans,score[j]);
        else if(circle<0)rep2(j,1,res+1)ans=max(ans,score[j]);
        else{
            rep2(j,1,num[tmp]+1)ans=max(ans,score[j]);
            k-=num[tmp];
            tokuten=score[num[tmp]];
            lap=k/t-1;
            tokuten+=circle*lap;
            ans=max(ans,tokuten);
            rep2(j,num[tmp],res){
                tokuten+=score[j+1]-score[j];
                ans=max(ans,tokuten);
            }
            rep2(j,num[tmp],num[tmp]+k%t){
                tokuten+=score[j+1]-score[j];
                //if(tokuten==29544642561)cout<<555<<" "<<num[tmp]<<endl;
                ans=max(ans,tokuten);
            }
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main()
{
    int n;
    long long v[110], x;
    scanf("%d%lld", &n, &x);
    for(int i = 0; i < n; i++)
        scanf("%lld", &v[i]);
    sort(v, v + n);
    long long s = 0;
    for(int i = 0; i < n; i++)
        s += v[i];
    if(x > s)
        printf("%d", n - 1);
    else if(s == x)
        printf("%d", n);
    else
    {
        for(int i = n - 1; i >= 0; i--)
        {
            s -= v[i];
            if(x >= s)
            {
                printf("%d", i);
                return 0;
            }
        }
        printf("0");
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    int cost,cost2;
    cost=a*e;
    cost2=b;
    e>c ? cost2+=(e-c)*d:cost2=cost2;
    cout<<min(cost2,cost)<<endl;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;
ll n  ;
vl v;
ll dp[105][10005];
ll solve(ll curr , ll sum)
{
    ///cout << "curr is " << curr << " sum is " << sum << el ;
    if(curr == n){
        ll foo = sum % 10 ;
        if(foo == 0) return 0 ;
        else return sum ;
    }
    if(dp[curr][sum] != -1) return dp[curr][sum ] ;
    ll res = sum + v[curr];
    ll correct = solve(curr + 1 ,res);
    ll nott = solve(curr + 1 , sum) ;
    ll maxx = max(correct , nott) ;
    dp[curr][sum ] = maxx;
    return maxx ;

}

int main()
{
    ios;
    forn(i , 0 , 104) forn(j , 0 , 10004) dp[i][j] = -1;
    cin >> n;
    forn(i ,  1 , n ) {
       ll x;
       cin >> x;
       v.pb(x) ;
    }
    ll foo = solve( 0 , 0 ) ;
    cout << foo << el ;
}































Measured memory_bytes: 8448
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
vector<int>g[123456];
int dfs(int s,int p){
    int res = 0;
    vector<int>a;
    for(int x:g[s]){
        if(x != p){
            a.push_back(dfs(x,s));
        }
    }
    sort(a.rbegin(),a.rend());
    int cnt = 1;
    for(int x:a){
        res = max(res, x + cnt);
        cnt++;
    }
//    cerr << s + 1 << " " << res << endl;
    return res;
}
int main(){
    int n;
    cin >> n;
    rep(i,n-1){
        int a;
        cin >> a;
        a--;
        g[a].push_back(i+1);
        g[i+1].push_back(a);
    }
    cout << dfs(0,-1) << endl;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N, K;
    string S;
    cin >> N >> S >> K;
    char a = S[K - 1];
    for (ll i = 0; i < N; i++) {
        if (S[i] != a) {
            S[i] = '*';
        }
    }
    cout << S << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(void) {
    string input;
    vector<char> v;

    getline(cin, input);

    for (int i = 0; i < input.size(); i++) {
        if (input[i] == '0') {
            v.push_back('0');
        } else if (input[i] == '1') {
            v.push_back('1');
        } else if (input[i] == 'B') {
            if (!v.empty()) {
                v.pop_back();
            }
        }
    }

    cout << string(v.begin(), v.end()) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N;
    cin>>N;
    vector<ll> s(N);
    rep(i,N){
        cin>>s.at(i);
    }
    ll ans=0;
    vector<ll> S(N);//indexの和がN-1になる物をペアにして和をとる
    rep(i,N){
        S.at(i)=s.at(i)+s.at(N-1-i);
    }
    
    for(int aminusb=1;aminusb<N-1;aminusb++){
        ll nowsum=0;

        if((N-1)%aminusb==0){
            for(int i=0;2*i<(N-1)/aminusb;i++){
                nowsum+=S.at(i*aminusb);
                chmax(ans,nowsum);
            }
        }
        
        else{
            for(int i=0;(i+1)*aminusb<N-1;i++){
                nowsum+=S.at(i*aminusb);
                chmax(ans,nowsum);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>

using namespace std;

int N, K;
int a[5001];
int ans;
bool is;

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

  for(int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a,a+N);
 
  int l = 0;
  int r = N;
  while(r > l){
    int s = (l+r)/2;
    if(a[s] > K){r = s;continue;}
    
    is = false;
    bool dp[N+2][K+2] = {};
    dp[0][0] = true;
    if(s > 0)dp[0][a[0]] = true;
    for(int j = 1; j < N; j++) {
      for(int k = 0; k < K; k++) {
	if(dp[j-1][k]) dp[j][k] = true;
	if(j != s && k >= a[j] && dp[j-1][k-a[j]]) {
	  dp[j][k] = true;
	}
      }
    }
    for(int m = K - a[s]; m < K; m++) {
      if(dp[N-1][m]) {is = true; break;}
    }
    if(is) r = s;
    else l = s+1;
  
  }
  cout << r <<endl;
}


	      
      
  


Measured memory_bytes: 24704
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <map>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e7 * 2, S2 = 1e7 * 2;

char nt(char a) {
    if (a == 'S') return 'W';

    return 'S';
}
int main() {
    fastInp;

    ll n;
    string s;
    cin >> n;
    cin >> s;

    string ans;
    for (int i = 0; i < 4; i++) {
        ans.clear();
        if (i % 2 == 0) {
            ans.push_back('S');
        }
        else {
            ans.push_back('W');
        }
        if (i / 2 == 0) {
            ans.push_back('S');
        }
        else {
            ans.push_back('W');
        }
        ans.resize(n);
        for (int i = 1; i < n - 1; i++) {
            if (ans[i] == 'S') {
                if (s[i] == 'o') {
                    ans[i + 1] = ans[i - 1];
                }
                else {
                    ans[i + 1] = nt(ans[i - 1]);
                }
            }
            if (ans[i] == 'W') {
                if (s[i] == 'o') {
                    ans[i + 1] = nt(ans[i - 1]);
                }
                else {
                    ans[i + 1] = (ans[i - 1]);
                }
            }
        }

        bool flag = true;
        if (ans[n - 1] == 'S') {
            if (ans[0] != ans[n - 2] && s[n - 1] == 'o') flag = false;
            if (ans[0] == ans[n - 2] && s[n - 1] == 'x') flag = false;
        }
        if (ans[n - 1] == 'W') {
            if (ans[0] != ans[n - 2] && s[n - 1] == 'x') flag = false;
            if (ans[0] == ans[n - 2] && s[n - 1] == 'o') flag = false;
        }
        bool flag2 = true;
        if (ans[0] == 'S') {
            if (ans[n - 1] != ans[1] && s[0] == 'o') flag2 = false;
            if (ans[n - 1] == ans[1] && s[0] == 'x') flag2 = false;
        }

        if (ans[0] == 'W') {
            if (ans[n - 1] != ans[1] && s[0] == 'x') flag2 = false;
            if (ans[n - 1] == ans[1] && s[0] == 'o') flag2 = false;
        }
        if (flag2 && flag) {
            cout << ans;
            return 0;
        }
    }

    cout << "-1";
    return 0;
}



Measured memory_bytes: 640
#include <math.h>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <numeric>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> x(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	int cnt = 0;
	for (int i = 0; i < n - 2; i++) {
		if (x[i] < x[i+1] && x[i+1] < x[i+2]) {
			cnt++;
		}
		else if (x[i+2] < x[i+1] && x[i+1] < x[i]) {
			cnt++;
		}
	}

	cout << cnt << endl;
	return(0);
}





Measured memory_bytes: 256
import fractions
n=int(input())
lis=list(map(int,input().split()))
li=[lis[0]]
l=[lis[n-1]]
for i in range (0,n-1):
  li.append(fractions.gcd(li[i],lis[i+1]))
  l.append(fractions.gcd(l[i],lis[n-i-2]))
ans_li=[]
for i in range(0,n-2):
  ans_li.append(fractions.gcd(li[i],l[n-3-i]))
ans_li.insert(0,li[n-2])
ans_li.append(l[n-2])
ans_li.sort()           
ans_li.reverse()
print(ans_li[0])

Measured memory_bytes: 16152
#include <stdio.h>
#include <stdlib.h>

int main(void){
  int a,b,v,w;
  double t;
  scanf("%d %d %d %d %lf",&a, &v, &b, &w, &t);
  if(abs(a-b)/t <= (v-w)){
    printf("YES");
  }
  else{
    printf("NO");
  }
  return 0;
}


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

int main() {
  int N, a, b, c, d;
  cin >> N;
  
  a = N/1000;
  b = (N%1000)/100;
  c = (N%100)/10;
  d = N%10;

  if ((a==b && b==c) || (b==c && c==d)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
using namespace std;
int main(){
int D;
cin >> D;
int max = 0;
int sum=0;
for (int i=0;i<D;i++)
{
int p;
cin>>p;
if(p>max)
max=p;
sum+=p;
}
cout << sum - (int)max /2 <<endl;
}

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


int main(){
    int n; cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    double ans=0;
    rep(i,n){
        ans += 1.0/v[i];
    }
    cout << 1.0/ans;
}

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

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

        long sum = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                sum += xs[i] * xs[j];
            }
        }

        System.out.println(sum);
    }
}


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

int main() {

    string w; cin >> w;

    if( w.size() % 2 == 1 ) { // 奇数長のとき
	cout << "No" << endl;
	return 0;
    }

    int x[26] = {}; // { 0,0,0, ... , 0 }
    for( char c : w ) {
	x[c-'a']++;
    }

    for( int i=0; i<26; i++) {
	if( x[i]%2 == 1 ) {
	    cout << "No" << endl;
	    return 0;
	}
    }
    cout << "Yes" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;

int main(){
  long long n, d, x, y, ans = 0;
  cin>> n >> d;
  for(int i=0;i<n;i++){
    cin >> x >> y;
    if(x * x + y * y <= d * d){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

constexpr int L = 1e4;

constexpr int f(const int x, const int y, const int z) {
    return x * x + y * y + z * z + x * y + y * z + x * z;
}

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

    int n;
    cin >> n;
    vector<int> counts(L + 1, 0);

    for (int x = 1; x <= L; ++x) {
        if (x * x > L) break;

        for (int y = 1; y <= L; ++y) {
            if (x * x + y * y + x * y > L) break;

            for (int z = 1; z <= L; ++z) {
                const auto res = f(x, y, z);
                if (res > L) break;
                ++counts[res];
            }
        }
    }

    for (int i = 1; i <= n; ++i) {
        cout << counts[i] << '\n';
    }

    return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);
    long i;
    long min=1000000;
    for(i=0; i<n; i++) {
        long a;
        scanf("%ld", &a);
        long count=0;
        while(a>0 && a%2==0) {
            a/=2;
            count++;
        }
        if(min>count) min=count;
    }
    printf("%ld\n", min);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int cache[300][300][300];

int rec(int A,int B,int C){
    int &r = cache[A][B][C];
    if(r!=-1){
        ;
    }else if(A==B&&B==C)
        r = 0;
    else if(200<A || 200<B || 200<C)
        r = IMAX;
    else{
        r = 1 + rec(A+2, B, C);
        r = min(r, 1 + rec(A, B+2, C));
        r = min(r, 1 + rec(A, B, C+2));
        r = min(r, 1 + rec(A+1, B+1, C));
        r = min(r, 1 + rec(A, B+1, C+1));
        r = min(r, 1 + rec(A+1, B, C+1));
    }
    return r;
}

int main(void){
    int A,B,C;
    GI(A);GI(B);GI(C);
    memset(cache,-1,sizeof(cache));
    printf("%d\n",rec(A,B,C));
    return 0;
}

Measured memory_bytes: 105856
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String s = scan.next();
    int n = s.length();
    int sum1 = 0;
    int sum2 = 0;
      sum1 = 0;
      for (int i=0;i<n;i++){
        if (s.charAt(i) == '0'){
          if (i%2 == 1){
            sum1 += 1;
          }
        }
        else{
          if (i%2 == 0){
            sum1 += 1;
          }
        }
      }

      sum2 = 0;
      for (int i=0;i<n;i++){
        if (s.charAt(i) == '0'){
          if (i%2 == 0){
            sum2 += 1;
          }
        }
        else{
          if (i%2 == 1){
            sum2 += 1;
          }
        }
      }


    System.out.println(Math.min(sum1,sum2));
  }
}


Measured memory_bytes: 39316
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
 
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
 
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
 
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
int f[200];
int a,b,c;
int main(){
 
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	cin>>a>>b>>c;
	int x = a%b;
	a%=b;
	while(!f[a]){
		f[a] = true;
		a += x;
		a%=b;
	}
	if(f[c]) cout<<"YES\n";
	else cout<<"NO\n";
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	v, _ := strconv.Atoi(read())
	return v
}

func main() {
	sc.Split(bufio.ScanWords)
	count := 0
	max := 0
	S := read()

	for _, b := range S {

		if string(b) == "A" || string(b) == "T" || string(b) == "C" || string(b) == "G" {
			count++
			if max < count {
				max = count
			}
		} else {
			count = 0
		}

	}
	fmt.Println(max)
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) throws Exception {

        Town town = new Town();

	    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
	        br.readLine(); //1行目は捨てる
            br.lines().forEach(town::refresh);
        }

	    System.out.println(town);
    }

}

class Town {
    private final Map<Integer, Building> town;

    public Town() {
        super();
        town = new HashMap<>();
        IntStream.rangeClosed(1, 4).forEach(i -> town.put(i, new Building()));
    }

    public Building getBuilding(int i) {
        return town.get(i);
    }

    @Override
    public String toString() {
        return town.values().stream()
                .map(Building::toString)
                .collect(Collectors.joining(String.format("%n####################%n")));
    }

    private void refresh(int b, int f, int r, int v) {
        getBuilding(b).getFloor(f).getRoom(r).moveIn(v);
    }

    public void refresh(String s) {
        int[] arr = Arrays.stream(s.split(" ")).mapToInt(Integer::parseInt).toArray();
        refresh(arr[0], arr[1], arr[2], arr[3]);
    }
}

class Building {
    private final Map<Integer, Floor> building;

    public Floor getFloor(int i) {
        return building.get(i);
    }

    public Building() {
        super();
        building = new HashMap<>();
        IntStream.rangeClosed(1, 3).forEach(i -> building.put(i, new Floor()));
    }

    @Override
    public String toString() {
        return building.values().stream()
                .map(Floor::toString)
                .collect(Collectors.joining(String.format("%n")));
    }
}

class Floor {
    private final Map<Integer, Room> floor;

    public Room getRoom(int i) {
        return floor.get(i);
    }

    public Floor() {
        super();
        floor = new HashMap<>();
        IntStream.rangeClosed(1, 10).forEach(i -> floor.put(i, new Room()));
    }

    @Override
    public String toString() {
        return floor.values().stream()
                .map(Room::toString)
                .collect(Collectors.joining(" ", " ", ""));
    }
}

class Room {
    private int memberCount;

    public void moveIn(int i) {
        memberCount += i;
    }

    @Override
    public String toString() {
        return String.valueOf(memberCount);
    }

    public Room() {
        super();
        memberCount = 0;
    }

}


Measured memory_bytes: 31616
#include "bits/stdc++.h"

using namespace std;

int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 0; i < n - 1; i++)
	{
		int tmp = 0;
		int basket[28] = {};
		for (int t = 0; t < i; t++)
		{
			basket[(int)s[t] - 'a']++;
		}
		for (int t = i; t < s.size(); t++)
		{
			if (basket[(int)s[t] - 'a'] != 0) {
				tmp++;
				basket[(int)s[t] - 'a'] = 0;
			}
		}
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int a, b, c;
    int cnt=0;
    cin >> a >> b >> c;
    rep(1,11)   if(i == a || i == b || i == c) cnt++; 
    if(cnt%2 == 0) cout << "Yes" << endl;
    else           cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
using namespace std;
 
int main (){
	char s;
	stack<int> A;
	stack<pair<int,int> > B;
	int i=0,j,ans=0,a;
	while(cin>>s){
		if(s=='\\') A.push(i);
		else if(s=='/'&&!A.empty()){
			j=A.top();A.pop();
			a=i-j;
			ans+=a;
			while(!B.empty() && B.top().first>j){
				a=a+B.top().second;
				B.pop();
			}
			B.push(make_pair(j, a));
		} 
		i++;
	}
	cout<<ans<<endl;
	vector<int> X;
	int z;
	z=B.size();
	for(int i =0;i<z;i++){
		X.push_back(B.top().second);
		B.pop();
	}
	cout<<X.size();
	for(int i =X.size()-1;i>=0;i--){
		cout<<" "<<X[i];
	}
	cout<<endl;
	return 0;
}


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

const int mod = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define ll long long
#define vi vector < int >
#define si set <int>
#define mii map <int, int>
#define vll vector < ll >
#define pii pair < int , int >
#define ff first
#define tc \
    int ttt; cin >> ttt;\
    while(ttt --)
#define ss second
#define f(i,a,b) for(int i=a;i<b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define nl '\n'
#define all(x) x.begin() , x.end()
#define mne min_element
#define mxe max_element
#define pr(x) cout << fixed << setprecision(10) << x
ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);}
int logg(ll x , ll y) {if (x == 0) return -1; return logg(x / y, y) + 1;}
ll poww(ll a, ll b, ll m) {
	if (b == 0) return 1;
	ll ans = 1;
	ans = poww(a, b >> 1, m);
	ans = (ans * ans) % m;
	if (b & 1) ans = (ans * a) % m;
	return ans;
}
// Start of code
int n;
double prob[3001];
double dp[3001][3001];

double solve(int i, int x) {

	if (x == 0) return 1;
	if (i == 0) return 0;

	if (dp[i][x] > -0.9) return dp[i][x];

	dp[i][x] = prob[i] * solve(i - 1, x - 1) + (1 - prob[i]) * solve(i - 1, x);

	return dp[i][x];

}

int32_t main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast;
	cin >> n;
	memset(dp, -1, sizeof dp);
	f(i, 1, n + 1) cin >> prob[i];
	double x = solve(n, (n + 1) / 2);
	pr(x);
}


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

int main()
{
	int n;
	cin >> n;
	vector<int>v(n-1);
	for (int i = 0; i < n-1; i++)
	{
		cin >> v[i];
	}
	v.insert(v.begin(), INT_MAX);
	v.push_back(INT_MAX);
	int ans = 0;
	for (int i = 1; i < v.size(); i++)
	{
		ans += min(v[i - 1], v[i]);

	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = pow(10, 9) + 7;
//const int mod = 998244353;
//const int mod = ;
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int N, M;
  cin >> N >> M;
  vector<int> k(M);
  vector<vector<int>> s(M);
  for (int i = 0; i < M; i++)
  {
    cin >> k.at(i);
    for (int j = 0; j < k.at(i); j++)
    {
      int ss;
      cin >> ss;
      s.at(i).push_back(ss - 1);
    }
  }
  vector<int> p(M);
  for (int i = 0; i < M; i++)
  {
    cin >> p.at(i);
  }

  int ans = 0;
  for (int i = 0; i < pow(2, N); i++)
  {
    vector<int> sw(N);
    int ii = i;
    for (int j = 0; j < N; j++)
    {
      sw.at(j) = ii % 2;
      ii /= 2;
    }

    bool ok = true;
    for (int j = 0; j < M; j++)
    {
      int on = 0;
      for (int l = 0; l < k.at(j); l++)
      {
        on += sw.at(s.at(j).at(l));
      }
      if (on % 2 != p.at(j))
      {
        ok = false;
        break;
      }
    }
    if (ok)
    {
      ans++;
    }
  }

  cout << ans << endl;
}

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

class Dijkstra {
public:
    struct edge { long long v, dist; };

    struct state {
        long long v, cost;
        bool operator>(const state s) const { return cost > s.cost; }
    };

    const long long INF = (1LL << 60);
    long long N;
    vector< vector<edge> > E;

    Dijkstra(long long n): N(n), E(n) {}

    //有効グラフの時はこっち。u→vに距離dで結ぶ
    void add_directed_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
    }

    //無向グラフの時はこっち。uとvを双方向に距離dで結ぶ
    void add_undirected_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
        E[v].push_back((edge) { u, d });
    }

    //Sを始点として、他の頂点への最短経路を探す
    vector<long long> shortest_path(long long S) {
        vector<long long> dp(E.size(), INF);
        priority_queue<state, vector<state>, greater<state> > q;
        q.push((state) { S, 0 });
        while(!q.empty()) {
            long long v = q.top().v, cost = q.top().cost;
            q.pop();
            if(dp[v] <= cost) continue;
            dp[v] = cost;
            for(int i=0;i < E[v].size() ; i++) {
            long long nv = E[v][i].v, ncost = cost + E[v][i].dist;
            if(dp[nv] > ncost) q.push((state) { nv, ncost });
            }
        }
        return dp;
    }
};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n,s,t;
    cin>>n>>s>>t;
    s--,t--;
    Dijkstra dij(n);
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        dij.add_undirected_edge(a,b,1);
    }

    vector<ll> sd = dij.shortest_path(s);
    vector<ll> td = dij.shortest_path(t);
    ll ans = 0;
    for(int i=0;i<n;i++){
        if(sd[i] < td[i]){
            ans = max(ans, td[i]-1);
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 10312
while True:
    n, x = [int(i) for i in input().split()]

    if n == x == 0:
        break

    count = 0
    for s in range(1, n - 1):
        for m in range(s + 1, n):
            for e in range(m + 1, n + 1):
                if x == s+m+e:
                    count += 1

    print(count)

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

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

    li n, m; cin >> n >> m;
    vector<li> h(n+1,0); for (li i=1; i<=n; i++) cin >> h[i];
    vector<li> l(n+1,0); 
    //vector<vector<li>> table(n+1, vector<li>(n+1, 0));
    vector<li> table(n+1, 0);
    
    li c, d;
    for (li i=0; i<m; i++) 
    {
        cin >> c >> d;
        
        l[c] += 1;
        l[d] += 1;

        //li maxnum = max(c, d);
        //li minnum = min(c, d);

        if (h[c] > h[d])
        {
            table[c] += 1;
        }
        else if (h[c] < h[d])
        {
            table[d] += 1;
        }        
    }

    li ans = 0;
    for (li i=1; i<n+1; i++)
    {
        if (table[i] == l[i]) ans += 1;
    }

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

Measured memory_bytes: 5544
#include<iostream>
#include<cstdio>
#include<string>
#include <cstring>
#include <stack>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
#define INF 0x3f3f3f3f
#define mod 998244353
int main() {
	string s;
	int a[] = { 0 ,0,0};
	cin >> s;
	for (int i = 0; s[i] != '\0'; ++i) {
		a[s[i] - 'a']++;
	}
	int c = 0;
	for (int i = 0; i < 3; ++i) {
		if (a[i]) {
			c++;
		}
	}
	if (c == 3) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int xcomp(vector<LL>& a, vector<LL>& b) {
	return a[0] < b[0];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;



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

	vector<LL> D(N, 0);
	REP(i, N) {
		cin >> D[i];
	}


	LL M;
	cin >> M;

	vector<LL> T(M, 0);
	REP(i, M) {
		cin >> T[i];
	}

	SORT(D);
	SORT(T);

	bool flag = true;
	LL j = 0;
	REP(i, T.size()) {
		while (true) {
			if (j >= D.size()) {
				flag = false;
				break;
			}
			if (D[j] == T[i]) {
				j++;
				break;
			}
			if (D[j] < T[i]) {
				j++;
			}
			if (D[j] > T[i]) {
				flag = false;
				break;
			}
		}
	}

	if (flag) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 3328
// Author: Shusuke Ueda
// AOJ GRL_1_A (Single Source Shortest Path)

#include <iostream>
#include <limits>
#include <vector>
#include <queue>

namespace graph {
    template <typename T>
    class Graph {
        int n;
        std::vector<std::vector<int>> to;
        std::vector<std::vector<T>> cost;

        T inf = std::numeric_limits<T>::max() / 2;

      public:
        Graph(int init_n): n(init_n) {
            to.assign(n, std::vector<int>(0));
            cost.assign(n, std::vector<T>(0));
        }

        void add_directed_edge(int u, int v, T c) {
            to[u].push_back(v);
            cost[u].push_back(c);
        }
        void add_undirected_edge(int u, int v, T c) {
            add_directed_edge(u, v, c);
            add_directed_edge(v, u, c);
        }

        T get_inf() {
            return inf;
        }

        std::vector<T> single_source_shortest_path(int start) {
            std::vector<T> res;
            res.assign(n, inf);
            res[start] = 0;
            auto comp = [](const std::pair<int, T> u, const std::pair<int, T> v) -> bool {
                return u.second > v.second;
            };
            std::priority_queue<std::pair<int, T>, std::vector<std::pair<int, T>>, decltype(comp)> que(comp);
            que.push(std::make_pair(start, 0));
            while (!que.empty()) {
                auto pos = que.top();
                que.pop();
                for (int i = 0; i < to[pos.first].size(); i++) {
                    int next = to[pos.first][i];
                    T next_cost = cost[pos.first][i];
                    if (pos.second + next_cost < res[next]) {
                        res[next] = res[pos.first] + next_cost;
                        que.push(std::make_pair(next, res[next]));
                    }
                }
            }
            return res;
        }
        void print_single_source_shortest_path(int start) {
            auto res = single_source_shortest_path(start);
            for (int i = 0; i < n; i++) {
                if (res[i] == inf) {
                    std::cout << "INF" << std::endl ;
                } else {
                    std::cout << res[i] << std::endl;
                }
            }
        }
    };
}

using lint = int_fast64_t;

int main() {
    int v, e, r;
    std::cin >> v >> e >> r;
    graph::Graph<lint> g(v);
    for (int i = 0; i < e; i++) {
        int s, t;
        lint d;
        std::cin >> s >> t >> d;
        g.add_directed_edge(s, t, d);
    }

    g.print_single_source_shortest_path(r);

    return 0;
}


Measured memory_bytes: 20888
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<pair<int, int> > A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i].first >> A[i].second;
	}

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

	for (int i = 0; i < N; i++) {

		int num = min(M, A[i].second);
		M -= num;
		res += A[i].first*num;
	}

	cout << res << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()

signed main() {
  int n;
  cin >> n;
  int a[n], b[n];
  vector<int> v(n);
  REP(i,n) {
    cin >> a[i];
    v[i] = i+1;
  }
  REP(i,n) cin >> b[i];
  int a_position = 0, b_position = 0;
  bool a_flag = true, b_flag = true;
  int current_position = 1;
  do {
    REP(i,n) {
      if(a[i] != v[i]) a_flag = false;
      if(b[i] != v[i]) b_flag = false;
      if(!a_flag && !b_flag) break;
    }
    if(!a_position && a_flag) a_position = current_position;
    if(!b_position && b_flag) b_position = current_position;
    if(a_position && b_position) break;
    a_flag = true;
    b_flag = true;
    ++current_position;
  } while(next_permutation(ALL(v)));

  cout << abs(a_position - b_position);
  cout << "\n";
  return 0;
}


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

using namespace std;

long long dp[3003][3003];
bool done[3003][3003];
long long A[3003];

long long f(int a, int b) {
    if (a > b)  return 0;
    if (done[a][b]) return dp[a][b];
    done[a][b] = true;

    long long ans = 0;
    ans = A[a] - f(a+1, b);
    ans = max(ans, A[b] - f(a, b-1));    

    // if (turn == 1)  ans *= -1;  
    dp[a][b] = ans;
    return ans;
}


int main(void) {

    int n;
    cin>>n;
    for(int i = 0; i < n; ++i) {
        cin>>A[i];
    }
    memset(done, 0, sizeof(done));
    cout<<f(0, n-1);

    return 0;
}



Measured memory_bytes: 78464
import java.io.*
import java.util.*

fun solve(N: Long, s: Array<String>, M: Long, t: Array<String>){
    val ans = (0 until N.toInt()).map{ outer -> s.count{ it == s[outer] } - t.count{it==s[outer]} }.max()!!
    println(if (ans>=0) ans else 0)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val s = StringArray(N.toInt())
    for (i in 0 until N.toInt()) {
        s[i] = sc.next()
    }
    val M = sc.next().toLong()
    val t = StringArray(M.toInt())
    for (i in 0 until M.toInt()) {
        t[i] = sc.next()
    }
    solve(N, s, M, t)
}



Measured memory_bytes: 31644