akhauriyash/Code-Regression huggingface dataset:
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
int main(){
    LL x;
    double y;
    R(x,y);
    W((LL)(x*(LL)(y*100+0.5))/100);
    return 0;
}


Measured memory_bytes: 3772
#author: raghav_0901
from math import *

mod = (10**9) + 7


def _in():
    return [int(x) for x in input().split(' ')]


def main():
    x = int(input())
    for i in range(-1001, 1001):
        for j in range(-1001, 1001):
            a = pow(i, 5) - pow(j, 5)
            if(a == x):
                print(i, j)
                return


if __name__ == "__main__":
    main()


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

int main(void) {
    string N;
    cin >> N;
    int ans = 0;
    for (int i = 0; i < N.length(); i++) {
        ans += N[i] == '2';
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int A[N + 1];
    for(int i =0; i < N + 1; i++){
        cin >> A[i];
    }
    int B[N];
    for(int i =0; i < N; i++){
        cin >> B[i];
    }
    int64_t ans = 0;
    for(int i =0; i < N; i++){
        int monster = min(A[i] + A[i + 1], B[i]);
        ans += monster;
        if(monster <= A[i]) A[i] -= monster;
        else A[i + 1] = A[i] + A[i + 1] - monster;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
n, W = map(int, input().split())

dp = [[0 for _ in range(W+1)] for _ in range(n+1)]

for i in range(n):
    w, v = map(int, input().split())
    for j in range(W+1):
        dp[i+1][j] = dp[i][j]
        if j-w >= 0:
            dp[i+1][j] = max(dp[i][j], v+dp[i][j-w])

print(dp[-1][-1])

Measured memory_bytes: 171656
#include<iostream>
using namespace std;
int main(void){
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;
	if(w>=x+r&&h>=y+r&&x>0&&y>0){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1156
#include<stdio.h>

int main(void)
{
	void swap(int *,int *);
  	int n[4];
  
  	scanf("%d %d %d",&n[0],&n[1],&n[2]);
  	
  	swap(&n[0], &n[1]);
  	swap(&n[0], &n[2]);
  
  	printf("%d %d %d\n",n[0], n[1] ,n[2]);
  
  	return 0;
}

void swap(int *a,int *b)
{
	int temp;
  	temp = *a;
  	*a = *b;
  	*b = temp;
}

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

int diff(int a, int b){
    if(a>b){
        return a-b;
    }
    return b-a;
}

int sort(int* a, int m){
    int min=*a;
    for(int i=1;i<m;i++){
        if(*(a+i)<min){
            min=*(a+i);
        }
    }
    return min;
}

int find(int n, int k, int* a, int* dp, int curr){
    int loop_counter_limit=n-1-curr;
    if(loop_counter_limit>=k){
        loop_counter_limit=k;
    }
    int res;
    int* temp=(int*)malloc(sizeof(int)*loop_counter_limit);
    for(int i=1;i<=loop_counter_limit;i++){
        res=diff(*(a+curr), *(a+curr+i))+*(dp+curr+i);
        *(temp+i-1)=res;
    }
    res=sort(temp, loop_counter_limit);
    return res;
}

int main(){
    int n;
    scanf("%d", &n);
    int* a= (int*)malloc(sizeof(int)*n);
    int k;
    scanf("%d", &k);
    for(int i=0;i<n;i++){
        scanf("%d", a+i);
    }
    int* dp=(int*)malloc(sizeof(int)*n);
    *(dp+n-1)=0;
    for(int i=n-2;i>=0;i--){
        *(dp+i)=find(n, k, a, dp, i);
    }
    printf("%d", *dp);
    return 0;
}


Measured memory_bytes: 41600
N = int(input())
s = []
for i in range(N):
    a = int(input())
    s.append(a)

m = sum(s)
if m%10!=0:
    print(m)
    exit()
s.sort()
for i in range(N):
    if s[i]%10==0:
        continue
    else:
        m-=s[i]
        break
if m%10==0:
    print(0)
    exit()
print(m)

Measured memory_bytes: 3060
import fractions

N = int(input())
A = list(map(int, input().split()))

if N == 2:
  print(max(A))
else:
  ans = [A[1], A[0]]
  for i in range(2,N):
    ans_0 = max(fractions.gcd(ans[0], A[i]),fractions.gcd(ans[1], A[i]))
    ans_1 = fractions.gcd(ans[0], ans[1])
    ans = [ans_0, ans_1]
  print(max(ans))

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

int main(){
  int H,W;
  cin>>H>>W;
  vector<string> S(H);
  for(string &s:S)
    cin>>s;
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++){
      if(S[i][j]=='.')
        continue;
      else if(i!=0 && S[i-1][j]=='#')
        continue;
      else if(i!=H-1 && S[i+1][j]=='#')
        continue;
      else if(j!=0 && S[i][j-1]=='#')
        continue;
      else if(j!=W-1 && S[i][j+1]=='#')
        continue;
      else{
        cout<<"No"<<endl;
        return 0;
      }
    }
  cout<<"Yes"<<endl;
}

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


void solve(long long N, std::vector<long long> p){
  int ans = 0;
  rep(i,N) {
    if(i!=N-1) {
      if(p[i]==i+1) {
	ans++;
	swap(p[i], p[i+1]);
      }
    }
  }
  if(p[N-1]==N) ans++;
  std::cout << ans << std::endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(N, std::move(p));
    return 0;
}


Measured memory_bytes: 4040
import java.util.Scanner;

//Earth Invasion Diary of Miyabi-sensei
public class Main{

	int f(int n){
		if(n<=1)return 0;
		if(n<=3)return 1;
		return (n%3==0?f(n/3):f(n/3+1))+1;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		System.out.println(f(sc.nextInt()));
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main(){
  long long int A ,B, K;
  string S ;
  cin >> A >> B >> K;
  if(K < A)cout << A - K << " " << B <<endl;
  else if(K < A + B) cout << 0 << " " << A + B - K << endl;
  else cout << 0 << " " << 0 << endl;
}


Measured memory_bytes: 3628
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
#include <bitset> // bitset
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N;
    cin >> N;
    bool check = false;
    while (true) {
        if (N % 4 == 0) {
            check = true;
            break;
        }
        if (N < 7) {
            break;
        }
        N -= 7;
    }
    if (check) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3632
N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N-1)]
Q, K = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in range(Q)]

adjacent_dict={i:{} for i in range(1,N+1)}
for a,b,c in ABC:
  adjacent_dict[a][b]=c
  adjacent_dict[b][a]=c

from collections import deque
fromK = [0]*(N+1)
stack = deque([K])
while stack:
  k = stack.popleft()
  for v, d in adjacent_dict[k].items():
    if fromK[v] == 0:
      fromK[v] = fromK[k]+d
      stack.append(v)

for x,y in XY:
  print(fromK[x]+fromK[y])
  
  

Measured memory_bytes: 103264
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=1e5+5;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
ll a[N],b[N],p[N];
int main()
{
    std::ios::sync_with_stdio(false);
    ll n,k;
    while(cin>>n>>k)
    {
        memset(p,0,sizeof(p));
        for(int i=1; i<=n; i++)
        {
            cin>>a[i]>>b[i];
            p[a[i]]+=b[i];
        }
        ll ans=0;
        for(int i=1; i<N; i++)
        {
            ans+=p[i];
            if(ans>=k)
            {
                cout<<i<<endl;
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 2560
li = list(map(int,input().split()))

def count(s):
    a = int(s[0])
    b = int(s[1])
    t = int(s[2])
    a_now = a
    sum_ = 0
    while a_now< t+0.5:
        sum_ += b
        a_now += a
    
    return sum_

print(count(li))


Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[]k = new int[n];
		int[]a = new int[n*m];
		int[]A = new int[m];

		for(int i=0; i<n; i++) {
			k[i] = sc.nextInt();
				for(int j=0; j<k[i]; j++) {
					a[i] = sc.nextInt();
					A[a[i]-1]++;
				}
		}
		int cou = 0;
		for(int i=0; i<m; i++) {
			if(A[i]== n) {
				cou++;
			}
		}
		System.out.println(cou);
	}
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using llu = long long unsigned int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,M;
    Scd2(N,M);

    vector<vi> e(N);

    int a,b;
    Rep(i,M){
        Scd2(a,b);
        a--,b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }

    vi id(N,-1);

    int ans = 0;
    int idd = 0;
    int cnt = 0;

    stack<int> s;

    Rep(i,N){
        if( id[i] == -1 ){
            cnt = 0;
            s.push(i);
            id[i] = idd;
            while( s.size() ){
                int from = s.top(); s.pop();
                cnt++;
                for( int to : e[from] ){
                    if( id[to] == -1 ){
                        id[to] = idd;
                        s.push(to);
                    }
                }
            }
            idd++;
            ans = max( ans, cnt );
        }
    }

    printf ("%d\n", ans );

    return 0;
}




Measured memory_bytes: 15684
#include <iostream>
using namespace std;
int main(){
    int n,ma,mb;
    cin >> n >> ma >> mb ;
    int a[n], b[n], c[n];
    for (int i=0; i<n; i++){
        int x,y,z;
        cin >>x >> y >> z;
        a[i]=x;
        b[i]=y;
        c[i]=z;
    }
    int dp[n][401][401];//dp[i][j][k]:=i番目まででaをj,bをkグラムにする最小経費
    for (int i=0;i<n;i++){
        for (int j=0; j<=400; j++){
            for (int k=0; k<=400; k++){
                dp[i][j][k]=1e5;
            }
        }
    }
    for (int i=0; i<n; i++){
        dp[i][0][0]=0;
    }
    
    dp[0][a[0]][b[0]]=c[0];
    for (int i=1; i<n; i++){
        for (int j=1; j<=400; j++){
            for (int k=1; k<=400; k++){
                if (j-a[i]<0 || k-b[i]<0){
                    dp[i][j][k]=dp[i-1][j][k];
                }
                else {
                    dp[i][j][k]=min(dp[i-1][j][k],dp[i-1][j-a[i]][k-b[i]]+c[i]
                    );
                }
            }
        }
    }
    int ans=1e5;
    for (int j=1; j<=400; j++){
        for (int k=1; k<=400; k++){
            if (j*mb==k*ma){
                ans=min(ans,dp[n-1][j][k]);
            }
        }
    }
    if (ans!=1e5){
        cout << ans << endl;
    }
    else {
        cout << -1 << endl;
    }
    /*for (int i=0; i<n; i++){
        for (int j=0; j<=6; j++){
            for (int k=0; k<=6; k++){
                cout <<  dp[i][j][k]<< " ";
            }
            cout <<endl;
        }
    }*/
}


Measured memory_bytes: 25344
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 3e5 + 5;
int main() {
    abdelrahman010
    char a[2][3];
    for(int i = 0;i < 2;i++)
        for(int j = 0;j < 3;j++)
            cin >> a[i][j];
    if(a[1][2] == a[0][0] && a[0][1] == a[1][1] && a[0][2] == a[1][0])
        cout << "YES";
    else
        cout << "NO";
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>

int main(){
  int n;
  int sq=0;

  scanf("%d",&n);

  for(int i=n;i>=0;i--){
    sq=sqrt(i);
    if(sq*sq==i){
      printf("%d\n",i);
      break;
    }
 }

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include <iomanip>
#include<stack>
#include<queue>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef long double ld;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> m;
    rep(i, n) cin >> a[i];

    ll cnt = 0;
    rep(i, n){
        if(i == 0){
            m.push_back(a[i]);
            cnt++;
            continue;
        }
        if(upper_bound(all(m), a[i], greater<ll>())-m.begin() == m.size()){
            m.push_back(a[i]);
            cnt++;
        }else{
            ll itr = upper_bound(all(m), a[i], greater<ll>())-m.begin();
            m[itr] = a[i];
        }
    }
    cout << cnt;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

int D;
vector<int> c(26);
vector<vector<int>> s;

int scoring(const vector<int>& t) {
    int v = 0;
    vector<int> last(26, -1);
    rep(i, D) {
        v += s[i][t[i]];
        last[t[i]] = i;
        rep(j, 26) {
            v -= c[j] * (i - last[j]);
        }
    }
    return v;
}

// int diff_scoring(const vector<int>&t, int v, int to_d, int to_t) {
//     int last = -1;
//     rep(i, D) {
//         if (t[i] == to_t) v -= s[i][t[i]], last = i;
//         v += c[to_t] * (i - last)
//     }
//     last = -1;
//     rep(i, D) {
//         if (i == to_d || t[i] == to_d) {
//             v += s[i][t[i]], last = i;
//         }
//         v -= c[to_t] * (i - last);
//     }
//     return v;
// }

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

    auto start = chrono::system_clock::now();
    
    cin >> D;
    rep(i, 26) cin >> c[i];
    s.resize(D, vector<int>(26));
    rep(i, D) rep(j, 26) cin >> s[i][j];

    vector<int> t(D);

    rep(i, D) {
        t[i] = max_element(all(s[i])) - s[i].begin();
    }
    
    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<> rand_d(0, D-1);
    uniform_int_distribution<> rand_t(0, 25);
    
    int v = scoring(t);
    
    while (true) {
        int to_d = rand_d(mt);
        int to_t = rand_t(mt);
        if (t[to_d] == to_t) continue;
        int old = t[to_d];
        t[to_d] = to_t;
        if (!chmax(v, scoring(t))) {
            t[to_d] = old;
        }
        auto end = chrono::system_clock::now();
        auto dur = end - start;
        auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
        if (msec >= 1980) break;
    }
    
    rep(i, D) cout << t[i] + 1 << '\n';
}


Measured memory_bytes: 3684
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

  		int num = sc.nextInt(); 
      	int stack;
      	int ans = 1;
      	
      	for(int i = 2; i <= 32; i++){
          	stack  = i;
        	while(stack*i <= num) {
              stack *= i;
          	  if(stack > ans) ans = stack;
            }
        }
      	
      	System.out.println(ans);
        
	}
}


Measured memory_bytes: 35516
#include "bits/stdc++.h"
#pragma optimize("unroll-loops");
#pragma optimize("Ofast");
//#include "pch.h"    
using namespace std;

#ifdef DEBUG_BUILD
#  define DEBUG(x) cerr << x
#else
#  define DEBUG(x) do {} while (1)
#endif

#define imie(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)

using ll = long long;
const int nax = 1e6 + 10;

vector<int> primes;
ll lcm(ll a, ll b) {
    return (a*b)/__gcd(a, b);
}

vector<bool> prime(nax, true);

ll abs(ll a, ll b) {
    if(a > b) {
        return a - b;
    }
    return b - a;
}

ll min(ll a, ll b) {
    if(a < b) {
        return a;
    }
    return b;
}
int main() {
    
    int l;
    cin >> l;
    
    double a = (l * 1.0) / 3;
    a *= (a*a);
    
    printf("%0.10lf\n", a);
}
    


Measured memory_bytes: 384
#include<stdio.h>

typedef struct{
  char pn[10];
  int time;
}process;

void enque(process);
process deque(void);

int head=0, tail=0;
process p[1000000];

int main(){
  int N,qtime;
  process P,Q;
  int stime=0;
  int i;

  scanf("%d%d",&N,&qtime);

  for(i=0;i<N;i++){
    scanf("%s%d",P.pn,&P.time);
    enque(P);
  }
  
  while(head!=tail){
    Q=deque();
    
    if(Q.time>qtime){
      Q.time-=qtime;
      stime+=qtime;
      enque(Q);
    }
    
    else{
      stime+=Q.time;
      printf("%s %d\n",Q.pn,stime);
     
    }
  }
  
  return 0;
}

void enque(process q){
  p[head]=q;
  head++;
}

process deque(void){
  tail++;
  return p[tail-1];
}



Measured memory_bytes: 4664
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)

    val n, r = sc.nextInt()


    if (n >= 10) println(r)
    else {
      println(r + 100 * (10 - n))
    }


  }
}


Measured memory_bytes: 25892
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

#define equals(a, b) (fabs((a)-(b)) < EPS)
const double EPS = (1e-10);

class Point {
public:
    double x, y;

    Point(double x = 0, double y = 0): x(x), y(y) {}

    Point operator + (Point p) {
        return Point(x+p.x, y+p.y);
    }
    Point operator - (Point p) {
        return Point(x-p.x, y-p.y);
    }
    Point operator * (double a) {
        return Point(x*a, y*a);
    }
    Point operator / (double a) {
        return Point(x/a, y/a);
    }

    double abs() {
        return sqrt(norm());
    }
    double norm() {
        return x*x + y*y;
    }

    bool operator < (const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }

    bool operator == (const Point &p) const {
        return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
    }
};

typedef Point Vector;
// 内積
double dot(Vector a, Vector b) {
    return a.x*b.x + a.y*b.y;
}
// 外積
double cross(Vector a, Vector b) {
    return a.x*b.y - a.y*b.x;
}

class Segment {
public:
    Point p1, p2;

    Segment(Point p1, Point p2): p1(p1), p2(p2) {}
};
typedef Segment Line;

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
int ccw(Point p0, Point p1, Point p2) {
    Vector a = p1 - p0;
    Vector b = p2 - p0;

    if (cross(a, b) > EPS) return COUNTER_CLOCKWISE;
    if (cross(a, b) < -EPS) return CLOCKWISE;
    if (dot(a, b) < -EPS) return ONLINE_BACK;
    if (a.norm() < b.norm()) return ONLINE_FRONT;

    return ON_SEGMENT;
}

bool intersect(Point p1, Point p2, Point p3, Point p4) {
    return (ccw(p1, p2, p3)*ccw(p1, p2, p4) <= 0 &&
            ccw(p3, p4, p1)*ccw(p3, p4, p2) <= 0);
}
bool intersect(Segment s1, Segment s2) {
    return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

double getDistanceLP(Line l, Point p) {
    return abs(cross(l.p2-l.p1, p-l.p1) / (l.p2-l.p1).abs());
}
double getDistanceSP(Segment s, Point p) {
    if (dot(s.p2-s.p1, p-s.p1) < 0.0) return (p-s.p1).abs();
    if (dot(s.p1-s.p2, p-s.p2) < 0.0) return (p-s.p2).abs();
    return getDistanceLP(s, p);
}
double getDistance(Segment s1, Segment s2) {
    if (intersect(s1, s2)) return 0.0;
    return min(min(getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2)),
               min(getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)));
}

Point getCrossPoint(Segment s1, Segment s2) {
    Vector base = s2.p2 - s2.p1;
    double d1 = abs(cross(base, s1.p1 - s2.p1));
    double d2 = abs(cross(base, s1.p2 - s2.p1));
    double t = d1 / (d1 + d2);
    return s1.p1 + (s1.p2-s1.p1)*t;
}

int main(void) {
    int q; cin >> q;

    double x0, y0, x1, y1, x2, y2, x3, y3;
    for (int i = 0; i < q; i++) {
        cin >> x0 >> y0 >> x1 >> y1
            >> x2 >> y2 >> x3 >> y3;
        Segment s1(Point(x0, y0), Point(x1, y1));
        Segment s2(Point(x2, y2), Point(x3, y3));

        Point ans = getCrossPoint(s1, s2);
        printf("%.9f %.9f\n", ans.x, ans.y);
    }

    return 0;
}

Measured memory_bytes: 1240
import math
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

CB = []
for i in range(M):
    B, C = map(int, input().split())
    CB.append([C, B])
CB.sort(reverse=True)

p = 0
for C, B in CB:
    while p < len(A) and A[p] >= C:
        p += 1
    if p >= len(A):
        break
    for i in range(B):
        if p >= len(A):
            break
        if A[p] < C:
            A[p] = C
            p += 1
        else:
            break
print(sum(A))


Measured memory_bytes: 76184
#include <iostream>

using namespace std;

int bubble_sort(int a[],int n){
    int c=0;
    for(int i=0;i<n;i++){
        for(int j=1;j<n-i;j++){
            if(a[j-1]>a[j]){
                c++;
                swap(a[j-1],a[j]);
            }
        }
    }
    return c;
}

int main(){
    int n,a[100];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int change = bubble_sort(a,n);
    for(int i=0;i<n-1;i++){
        cout << a[i] << ' ';
    }
    cout << a[n-1] << endl;
    cout << change << endl;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(long long i=1;i<=n;i++)
#define pb push_back
using namespace std;
typedef long long ll;
long long n,k,W;
const ll maxn=500004;
ll a[maxn];
int main(){

   ll n;
   while(cin>>n)
    {
        rep(i,n)
        {
            cin>>a[i];
        }
        ll ans=0;
        ll tmp=0;
        rep(i,n-1)
        {
            if(a[i]>=a[i+1]) tmp++;
            else tmp=0;
            ans=max(ans,tmp);
        }
        cout<<ans<<"\n";
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
ll n, m; 
ll a[300][300];
pair<ll, ll> po(bool *u){
	ll yo[m] = {};
	for(ll i = 0; i < n; i++){
		for(ll j = 0; j < m; j++){
			if(u[a[i][j]]){
				yo[a[i][j]]++;
				break;
			}
		}
	}
	auto ret = pair<ll, ll>(0, 0);
	for(ll i = 0; i < m; i++)if(ret.first < yo[i]) ret = pair<ll, ll>(yo[i], i);
	return ret;
}
int main(){
	cin >> n >> m;
	for(ll i = 0; i < n; i++){
		for(ll j = 0; j < m; j++){
			cin >> a[i][j];
			a[i][j]--;
		}
	}
	bool u[m];
	memset(u, 1, m);
	ll ans = n;
	for(ll i = 0; i < m - 1; i++){
		auto ret = po(u);
		ans = min(ret.first, ans);
		u[ret.second] = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 896
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class AWeLoveGolf {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int k, a, b; cin >> k >> a >> b;
      for(int i=a; i<=b; i++) {
        if (i%k==0) {
          cout << "OK" << endl;
          return;
        }
      }
      cout << "NG" << endl;
    }
};

signed main() {
  AWeLoveGolf solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3664
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N; string S;
  cin >> N >> S;

  int black[N+1]; black[0] = 0;
  rep(i, N)
    black[i+1] = black[i] + (S[i] == '#');
  int ans = N;
  rep(i, N+1) {
    int b = black[i], w = N - i - (black[N] - black[i]);
    ans = min(ans, b + w);
  }
  out(ans);

  return 0;
}


Measured memory_bytes: 1300
r,c = gets.split(" ").map{|x| x.to_i}
arr = Array.new(r)
r_sum = Array.new(r)
c_sum = Array.new(c)
r.times do |i|
	r_sum[i] = 0
end
c.times do |i|
	c_sum[i] = 0
end
r.times do |i|
	arr[i] = gets.split(" ").map{|x| x.to_i}
end
r.times do |i|
	c.times do |j|
		r_sum[i] += arr[i][j]
	end
end
c.times do |i|
	r.times do |j|
		c_sum[i] += arr[j][i]
	end
end
arr2 = arr.flatten
all_sum = arr2.inject(:+)
r.times do |i|
	arr[i] = arr[i].join(" ") + " #{r_sum[i]}"
	puts arr[i]
end
c_sum = c_sum.join(" ") + " #{all_sum}"
puts c_sum

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

int a[100001], b[100001], c[100001];
long long f[100001];

inline int read() {
    int x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x*=10;x+=(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
    register int n=read(),i,s;
    for(i=0;i<n;i++)a[i]=read();
	for(i=0;i<n;i++)b[i]=read();
	for(i=0;i<n;i++)c[i]=read();
    sort(a,a+n);sort(b,b+n);sort(c,c+n);
    register long long ans = 0;
    for(i=0;i<n;i++){if(b[i]>=c[n-1])break;f[i+1]=1ll*n-(upper_bound(c,c+n,b[i])-c);}
    f[0]=0;for(i=1;i<=n;i++)f[i]+=f[i-1];
    for(i=0;i<n;i++){if(a[i]>=b[n-1])break;s=upper_bound(b,b+n,a[i])-b;ans+=f[n]-f[s];}
    printf("%lld\n", ans);
    return 0; 
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

  vector<int> height;
  int h;

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

    cin >> h;

    height.push_back(h);

  }

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

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

    cout << height[9-i] << endl;

  }

  return 0;

}

Measured memory_bytes: 0
use std::io;
use std::str::FromStr;

fn main(){
    let stdin = io::stdin();
    let mut buf = String::new();

    let _ = stdin.read_line(&mut buf);
    buf.clear();

    let _ = stdin.read_line(&mut buf);
    let vec : Vec<i64> = buf.split_whitespace().map( |x| i64::from_str(x).unwrap() ).collect();

    println!("{} {} {}", vec.iter().min().unwrap(), vec.iter().max().unwrap(), vec.iter().fold(0, |sum, x| sum + x));
}



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

using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;

#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++)


const int mod = 1e9 + 7;

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    string n;
    ll ans = 0;
    cin >> n;
    vector<int> v;

    int a[10] = {0,
                 1,
                 2,
                 3,
                 4,
                 5,
                 5,
                 4,
                 3,
                 2};

    rep(i, n.length())
    {
        v.push_back(n[i] - '0');
    }

    reverse(v.begin(), v.end());
    v.push_back(0);

    ans = 0;

    rep(i, v.size())
    {
        int j = 0;

        while (v[i + j] > 5 || (v[i + j] == 5 && v[i + j + 1] >= 5))
        {

            ans += 10 - v[i + j];
            v[i + j] = 0;
            j++;
            v[i + j]++;
        }


        ans += v[i];

    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7804
S = input()
K = int(input())

def check_one(sgn,arr):
    cnt = 0
    for i in range(sgn):
        if S[i] == '1':
            cnt += 1
    if cnt == sgn:
        return True

def first_num(arr):
    list = []
    for i in range(len(arr)):
        if arr[i] != '1':
            list.append(int(arr[i]))
    return list[0]
            

if len(S) >= K and check_one(K,S):
        print(1)
else:
    print(first_num(S))
    

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

int main(){
    long int k,a,b;
    long int cnt=1;
    cin>>k>>a>>b;
    for(long int i=0;i<k;i++){
        if(cnt<a||i==(k-1)||((b-a)<=2)){cnt++;}
        else{
             cnt+=(b-a);
             i++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include<iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <cstdio>

using namespace std;

int main()
{
	for (int i = 1; i <= 9; ++i)
	{
		for (int j = 1; j <= 9; ++j)
		{
			cout<<i<<"x"<<j<<"="<<i*j<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1116
a,b=map(int,input().split())
c,d=0,0
if a!=0:
  a-=1
  m=(-(-a//2))%2
  c=m if a%2 else m^a
m=m=(-(-b//2))%2
d=m if b%2 else m^b
print(c^d)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var ass = new int[n];
        for (int i = 0; i < ass.Length; ++i)
        {
            ass[i] = int.Parse(Console.ReadLine());
        }

        int max1 = 0, max2 = 0;

        for (int i = 0; i < ass.Length; ++i)
        {
            var a = ass[i];
            if (a > max1)
            {
                max2 = max1;
                max1 = a;
            }
            else if (a > max2)
            {
                max2 = a;
            }
        }

        for (int i = 0; i < ass.Length; ++i)
            Console.WriteLine(ass[i] == max1 ? max2 : max1);
    }

    private static int GCD(int a, int b) => a > b ? GCD_impl(a, b) : GCD_impl(b, a);
    private static int GCD_impl(int a, int b) => b == 0 ? a : GCD_impl(b, a % b);
    private static long LCM(int a, int b) => (long)a * b / GCD(a, b);

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


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

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;

    public void go() throws IOException
    {
        ntok();
        int n = ipar();
        ntok();
        char[] s = spar().toCharArray();
        int[] rPre = new int[n+1];
        int[] gPre = new int[n+1];
        int[] bPre = new int[n+1];
        for (int i = 0; i < n; i++) {
            rPre[i+1] = rPre[i];
            gPre[i+1] = gPre[i];
            bPre[i+1] = bPre[i];
            if (s[i] == 'R') {
                rPre[i+1]++;
            } else if (s[i] == 'G') {
                gPre[i+1]++;
            } else {
                bPre[i+1]++;
            }
        }

        long sum = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                if (s[i] != s[j]) {
                    if (s[i] == 'R' && s[j] == 'G' || s[i] == 'G' && s[j] == 'R') {
                        sum += bPre[n] - bPre[j+1];
                        if (j + j-i < n && s[j + j-i] == 'B') {
                            sum--;
                        }
                    }
                    if (s[i] == 'R' && s[j] == 'B' || s[i] == 'B' && s[j] == 'R') {
                        sum += gPre[n] - gPre[j+1];
                        if (j + j-i < n && s[j + j-i] == 'G') {
                            sum--;
                        }
                    }
                    if (s[i] == 'B' && s[j] == 'G' || s[i] == 'G' && s[j] == 'B') {
                        sum += rPre[n] - rPre[j+1];
                        if (j + j-i < n && s[j + j-i] == 'R') {
                            sum--;
                        }
                    }
                }
            }
        }
        out.println(sum);

        out.flush();
        in.close();
    }

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public int[] iapar(int n)
    {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = ipar();
        }
        return arr;
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public long[] lapar(int n)
    {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = lpar();
        }
        return arr;
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

    public static void main(String[] args) throws IOException
    {
        new Main().go();
    }
}


Measured memory_bytes: 33708
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    string nickname;
    cin >> nickname;
    cout << nickname[0] << nickname[1] << nickname [2] << endl;
    return 0;    
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    vector<ll> L(N);
    rep(i, N) { cin >> L[i]; }
    sort(L.begin(), L.end());

    ll ans = 0;

    // aとbを固定
    rep(i, N)
    {
        for (ll j = i + 1; j < N; j++) {
            // c > a+bなので,c = L[k]となる添字を求める
            auto k = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();
            // c の動ける範囲は[j+1, k)
            ans += max(k - (j + 1), 0ll);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include <vector>
#include <string>

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

using namespace std;

int main()
{
	int a, p;

	cin >> a >> p;

	cout << (a * 3 + p) / 2;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int A, B, i, G;
	G = 0;
	scanf("%d", &A);
	scanf("%d", &B);
	for (i = 0; i < 2; i++) {
		if (A < B) {
			G = G + B;
			B = B - 1;
		}
		else {
			G = G + A;
			A = A - 1;
		}
	}
	printf("%d\n", G);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
	int a,b,c;
scanf("%d",&a);
getchar();
scanf("%d",&b);

if(a==1 && b==2){
	printf("3");
}
else if(a==1 && b==3){
	printf("2");
}
else if(a==2 && b==3){
	printf("1");
}
else if(a==2 && b==1){
	printf("3");
}
else if(a==3 &&b==1){
	printf("2");
}
else if(a==3 && b==2){
	printf("1");
}
}

Measured memory_bytes: 2088
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll x,y;
    // x,2x,4x,8x,...
    std::cin >> x>>y;
    ll result = 0;
    while(x<=y){
        result++;
        y/=2;
    }
    std::cout << result << std::endl;
}


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

using namespace std;

constexpr int MOD = 1000000007;

using Long = long long;
template<typename T>
using V = vector<T>;
template<typename T>
using Vv = V<V<T>>;
using Vb = V<bool>;
using Vvb = V<Vb>;
using Vi = V<int>;
using Vvi = V<Vi>;
using Vl = V<Long>;
using Vvl = V<Vl>;
using Vd = V<double>;
using Vvd = V<Vd>;
using Vs = V<string>;

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& x : v) {
        is >> x;
    }
    return is;
}

template <typename First, typename Second>
istream& operator>>(istream& is, pair<First, Second>& v) {
    for (auto& x : v) {
        is >> v.first >> v.second;
    }
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (const auto& x : v) {
        os << x << ' ';
    }
    return os;
}

// *** SOLUTION BEGIN ***

void solve() {
    Vi a(3);
    cin >> a;
    int ans = 0;
    while (true) {
        if (a[0] == a[1] && a[1] == a[2]) {
            break;
        }
        sort(begin(a), end(a));
        if (a[0] < a[1]) {
            if (a[0] + 1 == a[1] && a[1] == a[2]) {
                a[1]++;
                a[2]++;
            } else {
                a[0] += 2;
            }
        } else {
            a[0]++;
            a[1]++;
        }
        ans++;
    }
    cout << ans;
}

// *** SOLUTION END ***

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


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < int(n); ++(i))
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;

ll gcd(ll a, ll b) { while (a) { b %= a; swap(a, b); } return b; }

bool solve(vector<ll> & a, ll k) {
    assert (not a.empty());
    assert (k != 0);
    whole(sort, a);
    a.erase(whole(unique, a), a.end());
    if (a.back() < k) return false;
    ll gcd_a = a[0]; for (ll a_i : a) gcd_a = gcd(gcd_a, a_i);
    if (k % gcd_a != 0) return false;
    return true;
}

int main() {
    int n; ll k; scanf("%d%lld", &n, &k);
    vector<ll> a(n); repeat (i, n) scanf("%lld", &a[i]);
    bool result = solve(a, k);
    printf("%s\n", result ? "POSSIBLE" : "IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
using namespace std;
typedef pair <int,int> pii;
int N, M, P;
vector <pii> edges[2505];
vector <int> edgeBack[2505];
int dist1[2505];
bool toN[2505];
int INF = 0x3f3f3f3f;

void bellmanFord(int v){
    memset(dist1, INF, sizeof(dist1));
    dist1[v] = 0;
    for (int i=0; i<N-1; i++){
        for (int idx=1; idx<=N; idx++){
            for (pii e: edges[idx]){
                if (dist1[idx] != INF && dist1[e.first] > dist1[idx] + e.second){
                    dist1[e.first] = dist1[idx] + e.second;
                }
            }
        }
    }
}

void dfs(int v){
    toN[v] = true;
    for (int e: edgeBack[v]){
        if (!toN[e]) dfs(e);
    }
}

int main() {
    cin >> N >> M >> P;
    int a, b, c;
    for (int i=0; i<M; i++){
        scanf("%d %d %d", &a, &b, &c);
        edges[a].push_back({b,-c+P});
        edgeBack[b].push_back(a);
    }
    bellmanFord(1);
    dfs(N);
    bool neg = false;
    for (int i=1; i<=N; i++){
        for (pii e: edges[i]){
            if (dist1[i] != INF && dist1[e.first] > dist1[i]+e.second && toN[i]) neg = true;
        }
    }
    if (neg) cout << "-1" << endl;
    else cout << max(0, -dist1[N]) << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int MAX = 1005;
const int INF = 1001001001;
const int MOD = 1000000007;

int dist[MAX][MAX];
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};

int main(){
    int H, W, sy, sx, gy, gx;
    cin >> H >> W >> sy >> sx >> gy >> gx;

    sy--, sx--, gy--, gx--;

    vector<string> S(H);
    for (auto &i : S) cin >> i;

    rep(i, H)rep(j, W) dist[i][j] = INF;
    dist[sy][sx] = 0;

    deque<tuple<int, int, int>> q;
    q.emplace_back(0, sy, sx);

    while (q.size()) {
        auto [d, y, x] = q.front();
        q.pop_front();

        if (dist[y][x] < d) continue;

        rep(i, 4) {
            int ny = y + dy[i], nx = x + dx[i];
            if (ny < 0 || H <= ny || nx < 0 || W <= nx) continue;
            if (S[ny][nx] == '#') continue;
            if (dist[ny][nx] <= d) continue;
            dist[ny][nx] = d;
            q.emplace_front(d, ny, nx);
        }

        for (int dy = -2; dy <= 2; ++dy) {
            for (int dx = -2; dx <= 2; ++dx) {
                int ny = y + dy, nx = x + dx;
                if (ny < 0 || H <= ny || nx < 0 || W <= nx) continue;
                if (S[ny][nx] == '#') continue;
                if (dist[ny][nx] <= d+1) continue;
                dist[ny][nx] = d+1;
                q.emplace_back(d+1, ny, nx);
            }
        }
    }

    int ans = dist[gy][gx];
    if (ans == INF) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 9556
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

        int happiness = (x/500)*1000;
        x %= 500;
        happiness += (x/5)*5;
        
        System.out.println(happiness);
    }
}


Measured memory_bytes: 21972
#!/usr/bin/env python3
import sys
from collections import deque
from collections import defaultdict
INF = float("inf")


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = defaultdict(list)

    def add_edge(self, src, dest, w=1):
        self.E[src].append((dest, w))
        self.E[dest].append((src, w))


def solve(N: int, a: "List[int]", b: "List[int]"):

    g = Graph(N)
    for i, (aa, bb) in enumerate(zip(a, b)):
        g.add_edge(aa-1, bb-1, i)

    visited = [False]*N
    edge_color = [-1]*(N-1)

    q = deque([(0, -1)])

    while len(q) > 0:
        node, color = q.popleft()
        penki = 1
        if color == penki:
            penki += 1

        for to_, weight in g.E[node]:
            if edge_color[weight] != -1:
                continue
            edge_color[weight] = penki
            q.append((to_, penki))
            penki += 1
            if color == penki:
                penki += 1

    print(max([len(g.E[k]) for k in g.E]))
    print(*edge_color, sep="\n")
    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
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 55704