akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define endt '\t'
#define ends ' '
#define die(x) return cout << x << endl, 0;
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << '[' << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 1e9 + 7; 

////////////////////////

const int MAXN = 1e5 + 5;

int DP[MAXN][2];
vector<int> G[MAXN];

void DFS(int v, int p = 0) {
	for (int u : G[v]) if (u != p)
		DFS(u, v), DP[v][0] += max(DP[u][0], DP[u][1]);
	for (int u : G[v]) if (u != p)
		DP[v][1] = max(DP[v][1], DP[v][0] - max(DP[u][0], DP[u][1]) + DP[u][0] + 1);
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	#ifdef LOCAL
	ifstream cin("sample.in");
	#endif

	int n; cin >> n;
	for (int i = 1; i < n; i++) {
		int v, u; cin >> v >> u;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	DFS(1);
	int mx = max(DP[1][0], DP[1][1]);
	cout << (n % 2 == 0 && (mx << 1) == n ? "Second" : "First") << endl;
	
	return 0;
}

Measured memory_bytes: 9928
from decimal import Decimal
#decimal.Decimalってしなくて済むよ
a,b,c = map(int,input().split())
a = a ** Decimal("0.5")
b = b ** Decimal("0.5")
c = c ** Decimal("0.5")
a_b = a + b
if c > a_b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 59756
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N ,M;
  int result=0;
  int total=0;
  int th = 0;
  cin >> N >> M;

  vector<int> A(N);

  for(int i=0; i < N ; i++){
    cin >> A.at(i);
    total += A.at(i);
  } 

  for(int i=0; i < N ; i++){
     if(total > (A.at(i) * 4 * M)){
     }else{
       result++;
     }
  }

  if(result >= M){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> a(n), b(n);
long long cp = 0;
for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
for(int i = n; i--;) {
a[i] += cp;
cp += (b[i] - a[i]%b[i])%b[i];
}
cout << cp;
}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int X, A; cin >> X >> A;
    if (X < A) cout << 0 << endl;
    else cout << 10 << endl;
}

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

int n,m,k;

int dfs(int sum,int num)
{
  if(num>=n){
    if(sum-k<1)return 1;
    return sum-k;
  }
  else {
    int ans=0;
    for(int i=1;i<=m;i++)ans+=dfs(sum+i,num+1);
    return ans;
  }
}

int main()
{
  while(1){
    cin>>n>>m>>k;
    if(n+m+k==0)break;
    
    printf("%.8f\n",dfs(0,0)/pow(m,n));
  }
  return 0;
}

Measured memory_bytes: 1248
#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--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

int main() {
    int n, k;
    cin >> n >> k;
    vi h(n);
    rep(i, n) cin >> h[i];

    sort(ALL(h));
    int min_h = INF;
    for (int i = 0; i+k-1 < n; i++) {
        min_h = min(min_h, h[i+k-1]-h[i]);
    }
    cout << min_h << endl;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  int a,b;
  cin >>a>>b;
  
  int ans = 0;
    
  if(a==1) ans+=3;
  if(a==2) ans+=2;
  if(a==3) ans+=1;
  if(b==1) ans+=3;
  if(b==2) ans+=2;
  if(b==3) ans+=1;
  if(a==1 && b==1) ans+=4;
    
  cout << ans*100000 <<endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n , x , ganjil;
int main(){
	cin >> n;
	for(int i = 1 ; i <= n ; i++){
		cin >> x;
		if(x % 2 != 0)ganjil++;
	}
	if(ganjil % 2 == 0)cout << "YES" << endl;
	else cout << "NO" << endl;
}


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

#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

void Main()
{
   int A, B;
   cin >> A >> B;
   if (A <= 5)
   {
      cout << 0 << endl;
      return;
   }
   if (A <= 12)
   {
      cout << B / 2 << endl;
      return;
   }
   cout << B << endl;
   return;
}

int main()
{
   std::cin.tie(nullptr);
   std::ios_base::sync_with_stdio(false);
   std::cout << std::fixed << std::setprecision(15);
   Main();
   return 0;
}


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



int main(){
    double R;
    cin>>R;
    double pi =3.141592;
    cout<<2.0*pi*R<<endl;
    return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int a, b, k[1005], l[1005], ans = 0, sum = 0;
	cin >> a >> b;
	for (int i = 0; i < b; ++i) {
		cin >> k[i] >> l[i];
		if (a - k[i] > 0) ans += a - k[i];
		if (a - k[i] > sum) sum = a - k[i];
	}
	cout << ans - sum << endl;
}



Measured memory_bytes: 3112
// Apna Time Aayega...
#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define ll long long
#define inf 100000000000000000
int addMod(int x, int y)
{
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

int mulMod(int x, int y)
{
    return (x * 1ll * y) % MOD;
}

int binpow(int x, int y)
{
    int z = 1;
    while(y)
    {
        if(y & 1) z = mulMod(z, x);
        x = mulMod(x, x);
        y >>= 1;
    }
    return z;
}

int inv(int x)
{
    return binpow(x, MOD - 2);
}

int divide(int x, int y)
{
    return mulMod(x, inv(y));
}

ll gcd(int a, int b) 
{   if (a == 0) return b; 
    if (b == 0) return a;  
    if (a == b) return a; 
    if (a > b)  return gcd(a-b, b); 
    return gcd(a, b-a); 
} 

ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}

ll h(ll* A, int N){
    ll pro = 1;
    for(int i=0; i<N; ++i) pro = mulMod(A[i], pro);
    return pro;
}

ll f(ll* A, int N){
    int alpha = A[0];
    for(int i=1; i<N; ++i){
        alpha = gcd(alpha, A[i])%MOD;
    }
    return alpha;
}

void generateNormal(string ans, int N, int charUsed){
    if(N==0) {cout<<ans<<endl; return;}
    for(int i=0; i<charUsed+1; ++i){
        char currentChar = 'a' + i;
        generateNormal(ans+currentChar, N-1, i+1);
    }
    return;
}
int N, X;
int A[100005];
vector <int> adj[100005];
int dfs(int u, int p){
    int sum = A[u];
    for(auto &i:adj[u]){
        if(i!=p){
            sum += dfs(i, u);
        }
    }
    return max(sum, -X);
}

void cl()
{
    for(int i=1;i<=N;i++)
        adj[i].clear();
}

unsigned long long int counting(int a, int b){
    unsigned long long int count = 1;
    while(a>0 || b>0){
        if(a&1 && b&1){
            count = mulMod(2, count);
        }
        a = a>>1;
        b = b>>1;
    }
    return count;
}

int main(){
    FIO
    string x; cin>>x;
    if(x[2]==x[3] && x[4]==x[5]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 2560
def solve(string):
    n, m, *ab = map(int, string.split())
    ab = sorted([(a, b) for a, b in zip(ab[::2], ab[1::2])])
    ans = 0
    for a, b in ab:
        if m <= b:
            ans += a * m
            break
        ans += a * b
        m -= b
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 26124
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		int sec, min, hour;
		sec = sc.nextInt();
		
		hour = sec / 3600;
		min = (sec%3600) / 60;
		sec = sec % 60;
		
		System.out.println(hour+":"+min+":"+sec);
	}
}


Measured memory_bytes: 26204
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

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

    int N; cin >> N;
    int cnt=0;
    rep(i,N){
        string S; cin >> S;
        if(S=="A") cnt++;
        else cnt--;
        if(cnt<0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    if(cnt!=0) cout << "NO" << endl;
    else cout << "YES" << endl;
}


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

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

using namespace std;
const long long INF = 1LL << 61;

int main() {
	int N; cin >> N;
	map<string, int> mp;
	rep(i, N) {
		string str; cin >> str;
		sort(str.begin(), str.end());
		++mp[str];
	}
	long long ans = 0;
	for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
		long long num = itr->second;
		ans += num * (num - 1) / 2;
	}
	cout << ans;
}

Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <math.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;


int main() {
   int ans = 1;
   int n, k;
   cin >> n >> k;
   rep(i, n) {
      if (ans * 2 >= ans + k) {
         ans += k;
      } else {
         ans *= 2;
      }
   }
   cout << ans << endl;
   return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	string s; cin>>s;
	ll ans=700;
	rep(i,3){
		if(s[i]=='o') ans+=100;;
	}
	cout<<ans;
}

Measured memory_bytes: 256
import math

n,d=map(int,input().split())

a=[list(map(float,input().split())) for i in range (n)]

ans=0

for i in range (n-1):
    for j in range(i+1,n):
        sum=0.0

        #各次元についての距離を求める
        for k in range(d):
            sum+=math.pow(a[i][k]-a[j][k],2)
        
        sum=math.sqrt(sum)

        #実数を整数にしても数が変わらないなら整数
        if(sum==int(sum)):
            ans+=1

print(ans)


Measured memory_bytes: 3060
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //定番のn回繰り返しを省略
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <math.h>
 
using namespace std;
 

//ここから書き始める
int main(int argc, char const *argv[])
{
	int n, m;
	cin >> n >> m;

	stack<int> kouho;
	stack<int> kouho1;
	//mの約数をすべて求める
	rep(i, int(sqrt(m))+1)
	{
		if(i==0) continue;

		if(m%i == 0)
		{
			kouho.push(i);
			kouho1.push(i);
			//cout << i << ",";
		}

	}
	int loop1 = SZ(kouho1);
	int y;
	rep(i,loop1)
	{
		y = kouho1.top();
		kouho1.pop();
		kouho.push(m/y);

	}


	int x;
	int loop = SZ(kouho);
	//rep(i, loop)
	//{
	//	cout << kouho.top() << ",";
	//	kouho.pop();
	//}


	//候補を順にチェック
	rep(i, loop)
	{
		x = kouho.top();
		kouho.pop();
		if(n <= m/x)
		{
			cout << x << endl;
			break;
		}

	}

    return 0;
}


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

int n, k;
set<int> D;

bool check(int x){
    while(x > 0){
        if(D.find(x%10) != D.end()) return false;
        x /= 10;
    }

    return true;
}

int main(){

    cin >> n >> k;

    int d;
    for(int i = 0; i < k; i++){
        cin >> d;
        D.insert(d);
    }

    while(!check(n)){
        n++;
    }

    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin>>N>>S;
  int sum=0;
  int ans=0;
  for(int i=0;i<N;i++){
    if(S.at(i)=='I'){
      sum++;
    }
    if(S.at(i)=='D'){
      sum--;
    }
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int count = 0;
		
		for(int i = 0; i < n ;i++) {
			int a = sc.nextInt();
			
			while(a % 2 == 0) {
				a = a/2;
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 36616
import sys
N = int(sys.stdin.readline())
s = [sys.stdin.readline().rstrip() for i in range(N)]
M = int(sys.stdin.readline())
t = [sys.stdin.readline().rstrip() for i in range(M)]
ans = 0
p = 0
m = 0
for i in s:
    p = s.count(i)
    m = t.count(i)
    ans = max(ans, p - m)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  int n,m,p;
  cin>>n>>m>>p;
  double dp2[101];
  dp2[0]=1.0;
  for(int i=1;i<101;i++) dp2[i]=dp2[i-1]*(p/100.0);
  int e[15][15]={};
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    e[a][b]++;
    e[b][a]++;
  }
  double dp[1<<15]={};
  int look[1<<15]={};
  for(int i=0;i<(1<<n);i++){
    look[i]=0;
    for(int j=0;j<n;j++){
      for(int k=0;k<j;k++){
	if((i>>j)&1 && (i>>k)&1){
	  //look[i]*=1.0-get(e[j][k]);
	  look[i]+=e[j][k];
	}
      }
    }
    //look[i]=1.0-look[i];
    //cout<<i<<":"<<look[i]<<endl;
  }
  int used[1<<15]={};
  function<double(int)> dfs=[&](int b){
    //cout<<b<<" "<<used[b]<<" "<<dp[b]<<endl;
    if(used[b]) return dp[b];
    used[b]=1;
    if(b==0) return 0.0;
    double res=1;
    //double res=look[b];
    for(int i=b;i>0;i=(i-1)&b){
      if((i^b)&1){
	//cout<<(i^b)<<":"<<dfs(i^b)*look[i^b]<<endl;
	res-=dfs(i^b)*dp2[look[b]-(look[i]+look[i^b])];
      }
    }
    //cout<<b<<" "<<res<<endl;
    return dp[b]=res;
  };
  cout<<fixed<<setprecision(12)<<dfs((1<<n)-1)<<endl;
  return 0;
}

Measured memory_bytes: 3792
# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 22/08/2020

from sys import stdin, stdout, setrecursionlimit
from math import gcd, ceil, sqrt
from collections import Counter, deque
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
setrecursionlimit(100000)
mod = 1000000007

n = is1()
tot = 0
for i in n:
    tot += int(i)
if tot % 9 == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 68572
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void in(T&t){cin>>t;}
template<class T,class... Ts>inline void in(T&t,Ts&...ts){cin>>t;in(ts...);}
template<class T>inline void out(T t){cout<<t<<"\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout<<t<<" ";out(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill(T&t,const V&v){for(auto &e:t)fill(e,v);}
constexpr long long INF = 1e18;

signed main(){
	int A,B,K;
	in(A,B,K);
	int t = min(A,K);
	A-=t;
	K-=t;
	t = min(B,K);
	B-=t;
	K-=t;
	out(A,B);
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
using namespace std;
long long eat_burger(int n, long long x)
{
  if(n==0){
    if(x==0)
      return 0;
    else
      return 1;
  }
  long long c=((long long)1<<(n+1))-1;
  long long p=(long long)1<<n;
  if(x<=1){
    return 0;
  }else if(x<c){
    return eat_burger(n-1,x-1);
  }else{
    return eat_burger(n-1,x-c)+p;
  }
}
int main()
{
  int n,i;
  long long x,res;
  cin >> n >> x;
  res=eat_burger(n,x);
  cout << res << endl;
  return 0;
}

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

namespace atCorder_A1222
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] lineArr = Console.ReadLine().Split(' ');
            int cnt = int.Parse(lineArr[0]);
            int hLen = int.Parse(lineArr[1]);
            int wLen = int.Parse(lineArr[2]);

            int ret = 0;
            for (int i = 0; i < cnt; i++)
            {
                string[] tmpArr = Console.ReadLine().Split(' ');
                if((hLen <= int.Parse(tmpArr[0]))&&(wLen <= int.Parse(tmpArr[1])))
                {
                    ret++;
                }
            }
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 11092
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double EPS = 1e-8;

static int cards[256];

int compute_score(bool& has_ace11,const vector<string>& hands){
  int sum = 0;

  bool has_ace = false;
  for(int i = 0; i < hands.size();i++){
    int num = cards[hands[i][0]];
    if(num == 1) has_ace = true;
    sum += num;
  }
  if(has_ace){
    if(sum + 10 <= 21){
      has_ace11 = true;
      sum += 10;
    }
  }
  return sum;
}

int main(){
  int total_testcases;
  for(int i = 2; i < 10; i++){
    cards['0' + i] = i;
  }
  cards['A'] = 1;
  cards['T'] = 10;
  cards['J'] = 10;
  cards['Q'] = 10;
  cards['K'] = 10;

  while(~scanf("%d",&total_testcases)){
    for(int test_i = 0; test_i < total_testcases; test_i++){
      string lhs,rhs;
      vector<string> hands;
      cin >> lhs >> rhs;

      bool is_ace11 = false;
      hands.push_back(lhs);
      hands.push_back(rhs);

      int sum = 0;
      for(int pile_i = 0; pile_i < 8; pile_i++){

        string pile;
        cin >> pile;
        bool is_ace11 = false;
        sum = compute_score(is_ace11,hands);

        if(sum <= 16){
          hands.push_back(pile);
        }
        else if(sum == 17 && is_ace11){
          hands.push_back(pile);
        }
      }
      sum = compute_score(is_ace11,hands);
      
      if(sum > 21){
        printf("bust\n");
      }
      else if(sum == 21 && hands.size() == 2){
        printf("blackjack\n");
      }
      else{
        printf("%d\n",sum);
      }
    }
  }
}

Measured memory_bytes: 1224
#include <stdio.h>
#define MAX 100000

int partition( int A[], int p, int r);

int A[MAX];
int n;




int main()
{

  int i;
  int hen;

  
  scanf("%d",&n);
  for( i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }

  hen = partition( A, 0, n-1);

  for( i = 0; i < n; i++){
    if(i > 0)printf(" ");
    if(i == hen)printf("[");
    printf("%d",A[i]);
    if( i == hen)printf("]");
  }

  printf("\n");
  
  return 0;
}


int partition( int A[], int p, int r)
{
  
  int i;
  int j;
  int x;
  int kou;
  
  x = A[r];
  i = p - 1;
  for( j = p; j < r; j++){
    if( A[j] <= x){
      i = i + 1;
      kou = A[i];
      A[i] = A[j];
      A[j] = kou;
    }
  }
  kou = A[i+1];
  A[i+1] = A[r];
  A[r] = kou;
  
  
  
  return i + 1;
}



Measured memory_bytes: 2116
// abc154_b
#include <iostream>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>

#define US unsigned short
#define UI unsigned int
#define UC unsigned char
#define UL unsigned long
#define ULL unsigned long long
using namespace std;

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    for (US i = 0; i < s.length(); i++)
        cout << 'x';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORr(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

int main(void){
  int n;
  cin >> n;
  double ans = 0;
  REP(i, n){
    double a;
    cin >> a;
    ans += 1/a;
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
// #include <regex> //正規表現
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int N, M; cin >> N >> M;
priority_queue<int> A; 
int a;
rep(i, 0, N) {
    cin >> a;
    A.push(a);
}

// 割引券1枚使うと半額．2枚使うと更にその額を半額．
// 最小値段のためには 割引券をすべて使う必要がある．
// A の中で1番大きい品物に割引券を使う．
// 計算量O(M logN). 間に合わない．

rep(i, 0, M){
    int a0 = A.top();
    A.pop();
    A.push(a0 / 2);
}
int64_t sum = 0;
while(!A.empty()){
    sum += A.top();
    A.pop();
}

cout << sum << endl;

}

// 境界，出力文字列 チェック



Measured memory_bytes: 892
from collections import defaultdict


def main():
    K, S = map(int, input().split())
    ans = 0
    for x in range(0, K + 1):
        for y in range(0, K + 1):
            if 0 <= S - (x + y) <= K:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
signed main()
{
   SPEED;
   string s,t;
   cin>>s>>t;
   t=t.substr(0,s.size());
   if(t==s)
   {
       cout<<"Yes";
   }
   else
   cout<<"No";
}

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

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

bool is_prime(int num) {
  if (num <= 1) return false;
  else
    for (int i=2; i<num; i++)
      if (num%i == 0) return false;
  return true;
}
 
int main() {
  int X;
  
  cin >> X;
  
  while (1) {
    if (is_prime(X)) {
      break;
    }
    X++;
  }
  cout << X << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int ans;
    string S;
    cin >> S;
    for (int i = 0;i < 4 ; i++) {
        if (S[i] == '+') {
            ans++;
        } else {
            ans--;
        }
    }

    cout << ans;
}

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

int main(){
	int n,a,b;
	int x,y;
	while(cin>>n&&n){
		x=y=0;
		for(int i=0;i<n;i++){
			cin>>a>>b;
			if(a>b)x+=a+b;
			else if(a<b)y+=a+b;
			else{
				x+=a;
				y+=a;
			}
		}
		cout<<x<<' '<<y<<endl; 
	}
	return 0;
}

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

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

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    vector<int> x1, x2, y1, y2;
    x1.push_back(0);
    x2.push_back(w);
    y1.push_back(0);
    y2.push_back(h);
    for (int i = 0; i < n; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            x1.push_back(x);
        } else if (a == 2) {
            x2.push_back(x);
        } else if (a == 3) {
            y1.push_back(y);
        } else {
            y2.push_back(y);
        }
    }
    sort(x1.begin(), x1.end(), greater<int>());
    sort(x2.begin(), x2.end());
    sort(y1.begin(), y1.end(), greater<int>());
    sort(y2.begin(), y2.end());
    int ans = 0;
    if (x2 <= x1 || y2 <= y1) {
        ans = 0;
    } else {
        ans = (x2[0] - x1[0]) * (y2[0] - y1[0]);
    }
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int h,n;
    cin >> h >> n;
    int sum = 0;
    for(int i = 0;i < n;i++)
    {
        int a;
        cin >> a;
        sum += a;
    }
    if(sum >= h)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define all(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int main()
{
	int n;
	ll a[200001] = {};
	ll p[200001] = {};
	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		p[i] = a[i] + p[i - 1]; //iまでの累積和
	}

	ll ans = INF;
	ll diff[4];

	ll l = 1, r = 3;

	for (int i = 2; i <= n; i++) { //iは真ん中
		while (l < i && abs(p[l] - (p[i] - p[l])) >= abs(p[l + 1] - (p[i] - p[l + 1]))) {
			l++;
		}
		while (r < n && abs((p[r] - p[i]) - (p[n] - p[r])) >= abs((p[r + 1] - p[i]) - (p[n] - p[r + 1]))) {
			r++;
		}

		diff[0] = p[l];
		diff[1] = p[i] - p[l];
		diff[2] = p[r] - p[i];
		diff[3] = p[n] - p[r];

		sort(diff, diff + 4);
		ans = min(ans, diff[3] - diff[0]);
	}

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


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
vector<Int> get_primes(Int x) {
    vector<Int> ans, flag(x);
    for (Int i = 2; i * i < x; i++) {
        if (!flag[i]) {
            for (int j = i + i; j < x; j += i) {
                flag[j] = 1;
            }
        }
    }
    for (Int i = 2; i < x; i++) {
        if (!flag[i]) {
            ans.push_back(i);
        }
    }
    return ans;
}
int main() {
    int N; cin >> N;
    vector<Int> S(N); for (auto &s : S) cin >> s;
    map<Int, int> M;
    map<Int, Int> NP;
    set<Int> P2;
    {
        auto X = get_primes(100000);
        for (auto &x : X) x *= x;
        P2.insert(begin(X), end(X));
    }
    auto P3 = get_primes(2154);
    for (auto s : S) {
        Int norm = 1, pair = 1;
        for (auto p : P3) {
            int cnt = 0;
            while (s % p == 0) s /= p, cnt++;
            cnt %= 3;
            if (cnt == 1) { norm *= p, pair *= p * p; }
            if (cnt == 2) { pair *= p, norm *= p * p; }
        }
        if (P2.count(s)) {
            norm *= s, pair *= sqrt(s);
        } else {
            norm *= s, pair *= s * s;
        }
        M[norm] += 1;
        NP[norm] = pair;
        NP[pair] = norm;
    }
    int ans = 0;
    for (auto &p : M) {
        if (p.first == 1) {
            ans += 1;
        } else {
            ans += max(p.second, M[NP[p.first]]);
            p.second = M[NP[p.first]] = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 26532
import sys

def swap(dice,i,j,k,l):#diceの目をi→ｊ→ｋ→ｌ→iの順に入れ替える
    x=dice[l]
    dice[l]=dice[k]
    dice[k]=dice[j]
    dice[j]=dice[i]
    dice[i]=x
    return dice

def Sroll(dice):
    dice=swap(dice,0,1,5,4)
    return dice

def Eroll(dice):
    dice=swap(dice,0,2,5,3)
    return dice

def Wroll(dice):
    dice=swap(dice,0,3,5,2)
    return dice

def Nroll(dice):
    dice=swap(dice,0,4,5,1)
    return dice


def judge(dice1,dice2):#2つのダイスが同じなら１を返し、違うなら０を返す
    top=dice1[0]
    fro=dice1[1]

    for j in range(0,8):
        if(fro==dice2[1]):
            break
        if(j==3):
            dice2=Eroll(dice2)
        if(j==7):
            return 0
        dice2=Sroll(dice2)
        
    i=0
    while(top!=dice2[0]):
        dice2=Eroll(dice2)
        if(i==3):
             return 0
        i+=1


    if(dice1[2]==dice2[2] and dice1[3]==dice2[3] and dice1[4]==dice2[4] and dice1[5]==dice2[5]):
        return 1
    else:
        return 0


n=int(input())

if(n==1):
    print("Yes")
    sys.exit()

Dice=[[]]

for i in range(0,n):
    Dice.append(list(map(int,input().split())))
del Dice[0]

for i in range(0,n):
    for j in range(i+1,n):
        if(judge(Dice[i],Dice[j])):
            print("No")
            sys.exit()


print("Yes")


Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t,k = "";int i,ans = 0;cin >> s;
  t = s.substr(0,1);
  for(i=1;i<s.size();i++){
    k += s.substr(i,1);
    if(k!="" && t!=k){
      ans++;t = k;k = "";
    }
  }
  cout << ans+1 << "\n";
}

Measured memory_bytes: 640
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define output(x) cout<<x<<endl;
typedef long long int ll;



int main()
{
	ll  i, j, k, l, m, sum, flag,ans,W,H,N;
	sum = 0;
	flag = 0;
	char S[100001];
	cin >> S;
	N = strlen(S);
	vector<pair<int, int>>edge(N - 1);
	i = 1;
	j = 0;
	if (S[0] == '0'||S[N-1]=='1'||S[N-2]=='0') {
		output("-1");
		return 0;
	}
		REP(i, 0, N - 1) {
			if (S[i] != S[N - i - 2]) {
				output("-1");
				return 0;
			}
		}


	i=1;
j=0;
		
		while (i < N - 1) {
			if (S[i] == '1') {
				if (j != 0) {
					REP(k, i - j, i) {
						edge[k-1].first = k;
						edge[k-1].second = i + 1;
					}
				}
				j = 0;
				edge[i-1].first = i ;
				edge[i-1].second = i + 1;
				i++;
			}
			else {
				j++;
				i++;
			}
		}
		edge[N - 2].first = N - 1;
		edge[N - 2].second = N;
		REP(i, 0, N-1) {
			cout << edge[i].first << " " << edge[i].second << endl;
		}
	
	//ソートしてある配列aの各要素の数を前から数え上げることで新しい配列lenに入れている
	return 0;
}



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

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

        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[][] a = new int[n][m];
        int[] b = new int[m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i][j] = Integer.parseInt(sc.next());
            }
        }
        for (int i = 0; i < m; i++) {
            b[i] = Integer.parseInt(sc.next());
        }

        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                c[i] += a[i][j] * b[j];
            }
            out.printf("%d\n", c[i]);
        }
        out.flush();
    }
}


Measured memory_bytes: 39644
s = input()[:-2]
while True:
    # print('Check',s)
    p = int(len(s)/2)-1
    # print('Divided into',s[:p+1],s[p+1:])
    if s[:p+1] == s[p+1:]:
        break
    s = s[:-2]
print(len(s))

Measured memory_bytes: 2940
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W = map(int, readline().split())
    A = [list(map(int, readline().split())) for _ in range(H)]
    B = [list(map(int, readline().split())) for _ in range(H)]

    G = [[0] * W for _ in range(H)]
    M = 0
    for i in range(H):
        for j in range(W):
            G[i][j] = abs(A[i][j] - B[i][j])
            if M < G[i][j]:
                M = G[i][j]

    dp = [[set() for j in range(W + 1)] for i in range(H + 1)]
    dp[0][1].add(0)
    dp[1][0].add(0)

    for i in range(H):
        for j in range(W):
            s = dp[i + 1][j + 1]
            b = G[i][j]
            for k in dp[i + 1][j]:
                s.add(k + b)
                s.add(abs(k - b))
            for k in dp[i][j + 1]:
                s.add(k + b)
                s.add(abs(k - b))

    print(min(dp[H][W]))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 546308
N,M =  [int(x) for x in input().split()]
Min = 0
Max = N
for _ in range(M):
    L_i,R_i = map(int, input().split())
    if L_i > Min:
        Min = L_i
    if R_i < Max:
        Max = R_i
        
if Min > Max:
    print("0")
else:
    print(Max-Min+1)

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	string S;
	cin >> S;
	map<int, int> vmap;

	int b = 1;
	int sum = 0;
	vmap[0] = 1;
	rrep(i, 0, SZ(S))
	{
		sum = (sum + (S[i] - '0')*b) % 2019;
		b = (b * 10) % 2019;
		vmap[sum]++;
	}

	int ans = 0;
	for (auto v : vmap)
	{
		ans += v.second * (v.second - 1) / 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int n;
string s;
ll cnt = 1;

int main() {
    cin >> n >> s;
    ll st = 0;
    rep(i,s.size()) {
        if (s[i] == 'B') {
            if (st%2 == 0) {
                st++;
            } else {
                cnt = cnt * st % MOD;
                st--;
            }
        } else {
            if (st%2 == 0) {
                cnt = cnt * st % MOD;
                st--;
            } else {
                st++;
            }
        }
    }
    rep(i,n) cnt = cnt * (i+1) % MOD;
    if (st > 0) cnt = 0;
    cout << cnt << endl;
}

Measured memory_bytes: 640
a = []
gets.chomp.to_i.times do
  a.push(gets.chomp.to_i)
end

n = 0
a.each do |item|
  if item == 2
    n += 1
  else
    bool = true
    i = 3
    bool = false if item % 2 == 0
    until i > Math.sqrt(item) || bool == false
      bool = false if item % i == 0
      i += 2
    end
    n += 1 if bool == true
  end
end

puts n

Measured memory_bytes: 6192
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}



use std::cmp;
use std::iter::Iterator;

fn main() {
    input! {
      n: usize,
      sp:[(String, i32); n],
    }

    let mut vec = vec![];

    for (i,v) in sp.into_iter().enumerate(){
        vec.push((v.0, -v.1,i));
    }

    vec.sort();
    
    for elem in vec {
        println!("{}", elem.2 +1);
    }
}



Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int R, G, B, N; cin >> R >> G >> B >> N;
    ll ans = 0;
    for(int i=0; i<=N; i++){
        for(int j=0; j<=N; j++){
            int k = (N - R * i - G * j)/B;
            if(R*i + G*j + B*k == N &&  k>=0 && k<=N) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
n = gets.split[0].to_i
c = gets.split.map(&:to_i).select {|i| i <= n}
m = (0..n+1).to_a

(2..n).each do |i|
  c.each {|j| m[i] = m[i-j]+1 if j <= i && m[i-j]+1 < m[i] }
end

puts m[n]

Measured memory_bytes: 9132
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    if(n < 1200)cout << "ABC" << endl;
    else if(n < 2800)cout  << "ARC" << endl;
    else cout << "AGC" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    string s,ss;
    cin >> s;
    int rs=0;
    ss = s;
    reverse(ss.begin(),ss.end());

    for(int i = 0;i < s.size();i++){
        if(s.at(i) != ss.at(i))
            rs++;
    }

    cout << rs/2 << endl;

    return 0;


    
} 

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

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	long long ans=INT_MIN;
	ans=max(b*d,max(b*c,max(a*c,a*d)));
	cout<<ans<<endl;
    return 0;
}


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

int main() {

  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  if(min(b,d) - max(a,c) > 0) cout << min(b,d) - max(a,c) << endl;
  else cout << 0 << endl;
  
}


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

int main()
{
  int n,k;
  cin>>n>>k;
  int h[n];
  for(int i=0 ; i<n ; i++)
    cin>>h[i];
  int dp[n];
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  for(int i=1 ; i<n ; i++){
      int temp=INT_MAX;
      for(int j=i-1 ; j>=i-k && j>=0 ; j--){
          temp=min(temp,abs(h[i]-h[j])+dp[j]);
      }
      dp[i]=temp;
  }
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define N 100000
#define D 2
int main(void) {
  int i,j,n,h[N],dp[N],dif[D];
 cin >> n;
  for(i=0;i<n;i++) {
    cin >> h[i];
  }
  for(i=0;i<N;i++){
    dp[i]=10000;
  }
  dp[0] = 0;
  dp[1] = abs(h[1]-h[0]);
  for(i=2;i<n;i++) {
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2] + abs(h[i]-h[i-2]));
  }
  /*
  dp[0] = 0;
  for(i=0;i<n;i++){
    for(j=0;j<D;j++) {
      dif[j] = dp[i] + abs(h[i] - h[i+j+1]);
      if(dif[j] < dp[i+j+1]) {
        dp[i+j+1] = dif[j];
      }
    }
  }
  */
  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    R = II()
    print(2 * R * 3.141592)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9136
#include <iostream>
#include <cstdio>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;

int d, len;
ll ten[30], ans;
map<ll, ll> f[30];

ll dp(ll x, ll y)
{
	if (x >= len / 2) return (y == 0) * ten[len & 1];
	if (ten[len - x] < abs(y)) return 0;
	if (f[x].count(y)) return f[x][y];
	ll out = 0;
	for (int i = -9; i <= 9; ++i)
	{
		int times = 10 - abs(i) - (i <= 0 && x == 0);
		out += times * dp(x + 1, y + i * (ten[len - 1 - x] - ten[x]));
	}
	return f[x][y] = out;
}

int main()
{
	cin >> d;
	
	ten[0] = 1;
	for (int i = 1; i <= 18; ++i) ten[i] = ten[i - 1] * 10;
	
	for (len = 2; len <= 18; ++len)
	{
		for (int i = 0; i <= 18; ++i) f[i].clear();
		ans += dp(0, d);
	}
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll dp[100],n,a[100],i,j;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a[i];
    dp[i]=0;
  }
  dp[0]=1000;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      dp[j]=max(dp[j],dp[i]/a[i]*a[j]+dp[i]%a[i]);
      dp[j]=max(dp[j],dp[j-1]);
    }
  }
  cout << dp[n-1] << endl;
  return 0;
}

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

#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

inline int readInt() {
	int n, c;
	while ((c = getchar()) < '0');
	n = c - '0';
	while ((c = getchar()) >= '0') {
		n = n * 10 + c - '0';
	}
	return n;
}

const int N = 5000;
const int M = 200;

struct Stack {
	short dat[N + 1];
	short sp;

	void push(short v) {
		dat[sp++] = v;
	}

	void pop() {
		sp--;
	}

	short fst() {
		return dat[sp - 1];
	}

	short snd() {
		return dat[sp - 2];
	}
};

int n, m;
Stack mono[M];
int b[N + 1][M];
long long a[N];

struct Tuple {
	long long val, imos;
};
Tuple tup[N + 1];

int main() {
	n = readInt();
	m = readInt();
	for (int i = 1; i < n; i++) {
		a[i] = readInt() + a[i - 1];
		tup[i].val -= a[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			b[i][j] = readInt();
		}
	}
	for (int i = 0; i < m; i++) {
		b[n][i] = 2e9;
		mono[i].push(n);
	}

	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j < m; j++) {
			while (b[mono[j].fst()][j] <= b[i][j]) {
				int l = mono[j].fst();
				int r = mono[j].snd();
				int v = b[l][j];
				mono[j].pop();
				tup[l].imos -= v;
				tup[r].imos += v;
			}
		}
		long long sum = 0;
		for (int j = 0; j < m; j++) {
			tup[mono[j].fst()].imos -= b[i][j];
			mono[j].push(i);
			sum += b[i][j];
		}
		long long u = -1e18;
		for (int j = i; j < n; j++) {
			sum += tup[j].imos;
			tup[j].imos = 0;
			tup[j].val += sum;
			u = max(u, tup[j].val);
		}
		ans = max(ans, u + a[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5120