akhauriyash/Code-Regression huggingface dataset:
unittest
{
	assert( [ "2", "3 1 4 1 5 9" ].parse.expand.solve == 1 );
	assert( [ "1", "1 2 3" ].parse.expand.solve == -1 );
	assert( [ "3", "8 2 2 7 4 6 5 3 8" ].parse.expand.solve == 5 );
}



import std.algorithm;
import std.container;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( n, as );
}

auto solve( long n, long[] as )
{
	// 「前1/3のグループ」と「後ろ2/3のグループ」と「後ろのグループから取り除かれたグループ」に分ける
	auto rbt_a = redBlackTree!( true )( as[ 0 .. n ] );
	auto rbt_b = redBlackTree!( true )( as[ n .. $ ] );
	auto rbt_c = redBlackTree!( true, long )();
	while( n < rbt_b.length )
	{
		rbt_c.insert( rbt_b.back );
		rbt_b.removeBack;
	}
	
	// 後ろのグループから一つずつ前のグループに移動したときのスコアを計算
	auto at = rbt_a[].sum;
	auto bt = rbt_b[].sum;
	auto ans = at - bt;
	foreach( a; as[ n .. n * 2 ] )
	{
		if( a in rbt_c )
		{
			rbt_c.removeKey( a );
		}
		else
		{
			rbt_b.insert( rbt_c.front );
			rbt_b.removeKey( a );
			bt += rbt_c.front - a;
			rbt_c.removeFront;
		}
		rbt_a.insert( a );
		at += a - rbt_a.front;
		rbt_a.removeFront;
		
		ans = max( ans, at - bt );
	}
	return ans;
}


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

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

  int ans = 0, sum = 0;
  for (int i = 1; i <= 50000; i++) {
    sum += i;
    if (X <= sum) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
int main(){
  int n,m;
  map<int,int> day;
  cin >>n>>m;
  for(int i=0,a,b; i<m; i++){
    cin >>a>>b;
    day[a-1] = b;
  }
  int dp[101][3][3]={0};
  if(day[0]!=0) dp[0][day[0]-1][0] = 1;
  else for(int i=0; i<3; i++) dp[0][i][0] = 1;
  for(int i=1; i<n; i++){
    if(day[i] == 0){
      for(int kinou=0; kinou<3; kinou++){
	for(int kyou=0; kyou<3; kyou++){
	  for(int len=0; len<2; len++){
	    if(kyou == kinou) dp[i][kyou][len+1] =(dp[i][kyou][len+1]+dp[i-1][kinou][len])%10000;
	    else dp[i][kyou][0] = (dp[i][kyou][0]+dp[i-1][kinou][len])%10000;
	  }
	}
      }
    }
    else{
      for(int kinou=0; kinou<3; kinou++){
	for(int len=0; len<2; len++){
	  if(day[i]-1 == kinou) dp[i][day[i]-1][len+1] = (dp[i][day[i]-1][len+1]+dp[i-1][kinou][len])%10000;
	  else dp[i][day[i]-1][0] = (dp[i][day[i]-1][0]+dp[i-1][kinou][len])%10000;
	}
      }
    }
  }
  int ans = 0;
  for(int i=0; i<3; i++){
    for(int j=0; j<2; j++){
      ans+=dp[n-1][i][j];
    }
  }
  cout <<ans%10000<<endl;
  return 0;
}

Measured memory_bytes: 1200
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int H = Integer.parseInt(sc.next());
		int W = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		char s[][] = new char[H][W];
		int table[][] = new int[H][W];
		boolean[] row = new boolean[H];
		String line;
		for(int i=0;i<H;i++) {
			line = sc.next();
            s[i]= line.toCharArray();
            row[i]=line.contains("#");
        }
        sc.close();
        int now=1;
        for(int i=0;i<H;i++){
            boolean first=true;
            if(row[i]){
                for(int j=0;j<W;j++){
                    if(s[i][j]=='#'){
                        if(!first) now++;
                        else first=false;
                    }
                    table[i][j]=now;
                }
                now++;
            }
        }

		int ins1=-1,ins2=-1;
		for(int i=0;i<H;i++) {
			if(!row[i]) {
				for(int j=0;j<W;j++) {
					if(i!=H-1) {
						for(int k=i+1;k<H;k++) {
							if(row[k]) {
								ins1 = k;
								break;
							}
						}
						for(int k=i-1;k>=0;k--) {
							if (row[k]) {
								ins2 = k;
								break;
							}
						}
						table[i][j] = table[Math.max(ins1, ins2)][j];
					}
					else {
						for(int k=i;k>=0;k--) {
							if (row[k]) {
								table[i][j] = table[k][j];
								break;
							}
						}
					}
				}
			}
        }
        
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				System.out.print(table[i][j] + " ");
			}
			System.out.println("");
		}
	}

}


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

int main(){
  int h,a;
  cin>>h>>a;
  int cnt=0;
  while(h>0){
    h-=a;
    cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> memo(26);
    rep(i,S.length()){
        memo[S[i]-'a']++;
    }
    ll ans = 1;
    rep(i,26){
        ans*=memo[i]+1;
        ans%=1000000007;
    }
    ans--;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	 public static void main(String[] args){
	        Scanner scan = new Scanner(System.in);
	        double d = scan.nextInt();
	        double t = scan.nextInt();
	        double s = scan.nextInt();

	        if(d/s<=t) {
	        	System.out.println("Yes");
	        }else {
	        	System.out.println("No");
	        }
	    }
}

Measured memory_bytes: 35496
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
String st=Integer.toString(b);
int suu=st.length();

int c=1;

for(int i=1;i<=suu;i++){
	c=c*10;
}
c=a*c+b;
double y=c;
double x=Math.sqrt(y);

if(x%1==0){
	System.out.println("Yes");
}else{
	System.out.println("No");
}

	}}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 2147483647//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    string s;
    cin >> s;
    rep(i,s.length()-1){
        if(s[i] == 'A' && s[i+1] == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
var lines = [];

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var X = Number(lines[0].split(" ")[0]);
    var Y = Number(lines[0].split(" ")[1]);
    var Z = Number(lines[0].split(" ")[2]);
    var K = Number(lines[0].split(" ")[3]);

    var A = lines[1].split(" ").map(value => Number(value));
    var B = lines[2].split(" ").map(value => Number(value));
    var C = lines[3].split(" ").map(value => Number(value));

    A.sort((a, b) => b - a);
    B.sort((a, b) => b - a);
    C.sort((a, b) => b - a);

    var cake_AB = [];

    for (var i = 0; i < X; i++) {
        for (var j = 0; j < Y; j++) {
            cake_AB.push(A[i] + B[j]);
        }
    }

    cake_AB.sort((a, b) => b - a);

    var cake_ABC = []

    for (var i = 0; i < Math.min(K, cake_AB.length); i++) {
        for (var j = 0; j < Z; j++) {
            if (Math.min(K, cake_AB.length) < i * j) { continue; }
            cake_ABC.push(cake_AB[i] + C[j])
        }
    }

    cake_ABC.sort((a, b) => b - a);

    for (var i = 0; i < K; i++) {
        console.log(cake_ABC[i]);
    }

});

Measured memory_bytes: 96052
#include <iostream>

using namespace std;

int main() {
    int a[3]={0};
    int s[3]={0};
    int c[3]={0};
    cin>>a[0]>>a[1]>>a[2];
    
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            if(a[i]<=s[j] || c[j]==0){
                for(int k=(2-j); k>0;k--){ //ずらす
                    s[j+k]=s[j+k-1];
                }
                s[j]=a[i];
                c[j]=1;
                break;
            }
        }
    }
    
    cout<<s[0]<<" "<<s[1]<<" "<<s[2]<<endl;
}



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

int main() {
  int N;
  cin >> N;
  vector<long> A(N), Idx(N+1);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    Idx[A[i]] = i;
  }

  long ans = 0, r, l;
  set<int> S;
  S.insert(-1);
  S.insert(N);
  for (int i = 1; i <= N; i++) {
    auto it = S.lower_bound(Idx[i]);
    r = (*it) - Idx[i];
    it--;
    l = Idx[i] - (*it);
    ans += i * l * r;
    S.insert(Idx[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 12800
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,k = nm()

MOD = 10**9+7
ans = 0

for kk in range(k,n+2):
  # print()
  aa = (n-kk+n+1)*kk//2
  bb = (0+kk-1)*kk//2
  # print(aa)
  # print(bb)
  a=aa-bb
  # print(a)
  ans+=a+1%MOD

print(ans%MOD)

Measured memory_bytes: 9108
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int main()
{
	int n;
	int d[100];
	int ans=0;
	
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>d[i];
	}
	sort(d,d+n);
	ans++;
	for(int i=1;i<n;i++)
	{
		if(d[i-1]<d[i])
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
a = input()
count = 0
countd=0
for i in a:
    if i in ('A' , 'T' , 'G' , 'C'):
        count+=1
    else:
        if countd < count:
            countd = count
            count = 0
if countd < count:
    countd = count
    count = 0
print(countd)


Measured memory_bytes: 2940
// May this submission get accepted
#pragma GCC optimize ("O3")
#pragma GCC target("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール

// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll n = inp1;

    vector<ll> dp(n+1, INF);
    vector<ll> u = {1};
    for (ll base = 1; (base *= 9) <= n; ) {
        u.push_back(base);
    }
    for (ll base = 1; (base *= 6) <= n; ) {
        u.push_back(base);
    }
    sort(ALL_OF(u));
    dp[0] = 0;
    REP(j, n) {
        REP(i, u.size()) {
            if (j+u[i] > n) break;
            chmin(dp[j+u[i]], dp[j] + 1);
        }
    }
    say(dp[n]);
    
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
	int n,A[100],flag = 0;
	cin>>n;
	for(int i=0 ; i<n ; i++)
	{
		cin>>A[i];
	}
	for(int i=0 ; i<n ; i++)
	{
		int minJ = i;
		for(int j=i+1 ; j<n ; j++)
		{
			if(A[j] < A[minJ])
			{
				minJ = j;
			}
		}
		if(minJ != i) flag++;
		int temp = A[i];
		A[i] = A[minJ];
		A[minJ] = temp;
		
	}
	for(int i=0 ; i<n ; i++)
	{
		cout<<A[i];
		if(i != n-1)
		{
			cout<<" ";
		}
	}
	cout<<endl<<flag<<endl;
}



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

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

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

    int result = 0;
    REP(i, n) {
        int a, b;
        cin >> a >> b;
        result += b;
        result -= a;
        result++;
    }
    cout << result;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e16
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010
const int N=51;

void print(ll a[][N],ll n){rep(i,0,n){rep(j,0,n)cout<<a[i][j]<<" ";cout<<"\n";}}
void id(ll a[][N],ll n){rep(i,0,n)rep(j,0,n){a[i][j]=(i==j);}}
void mul(ll a[][N],ll b[][N],ll c[][N],ll n){rep(i,0,n)rep(j,0,n){c[i][j]=0;rep(k,0,n)c[i][j]=(c[i][j]+a[i][k]*b[k][j])%md;}}

void exp(ll a[][N],ll k,ll n){
	ll temp[N][N],ans[N][N];id(ans,n);
	while(k){
		if(k&1){
			mul(ans,a,temp,n);
			rep(i,0,n)rep(j,0,n)ans[i][j]=temp[i][j];
		}
		mul(a,a,temp,n);
		rep(i,0,n)rep(j,0,n)a[i][j]=temp[i][j];
		k/=2;
	}
	rep(i,0,n)rep(j,0,n)a[i][j]=ans[i][j];
}

int main(){
	IOS;
	ll n,k;cin>>n>>k;
	ll a[N][N];
	rep(i,0,n)rep(j,0,n)cin>>a[i][j];exp(a,k,n);
	ll ans=0;rep(i,0,n)rep(j,0,n)ans=(ans+a[i][j])%md;
	cout<<ans;
	
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
/*iamsorry*/
 
#define thegamebegins   ios_base::sync_with_stdio(false); cin.tie(NULL);
#define fileio          freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define int             long long
#define float           long double
#define test            int t; cin>>t; while(t--)
#define in(a,n)         for(int i=0; i<n; ++i)  cin>>a[i]
#define r0              return 0
#define E               "\n"
#define S               " "
#define elif            else if 
#define M               1000000007
#define fi(i,x,y)       for(int i=x; i<y; ++i)
#define fa(i,s)         for(auto i:s)
#define fp(i,s)         for(auto i=(s).begin(); i!=(s).end(); ++i)
#define vi              vector <int>
#define vpii            vector <pair <int,int> >
#define mii             map <int,int>
#define pii             pair <int,int>
#define seti            set <int>
#define setd            set <int,greater <int> >
#define all(s)          (s).begin(),(s).end()
#define sortd(a,n)      sort(a, a+n, greater<int>())
#define pb              push_back
#define mp              make_pair
#define fr              first
#define sc              second
#define lb              lower_bound
#define ub              upper_bound
#define er              equal_range
 
const int INF = 0x3f3f3f3f;

signed main()
{
    thegamebegins

    int k,n;    cin>>k>>n;
    int a[n], mx=-1;
    fi(i,0,n)
    {
        cin>>a[i];
        if(i)   mx=max(mx,a[i]-a[i-1]);
    }
    mx=max(mx,a[0]+k-a[n-1]);
    cout<<k-mx;
    r0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
ll a[maxn], n;
int main(){
   // freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    ll b[2];
    int cnt = 0;
    for(int i = n-2; i >= 0; i--){
        if(a[i] == a[i+1]){b[cnt++] = a[i];i--;}
        if(cnt == 2) break;
    }
    if(cnt == 2) cout << b[0] * b[1] << endl;
    else puts("0");
    return 0;
}

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

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

  int minsec = std::min(B, D);
  int maxsec = std::max(A, C);
  int duration = ( minsec <  maxsec ) ? 0 : minsec - maxsec;
  std::cout << duration << std::endl;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter

H, W, K = map(int, input().split())
c = [input() for _ in range(H)]

cnt = 0
for h in range(2**H):
    h_list = []
    for _ in range(H):
        h_list.append(h%2)
        h //= 2
    for w in range(2**W):
        w_list = []
        for _ in range(W):
            w_list.append(w%2)
            w //= 2
        tmp = []
        
        for i in range(H):
            for j in range(W):
                if h_list[i] == 0 and w_list[j] == 0:
                    tmp.append(c[i][j])
        
        tmp = Counter(tmp)
        if tmp['#'] == K:
            cnt += 1
print(cnt)

Measured memory_bytes: 9460
#include <iostream>

using namespace std;

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

    for(int iii=0; iii<n; ++iii ) {
        int cx = 0, cy = 0;
        int lx = 0, ly = 0;
        int dist = 0;

        for(;;) {
            int dx, dy;
            cin >> dx >> dy;
            if ( dx == 0 && dy == 0 ) {
                cout << lx << " " << ly << endl;
                break;
            }

            cx += dx;
            cy += dy;

            const int d = cx * cx + cy * cy;
            if ( d > dist ) {
                dist = d;
                lx = cx;
                ly = cy;
            } else if ( d == dist ) {
                if ( cx > lx ) {
                    lx = cx;
                    ly = cy;                   
                }
            }
        }
    }
}

Measured memory_bytes: 1160
N = input()
K = int(input())

n = len(N)

dp = [[[0]*2 for _ in range(5)] for _ in range(n+1)]
N0 = int(N[0])
if N0 == 0:
    dp[1][0][0] = 1
    dp[1][0][1] = 0
    dp[1][1][0] = 0
    dp[1][1][1] = 0
else:
    dp[1][0][0] = 0
    dp[1][0][1] = 1
    dp[1][1][0] = 1
    dp[1][1][1] = N0-1

for keta in range(1,n):
    Ni = int(N[keta])
    for k in range(4):
        for smaller in range(2):
            if smaller == 1:
                dp[keta+1][k+1][smaller] += dp[keta][k][smaller]*9
                dp[keta+1][k][smaller] += dp[keta][k][smaller]
            elif smaller == 0:
                if Ni == 0:
                    dp[keta+1][k][smaller] += dp[keta][k][smaller]
                else:
                    dp[keta+1][k][smaller+1] += dp[keta][k][smaller]
                    dp[keta+1][k+1][smaller+1] += dp[keta][k][smaller]*(Ni-1)
                    dp[keta+1][k+1][smaller] += dp[keta][k][smaller]
    
print(dp[n][K][0]+dp[n][K][1])




Measured memory_bytes: 38384
#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 OUT(s) cout << s << "\n";

using namespace std;
// https://atcoder.jp/contests/abc161

int N,M;
vector<int> A(1010);
int ALL = 0;

void Main()
{
    auto t = 1.0 * accumulate(A.begin(), A.end(), 0U) / (4 * M);
    int c = 0;
    REP(i, N) {
        if (A[i] >= t) {
            c++;
        }
    }
    if (c >= M) {
        OUT("Yes");
    } else {
        OUT("No");
    }
}

int main()
{
	cin.tie(0);
    ios::sync_with_stdio(false);
	// cout << fixed << setprecision(15);
    cin >> N >> M;
    REP(i, N) {
        cin >> A[i];
        ALL = ALL + A[i];
    }
	Main();
    return 0;
}


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

int main(){
 string T;
 cin >> T;
 for (int i = 0; i < T.size() ; i++){
     if(T.at(i) == '?'){
         T.at(i) = 'D';
     }
 }

/*
 int count = 0;

 for (int i = 0; i < T.size() ; i++){
     if(T.at(i) == 'D'){
         count ++;
     }
 }

  for (int i = 0; i < T.size() - 1; i++){
     if(T.at(i) == 'P' && T.at(i+1) == 'D'){
         count ++;
     }
 }

 */

 cout << T << endl;

}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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;}
int const INF = 1001001001;


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

ll N,A,B;
cin >> N >> A >> B;

vl X(N);
rep(i,N) cin >> X[i];

ll ans = 0;
rep(i,N-1) {
    ans += min(A*(X[i+1]-X[i]), B);
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};

int cnt[10][10];

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

	int n;
	cin >> n;

	for(int i = 1; i <= n; i++) {
		string s = to_string(i);
		int fi = s[0] - '0';
		int la = s[s.size()-1] - '0';
		cnt[fi][la]++;
	}

	int ans = 0;

	REP(i, 1, 10) {
		REP(j, 1, 10) {
			ans += cnt[i][j] * cnt[j][i];
		}
	}

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

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

using namespace std;

int main(){
  int n;
  cin >> n;
  
  vector<int> l(n);
  for(int i = 0; i < n; i++) cin >> l[i];
  sort(l.begin(), l.end());
  
  int count = 0;
  for(int i = 0; i < n - 2; i++){
    for(int j = i + 1; j < n - 1; j++){
      for(int k = j + 1; k < n && l[k] < l[i] + l[j]; k++){
        count++;
      }
    }
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	int R;
	cin >> R;
	string ans;
	if (R<1200){
		ans = "ABC";
	}else if (R<2800){
		ans = "ARC";
	}else {
		ans = "AGC";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return (a/g*b);
}
int main() {
    int n;
    cin >> n;
    vector<ll> T(n);
    for (int i = 0; i < n; ++i) {
        cin >> T[i];
    }
    ll ans = 1;
    for (int i = 0; i < n; ++i) {
         ans = lcm(ans,T[i]);
    }
    cout << ans << endl;
    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=1e18+5;


int main() {
  set<int> s;
  int n,ans=0;
  rep(i,3){
    int f;
    cin >> f;
    if (s.find(f)==s.end()) {s.insert(f);ans++;}
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
from math import floor
a, b = [int(i) for i in sys.stdin.readline().split()]
flg = False
ans = 0
for i in range(10000):
    if floor(i * 1.08) - i == a and floor(i * 1.1) - i == b:
        flg = True
        ans = i
        break
if flg:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#define FI first
#define SE second
using namespace std;
const double EPS = 1e-8;
const int MAXN = 10005;
const int INF = 1111111111;
const double PI = acos(-1.0);
int dcmp(double x)
{
	if(fabs(x)<EPS) return 0;
	return x<0?-1:1;
}
struct Point{
	double x,y;
	Point(){}
	Point(double a,double b):x(a),y(b){}
	Point operator+(const Point&a)const{return Point(x+a.x,y+a.y);}
	Point operator-(const Point&a)const{return Point(x-a.x,y-a.y);}
	Point operator*(double k)const{return Point(x*k,y*k);}
	Point operator/(double k)const{return Point(x/k,y/k);}
	void input(){scanf("%lf%lf",&x,&y);}
};
typedef Point Vector;
double length(Vector a)
{
	return sqrt(a.x*a.x+a.y*a.y);
}
Vector normal(Vector a)
{
	double l = length(a);
	return Vector(-a.y/l,a.x/l);
}

Vector rotate(Vector a,double rad)
{
	Vector c;
	c.x = a.x*cos(rad)-a.y*sin(rad);
	c.y = a.x*sin(rad)+a.y*cos(rad);
	return c;
}

int main()
{
	//freopen("/home/qitaishui/code/in.txt","r",stdin);
	Point o,left,right,vec;
	double d,v1,v2,r1,r2,t;
	int n;
	while(scanf("%d%lf",&n,&d)&&n)
	{
		left = Point(-d,0);
		right = Point(d,0);
		d*=2;
		for(int i = 0; i < n; i++)
		{
			scanf("%lf%lf%lf",&v1,&v2,&t);
			v1 = v1/180*PI;
			v2 = v2/180*PI;
			if(dcmp(v1-v2)==0)
			{
				vec = normal(right-left);
				left = left+vec*v1*t;
				right = right+vec*v1*t;
			}
			else if(dcmp(v1*v2)>0)
			{
				vec = (right-left)/length(right-left);

				if(fabs(v1)>fabs(v2))
				{
					r2 = d/(v1/v2-1);
					o = right+vec*r2;
					left = o + rotate(left-o,-v1*t/length(left-o));
					right =o+rotate(right-o,-v2*t/length(right-o));
				}
				else
				{
					r1 = d/(v2/v1-1);
					o = left-vec*r1;
					left = o+rotate(left-o,v1*t/length(left-o));
					right = o+rotate(right-o,v2*t/length(right-o));
				}
			}
			else
			{
				o = left+(right-left)*fabs(v1)/(fabs(v1)+fabs(v2));
				if(dcmp(length(left-o))>0)
					left = o+rotate(left-o,-v1*t/length(left-o));
				if(dcmp(length(right-o))>0)
					right = o+rotate(right-o,v2*t/length(right-o));
			}
		}
		o = (left+right)/2;
		printf("%.5f\n%.5f\n",o.x+EPS,o.y+EPS);
	}
	return 0;
}

Measured memory_bytes: 1260
n = int(input())
a = list(map(int,input().split()))
ans = []
a.sort(reverse=True)
key = a[0]
i = 1
while True:
    if i > n-1:
        break
    if len(ans) == 2:
        break
    if a[i] == key:
        i += 1
        ans.append(key)
        if i > n-1:
            break
        key = a[i]
    else:
        key = a[i]
    i += 1


if len(ans) != 2:
    print(0)
else:
    print(ans[0]*ans[1])


Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
using LP = pair<ll,ll>;
using P = pair<ll,int>;
ll inf = 1e18;

int di[2] = {0, 1};
int dj[2] = {1, 0};
int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> g(h);
    rep(i, h) cin >> g[i];
    vector<vector<ll>> dist(h, vector<ll>(w, inf));
    priority_queue<P,vector<P>,greater<P>> q;
    int cost = 0;
    if (g[0][0] == '#') cost = 1;
    q.emplace(cost, 0);
    dist[0][0] = cost;
    
    //id 
    auto toId = [&](int i, int j){
        return i*w+j;
    };

    auto push = [&](int i, int j, ll x){
        int id = toId(i, j);
        if (x >= dist[i][j]) return;
        dist[i][j] = x;
        q.emplace(x, id);
    };
    
    //dijkstra
    while (!q.empty()){
        P node = q.top();
        int cost = node.first;
        int id = node.second;
        int i = id/w;
        int j = id%w;
        q.pop();

        if (cost > dist[i][j]) continue;
        if (i==h-1 and j == w-1){
            break;
        }
        rep(k, 2){
            int ni = i+di[k];
            int nj = j + dj[k];
            if (ni< 0 or ni >= h or nj < 0 or nj >= w) continue;
            if (g[i][j] == g[ni][nj]) push(ni, nj, cost);
            else push(ni, nj, cost+1);
        }
    }
    ll ans = (dist[h-1][w-1]+1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 3736
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	list := getStdinIntArr()
	A := list[0]
	B := list[1]
	H := list[2]
	M := list[3]

	Apos := (60.0*float64(H) + float64(M))
	BposN := ((60*H + M) % 60) * 12
	Bpos := float64(BposN)

	if Apos == Bpos {
		fmt.Printf("%.20f", float64(math.Abs(float64(A)-float64(B))))
	} else if Apos < Bpos {
		CosCA := 2 * math.Pi * Apos / 720.0
		CosCB := 2 * math.Pi * Bpos / 720.0
		CosC := math.Abs(CosCA - CosCB)
		C := math.Sqrt(float64(A*A) + float64(B*B) - 2.0*float64(A)*float64(B)*math.Cos(CosC))
		fmt.Printf("%.20f", C)
	} else {
		CosCA := 2 * math.Pi * Apos / 720.0
		CosCB := 2 * math.Pi * Bpos / 720.0
		CosC := math.Abs(CosCA - CosCB)
		C := math.Sqrt(float64(A*A) + float64(B*B) - 2.0*float64(A)*float64(B)*math.Cos(CosC))
		fmt.Printf("%.20f", C)
	}

	fmt.Printf("\n")
}

func getStdin() string {
	sc.Scan()
	return sc.Text()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}


Measured memory_bytes: 1728
// aribon4-2_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll X, Y;
    cin >> X >> Y;

    if (abs(X - Y) <= 1){
        print("Brown");
    } else {
        print("Alice");
    }
    
    return 0;
}


Measured memory_bytes: 256
H,W = map(int, input().split())
s = [list(input()) for i in range(H)]

for h in range(1, H):
    for w in range(1, W):
        if s[h][w] == '#':
            if h != 0 and w != 0 and h != H - 1 and w != W - 1:
                if s[h - 1][w] != '#' and s[h + 1][w] != '#' and s[h][w - 1] != '#' and s[h][w + 1] != '#':
                    print('No')
                    exit()
print('Yes')


Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		if((A+B)%2==1) {
			out.println("IMPOSSIBLE");
		}else {
			out.println((A+B)/2);
		}

		out.flush();
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

	public int[] nextIntsN(int N) {
		int[] ints = new int[N];
		for (int i = 0; i < N; i++) {
			ints[i] = nextInt();
		}
		return ints;
	}
	
	public long[] nextLongsN(int N) {
		long[] longs = new long[N];
		for (int i = 0; i < N; i++) {
			longs[i] = nextLong();
		}
		return longs;
	}
	
	public char[] nextCharsN(int N) {
		char[] chars = new char[N];
		String msg=next();
		for (int i = 0; i < N; i++) {
			chars[i] = msg.charAt(i);
		}
		return chars;
	}

	public char[][] nextCharsHW(int H, int W) {
		char[][] chars = new char[H][W];
		for (int i = 0; i < H; i++) {
			String str = next();
			for (int j = 0; j < W; j++) {
				chars[i][j] = str.charAt(j);
			}
		}
		return chars;
	}

	public int[][] nextIntsNM(int N, int M) {
		int[][] ints = new int[N][M];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < M; j++) {
				ints[i][j] = nextInt();
			}
		}
		return ints;
	}
}


Measured memory_bytes: 20564
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n * a, b) << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
#input = sys.stdin.buffer.readline
from collections import deque

def main():
    s = list(input())
    s = deque(s)
    q = int(input())
    count,b = 0,1
    for _ in range(q):
        x = list(input().split())
        if x[0] == "1":
            b *= -1
            count += 1
        else:
            if x[1] == "1":
                if b == 1:
                    s.appendleft(x[2])
                else:
                    s.append(x[2])
            else:
                if b == 1:
                    s.append(x[2])
                else:
                    s.appendleft(x[2])
    
    if count%2 != 0:
        s.reverse()
        
    print("".join(s))

if __name__ == "__main__":
    main()


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

using namespace std;

int n, cnt;
char p = '!', c;

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

    cin >> n; cnt = n;
    while (n--) {
        cin >> c;
        if (c == p) cnt--;
        p = c;
    }
    cout << cnt << '\n';

    return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static Scanner;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Solve();
        Console.Out.Flush();
    }
    static void Solve() {
        int N = ScanInt(), K = ScanInt();
        var nums = new Dictionary<int, int>();
        for (int i = 0; i < N; i++) {
            var A = ScanInt();
            if (!nums.ContainsKey(A)) nums.Add(A, 0);
            nums[A]++;
        }
        var answer = 0;
        if (nums.Count > K) {
            var sorted = nums.OrderBy(x => x.Value);
            var c = 0;
            foreach (var (_, count) in sorted) {
                answer += count;
                c++;
                if (c == nums.Count - K) break;
            }
        }
        Console.WriteLine(answer);
    }
}

public static class Scanner
{
    static readonly Stream stream = Console.OpenStandardInput();
    static readonly byte[] buffer = new byte[1024];
    static int length, p;
    static bool isEof;
    private static byte ConsoleIn() {
        if (isEof) return 0;
        if (p < length) return buffer[p++];
        p = 0;
        if ((length = stream.Read(buffer, 0, 1024)) > 0) return buffer[p++];
        isEof = true;
        return 0;
    }
    public static char GetChar() {
        var by = ConsoleIn();
        while ((by < '!' || '~' < by) && !isEof) by = ConsoleIn();
        return (char) by;
    }
    public static int ScanInt() {
        var temp = 0;
        for (var ch = GetChar(); '0' <= ch && ch <= '9'; ch = (char) ConsoleIn()) {
            temp = temp * 10 + ch - '0';
        }
        return temp;
    }
}

Measured memory_bytes: 35500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < A.length; i++) {
            A[i] = sc.nextInt();
        }
        int max = 0;
        for (int i = 0; i < A.length; i++) {
            for (int j = i + 1; j < A.length; j++) {
                int dif = Math.abs(A[i] - A[j]);
                max = Math.max(max, dif);
            }
        }
        System.out.println(max);
        sc.close();
    }
}

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

using namespace std;
typedef long long ll;

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

    vector<int> order(n);

    for(int i=0; i < n; i++) {
        int val;
        cin >> val;

        order[val-1] = i+1;
    }

    for(auto val : order) {
        cout << val << " ";
    }
}

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

int main(){
  int x;
  cin >> x;
  int ans = 0;
  ans += (x/500) * 1000;
  x -= (x/500) * 500;
  ans += (x/5) * 5;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import math
N = int(input())
n = 72

x = [None] * N
y = [None] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

ans = 0
for i in range(n):
    theta = (2 * math.pi / n) * i
    c = math.cos(theta)
    s = math.sin(theta)
    tmp_x = 0
    tmp_y = 0
    for j in range(N):
        if x[j] * c + y[j] * s > 0:
            tmp_x += x[j]
            tmp_y += y[j]
    if tmp_x**2 + tmp_y**2 > ans**2:
        ans = math.sqrt(tmp_x**2 + tmp_y**2)

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,count=0,b;
  string u[300],t[300];
  int a[300];
  cin >> n;
  for(int i=0; i<n; i++) cin >> u[i];
  cin >> m;
  for(int i=0; i<m; i++) cin >> t[i];
    
  b=0;
  for(int i=0; i<m; i++){
    for(int j=0; j<n; j++){
      if(t[i]==u[j]){
	    a[b] = 1;
	    break;
	  }
	  else a[b] = 0;
	}
	b++;
  }
  //for(int i=0; i<m; i++) cout << a[i] << " ";
  for(int i=0; i<m; i++){
    if(a[i]==1){
      if(count==0){
        cout << "Opened by " << t[i] << endl;
	    count = 1;
	    }
	    else if(count==1){
	    cout << "Closed by " << t[i] << endl;
	    count = 0;
	    }
	  }
    else cout << "Unknown " << t[i] << endl;
  }
  return 0;
}
//cout << "Opend by " << t[j] << endl;
//cout << "Closed by " << t[j] << endl;
//cout << "Unknown " << t[j] << endl;


Measured memory_bytes: 3216
#include<queue>
#include<cctype>
#include<cstdio>

#define	mp			make_pair
#define	rep(i,n)	for(int i=0;i<n;i++)

using namespace std;

typedef	pair<int,int>	pii;

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

int h,w;
char grid[1000][1001];

int shortestDistance(int sx,int sy,int gx,int gy){
	static bool visited[1000][1000];
	rep(i,h)rep(j,w)	visited[i][j]=false;
	visited[sy][sx]=true;

	queue< pair<int,pii> > qu;	qu.push(mp(0,mp(sy,sx)));
	while(1){
		pair<int,pii> a=qu.front();	qu.pop();
		int d=a.first,x=a.second.second,y=a.second.first;
		if(x==gx && y==gy)	return d;

		rep(i,4){
			int xx=x+dx[i],yy=y+dy[i];
			if(0<=xx && xx<w && 0<=yy && yy<h && grid[yy][xx]!='X' && !visited[yy][xx]){
				visited[yy][xx]=true;
				qu.push(mp(d+1,mp(yy,xx)));
			}
		}
	}
}

int main(){
	int n;	scanf("%d%d%d",&h,&w,&n);
	int cx[10],cy[10];
	rep(i,h){
		scanf("%s",grid[i]);
		rep(j,w){
			if(grid[i][j]=='S')		cx[0]=j,cy[0]=i;
			if(isdigit(grid[i][j]))	cx[grid[i][j]-'0']=j,cy[grid[i][j]-'0']=i;
		}
	}

	int cost=0;
	rep(i,n)	cost+=shortestDistance(cx[i],cy[i],cx[i+1],cy[i+1]);
	printf("%d\n",cost);

	return 0;
}

Measured memory_bytes: 0
from collections import deque

N,M=map(int,input().split())

graph=[[]for _ in range(N+1)]

for _ in range(M):
    A,B=map(int,input().split())
    graph[A].append(B)
    graph[B].append(A)

dist=[-1]*(N+1)
dist[0]=0
dist[1]=0

D=deque()
D.append(1)

while D:
    V=D.popleft()
    for i in graph[V]:
        if dist[i]!=-1:
            continue
        dist[i]=V
        D.append(i)

print('Yes')
for j in dist[2:]:
    print(j)

Measured memory_bytes: 35096
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n,a,b,c,A,B,C;

int main(){
	cin>>n>>a>>b>>c>>A>>B>>C;
	vl dp(n+1);
	for(int i=0;i<=n;i++) dp[i]=i;
	for(int i=a;i<=n;i++) dp[i]=max(dp[i],dp[i-a]+A);
	for(int i=b;i<=n;i++) dp[i]=max(dp[i],dp[i-b]+B);
	for(int i=c;i<=n;i++) dp[i]=max(dp[i],dp[i-c]+C);
	n=dp[n];
	dp=vl(n+1);
	for(int i=0;i<=n;i++) dp[i]=i;
	for(int i=A;i<=n;i++) dp[i]=max(dp[i],dp[i-A]+a);
	for(int i=B;i<=n;i++) dp[i]=max(dp[i],dp[i-B]+b);
	for(int i=C;i<=n;i++) dp[i]=max(dp[i],dp[i-C]+c);
	cout<<dp[n]<<endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int cal(ll val)
{
  int ret = 0;
  while (val > 0) {
    val /= 10;
    ++ret;
  }
  return ret;
}

int main()
{
  ll N; scanf("%lld", &N);
  int ans = INF;
  for (ll i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      ans = min(ans, max(cal(i), cal(N / i)));
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _20170409_AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] sArr = Console.ReadLine().Split(' ');
            int a = int.Parse(sArr[0]);
            int b = int.Parse(sArr[1]);
            int c = int.Parse(sArr[2]);

            if (a < b && b < c)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            Console.ReadLine();
        }
    }
}

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

int main(){
  int i,j,n,*a,key;
  scanf("%d",&n);
  a=malloc(4*n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[i]);
  
  for(i=1;i<n;i++){
    key=a[i];
    j=i-1;
    while(j>=0 && a[j]>key){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=key;
    for(j=0;j<n-1;j++){
      printf("%d ",a[j]);
    }
    
      printf("%d\n",a[j]);
    
  }
  return 0;
}




Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M=1e9+7,N=100010;
ll n,k,ans;
ll gc[N];
ll prime[N];
bool isp[N];
ll expo(ll base,ll ex,ll mod){
	if(ex==0) return 1;
	ll tmp=expo(base,ex>>1,mod);
	tmp=tmp*tmp%mod;
	if(ex&1) return tmp*base%mod;
	return tmp;
}
int main()
{
	scanf("%lld%lld",&n,&k);
	for(ll i=2;i<N;++i) isp[i]=true;
	for(ll i=2;i<N;++i){
		if(isp[i]){
			prime[++prime[0]]=i;
		}
		for(ll j=1;j<=prime[0]&&prime[j]*i<N;++j){
			isp[prime[j]*i]=false;
			if(i%prime[j]==0) break;
		}
	}
	for(ll g=1;g<=k;++g){
		if(g>1){
			if(k/g==k/(g-1)) gc[g]=gc[g-1];
		}
		gc[g]=expo(k/g,n,M);
	}
	for(ll g=k;g>=1;--g){
		for(ll i=2;i*g<=k;++i){
			gc[g]-=gc[g*i];
			if(gc[g]<0) gc[g]+=M;
		}
	}
	for(ll g=1;g<=k;++g){
		ans+=gc[g]*g%M;
		ans%=M;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 4788