akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
 
using namespace std;
using ll = long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
 
int main()
{
	string s;
	int i = 0;

	cin >> s;

	if(s[i] == 'A'){
		i++;
	}
	if(s[i] == 'K'){
		i++;
	}
	else{
		cout << "NO" << endl;
		return 0;
	}
	if(s[i] == 'I'){
		i++;
	}
	else{
		cout << "NO" << endl;
		return 0;
	}
	if(s[i] == 'H'){
		i++;
	}
	else{
		cout << "NO" << endl;
		return 0;
	}
	if(s[i] == 'A'){
		i++;
	}
	if(s[i] == 'B'){
		i++;
	}
	else{
		cout << "NO" << endl;
		return 0;
	}
	if(s[i] == 'A'){
		i++;
	}
	if(s[i] == 'R'){
		i++;
	}
	else{
		cout << "NO" << endl;
		return 0;
	}
	if(s.size() > i && s[i] == 'A'){
		i++;
	}
	if(s.size() == i){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string a;
    cin>>a;
    int ans=0;
    for(auto i : a)
    {
        ans+=i-'0';
    }
    if(ans%9==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
//long long a[200005];
//long long b[200005],c[200005];

int main ()
{

    long long int a,b, c,d,e,f,g,h,i,j,k,t,n,sum=0;

    cin >> a>>b;

    c= min (a,b);


    if (c==b)
    {
        while (a--)
        {
            cout << b;
        }
    }

   else  if (c==a)
    {
        while (b--)
        {
            cout << a;
        }
    }
}


Measured memory_bytes: 256
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)*}
    };
}

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

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

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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

fn main() {
    input!{
        n: usize,
        a: usize1,
        b: usize1,
        c: usize1,
        d: usize1,
        s: chars
    }
    for i in b..d {
        if s[i] == '#' && s[i + 1] == '#' {
            println!("No");
            return;
        }
    }
    for i in a..c {
        if s[i] == '#' && s[i + 1] == '#' {
            println!("No");
            return;
        }
    }
    if d < c {
        let mut sp = 0;
        for i in b..d + 1 {
            if s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.' {
                sp += 1;
            }
        }
        if sp == 0 {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=105,K=1e5+10;
int n,k,a[N],dp[K];
int dfs(int x)
{
	if(~dp[x])return dp[x];
	bool win=0;
	for(int i=1;i<=n;++i)
	{
		if(x-a[i]<0)continue;
		win|=(dfs(x-a[i])==0); 
	}
	return dp[x]=win;
}
int main()
{
	memset(dp,-1,sizeof dp);
	dp[0]=0;//0先手败 大于0先手胜
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)
	scanf("%d",&a[i]);
	puts(dfs(k)?"First":"Second");
	//for(int i=1;i<=5;++i)
	//printf("%d:%d\n",i,dp[i]);
	return 0;
}

Measured memory_bytes: 5376
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 1E5 + 10;

int a[MAXN << 1];
bool vis[MAXN << 1];

int main(){
	int n, x;
	scanf("%d%d", &n, &x);
	if (x == 1 || x == 2 * n - 1)
		puts("No");
	else{
		puts("Yes");
		if (n == 2){
			a[1] = 1, a[2] = 2, a[3] = 3;
		}
		else if (x == 2){
			a[n] = 2;
			a[n - 1] = 1;
			for (int j = 3, i = 1; i < 2 * n; ++i)
				if (a[i] == 0){
					for (; vis[j]; ++j);
					a[i] = j++;
				}
		}
		else{
			a[n] = x;
			a[n - 1] = x + 1;
			a[n - 2] = x - 1;
			a[n + 1] = x - 2;
			fill_n(vis + x - 2, 4, true);
			for (int j = 1, i = 1; i < 2 * n; ++i)
				if (a[i] == 0){
					for (; vis[j]; ++j);
					a[i] = j++;
				}
		}
		for (int i = 1; i < 2 * n; ++i)
			printf("%d\n", a[i]);
	}
	return 0;
}


Measured memory_bytes: 2176
p = 998244353
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    if m%2==1:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
N,M,K = map(int,input().split())
A = [1 for _ in range(N+1)]
for i in range(2,N+1):
    A[i] = (A[i-1]*i)%p
B = [1 for _ in range(N+1)]
B[N] = pow(A[N],p-2)
for i in range(N-1,1,-1):
    B[i] = (B[i+1]*(i+1))%p
C = [1 for _ in range(N)]
C[0] = M
for i in range(1,N):
    C[i] = (C[i-1]*(M-1))%p
tot = C[N-1]
for k in range(1,K+1):
    cnt = (A[N-1]*B[k]*B[N-1-k])%p
    cnt = (cnt*C[N-1-k])%p
    tot = (tot+cnt)%p
print(tot)

Measured memory_bytes: 111660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for(ll i=a;i <= b;i++)
#define rep(i,n) for(ll i=0;i < n;i++)
#define sz(x) x.size()
#define accuracy ll precision = numeric_limits<double>::digits10
#define fast_io ios_base::sync_with_stdio(false)
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define fir first
#define sec second
#define N 100005
#define fd(i,a,b) for(ll i=a;i >= b;i--)

ll n,l,a[N];

int main() {
	fast_io;
	accuracy;
	cin >> n >> l;
	fr(i,1,n) cin >> a[i];
	ll MAX = LLONG_MIN;
	fr(i,1,n-1) {
		MAX = max(MAX,a[i]+a[i+1]);
	}
	ll j = -1;
	fr(i,1,n-1) {
		if(a[i]+a[i+1] == MAX) {
			j = i;
			break;
		}
	}	
	if(MAX >= l) {
		cout << "Possible\n";
		fr(i,1,j-1) cout << i << "\n";
		fd(i,n-1,j+1) cout << i << "\n";
		cout << j << "\n";
	}
	else cout << "Impossible\n";
}

Measured memory_bytes: 1664
/**
 *  author: chaitanya
 *  created: 05:09:01 PM, 13 September 2020
 **/
#include <bits/stdc++.h>
using namespace std;

#define intll 1
#define interactive 0

#ifdef chaitanya
#include "/home/chaitanya/.templates/header.h"
#else
#define debug(x...)
#endif

#if !interactive
#define IOS                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);                      \
  cin.exceptions(cin.failbit);
#define endl "\n"
#else
#define IOS
#endif

#if intll
#define int long long int
#endif

#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define F first
#define S second

const int N = 300009;
const int mod = 1000000007;

void pre() {}

int32_t main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = a*c;
  ans = max(ans,b*c);
  ans = max(ans,a*d);
  ans = max(ans,b*d);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

int main()
{
	using namespace std;
	int N;
	cin >> N;

	vector<int> L;
	L.resize(N);
	for (auto &v : L)
		cin >> v;

	sort(L.begin(), L.end(),greater<int>());

	int sum = 0;
	for (int i = 1; i < N; i++)
		sum += L[i];
	if (L[0] < sum)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

}


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

#define MAX_NODE 10000000

typedef long long ll;
typedef unsigned int uint;
ll INF=(1LL<<60);

extern inline uint xor128(void){
  static uint x=123456789,y=362436069,z=521288629,w=88675123; 
  uint t=x^(x<<11);
  x=y; y=z; z=w;
  return w=(w^(w>>19))^(t^(t>>8)); 
}

struct treap{
  treap* lch;
  treap* rch;
  uint pri;
  int cnt;
  ll val;
  ll min;
  treap(){  }
};

treap Field[MAX_NODE];
typedef treap* Treap;

int cnt(Treap t){  return (t?t->cnt:0); }
ll min(Treap t){ return (t?t->min:INF); }

Treap update(Treap t){
  if(!t)return NULL;
  t->cnt = cnt(t->lch) + cnt(t->rch) + 1;
  ll dat=t->val;
  dat=min(dat, min(t->lch) );
  dat=min(dat, min(t->rch) );
  t->min = dat;
  return t;
}

Treap makenode(ll v){
  static int cc=1;
  treap &res=Field[cc++];
  res.lch=res.rch=NULL;
  res.val=v;
  res.min=v;
  res.cnt=1;
  res.pri=xor128();
  return &res;
}

ll Find(Treap t,int k=1e9){
  k=min(k,cnt(t)-1);
  int f=cnt(t->lch);
  ll res;
  if(f>k)res=Find(t->lch,k);
  if(f<k)res=Find(t->rch,k-f-1);
  if(f==k)res=t->val;
  return res;
}

Treap merge(Treap l,Treap r){
  if(!l)return r;
  if(!r)return l;
  
  if( l->pri > r->pri ){
    l->rch = merge( l->rch , r );
    return update(l);
  }else{
    r->lch = merge( l , r->lch );
    return update(r);
  }
}

typedef pair< Treap, Treap > treaps;
treaps split(Treap t,int k){
  if(!t)return treaps(NULL,NULL);
  
  if(k<=cnt(t->lch)){
    treaps s=split(t->lch,k);
    t->lch=s.second;
    return treaps(s.first,update(t));
  }else{
    treaps s=split(t->rch, k-cnt(t->lch)-1 );
    t->rch=s.first;
    return treaps( update(t), s.second );
  }
}

Treap insertk(Treap t,int k,ll val){
  Treap f=makenode(val);
  treaps s=split(t,k);
  Treap res= merge( merge(s.first,f) , s.second );
  return res;
}

Treap erasek(Treap t,int k){
  treaps a=split(t,k);
  treaps b=split(a.second,1);
  Treap res= merge(a.first,b.second);
  return res;
}


int main(){
  Treap root=NULL;
  int n,q;
  scanf("%d %d",&n,&q);
  for(int i=0;i<n;i++){
    root=insertk(root,i,2147483647);
  }
  while(q--){
    int type;
    scanf("%d",&type);
    if(type==0){
      int i,x;
      scanf("%d %d",&i,&x);
      root=erasek(root,i);
      root=insertk(root,i,x);
    }else{
      int l,r;
      scanf("%d %d",&l,&r);
      r++;
      treaps tmp = split(root,r);
      treaps tmp2 = split( tmp.first,l);
      printf("%lld\n",tmp2.second->min);
      root= merge( merge(tmp2.first,tmp2.second) , tmp.second );
    }
  }
  return 0;
}

Measured memory_bytes: 9036
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
//const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ld a, b;
    cin >> a >> b;
    cout << (ll)(a*b) << endl;
}


Measured memory_bytes: 3752
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = 1234567;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int main(void){
	int n;
	cin>>n;
	vector<string> W;
	string s;
	rep(i,n){
		cin>>s;
		W.push_back(s);
		if(i!=0){
			if(W[i-1][W[i-1].size()-1] != W[i][0]){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	sort(all(W));
	rep(i,n){
		if(i==0) continue;
		if(W[i] == W[i-1]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) 
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


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

  int n, k;
  cin >> n >> k;
  int r, s, p;
  cin >> r >> s >> p;

  string t;
  cin >> t;

  int ans = 0;
  for (int i = 0; i < k; i++) {
    char prev = 'x';
    for (int j = i; j < n; j += k) {
      if (t[j] == 'p' && prev != 's') {
        ans += s;
        prev = 's';
      } else if (t[j] == 's' && prev != 'r') {
        ans += r;
        prev = 'r';
      } else if (t[j] == 'r' && prev != 'p') {
        ans += p;
        prev = 'p';
      } else {
        prev = 'x';
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <cstdio>
using namespace std;
int mp[102][102];
int visited[102][102];
int a,b,c,d;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
pair<int,int> s1,s2;
int n;


void db(int x,int y){
  for(int i=1;i<=y;i++){
    for(int j=1;j<=x;j++)
      printf("%2d ",mp[i][j]);
    cout<<endl;
  }
  cout<<endl;
  for(int i=1;i<=y;i++){
    for(int j=1;j<=x;j++)
      printf("%2d ",visited[i][j]);
    cout<<endl;
  }
  cout<<s1.first<<" "<<s1.second<<" "<<b<<endl;
  cout<<s2.first<<" "<<s2.second<<" "<<d<<endl;
}
  

void init(int x,int y){
  for(int i=0;i<102;i++)
    for(int j=0;j<102;j++)
      mp[i][j]=-1;
  for(int i=1;i<=y;i++){
    for(int j=1;j<=x;j++){
      mp[i][j]=(i-1)*x+j;
      if(mp[i][j]==a) s1=make_pair(i,j);
      else if(mp[i][j]==c) s2=make_pair(i,j);
    }
  }
}

int dfs(int si,int sj,int e){
  queue< pair<int,int> > Q;
  for(int i=0;i<102;i++)
    for(int j=0;j<102;j++)
      visited[i][j]=0;
  Q.push(make_pair(si,sj));
  while(Q.empty()==false){
    pair<int,int> u=Q.front();
    Q.pop();
    for(int i=0;i<4;i++){
      int ny=u.first+dy[i];
      int nx=u.second+dx[i];
      if(mp[ny][nx]!=-1 && visited[ny][nx]==0&&mp[ny][nx]<=n){
	visited[ny][nx]= visited[u.first][u.second]+1;
	if(mp[ny][nx]==e) return visited[ny][nx];
	Q.push(make_pair(ny,nx));
      }
    }
  }
  return 100;
}
    

int main (){
  cin>>n;
  cin>>a>>b>>c>>d;
  int dismin=1000;
  for(int i=1;i<=n;i++){
    init(i,n/i+1);
    int dis1=dfs(s1.first,s1.second,b);
    int dis2=dfs(s2.first,s2.second,d);
    if(dismin>dis1+dis2){
      dismin=dis1+dis2;
    }
  }
  cout<<dismin<<endl;

  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main() {
	int k, a, b; cin >> k >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK";
			return 0;
		}
	}
	cout << "NG";
}

Measured memory_bytes: 3592
#include <iostream>
#include <array>

using namespace std;

int main(void){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
   if (A <= C && C <= B) {
       if (D < B) {
         cout << D-C << endl;   
       } else {
           cout << B-C << endl;   
       }
   } else if(C <= A && A <= D) {
         if (B < D) {
         cout << B-A << endl;   
       } else {
           cout << D-A << endl;   
       }
   } else {
       cout << 0 << endl;
   }
}


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

const int mod=1e9+7;
const int sz=2010;

int fact[sz],inv[sz],ifact[sz];
void make(){
    fact[0]=fact[1]=inv[1]=ifact[0]=ifact[1]=1;
    for(int i=2;i<sz;i++){
        fact[i]=fact[i-1]*i%mod;
        inv[i]=inv[mod%i]*(mod-mod/i)%mod;
        ifact[i]=ifact[i-1]*inv[i]%mod;
    }
}
int comb(int n,int k){
    if(n<k) return 0;
    return fact[n]*ifact[k]%mod*ifact[n-k]%mod;
}

signed main(){
    make();

    int N,K; cin>>N>>K;
    for(int i=1;i<=K;i++){
        cout<<comb(K-1,i-1)*comb(N-K+1,i)%mod<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools

COSTS = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)


def gen(base_digit, base_cost, base_length, digits, remain):
  number = [base_digit] * base_length
  remain -= base_cost * base_length

  if remain == 0:
    print(''.join(str(d) for d in number), flush=True)
    return True

  digits = [(d, c - base_cost) for d, c in digits if d != base_digit and c - base_cost <= remain]

  if len(digits) == 0:
    return False

  max_size = min(remain // min(digits, key=lambda x: x[1])[1], len(number))
  numbers = []

  for size in range(1, max_size + 1):
    for idxs in itertools.combinations_with_replacement(range(len(digits)), size):
      if sum(digits[i][1] for i in idxs) != remain:
        continue

      replaces = [digits[i][0] for i in idxs]
      replaces.sort(reverse=True)
      uppers = [d for d in replaces if d > base_digit]
      lowers = [d for d in replaces if d < base_digit]

      num = number[:]

      if len(uppers) > 0:
        num = uppers + num[len(uppers):]

      if len(lowers) > 0:
        num = num[:-len(lowers)] + lowers

      numbers.append(num)

  if len(numbers) == 0:
    return False

  number = max(numbers)

  print(''.join(str(d) for d in number), flush=True)

  return True


def main():
  remain, _ = list(map(int, input().split()))

  digits = {}

  for d in map(int, input().split()):
    if COSTS[d] not in digits or digits[COSTS[d]] < d:
      digits[COSTS[d]] = d

  digits = [(d, c) for c, d in digits.items()]
  base_digit, base_cost = min(digits, key=lambda x: x[1])

  for length in range(remain // base_cost, -1, -1):
    if gen(base_digit, base_cost, length, digits, remain):
      break


if __name__ == '__main__':
  main()



Measured memory_bytes: 3444
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h, w;
    in >> h >> w;
    string a[h];
    REP(i, h){
        in >> a[i];
    }

    REP(i, w+2) out << "#";
    out << endl;
    REP(i, h){
        out << "#";
        out << a[i];
        out << "#" << endl;
    }
    REP(i, w+2) out << "#";
    out << endl;
}


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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, std::vector<long long> a){
  for(int i=0; i<N; i++) {
    if(a[i]%2!=0) {
      std::cout << "first" << std::endl;
      return ;
    }
  }
  std::cout << "second" << std::endl;
  return ;
}

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


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;

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

            // main.solveA(sc);
            main.solveB(sc);
            // main.solveC(sc);
            // main.solveD(sc);
            // main.solveE(sc);

        }

    }

    private void solveD(Scanner sc) {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out)) {} catch (IOException e) {

        }
    }

    private void solveE(Scanner sc) {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out)) {

        } catch (IOException e) {

        }
    }

    private void solveC(Scanner sc) {

    }

    void solveB(Scanner sc) {
        int N = sc.nextInt();

        int sum = 0;

        if (N >= 10) {
            sum += 9;
        } else {
            System.out.println(N);
            return;
        }

        if (N >= 1000) {
            sum += 900;
        } else {
            System.out.println(sum + Math.max(N - 99, 0));
            return;
        }

        if (N >= 100000) {
            System.out.println(90909);
        } else {
            System.out.println(sum + Math.max(N - 9999, 0));
            return;
        }

    }

    class SolveB {
    }

    class Edge {
    }

    void solveA(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        System.out.println(Math.max(c - (a - b), 0));

    }
}


Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      for(int i=0; i!=n; i++)
        seq[i] = Integer.parseInt(br.readLine());

      System.out.println( shellSort(seq, n) );

      StringBuilder str = new StringBuilder(n*5);
      for (int i : seq)
        str.append(i).append("\n");

      str.setLength(str.length()-1);
      System.out.println(str);
    }
  }

  public static int shellSort(int a[], int n) {
    int cnt=0;
    int m = 0;
    int[] aG = new int[100];
    for (int g=1,max=n+1; g < max; g=(g*3+1)) {
      aG[m++] = g;
    }
    StringBuilder str = new StringBuilder(m*5);
    str.append(m).append("\n");

    for(int i=(m-1); i!=-1; i--){
      cnt += insertionSort(a, n,aG[i]);
      str.append(aG[i]).append(" ");
    }

    str.setLength(str.length()-1);
    System.out.println(str);

    return cnt;
  }
  
  public static int insertionSort(int a[], final int max, final int g) {
    int cnt=0;

    for (int i=g,j=0,v=0; i < max; i++) {
      for( j=(i-g), v=a[i]; j>=0 && a[j]>v; j-=g ) {
        a[j+g] = a[j];
        cnt++;
      }
      a[j+g] = v;
    }

    return cnt;
  }
}


Measured memory_bytes: 88184
a,b,c=map(int,input().split())

l=[]
for i in range(b):
    l.append((a*i)%b)
t=0
for i in range(len(l)):
    if l[i]==c:
        t+=1
        break
if t!=0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
int main(){
int n,x,a,b,c,i,wa,ans[256]={0},count=0;
	while(1){
		std::cin>>n>>x;
		if(n==0&&x==0)break;
		for(a=1;a<=n-2;a++){
			for(b=2;b<=n-1;b++){
				if(b<=a)b=a+1;
				if(b>=n)break;
				for(c=3;c<=n;c++){
					if(a>=c)c=a+2;
					if(b>=c)c=b+1;
					if(c>=n+1)break;
					wa=a+b+c;
					if(a<b&&b<c&&wa==x) ans[count]+=1;
				}
			}
		}
	count++;
	}
	for(i=0;i<count;i++){
		std::cout<<ans[i]<<std::endl;
	}
	return 0;
}

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

uint32_t pow_mod(uint32_t base, uint32_t exp, uint32_t mod) {
  if (exp == 0) return 1;

  uint64_t half = pow_mod(base, exp / 2, mod);
  uint64_t ans = (half * half) % mod;
  return (ans * (exp % 2 == 0 ? 1ll : base)) % mod;
}

uint32_t comb_mod(uint32_t n, uint32_t k, const std::vector<uint64_t>& fact_mod,
                  const std::vector<uint64_t>& inv_fact_mod, uint32_t mod) {
  if (n < k) return -1;
  return ((fact_mod[n] * inv_fact_mod[n - k]) % mod * inv_fact_mod[k]) % mod;
}

int main() {
  const uint32_t mod = 998'244'353;
  uint32_t N = 0, M = 0, K = 0;
  std::cin >> N >> M >> K;

  std::vector<uint64_t> fact_mod(N, 1);
  std::vector<uint64_t> inv_mod(N, 1);
  std::vector<uint64_t> inv_fact_mod(N, 1);
  for (size_t i = 2; i < fact_mod.size(); i++) {
    fact_mod[i] = (i * fact_mod[i - 1]) % mod;
    inv_mod[i] = mod - (inv_mod[mod % i] * (mod / i)) % mod;
    inv_fact_mod[i] = (inv_mod[i] * inv_fact_mod[i - 1]) % mod;
  }

  uint32_t ans = 0;
  for (size_t k = 0; k < K + 1; k++) {
    uint64_t pow = pow_mod(M - 1, N - 1 - k, mod);
    pow = (pow * M) % mod;
    uint64_t comb = comb_mod(N - 1, k, fact_mod, inv_fact_mod, mod);
    ans = (ans + (pow * comb) % mod) % mod;
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 7956
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		while(in.hasNext())
		{
			int N=in.nextInt();//number of room
			int M=in.nextInt();//number of Pr
			int s[]=new int[M];
			int t[]=new int[M];
			for(int i=0;i<M;i++)
			{
				s[i]=in.nextInt();
				t[i]=in.nextInt();
			}
			int te=0;
			int i;
			int ans=0;
			boolean fin=false;
			for(;;)
			{
				i=te;
				fin=false;
				for(int j=0;j<M;j++)
				{
					if(s[j]<=i+1&&i+1<=t[j])
					{
						if(te<t[j])
						{
							te=t[j];
							fin=true;
						}
					}
				}
				ans++;
				if(te==N)
					break;
				if(!fin)
					break;
			}
			System.out.println(fin ? ans:"Impossible");
		}
	}

	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 20476
=begin
N
A1 A2 ... An
=end
N = gets.chomp.to_i
AS = gets.chomp.split(" ").map(&:to_i)

h = {}

AS.each do |a|
  h[a] ||= 0
  h[a] += 1
end

# nC2
def comb(n)
  n * (n - 1) / 2
end

TOTALS = {}

h.each do |k, v|
  TOTALS[k] = comb(v)
end

sum = 0

TOTALS.each do |k,v|
  sum += v
end

AS.each do |a|
  t = TOTALS[a]

  puts(sum - t + comb(h[a] - 1))
end


Measured memory_bytes: 39844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var imp = Console.ReadLine().Split(' ');
            if (int.Parse(imp[0]) * int.Parse(imp[1]) %2 ==0)
            {
                Console.Write("Even");
            }
            else
            {
                Console.Write("Odd");
            }
            //System.Threading.Thread.Sleep(1000);
        }
    }
}


Measured memory_bytes: 11092
/*
     Author: Wasi Ur Rahman
     RMSTU,Rangamati,Chittagong,Bangladesh
*/
#include <bits/stdc++.h>
using namespace std;
#define  gcd(a,b) __gcd(a,b)
#define  lcm(a,b) (a*b)/gcd(a,b)
#define  PI acos(-1.0)
#define  sqr(x) ((x)*(x))
#define  min3(a,b,c) min(a,min(b,c))
#define  min4(a,b,c,d) min(d,min(a,min(b,c)))
#define  max4(a,b,c,d) max(d,max(a,max(b,c)))
typedef   pair<int, int> ii;
typedef   std::vector<ii> vii;
#define   vi   std::vector<int>
#define   vll  std::vector<ll>
#define   all(n) n.begin(),n.end()
#define  mpsi std::map<string, int>
#define  pb             push_back
#define  ll             long long
#define  ln             printf("\n");
#define  fast           ios::sync_with_stdio(false);cin.tie(0)
#define  max3(a,b,c)    max(a,max(b,c))
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define dec(x,y)        fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
#define  mod           1e9 + 7;
inline ll scf(){ll x;scanf("%I64d",&x);return x;}
#define scf scf()
bool isPrime(ll n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (ll i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int main()
{
    fast;
    ll x=scf;
    ll sum = (x)/500;
    ll waste = x%500;
    ll minimum = waste/5;
    cout << sum*1000+(minimum*5) << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>

int main()
{
  using namespace std;
  long long int N, K;
  cin >> N >> K;
  long long int t = N % K;
  // cout << t;
  long long int tmp = abs(t - K);
  if (tmp <= t)
    cout << tmp;
  else
    cout << t;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){
    string s;
    int k;
    cin >> s >> k;

    if(s[0] == '1'){
	int c = 0;
	while(s[c] == '1'){
	    c++;
	}
	if(k <= c || sz(s) == c)P(1);
	else {
	    
	    P(s[c]);
	
	}
    }else{
	P(s[0]);
    }
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 6e5+7;
const int INF = 1e9+7;
const double eps = 1e-5;
#define pb push_back

int main(){
    string x;
    cin >> x;
    if(x[2] == x[3] && x[4] == x[5]){
        cout << "Yes\n";

    }
    else{
        cout << "No\n";
    }
}



Measured memory_bytes: 256
s = input()

if s[0] == "R" and s[1] == "R" and s[2] == "R":
    print(3)
elif s[0] == "R" and s[1] == "R":
    print(2)
elif s[1] == "R" and s[2] == "R":
    print(2)
elif s[0] == "R" or s[1] == "R" or s[2] == "R":
    print(1)
else:
    print(0)


Measured memory_bytes: 9124
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

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

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

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

int main() {
    int a, b;
    cin >> a >> b;
    if(a <= 5){
        cout << 0 << endl;
    }else if(a <= 12){
        cout << b / 2 << endl;
    }else {
        cout << b << endl;
    }
}



Measured memory_bytes: 256
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr, tails, sort)
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

isTriangle :: Int -> Int -> Int -> Bool
isTriangle a b c = a < b + c && b < c + a && c < a + b

naive = do
  n <- readLn :: IO Int
  xs <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ length [ (a,b,c) | a:xss <- tails xs, b:xsss <- tails xss, c <- xsss, isTriangle a b c ]

-- v は昇順にソートされているとする。
-- count a v は a 以上の要素の個数を数える。
countGE :: Int -> U.Vector Int -> Int
countGE !a = loop 0
  where
    loop !s !v | U.null v = s
               | U.length v == 1 = if a <= U.head v then
                                     s + 1
                                   else
                                     s
               | otherwise = let n = U.length v
                                 n2 = n `quot` 2
                             in if a <= v U.! n2 then
                                  loop (n - n2 + s) (U.take n2 v)
                                else
                                  loop s (U.drop n2 v)

main = do
  n <- readLn :: IO Int
  xs <- mergeSort . U.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ sum [ n - (j+1) - countGE c_max ys
              | i <- [0..n-1]
              , let a = xs U.! i
              , j <- [i+1..n-1]
              , let b = xs U.! j
              , let c_max = a + b {- c < a + b, b - a < c, a - b < c -}
              , let ys = U.drop (j+1) xs
              ]

mergeSortBy :: (U.Unbox a) => (a -> a -> Ordering) -> U.Vector a -> U.Vector a
mergeSortBy !cmp !vec = doSort vec
  where
    doSort vec | U.length vec <= 1 = vec
               | otherwise = let (xs, ys) = U.splitAt (U.length vec `quot` 2) vec
                             in merge (doSort xs) (doSort ys)
    merge xs ys = U.create $ do
      let !n = U.length xs
          !m = U.length ys
      result <- UM.new (n + m)
      let loop !i !j
            | i == n = U.copy (UM.drop (i + j) result) (U.drop j ys)
            | j == m = U.copy (UM.drop (i + j) result) (U.drop i xs)
            | otherwise = let !x = xs U.! i
                              !y = ys U.! j
                          in case cmp x y of
                               LT -> do UM.write result (i + j) x
                                        loop (i + 1) j
                               EQ -> do UM.write result (i + j) x
                                        UM.write result (i + j + 1) y
                                        loop (i + 1) (j + 1)
                               GT -> do UM.write result (i + j) y
                                        loop i (j + 1)
      loop 0 0
      return result

mergeSort :: (U.Unbox a, Ord a) => U.Vector a -> U.Vector a
mergeSort = mergeSortBy compare


Measured memory_bytes: 1020
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int ans = 1;
      for (int i=2;i<=Math.floor(Math.sqrt(X));i++){
       
        int tmp = i;
        while (tmp<=X){
          if (tmp*i <= X){
            tmp *= i;
          }
          else{
            ans = Math.max(ans,tmp);
            break;
          }
        }
      }
      System.out.println(ans);
    }
}

Measured memory_bytes: 23636
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int n,m,x;
const int N = 25;
int c[N],a[N][N],b[N];
ll res = 0x3f3f3f3f;
bool st[N];
void dfs(int u)
{
	if(u == n + 1)
	{
		ll tmp = 0;
		bool ok = 1;
		for(int i = 1;i <= m;++i)	b[i] = 0;
		for(int i = 1;i <= n;++i)
		{
			if(st[i])
			{
				tmp += c[i];
				for(int j = 1;j <= m;++j)
					b[j] += a[i][j];
			}
		}
		for(int i = 1;i <= m;++i)
		{
			if(b[i] < x)
			{
				ok = 0;
				break;
			}
		}
		if(ok)	res = min(res,tmp);
		return;
	}
	
	st[u] = 1;
	dfs(u + 1);
	st[u] = 0;
	dfs(u + 1);
}
int main()
{
	scanf("%d%d%d",&n,&m,&x);
	for(int i = 1;i <= n;++i)
	{
		scanf("%d",&c[i]);
		for(int j = 1;j <= m;++j)	scanf("%d",&a[i][j]);
	}
	dfs(1);
	printf("%lld",res == 0x3f3f3f3f ? -1 : res);
    return 0;
}


Measured memory_bytes: 3256
import math
a,b,c,d=map(int,input().split())

l1 = a % c
r1 = b % c

if l1 > r1:
    cnt1 = (b - a)//c + 1
else:
    cnt1 = (b - a)//c
if l1 == 0:
    cnt1 += 1

l2 = a % d
r2 = b % d

if l2 > r2:
    cnt2 = (b - a)//d + 1
else:
    cnt2 = (b - a)//d
if l2 == 0:
    cnt2 += 1

e = (c*d)//math.gcd(c,d)
l3 = a % e
r3 = b % e

if l3 > r3:
    cnt3 = (b - a)//e + 1
else:
    cnt3 = (b - a)//e
if l3 == 0:
    cnt3 += 1

print((b - a + 1) - cnt1 - cnt2 + cnt3)

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

int main()
{
    int n;
    cin >> n;
    int acNum = 0, waNum = 0, tleNum = 0, reNum = 0;
    string temp;
    for(int i = 0; i < n; i++){
        cin >> temp;
        if(temp == "AC") acNum++;
        else if(temp == "WA") waNum++;
        else if(temp == "TLE") tleNum++;
        else if(temp == "RE") reNum++;
    }

    cout << "AC x " << acNum << endl;
    cout << "WA x " << waNum << endl;
    cout << "TLE x " << tleNum << endl;
    cout << "RE x " << reNum << endl;

    return 0;
}

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

int max(int x, int y) {
	if(x > y)
		return x;
	return y;
}

// モンスターを座標の小さい順にソート
void mergesort(int n, int *x, int *h) {
	if(n < 2)
		return;
	mergesort(n/2, x, h);
	mergesort(n - n/2, x + n/2, h + n/2);
	int *x_tmp = malloc(sizeof(int)*n);
	int *h_tmp = malloc(sizeof(int)*n);
	int i = 0;
	int j = 0;
	while(i + j < n)
		if(n/2 <= i) {
			*(x_tmp + i + j) = *(x + n/2 + j);
			*(h_tmp + i + j) = *(h + n/2 + j);
			j++;
		} else if(n - n/2 <= j) {
			*(x_tmp + i + j) = *(x + i);
			*(h_tmp + i + j) = *(h + i);
			i++;
		} else if(*(x + i) < *(x + n/2 + j)) {
			*(x_tmp + i + j) = *(x + i);
			*(h_tmp + i + j) = *(h + i);
			i++;
		} else {
			*(x_tmp + i + j) = *(x + n/2 + j);
			*(h_tmp + i + j) = *(h + n/2 + j);
			j++;
		}
	for(i = 0; i < n; i++) {
		*(x + i) = *(x_tmp + i);
		*(h + i) = *(h_tmp + i);
	}
	free(x_tmp);
	free(h_tmp);
}

// 長さnの整列済み配列aで、要素iはp以上だが要素i-1はpより小さいようなiを返す
int binarysearch(int n, int *a, int p) {
	if(n < 1)
		return 0;
	if(p <= *(a + 0))
		return 0;
	if(*(a + n - 1) < p)
		return n;
	if(p <= *(a + n/2))
		return binarysearch(n/2, a, p);
	return n/2 + binarysearch(n - n/2, a + n/2, p);
}

int main(void) {
	int n, d, a, i;
	scanf("%d%d%d", &n, &d, &a);
	int *x = malloc(sizeof(int)*n);
	int *h = malloc(sizeof(int)*n);
	for(i = 0; i < n; i++)
		scanf("%d%d", x + i, h + i);
	mergesort(n, x, h);
	long *sum = malloc(sizeof(long)*n);
	*(sum + 0) = (*(h + 0) + a - 1)/a;
	for(i = 1; i < n; i++) {
		int border = binarysearch(i, x, *(x + i) - 2*d);
		if(border == 0)
			*(h + i) -= (*(sum + i - 1))*a;
		else
			*(h + i) -= (*(sum + i - 1) - *(sum + border - 1))*a;
		*(h + i) = max(*(h + i), 0);
		*(sum + i) = *(sum + i - 1) + (*(h + i) + a - 1)/a;
	}
	printf("%ld\n", *(sum + n - 1));
	free(x);
	free(h);
	free(sum);
	return 0;
}

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

using namespace std;
const int N = 1e5 + 5;
char str[N];
pair<int, int> ans[N];
bool vis[N];

int main() {
    //freopen("in.txt", "rt", stdin);
    vector<int> ones;
    scanf("%s", str);
    int n = strlen(str);
    if (str[0] == '1') ones.push_back(1);
    else {
        puts("-1");
        return 0;
    }
    if (str[n - 1] == '1') {
        puts("-1");
        return 0;
    }
    for (int i = 2; i < n; ++i) {
        if (str[i - 1] != str[n - i - 1]) {
            puts("-1");
            return 0;
        }
    }

    for (int i = 1; i < n; ++i) {
        if (str[i - 1] == '1') {
            ones.push_back(i);
        }
    }
    vector<pair<int, int>> vec;
    ones.push_back(n);
    for (int i = 1; i < ones.size(); ++i) {
        int a = ones[i], b = ones[i - 1];
        for (int j = b; j < a; ++j) {
            vec.push_back({j, a});
        }
    }
    for (auto x:vec) {
        printf("%d %d\n", x.first, x.second);
    }
}

Measured memory_bytes: 2804
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
using namespace std;

int main()
{
	int a, b; float t;
	cin >> a >> b >> t;
	cout << static_cast<int>((t+0.5) / a) * b << endl;
	return 0;
}

Measured memory_bytes: 888
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String str = br.readLine();

			if(str == null){
				break;
			}

			String[] tmpArray = str.split(" ");

			GameManager gm = new GameManager();
			Player p1 = new Player(GameManager.PLAYER1, gm);

			gm.putCard(Integer.parseInt(tmpArray[0]), GameManager.PLAYER1);
			gm.putCard(Integer.parseInt(tmpArray[1]), GameManager.PLAYER1);
			gm.putCard(Integer.parseInt(tmpArray[2]), GameManager.PLAYER2);

			if(p1.decideDraw()){
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
		}

	}
}
class Player {
	GameManager gm;
	int name;

	public Player(int name, GameManager gm){
		this.gm = gm;
		this.name = name;
	}

	public boolean decideDraw(){
		ArrayList<Integer> myCards = gm.playersCards(this.name);
		ArrayList<Integer> invisibleCards = gm.invisibleCards(this.name);

		//????????????????¨?
		int sum = 0;
		for(int i = 0; i < myCards.size();i++){
			sum += myCards.get(i);
		}

		//System.out.println("Sum of My Cards "+sum);
		//20??\?????¨????????????????????°????±???????
		int safe = 0;
		for(int i = 0; i < invisibleCards.size() ; i++){
			if(sum + invisibleCards.get(i) <= 20){
				safe++;
			}
		}

		if((double)safe/invisibleCards.size() >= 0.5){
			return true;
		}
		else {
			return false;
		}
	}
}

class GameManager{
	static final int PLAYER1 = 1;
	static final int PLAYER2 = 2;
	static final int UNKNOWN = 3;

	Card[] cards = new Card[10];

	public GameManager(){
		for(int i = 0; i < cards.length ; i++){
			cards[i] = new Card();
		}
	}

	public void putCard(int num, int player){
		cards[num - 1].owner = player;
	}

	public ArrayList<Integer> invisibleCards(int player){
		ArrayList<Integer> list = new ArrayList<Integer>();

		for(int i = 0; i < cards.length ; i++){
			if(cards[i].owner == UNKNOWN){
				list.add(cards[i].num);
			}
		}
		return list;
	}

	public ArrayList<Integer> playersCards(int player){
		ArrayList<Integer> list = new ArrayList<Integer>();

		for(int i = 0; i < cards.length ; i++){
			if(cards[i].owner == player){
				list.add(cards[i].num);
			}
		}
		return list;
	}
}

class Card {
	private static int cnum = 1;
	int num;
	int owner;
	//	boolean visible;


	public Card(){
		num = cnum;
		cnum++;
		if(cnum == 11){
			cnum = 1;
		}
		owner = GameManager.UNKNOWN;
		//		visible = false;
	}

	public void setOwner (int owner){
		this.owner = owner;
	}
}

Measured memory_bytes: 24292