akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
	int i;
	int dat;
	int temp=0;
	int temp2=0;
	int data[3]={0};

	for(i=0;i<10;i++){
		scanf("%d",&dat);

		if(data[0]<dat){
			temp=data[0];
			data[0]=dat;
			temp2=data[1];
			data[1]=temp;
			data[2]=temp2;
		}
		else if(data[1]<dat){
			temp=data[1];
			data[1]=dat;
			data[2]=temp;
		}
		else if(data[2]<dat){
			data[2]=dat;
		}
		temp=0;
		temp=0;
	}

	printf("%d\n%d\n%d\n",data[0],data[1],data[2]);

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define M 1000005
#define L long long
#define MOD 1000000007
using namespace std;
L f[M]={0},g[M]={0};
int main(){
	L n,ans=0; cin>>n;
	f[1]=1;
	for(L i=1;i<=n;i++){
		f[i]=(f[i]+(i>=3?g[i-3]:0)+f[i-1])%MOD;
		g[i]=(g[i-1]+f[i])%MOD;
		if(i<n) ans=(ans+f[i]*(n-1)%MOD*(n-1)+f[i]*min(n-1,i+1))%MOD;
	}
	ans=(ans+f[n]*n)%MOD;
	cout<<ans<<endl;
}

Measured memory_bytes: 15872
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n;
vi v;

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen(fname".in", "r", stdin);
	// freopen(fname".out", "w", stdout);
	scanf("%d", &n);
	while(n > 0){
		v.pb(n % 10);
		n /= 10;
	}
	for(int i = 0; i < sz(v) / 2; ++i){
		if (v[i] != v[sz(v) - 1 - i]){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=1000000007;
ll MOD=998244353;
int inf=1000001000;
ll INF=100000000000000000;


int main() {
    int v,E;
    cin >> v >> E;
    vector<vector<pp>> e(v+1,vector<pp>(0));
    rep(i,E){
        int f,g,h;
        cin >> f >> g >> h;
        e[f].push_back(mk(g,h));
        e[g].push_back(mk(f,h));
    } 
    int t;
    cin >> t;
    rep(i,100){
        cout << -1 << endl;
        t--;
        if (t==0) return 0;
    }
    queue<int> q;
    q.push(1);
    while(true){
        int f=q.front();
        int u=rand()%e[f].size();
        q.pop();
        q.push(e[f][u].first);
        rep(i,e[f][u].second){
            cout << e[f][u].first << endl;
            t--;
            if (t==0) return 0;
        }
    }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
   vector<string> a={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string n;
  int cal;
  cin>>n;
  for(int i=0;i<7;i++){
    if(a.at(i)==n) cal=i;
  }
  cout<<(7-cal%7)<<endl;
}

Measured memory_bytes: 256
class dice():
    def __init__(self,number):
        self.number = number

    def korokoro(self,com):
        if com == 'E':
            self.number = [self.number[i] for i in [3,1,0,5,4,2]]
        if com == 'S':
            self.number = [self.number[i] for i in [4,0,2,3,5,1]]
        if com == 'N':
            self.number = [self.number[i] for i in [1,5,2,3,0,4]]
        if com == 'W':
            self.number = [self.number[i] for i in [2,1,5,0,4,3]]
i_number = [int(x) for x in input().split()]
com_list = input()
d = dice(i_number)
for c in com_list:
    d.korokoro(c)
print(d.number[0])



Measured memory_bytes: 5604
S = input()
T = input()

s = len(S)
t = len(T)

min_count = t
for i in range(s - t + 1):
    count = 0
    for j, tt in enumerate(T):
        if S[i: i + t][j] == tt:
            count += 1
    change = t - count
    if change < min_count:
        min_count = change
print(min_count)


Measured memory_bytes: 9108
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int main(){
  int a,b;cin>>a>>b;
  if(a+b==15) puts("+");
  else if(a*b==15) puts("*");
  else puts("x");


  return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#define INF 100000000

using namespace std;

int n;
int a[100005];
int p[100005];

int main()
{
    while(scanf("%d",&n)==1)
    {
        memset(p,0,sizeof(p));
        long long sum=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        long long tmp=(long long)((1+n))*n/2;
        if(sum%tmp !=0)
        {
            printf("NO\n");
            continue;
        }
        long long c=sum/tmp;
        a[n]=a[0];
        for(int i=0;i<n;i++)
        {
            p[i]=a[i+1]-a[i];
        }
        int flag=1;
        for(int i=0;i<n;i++)
        {
            if((p[i]-c)%n!=0 || p[i]-c>0)
            {
                flag=0;
                break;
            }
        }
        if(flag==0)
        {
            printf("NO\n");
        }
        else
        {
            printf("YES\n");
        }
    }
    return 0;
}







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

using namespace std;

int main(){
	int H, W, h, w;
	while(cin >> H >> W >> h >> w){
		vector<vector<int>> mtx(H, vector<int>(W, 0));
		long long sum = 0;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(i%h == h-1 && j%w == w-1){
					mtx[i][j] = -1000000000;
				} else if(i%h == 0 && j%w == 0){
					mtx[i][j] = 999999999 - (h*w-2);
				} else {
					mtx[i][j] = 1;
				}
				sum += mtx[i][j];
			}
		}
		if(sum > 0){
			cout << "Yes" << endl;
			for(int i=0;i<H;i++){
				cout << mtx[i][0];
				for(int j=1;j<W;j++) cout << " " << mtx[i][j];
				cout << endl;
			}
		} else {
			cout << "No" << endl;
		}
	}
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

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

  vi x(n), y(n);
  vector<pii> z(n);
  rep(i, 0, n){
    cin >> x[i] >> y[i];
    z[i] = {x[i], y[i]};
  }

  if(n == 1){
    cout << 1 << endl;
    return 0;
  }

  int ans = inf;
  rep(i, 0, n) rep(j, 0, n) if(i != j){
    int p = x[i]-x[j];
    int q = y[i]-y[j];

    if(p >= 0) sort(all(z));
    else sort(all(z), greater<pii>());
    
    vector<bool> used(n, false);
    int tmp = 0;
    rep(s, 0, n){
      if(used[s]) continue;
      tmp++;
      used[s] = true;
      int curx = z[s].first, cury = z[s].second;
      rep(k, s+1, n){
        if(curx+p == z[k].first and cury+q == z[k].second){
          used[k] = true;
          curx = z[k].first;
          cury = z[k].second;
        }
      }
    }

    chmin(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        string t = Console.ReadLine();

        int count = 0;

        for (int i = 0; i <= s.Length - t.Length; i++)
        {
            int tmp = 0;

            for (int j = 0; j < t.Length; j++)
            {
                if (s.Substring(i + j, 1).Equals(t.Substring(j, 1)))
                {
                    tmp++;
                }
            }

            if (count < tmp)
            {
                count = tmp;
            }
        }

        Console.WriteLine(t.Length - count);
    }
}

Measured memory_bytes: 37372
/* be name Khoda */
#include <bits/stdc++.h>
using namespace std;

// VJUDGE

const int N = 3006;
int n, a[N];
long long dp[N][N], sum[N];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum[i] = sum[i - 1] + a[i];
	}
	for (int i = n; 0 <= i; i--)
		for (int j = i; j < n; j++) {
			if (i == j)
				dp[i][j] = a[i];
			else {
				dp[i][j] = a[i] + (sum[j] - sum[i] - dp[i + 1][j]);
				dp[i][j] = max(dp[i][j], a[j] + (sum[j - 1] - sum[i - 1] - dp[i][j - 1]));
			}
//			cout << i << "  " << j << " == " << dp[i][j] << endl;
		}
//	cout << dp[0][n - 1] << endl;
	cout << 2 * dp[0][n - 1] - sum[n - 1] << endl;
}


Measured memory_bytes: 70016
///FUCKOUT
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
//#define endl '\n'

using ll = long long;
using db = long double;
using row = vector<int>;
using ii = pair<ll, ll>;

#define int ll

const int N = 2e5+5, M = 1e6 + 5, LG = 17, MOD = 1e6 + 3;
const int BLOCK = 55;
const int BLOCKN = N / BLOCK + 1;
const long double EPS = 1e-7;
using ull = unsigned long long;

int n, x[N], y[N], mxIdx, mnIdx;
ll solve1(int LR,int RR, int LB, int RB){

  f(i,0,n){
    if(i == mnIdx || i == mxIdx)continue;
    RR = max(RR,x[i]);
    LB = min(LB,y[i]);
  }

  assert(LR<=RR);
  assert(LB<=RB);
  return (RR-LR) * 1ll * (RB-LB);
}
int cnt[N];
ll solve2(int LR,int RR, int LB, int RB){
  vector<pair<int,int>> vp;
  f(i,0,n){
    if(i == mnIdx || i == mxIdx)continue;
    vp.emplace_back(x[i], i);
    vp.emplace_back(y[i], i);
  }

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

  int cntD = 0;
  int ans = INT_MAX;
  int sz = vp.size();
  for(int i = sz-1,j=sz-1; i >= 0; --i){

    if(!cnt[vp[i].S])cntD++;
    cnt[vp[i].S]++;
    while(cnt[vp[j].S] == 2){
      cnt[vp[j].S]--;
      --j;
    }

    if(cntD == n - 2)
      ans = min(ans, max(RB,vp[j].F) - min(LB,vp[i].F));

  }
  return 1ll * ans * (RR-LR);
}
int32_t main(){
#ifdef ONLINE_JUDGE
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#endif // ONLINE_JUDGE

  cin >> n;

  f(i,0,n){
    cin >> x[i] >> y[i];
    if(x[i] > y[i])swap(x[i], y[i]);
  }

  f(i,0,n){
    if(y[i] > y[mxIdx]){
      mxIdx = i;
    }
    if(x[i] < x[mnIdx]){
      mnIdx = i;
    }
  }

  if(mxIdx == mnIdx){
    ///same box
    cout<<solve1(x[mnIdx],x[mnIdx],y[mxIdx],y[mxIdx])<<'\n';
  } else {
    cout << min(
                solve1(x[mnIdx],x[mxIdx],y[mnIdx],y[mxIdx]),
                solve2(x[mnIdx],y[mxIdx],min(y[mnIdx],x[mxIdx]),max(y[mnIdx],x[mxIdx]))
                ) << '\n';
  }


  return 0;
}


Measured memory_bytes: 13676
//youtube模範解説
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main(void){
  int k;
  cin >> k;
  vector<ll> a;
  
  for (int i = 1; i <= 9; i++) a.push_back(i);
  while(1){
    if (k <= a.size()) {
      cout << a[k-1] << endl;
      return 0;
    }
    k -= a.size();
    vector<ll> old;
    swap(old, a);
    for (ll x : old) {
      for (int i = -1; i <= 1; i++){
        int d = x%10 + i;
        if (d < 0 || d > 9) continue;
        ll nx = x*10 + d;
        a.push_back(nx);
      }
    }
  }
}


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

int main() {
    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  string S;
  cin >> S;

  int result = INF;
  for (int i = 0; i < S.length() - 2; i++) {
    // cout << S.substr(i, 3) << endl;
    int X = stoi(S.substr(i, 3));
    int diff = abs(753 - X);
    if (diff < result) {
      result = diff;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

bool chk(ll inp){
    if(inp == 0 || inp > 12)return false;
    return true;
}

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

    string S ;
    cin >> S;

    int a = (S[0]-'0') * 10 + (S[1]-'0');
    int b = (S[2]-'0') * 10 + (S[3]-'0');

    if(chk(a) && chk(b)){
        cout << "AMBIGUOUS" << endl;
    }else if( (!chk(a)) && (!chk(b)) ){
        cout << "NA" << endl;
    }else if(chk(a)){
        cout << "MMYY" << endl;
    }else{
        cout << "YYMM" << endl;
    }

    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

template <ll mod>
struct modular {
    ll value;
    modular(ll x = 0) {
        value = x % mod;
        if (value < 0) value += mod;
    }
    modular& operator+=(modular other) {
        if ((value += other.value) >= mod) value -= mod;
        return *this;
    }
    modular& operator-=(modular other) {
        if ((value -= other.value) < 0) value += mod;
        return *this;
    }
    modular& operator*=(modular other) {
        value = value * other.value % mod;
        return *this;
    }
    modular& operator/=(modular other) {
        ll a = 0, b = 1, c = other.value, m = mod;
        while (c != 0) {
            ll t = m / c;
            m -= t * c;
            swap(c, m);
            a -= t * b;
            swap(a, b);
        }
        a %= mod;
        if (a < 0) a += mod;
        value = value * a % mod;
        return *this;
    }
    modular& operator^=(modular other) {
        ll r = 1, x = value, n = other.value;
        while (n > 0) {
            if (n & 1) r = r * x % mod;
            x = x * x % mod;
            n >>= 1;
        }
        value = r;
        return *this;
    }
    modular operator+(modular rhs) {
        return modular(*this) += rhs;
    }
    modular operator-(modular rhs) {
        return modular(*this) -= rhs;
    }
    modular operator*(modular rhs) {
        return modular(*this) *= rhs;
    }
    modular operator/(modular rhs) {
        return modular(*this) /= rhs;
    }
    modular operator^(modular rhs) {
        return modular(*this) ^= rhs;
    }
    bool operator==(modular rhs) {
        return value == rhs.value;
    };
    bool operator!=(modular rhs) {
        return value != rhs.value;
    };
    bool operator<(modular rhs) {
        return value < rhs.value;
    }
};
template <ll mod>
string to_string(modular<mod> x) {
    return to_string(x.value);
}
template <ll mod>
ostream& operator<<(ostream& stream, modular<mod> x) {
    x.value %= mod;
    if (x.value < 0) x.value += mod;
    return stream << x.value;
}
template <ll mod>
istream& operator>>(istream& stream, modular<mod>& x) {
    stream >> x.value;
    x.value %= mod;
    if (x.value < 0) x.value += mod;
    return stream;
}
const ll mod = 998244353;
using mint = modular<mod>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<mint> dp(s + 1);
    dp[0] = 1;
    mint ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (a[i] <= s) {
            ans += dp[s - a[i]] * (mint)(i + 1);
        }
        for (int j = s; j > 0; j--) {
            if (j + a[i] < s) dp[j + a[i]] += dp[j];
        }
        if (a[i] < s) {
            dp[a[i]] += mint(n - i);
        }
        dp[0] += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

bool bol(ll a,ll b,ll c){
    if(a==b || b==c || c==a){
        return false;
    }
    if(a>b)return bol(b,a,c);
    if(b>c)return bol(a,c,b);
    if(a+b>c){
        return true;
    }else{
        return false;
    }
}
int main(){fastio
    ll n;cin>>n;
    ll l[n];rep(i,0,n-1)cin>>l[i];
    if(n<3){
        cout<<0<<endl;
        return 0;
    }
    ll ans=0;
    rep(i,0,n-3){
        rep(j,i+1,n-2){
            rep(k,j+1,n-1){
                if(bol(l[i],l[j],l[k])){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}





Measured memory_bytes: 3576
#!/usr/bin/env python3
import sys


def solve(N: int, T: int, A: "List[int]", B: "List[int]"):
    # dp[i][w][超えたか超えてないか超えたら1]:= (i番目までの品物の中から重さが w を超えないように選んだときの、価値の総和の最大値,[index])

    AB = list(zip(A,B))
    AB.sort(key=lambda x:x[0])
    A = [AB[i][0] for i in range(N)]
    B = [AB[i][1] for i in range(N)]

    dp  = [[0 for _ in range(T)] for _ in range(N+1)]
    ans = 0
    for i in range(N):
        ans = max(ans,dp[i][T-1]+B[i])

        for j in range(0,T):

            if j >= A[i]: ##今回の商品がjよりも小さい
                dp[i+1][j] = max(dp[i][j-A[i]]+B[i],dp[i][j])
            else: ## 選ばない
                dp[i+1][j] = dp[i][j]
             
    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, T, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 122204
fun main(args: Array<String>) {
    // Your code here!
    var n = readLine()!!.toInt()
    var index = readLine()!!.split(" ").map{it.toInt()}
    var list:MutableList<Int> = mutableListOf()
    var ans:MutableList<Int> = mutableListOf()
    
    for(i in 0..n-1){
        list.add(i+1)
        ans.add(0)
    }
    
    for(i in 0..n-1){
        ans[index[i]-1] = list[i] 
    }
    ans.forEach{print("${it} ")}
}


Measured memory_bytes: 60448
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <math.h>
#include <bitset>

#define X first
#define Y second
#define vsort(v) sort(v.begin(), v.end())
#define vrev(v) reverse(v.begin(), v.end())
#define vmax_p(v) max_element(v.begin(), v.end())
#define vmin_p(v) min_element(v.begin(), v.end())
#define vmax_idx(v) distance(v.begin(), vmax_p(v))
#define vmin_idx(v) distance(v.begin(), vmin_p(v))
#define vcopy(src, dst) copy(src.begin(), src.end(), back_inserter(dst))
#define P pair

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

// floor(x): truncate

// 2進数変換
// string s = bitset<20>(x).to_string();

using namespace std;
using ll = long long;

void displayVec(vector<int> v)
{
    for (int i = 0; i < v.size(); i++)
    {
        cout << v[i] << endl;
    }
    cout << endl;
}

int binarySearch(vector<int> v, int target)
{
    int left = -1;
    int right = v.size();

    while (right - left > 1)
    {
        int mid = left + (right - left) / 2;

        if (v[mid] >= target)
        {
            right = mid;
        }
        else
        {
            left = mid;
        }
    }

    if (right < v.size() && v[right] == target)
    {
        return right;
    }
    return -1;
}

int main(int argc, const char *argv[])
{
    int n, m, l, r;
    cin >> n >> m;
    int r_min = INT_MAX, l_max = INT_MIN;
    for (int i = 0; i < m; i++)
    {
        cin >> l >> r;
        if (l > l_max)
        {
            l_max = l;
        }
        if (r < r_min)
        {
            r_min = r;
        }
    }
    if (l_max > r_min)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << max(l_max - r_min + 1, r_min - l_max + 1) << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  string a,b;
  cin>>a>>b;
  rep(i,b.size()){
    rep(j,b.size()-1){
      if(b[j]<b[j+1]) swap(b[j],b[j+1]);
    }
  }
  rep(i,a.size()){
    rep(j,a.size()-1){
      if(a[j]>a[j+1]) swap(a[j],a[j+1]);
    }
  }
  //cout<<a<<" "<<b<<endl;
  if(a<b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
n, z, w = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
if n > 1 and abs(a_ls[-1] - w) < abs(a_ls[-2] - a_ls[-1]):
    x = a_ls[-2]
    y = a_ls[-1]
else:
    x = a_ls[-1]
    y = w
print(abs(x - y))

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {	
	int n,ans=0;
	cin >> n;
	vector<int > vec(n);
	for (int i = 0;i < n;i++)
		cin >> vec.at(i);
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());
	bool flag = true;
	for (int i = 0;i < n;i++) {
		if (flag == true) 	ans += vec.at(i);
		else ans -= vec.at(i);
		flag = !flag;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
s,t=input(),input();l,m=len(s),len(t)
for i in range(l-m+1):
 if all(c in"?"+d for c,d in zip(s[-i-m:],t)):s=s.replace(*"?a");exit(print(s[:-i-m]+t+s[l-i:]))
print("UNRESTORABLE")

Measured memory_bytes: 9120
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#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;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	
	ll n ;
	cin>> n ;
	string str ;
	cin>> str ;
	ll l=0 , r= n-1;
	if(n==1 || n%2==1){
		cout<<"No"<<endl;
		return 0;
	}
	for(ll i=0 , j=ceil(n/2.0) ; j<n ; i++ , j++ ){
		if(str[i]!=str[j]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int
main(void) 
{
  int W, H, x, y, r;
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
  if (x < r || x > W - r || y < r || y > H - r) {
    printf("No\n");
  }
  else {
    printf("Yes\n");
  }
  return 0;
} 

Measured memory_bytes: 584
function Main(input) {
  input = input.split("\n")[0];
  var cnt0 = 0, cnt1 = 0;
  for(var i = 0; i < input.length; i++) {
	cnt0 += input[i] == 0 ? 1 : 0;
	cnt1 += input[i] == 1 ? 1 : 0;
  }
  console.log(2 * parseInt(Math.min(cnt0, cnt1)));
}

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


Measured memory_bytes: 7500
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;

int main() {
    string S, T;
    cin >> S >> T;

    int count[2][26];
    for (int i = 0; i < 26; i++) {
        count[0][i] = 0;
        count[1][i] = 0;
    }

    for (int i = 0; i < S.length(); i++) {
        count[0][S[i] - 'a']++;
    }

    for (int i = 0; i < T.length(); i++) {
        count[1][T[i] - 'a']++;
    }

    sort(count[0], count[0] + 26);
    sort(count[1], count[1] + 26);

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

Measured memory_bytes: 776
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#define ll long long
using namespace std;
int pos(int n)
{
    if(n<0)
        return 0;
    else
        return n;
}
int main()
{
    int a[100002][2]= {0};
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i][0]);
 
        sum+=abs(a[i-1][0]-a[i][0]);
    }
    sum+=abs(a[n][0]);
    for(int i=1; i<=n; i++)
    {
 
            cout<<sum-abs(a[i][0]-a[i+1][0])-abs(a[i][0]-a[i-1][0])+abs(a[i-1][0]-a[i+1][0])<<endl;
 
  
    }
}

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

using namespace std;

#define rep(i, a, n) for (int i = a, _n = n; i <= _n; ++i)
#define drep(i, a, n) for (int i = a, _n = n; i >= n; --i)
#define debug(x) cout << #x <<" = "<< x << endl

long long a, b, c, d;

long long D (long long x) {
	return x - x / c - x / d + x / (c / __gcd(c, d) * d);
}

int main () {
	scanf ("%lld%lld%lld%lld", &a, &b, &c, &d);
	cout << D(b) - D(a - 1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
bool is_prime(lli x) {
  for(lli i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}
int main() {
  lli A,B,C=1,D=0,E=0,F=0,G=0,H=0,N,M;
  string S;
  cin >> A;
  A*=2;
  vector<lli>P(A);
  rep(i,0,A)cin >> P[i];
  Sort(P);
  rep(i,0,A)if(i%2==0)D+=P[i];
  Out(D);
}
   

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

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

    int ans = 0;
    for(int i=1; i<ceil((float)n/2.0); i++){
        int tmp = n-1;
        if(tmp != i) ans++;
    }
    
    cout << ans << endl; 
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n;
		String string;
		StringBuffer string2 = new StringBuffer();;
		String s;
		int count;

		n = scanner.nextInt();
		while (n != 0) {
			count = 1;
			string = scanner.next();

			for (int j = 0; j < n; j++) {
				for (int i = 1; i < string.length(); i++) {
					if (string.charAt(i) == string.charAt(i - 1)) {
						count++;
					} else {
						string2.append(count);
						string2.append(string.charAt(i - 1));
						count = 1;
					}
				}
				string2.append(count);
				string2.append(string.charAt(string.length() - 1));
				count = 1;
				string = string2.toString();
				string2 = new StringBuffer();
			}
			System.out.println(string);
			n = scanner.nextInt();
		}
	}
}

Measured memory_bytes: 12000
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			// m_C_nの配列を計算
			long[][] c = calcC(n);
			long[] v = new long[n];
			Map<Long, Integer> map = new HashMap<>();
			IntStream.range(0, n).forEach(i -> {
				v[i] = scanner.nextLong();
				map.put(v[i], map.getOrDefault(v[i], 0) + 1);
			});
			Arrays.sort(v);
			System.out.println(IntStream.rangeClosed(1, a).mapToLong(i -> v[n - i]).average().getAsDouble());
			if (v[n - 1] == v[n - a]) {
				Integer count = map.get(v[n - 1]);
				int max = Math.min(count, b);
				System.out.println(IntStream.rangeClosed(a, max).mapToLong(i -> c[count][i]).sum());
			} else {
				long[] keys = map.keySet().stream().sorted((l1, l2) -> l2.compareTo(l1)).mapToLong(Long::longValue)
						.toArray();
				Map<Long, Integer> countMap = new HashMap<>();
				int count = 0;
				countMap.put(keys[0], count);
				for (int i = 1; i < keys.length; i++) {
					countMap.put(keys[i], count += map.get(keys[i - 1]));
				}
				System.out.println(c[map.get(v[n - a])][a - countMap.get(v[n - a])]);
			}
		}
	}

	/**
	 * パスカルの三角形を使ってm_C_nを計算
	 * 
	 * @param n 整数の最大値
	 * @return m_C_n の配列，c[m][n]はm_C_n
	 */
	private static long[][] calcC(int n) {
		long[][] c = new long[n + 1][n + 1];
		c[0][0] = 1;
		IntStream.rangeClosed(1, n).forEach(i -> IntStream.rangeClosed(0, i).forEach(j -> {
			// c[i][j] = c[i-1][j-1]+c[i-1][j]
			if ((i > 0) && (j > 0)) {
				c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
			} else {
				c[i][j] = 1;
			}
		}));
		return c;
	}

	@SuppressWarnings("unused")
	private static void print(long[][] c) {
		int n = c.length;
		IntStream.range(0, n).mapToObj(i -> IntStream.rangeClosed(0, i).mapToObj(j -> String.valueOf(c[i][j]))
				.collect(Collectors.joining(","))).forEach(System.out::println);
	}
}


Measured memory_bytes: 30548
#include<stdio.h>
#define a 10000
#define b 500

int main(){
  int n;
  int S[a];
  int q;
  int T[b];
  int i,j;
  int c=0;  
  scanf("%d",&n);  
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);  
  scanf("%d",&q);  
  for(i=0;i<q;i++)
    scanf("%d",&T[i]);  
  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(S[j]==T[i]){
	c++;
	break;
      }
    }
  }
  printf("%d\n",c);  
  return 0;
}



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

int main(){
  ll a,b,k; cin >> a >> b >> k;
  ll ans_a,ans_b;
  ll tmp_k;
  if(k<=a){cout << a-k << ' ' << b << endl;return 0;}
  else{
    ans_a = 0;
    tmp_k = k-a;
    cout << 0 << ' ' << max((ll)0,b-tmp_k) << endl;return 0;}
  
  //cout << a << ' ' << b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (){
	int x,y,z;
	int hasil = 0;
	scanf("%d %d %d", &x, &y, &z);
	for(int i = 0 ; i <= x; i++){
		int num=i;
		int temp = 0;
		while(num > 0){
			temp += num%10;
			num /= 10;
		}
		if(temp >= y && temp <=z){
			hasil += i;
		}
	}
	printf("%d",hasil);
	return 0;
}


Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n,k;cin >> n >> k;
    ll res = k;
    rep(i,n-1) res*=(k-1);
    cout << res << endl;
}


Measured memory_bytes: 256
n = gets.to_i
l = gets.chop.split.map(&:to_i)

l.sort!
ans = 0

# p l

0.upto(n-3) do |i|
  (i+1).upto(n-2) do |j|
    a_b = l[i] + l[j]

    idx = l.bsearch_index{ |x| x >= a_b }

    # p "i:#{i} j: #{j} a+b:#{a_b} idx: #{idx}"

    if idx.nil?
      ans += n - j - 1
    else
      ans += [idx - 1 - j, 0].max
    end
  end
end

puts ans


Measured memory_bytes: 3836
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    int n;cin>>n;
    string s;cin>>s;
    map<pair<string,string>,int> ma;
    for(int i=0;i<(1<<n);++i){
        int b=i;
        string k="",l="";
        for(int j=0;j<n;++j){
            if((i>>j)%2==0)k = k+s[j];
            else l = l+s[j];
        }
        ma[pair<string,string>(k,l)]++;
    }
    long long res=0;
    for(int i=0;i<(1<<n);++i){
        int b=i;
        string k="",l="";
        for(int j=0;j<n;++j){
            if((i>>j)%2==0)k = k+s[2*n-1-j];
            else l = l+s[2*n-1-j];
        }
        res+=ma[pair<string,string>(k,l)];
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 87808
n = int(input())
alst = list(map(int, input().split()))
ans = 10 ** 10
min_a = min(alst)
max_a = max(alst)
for y in range(min_a, max_a + 1):
    tmp = 0
    for num in alst:
        tmp += (num - y) ** 2
    ans = min(ans, tmp)
print(ans)



Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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






int main(){
    string s;
    cin >> s;
    ll cnt1 = 0, cnt2 = 0;
    REP(i, s.size()){
        if(i % 2 == 0){
            if(s[i] == '1') cnt1++;
            else cnt2++;
        }
        else{
            if(s[i] == '0') cnt1++;
            else cnt2++;
        }
    }
    cout << min(cnt1, cnt2) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int a, b;
    cin >> a >> b;

    if(b==1){
        cout << 0 << endl;
        return 0;
    }

    int ans=0;
    while(true){
        b = b-a+1;
        ans++;
        if(b<=1){
            cout << ans << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M 998244353
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ull
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>



int fac[310000];

int inv(int x){
  if(x==1) return 1;
  return (M-M/x)*inv(M%x)%M;
}


int comb(int n,int k){
  int x=(fac[k]*fac[n-k])%M;
  return (fac[n]*inv(x))%M;
}

int fac_init(int n){
  fac[0]=1;
  FOR(i,1,n+1){
    fac[i]=fac[i-1]*i;
    fac[i]%=M;
  }
}

int n,a,b,k;
map<int,int> ma,mb;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  cin>>n>>a>>b>>k;
  fac_init(n);

  rep(i,n+1){
    int m=comb(n,i);
    ma[a*i]=m;
    mb[b*i]=m;
  }

  int ans=0;
  rep(i,n+1){
    int res=ma[a*i]*mb[k-a*i];
    res%=M;
    ans+=res;
    ans%=M;
  }

  cout<<ans<<endl;


}

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

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

    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        if (i % 2 == 0) continue;

        int cnt = 0;
        for (int j = 1; j <= N; j++) {
            if (i % j == 0) cnt++;
        }
        if (cnt == 8) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <limits>
#include <tuple>
using namespace std;

template <typename T>
struct edge
{
	int src, to;
	T cost;
	edge(int to, T cost) : src(-1), to(to), cost(cost) {}
	edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
	edge &operator=(const int &x)
	{
		to = x;
		return *this;
	}
	operator int() const { return to; }
};

template <typename T>
using Edges = vector<edge<T>>;

template <typename T>
using WeightedGraph = vector<Edges<T>>;

using UnweightedGraph = vector<vector<int>>;

template <typename T>
using Matrix = vector<vector<T>>;

template <typename T>
vector<T> dijkstra(WeightedGraph<T> &g, int s)
{
	const auto INF = numeric_limits<T>::max();
	vector<T> dist(g.size(), INF);

	priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> que;
	dist[s] = 0;
	que.emplace(dist[s], s);
	while (que.empty() != true)
	{
		T cost;
		int idx;
		tie(cost, idx) = que.top();
		que.pop();
		if (dist[idx] < cost)
			continue;
		for (auto &e : g[idx])
		{
			auto next_cost = cost + e.cost;
			if (dist[e.to] <= next_cost)
				continue;
			dist[e.to] = next_cost;
			que.emplace(dist[e.to], e.to);
		}
	}
	dist.push_back(INF);
	return dist;
}

int main()
{
	int V, E, r;
	cin >> V >> E >> r;
	WeightedGraph<int> G(V);

	for (int i = 0; i < E; i++)
	{
		int s, t, d;
		cin >> s >> t >> d;
		G[s].emplace_back(t, d);
	}

	auto dist = dijkstra(G, r);

	for (int i = 0; i < V; i++)
	{
		if (dist[i] == dist[V])
			cout << "INF\n";
		else
			cout << dist[i] << "\n";
	}
}


Measured memory_bytes: 15428
import java.math.BigDecimal;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double L = sc.nextDouble();
        sc.close();
        double a = L / 3;
        double b = a;
        double c = b;
        double remain = L - (a + b + c);
        a += remain;
        double res = a * b * c;
        System.out.println(BigDecimal.valueOf(res).toPlainString());
    }

}


Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main(){
    int N; cin>>N;
    vector<int> a(N);
    int odd=0,four=0;
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
        if(a[i]%4==0) four++;
        else if(a[i]%2==1) odd++;
    }
    int two=N-odd-four;
    //cout<<four<<" "<<two<<" "<<odd<<endl;
    if((four+1>=odd&&two==0)||(four>=odd)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,T;
  cin>>N>>T;
  map<int,int> R;
  for(int i=0;i<N;i++){
  int c,t;
    cin>>c>>t;
    if(t<=T)
      R[i]=c;
  
  }
    int Min=1000;
  if(R.size()==0)
      cout<<"TLE"<<endl;
  else{
    for(auto p:R){
    auto k=p.first;
      auto v=p.second;
      if(v<=Min)
        Min=v;
    } cout<<Min<<endl;
  
  }
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define deb(x) cout<<#x<<" "<<x<<endl;
#define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
#define MOD 1000000007
#define finish return 0
using namespace std;
using namespace __gnu_pbds; 
typedef long long int ll;
typedef tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template<typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) { }}; template<typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, T val = T()) : vector<T>(n, val) { } };
inline ll mod(ll x) { return (x%MOD + MOD)%MOD; }
ll gcd(ll a, ll b, ll &x, ll &y){if(a == 0){x = 0, y = 1; return b;} ll x1, y1;  ll d = gcd(b%a, a, x1, y1); x = y1 - (b/a) * x1; y = x1; return d;}
ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; } 
ll power(ll x,ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res*x); y = y>>1; x = (x*x);   } return res; } 
ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); }
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,m;
    cin>>n>>m;
    vector<ll> h(n+1);
    for(ll i=1;i<=n;++i) cin>>h[i];
    vector< vector<ll> > G(n+1);
    while(m--)
    {
        ll a,b;
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    ll co = 0;
    for(ll i=1;i<=n;++i)
    {
        bool ok = true;
        for(auto v:G[i])
        {
            if(h[v] >= h[i])
            {
                ok = false;
                break;
            }
        }
        if(ok) co++;
    }
    cout<<co<<endl;

}

Measured memory_bytes: 9760
import itertools

N = int(input())
l = []
kyori = []

for _ in range(N):
    xy = list(map(int, input().split()))
    l.append(xy)

for i in itertools.combinations(l,2):
    t = ((i[0][0]-i[1][0])**2 + (i[0][1] - i[1][1])**2)**0.5
    kyori.append(t)

print((N-1)*sum(kyori)/len(kyori))

Measured memory_bytes: 9312
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	//コードの最大値 + 1
	public static final int MAX = 256;

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		doIt();
	}
	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		//size of input
		int n = sc.nextInt();
		//size of codeBook
		int m = sc.nextInt();
		while(n != 0){
			int[] codeBook = new int[m];
			for(int i = 0; i < m; i++){
				codeBook[i] = sc.nextInt();
			}
			int []input = new int[n];
			for(int i = 0; i < n; i++){
				input[i] = sc.nextInt();
			}
//			int result = DP(0, 0, max, 128);
//			System.out.println(result);
			int[][] dp = new int[2][MAX];
			int using = 0;
			int used = 1;
			for(int j = 0; j < MAX; j++){
				dp[used][j] = -1;
			}
			dp[used][128] = 0;
			for(int i = 0; i < n; i++){
				//まず、使う配列の初期化
				for(int j = 0; j < MAX; j++){
					dp[using][j] = -1;
				}
				for(int j = 0; j < MAX; j++){
					if(dp[used][j] != -1){
						for(int k = 0; k < m; k++){
							int tar = j + codeBook[k];
							if(0 > tar){
								tar = 0;
							}
							else if(tar >= MAX){
								tar = MAX - 1;
							}
							int tmp = tar - input[i];
							int temp = dp[used][j] + tmp*tmp;
							//System.out.println("tmp = " + tmp + ", temp = " + temp);
							if(dp[using][tar] == -1 || dp[using][tar] > temp){
								dp[using][tar] = temp;
							}
						}
					}
				}
				//usedとusingの入れ替え
				int tmp = using;
				using = used;
				used = tmp;
			}
			int min = (255*2)*(255*2)*20000;
			for(int j = 0; j < MAX; j++){
				if(dp[used][j] != -1 && min > dp[used][j]){
					min = dp[used][j];
				}
			}
			//minimumは？
			//結果はdp[used][n]?
			System.out.println(min);

			n = sc.nextInt();
			m = sc.nextInt();
		}

	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;


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

    int N;
    cin >> N;
    int a[N];
    rep(i,N) cin >> a[i];
    
    int x=0,count=0;
    int ans=0;
    while(count<=N){
        count++;
        x=a[x]-1;
        if(x==1){
            ans=count;
            break;
        }
    }
    if(ans>0) cout << ans << endl;
    else cout << -1 << endl;


}


Measured memory_bytes: 640
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
using namespace std;

int main() {
    int n, a;
    cin >> n >> a;
    cout << (n % 500 <= a ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256