akhauriyash/Code-Regression huggingface dataset:
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
using namespace std;
long long inf=100000000000007;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
struct edge{int to,cost;};
vector<edge> G[22];
vector<int> O[10];
P sg[10];
int d[1005][1005]={};
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
pair<int,double> s[1005];
int c=0;
int n,k;
int fi[1005][1005];
int ans[1005][1005]={};

signed main(){
    string s;cin>>s;
    int to=0;
    rep(i,3)if(s[i]=='1')to++;
    cout<<to<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e4+10;
const ll mod=1e9+7;
ll dp[maxn][120];
int a[maxn],d;
char num[maxn];
ll dfs(int pos,int sum,bool limit)
{
    if(pos==-1)
        return sum%d==0?1:0;
    if(!limit&&dp[pos][sum]!=-1)
        return dp[pos][sum];
    int up=limit?a[pos]:9;
    ll ans=0;
    for(int i=0; i<=up; i++)
    {
        int tmp=0;
        tmp=(i+sum)%d;
        ans=(ans+dfs(pos-1,tmp,limit&&i==a[pos]))%mod;
    }
    if(!limit)
        dp[pos][sum]=ans%mod;
    return ans%mod;
}
ll solve()
{
    int pos=0;
    int len=strlen(num);
    for(int i=len-1; i>=0; i--)
        a[pos++]=num[i]-'0';
    return dfs(pos-1,0,true);
}
int main()
{
    memset(dp,-1,sizeof(dp));
    scanf("%s",num);
    scanf("%d",&d);
    printf("%lld\n",(solve()-1+mod)%mod);
    return 0;
}


Measured memory_bytes: 10496
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>
#include <set>

using namespace std;


int main() {

    int A, B, C;
    cin >> A >> B >> C;

    cout << max(C - (A - B), 0) << "\n";

    return 0;
}

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

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    vector<int> L(N);
    int sum = 0;
    int m = 0;
    for(auto &i: L) cin >> i;
    for(auto i: L)
    {
        if (i > m) m = i;
        sum += i;
    }
    sum -= m;
    cout << ( (sum > m) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <array>
#include <list>
#include <string>
#include <algorithm>
#include <queue>
#include <numeric>
#include <random>
#include <iomanip>
#include <chrono>

using namespace std;

int main() {

	long long int n, k;
	cin >> n >> k;

	long long p = 1;
	int count = 0;
	while (n >= p)
	{
		p *= k;
		count++;
	}

	cout << count << endl;

	return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i<N; i++) cin >> A[i];
    long long money = 1000;
    long long stock = 0;
    for (int i=0; i<N-1; i++)
    {
        if (A[i]<A[i+1])
        {
            long long possible = money/A[i];
            money -= A[i] * possible;
            stock += possible;
        }
        else if (A[i]>A[i+1])
        {
            money += stock * A[i];
            stock = 0;
        }
    }
    money += A[N-1] * stock;
    cout << money << endl;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in); 
		
		String s = sc.nextLine();
		
		if(s.equals("A")) {
			System.out.println("T");
		}else if (s.equals("C")) {
			System.out.println("G");
		}else if(s.equals("T")) {
			System.out.println("A");
		}else {
			System.out.println("C");
		}

	}

}


Measured memory_bytes: 23124
import Data.Char

solve :: String -> Int -> Int
solve s k
  | isFirstKCharAll1 = 1
  | otherwise        = digitToInt $ firstCharNot1
  where isFirstKCharAll1 = all (== '1') $ take k s
        firstCharNot1 = head $ filter (/= '1') s

main :: IO ()
main = do
  s <- getLine
  k <- readLn
  print $ solve s k

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_M = (int)(1e5 + 5);

int n, m;

vector<pair<int, int>> claims;

int ans;

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &m);

  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);

    claims.push_back(make_pair(b, a));
  }

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

  int pos = 0;

  ans = 0;

  // for (auto &e: claims) {
  //   printf("%d %d\n", e.first, e.second);
  // }

  for (auto &e: claims) {
    // printf("pos: %d\n", pos);
    if (pos <= e.second) {
      pos = e.first;
      ans += 1;
    }
  }

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

  return 0;
}


Measured memory_bytes: 1400
//g++ main.cpp -I /usr/local/include/ac-library
#include<cmath>
//#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
//using namespace atcoder;
stack<int> st;
queue<int> qu;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define mod 1000000007
//#define mint=modint1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;

int node[1000005];
vector<int> to[1000005];
vector<int> du={-1,0,1,0};
vector<int> dw={0,-1,0,1};
vector<int> b;

int main(){
    int h,w;
    cin >> h>> w;
    vector<string> A(h);
    rep(i,h){
        cin >> A[i];
    }
    rep(i,h){
        rep(j,w){
            node[i*1000+j]=INF;
        }
    }
    
    rep(i,h){
        rep(j,w){
            int u=i*1000+j;
            if(A[i][j]=='#'){
                b.push_back(i*1000+j);
            }
            rep(k,4){
                int y=i+du[k];
                int x=j+dw[k];
                if(0<=x&&x<w&&0<=y&&y<h){
                    int v=y*1000+x;
                    to[u].push_back(v);
                    //to[v].push_back(u);
                }
            }
        }
    }
    //cerr<<1<<endl;
    rep(i,sz(b)){
        // BFS
        qu.push(b[i]);
        node[b[i]]=0;
    }
        
    while(!qu.empty()){
        int u=qu.front();
        qu.pop();
        for(int v:to[u]){
            if(node[v]>node[u]+1){
                node[v]=node[u]+1;
                qu.push(v);
            }
        }
        //cerr<<2<<endl;
    }
    int ans=0;
    rep(i,h){
        rep(j,w){
            if(node[i*1000+j]>ans){
                ans=node[i*1000+j];
            }
            //ans=max(ans,node[i*h+j]);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 71584
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> v(N); rep(i, 0, N) { cin >> v[i]; }
	vector<int>w(v);
	sort(all(w));
	vector<int>T(10101, 0);
	rep(i, 0, N)T[w[i]] = i;
	vector<bool>f(N, false);
	int ans(0);
	int min_value = *min_element(all(v));
	rep(i, 0, N) {
		if (f[i])continue;
		int m = INF;
		int sum(0);
		int j = i;
		int n(0);
		while (!f[j]) {
			f[j] = true;
			n++;
			sum += v[j];
			chmin(m, v[j]);
			j = T[v[j]];
		}
		ans += min(sum + (n - 2)*m, 2 * (m + min_value) + sum - m + min_value + min_value*(n - 2));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3172
#include<stdio.h>

int main(void)
{
    int a, b;
    char s[10];

    scanf("%d%d%s", &a, &b, s);

    if ('-' == s[a]) {
        s[a] = '0';
    }
    else {
        printf("No\n");
        return 0;
    }

    for (int i=0; (a+b) > i; i++) {
        if ('0' > s[i] || '9' < s[i]) {
            printf("No\n");
            return 0;
        }
    }
    
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

using ll = long long;
using namespace std;
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
ll M = 1000000007;
typedef pair<int, int> P;

typedef pair<ll, int> pli;

void solve()
{
    string a;
    cin >> a;
    int k;
    cin >> k;
    int len = a.size();
    vector<int> c(len);
    rep(i, len)
    {
        c[i] = i;
    }
    string s;
    rep(i, len)
    {
        s += '0';
    }
    int ans = 0;
    if (k == 3)
    {
        rep(i, len)
        {
            FOR(j, i + 1, len)
            {
                FOR(p, j + 1, len)
                {
                    string t = s;
                    rep(l, 9)
                    {
                        rep(m, 9)
                        {
                            rep(o, 9)
                            {
                                t[i] = '0' + l + 1;

                                t[j] = '0' + m + 1;
                                t[p] = '0' + o + 1;
                               // cout << t << endl;
                                if (t <= a)
                                {
                                    ans++;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    else if (k == 2)
    {
        rep(i, len)
        {
            FOR(j, i + 1, len)
            {

                string t = s;
                rep(l, 9)
                {
                    rep(m, 9)
                    {

                        t[i] = '0' + l + 1;

                        t[j] = '0' + m + 1;
                      //  cout << t << endl;
                        if (t <= a)
                        {
                            ans++;
                        }
                    }
                }
            }
        }
    }
    else
    {
        rep(i, len)
        {

            string t = s;
            rep(l, 9)
            {

                t[i] = '0' + l + 1;

                //cout << t << endl;
                if (t <= a)
                {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}
int main()
{
    solve();
}

Measured memory_bytes: 256
H,W,K=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
import sys
input=sys.stdin.readline
L=[]
l=["@" for i in range(W+2)]
L.append(l)
for i in range(H):
    c=["@"]+list(input().rstrip())+["@"]
    L.append(c)
L.append(l)
L[x1][y1]=0
#print(L)
Q=[[x1,y1]]
for i in range(10**7):
    if i>=len(Q):
        break
    for j in range(1,K+1):
        if L[Q[i][0]+j][Q[i][1]]==".":
            L[Q[i][0]+j][Q[i][1]]=L[Q[i][0]][Q[i][1]]+1
            Q.append([Q[i][0]+j,Q[i][1]])
        elif L[Q[i][0]+j][Q[i][1]]==L[Q[i][0]][Q[i][1]]+1:
            continue
        else:
            break
    for j in range(1,K+1):
        if L[Q[i][0]-j][Q[i][1]]==".":
            L[Q[i][0]-j][Q[i][1]]=L[Q[i][0]][Q[i][1]]+1
            Q.append([Q[i][0]-j,Q[i][1]])
        elif L[Q[i][0]-j][Q[i][1]]==L[Q[i][0]][Q[i][1]]+1:
            continue
        else:
            break
    for j in range(1,K+1):
        if L[Q[i][0]][Q[i][1]+j]==".":
            L[Q[i][0]][Q[i][1]+j]=L[Q[i][0]][Q[i][1]]+1
            Q.append([Q[i][0],Q[i][1]+j])
        elif L[Q[i][0]][Q[i][1]+j]==L[Q[i][0]][Q[i][1]]+1:
            continue
        else:
            break
    for j in range(1,K+1):
        if L[Q[i][0]][Q[i][1]-j]==".":
            L[Q[i][0]][Q[i][1]-j]=L[Q[i][0]][Q[i][1]]+1
            Q.append([Q[i][0],Q[i][1]-j])
        elif L[Q[i][0]][Q[i][1]-j]==L[Q[i][0]][Q[i][1]]+1:
            continue
        else:
            break
if L[x2][y2]==".":
    print(-1)
else:
    print(L[x2][y2])
#print(L)

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

int main() {
   int N;
   cin >> N;
   vector<int> vec(N);
   for(int i = 0; i < N; i++){
       cin >> vec.at(i);
   }
   sort(vec.begin(),vec.end());
   
   cout << vec.at(N-1) - vec.at(0) << endl;
   
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;

int main() {
    vector<vector<int>>c(3,vector<int>(3));
    vector<int>a(3);
    vector<int>b(3);
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> c[i][j];
        }
    }
    a[0] = 0;
    for(int i = 0; i < 3; i++) {
        b[i] = c[0][i] - a[0];
    }
    for(int i = 1; i < 3; i++) {
        a[i] = c[i][0] - b[0];
    }
    bool ans = true;
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            if(a[i] + b[j] != c[i][j]) ans = false;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
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 FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
  int n,a; cin>>n>>a;
  VI x(n); rep(i,n) cin>>x[i];
  const int m = 50*n;

  ll dp[n+1][2*m+1];
  rep(i,n+1) rep(j,2*m+1) dp[i][j]=0;

  dp[0][m] = 1;
  reps(i,n) rep(j,2*m+1){
    dp[i][j] = dp[i-1][j];
    if(j-(x[i-1]-a)>0||j-(x[i-1]-a)<=2*m){
      dp[i][j] += dp[i-1][j-(x[i-1]-a)];
    }
  }
  cout << dp[n][m]-1 << endl;


  return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <cassert>
#pragma GCC optimize("O3")
#pragma comment(linker, "STACK:36777216")
using namespace std;
using i64 = int64_t;
constexpr i64 mod = 17;
using vi = vector<i64>;
using vvi = vector<vi>;
using ii = pair<i64, i64>;
using vii = vector<ii>;

char b[100][100];

bool isgoodrow(int i) {
    for (int j = 0; j < 100; j++) {
        if (b[i][j]) return true;
    }
    return false;
}

bool isgoodcolumn(int i) {
    for (int j = 0; j < 100; j++) {
        if (b[j][i]) return true;
    }
    return false;
}

int main() {
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char c;
            cin >> c;
            if (c == '#') {
                b[i][j] = 1;
            }
        }
    }
    for (int i = 0; i < 100; i++) {
        int k = 0;
        for (int j = 0; j < 100; j++) {
            if (isgoodrow(i) && isgoodcolumn(j)) {
                k = 1;
                if (b[i][j]) {
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
        }
        if (k) {
            cout << endl;
        }
    }
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

ll mod = 998244353;

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

  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int ta = c/b;
  if(c%b > 0)ta++;
  int ao = a/d;
  if(a%d > 0)ao++;

  if(ta <= ao)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e6+5;
int tab[5][5];

bool solve(){
	for(int i=1;i<=3;i++)
		for(int j=0;j<2;j++)
			if(tab[i][j]-tab[i-1][j]!=tab[i][j+1]-tab[i-1][j+1])
				return false;
	for(int j=1;j<=3;j++)
		for(int i=0;i<2;i++)
			if(tab[i][j]-tab[i][j-1]!=tab[i+1][j]-tab[i+1][j-1])
				return false;
	return true;
}

int main(){
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			cin >> tab[i][j];
	for(int j=0;j<3;j++){
		tab[3][j]=tab[0][j];
		tab[j][3]=tab[j][0];
	}
	cout << (solve() ? "Yes" : "No"); 
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

int main(){
    ll n,free=0,d[10];
    rep(i,10) d[i]=0;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) {
        cin>>a[i];
        if(a[i]<=399) d[0]++;
        else if(a[i]>=400 && a[i]<=799) d[1]++;
        else if(a[i]>=800 && a[i]<=1199) d[2]++;
        else if(a[i]>=1200 && a[i]<=1599) d[3]++;
        else if(a[i]>=1600 && a[i]<=1999) d[4]++;
        else if(a[i]>=2000 && a[i]<=2399) d[5]++;
        else if(a[i]>=2400 && a[i]<=2799) d[6]++;
        else if(a[i]>=2800 && a[i]<=3199) d[7]++;
        else free++;
    }
    ll sum=0;
    rep(i,10) if(d[i]>=1) sum++;
    cout<<(sum>=1 ? sum:1)<<" "<<sum+free<<endl;
    return 0;
}


Measured memory_bytes: 256
n, m, L = map(int, input().split())

a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
c = [[sum(ak * bk for ak, bk in zip(ai,bj)) for bj in zip(*b)] for ai in a]

for ci in c:
    print(*ci)


Measured memory_bytes: 6988
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n-1);
    rep(i,n-1) cin >> b[i];
    a[0] = b[0];
    a[n-1] = b[n-2];
    repSE(i,1,n-1) {
        a[i] = min(b[i-1],b[i]);
    }
    int ans = 0;
    rep(i,n) ans += a[i];
    cout << ans << "\n";
    return 0;
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            int[] A = Array.ConvertAll(Console.ReadLine().Trim().Split(' '), int.Parse);
            int q = int.Parse(Console.ReadLine());
            int[] m = Array.ConvertAll(Console.ReadLine().Trim().Split(' '), int.Parse);

            StringBuilder sb = new StringBuilder();

            for(int i = 0; i < q; i++)
            {
                bool[] dp = new bool[m[i] + 1];
                dp[0] = true;

                foreach (var num in A)
                {
                    for(int j = m[i]; j >= 0; j--)
                    {
                        if (dp[j] == false) continue;
                        if (j + num <= m[i] && dp[j + num] == false) dp[j + num] = true;
                    }
                    if (dp[m[i]] == true) break;
                }
                sb.AppendLine(dp[m[i]] ? "yes" : "no");
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9068
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int idx = 0;
    while(1) {
        if (idx >= n) break;
        cout << s[idx];
        idx += 2;
    }
    cout << endl;
    return 0;
}

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

int main(){
  int n;
  cin>>n;
  int l[222];
  for(int i=0;i<2*n;i++){
    cin>>l[i];
  }
  sort(l,l+2*n);
  int sum=0;
  for(int i=0;i<2*n;i++){
    if(i%2)continue;
    sum+=l[i];
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static long f(long x) {
        if (x==1) return 1;
        else return 2*f(x/2)+1;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        System.out.println(f(H));
    }
}

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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>

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

#define ic(n) int (n); cin>>(n);

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> P;

int main(){

	
string s;
		cin >>s;
		char a ;
		rep(i,3){
			if(s.at(i)=='1'){
			  a='9';
			  }
			  else{
				  a='1';
				}
			cout<<a;
		  }
  }

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll N;
  cin>>N;
  vector<ll> v(N);
  for(ll i = 0; i < N; i++) cin>>v[i];
  bool f = false;
  for(ll i = 0; i < N ; i++) {
    if(v[i]%2LL!=0) f=true;
  }
  if(f) cout<<"first"<<endl;
  else cout<<"second"<<endl;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, sum = 0;
  cin >> n;
  vector<int> vt(n);
  for (int i = 0; i < n; ++i) {
    cin >> vt[i];
    sum += vt[i];
  }

  int m;
  cin >> m;
  vector<pair<int, int>> vp(m);
  for (auto &p : vp) {
    cin >> p.first >> p.second;
    p.first--;
  }

  for (auto &p : vp) {
    cout << sum - (vt[p.first] - p.second) << '\n';
  }
}

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

int main() {
  int N, N1, N2, N3, N4;
  cin >> N;
  N1 = N / 1000;
  N2 = (N - N / 1000 * 1000) / 100;
  N3 = (N - N / 100 * 100) / 10;
  N4 = N - N / 10 * 10;
  if ((N1 == N2 && N2 == N3) || (N2 == N3 && N3 == N4)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main(){

    int n;
    int alice=0,bob=0;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a.at(i);

    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());

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

        if(i%2==0) alice+=a.at(i);
        else bob+=a.at(i);
    }

    cout<<alice-bob<<endl;










    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
 
int main()
{
	int n = 0, x = 0;
	std::cin >> n >> x;
	
	std::vector<int> l(n, 0);
	for (int i = 0; i < n; i++)
	{
		std::cin >> l[i];
	}
	
	int c = 0;
	int buf = 0;
	while(buf <= x)
	{
		buf += l[c];
		c += 1;
	}
	if (c >= n + 1)
	{
		c = n + 1;
	}
	
	std::cout << c << '\n';
	
	return 0;
} 

Measured memory_bytes: 256
from heapq import heapify, heappush, heappop
n, m = map(int, input().split())
a = list(map(lambda x: -int(x), input().split()))

heapify(a)

for _ in range(m):
    top = heappop(a)
    top = -top // 2
    heappush(a, -top)

print(-sum(a))

Measured memory_bytes: 20368
n=int(input())
a=[list(input().split())for i in range(n)]
#print(a)
total=0
for i in range(n):
    if a[i][1]=="JPY":
        total+=int(a[i][0])
    elif a[i][1]=="BTC":
        total+=float(a[i][0])*380000
print(total)


Measured memory_bytes: 3060
A, B, C, K = map(int, input().split())

ans = 0
if K < 0:
    print(ans)
    exit()

if A > 0:
    if K > A:
        ans += A
        K -= A
    else:
        ans += K
        K -= A
if K < 0:
    print(ans)
    exit()

if B > 0:
    K -= B
if K < 0:
    print(ans)
    exit()
    

if C > 0:
    if K > C:
        ans -= C
    else:
        ans -= K
print(ans)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
const int maxn=500005;
int p[maxn];
int w[maxn<<2];
int x[maxn];
void init(int id,int l,int r)
{
    if(l==r){
        w[id]=p[l];
        return ;
    }
    int mid=(l+r)>>1;
    init(id<<1,l,mid);
    init(id<<1|1,mid+1,r);
    w[id]=min(w[id<<1],w[id<<1|1]);
}
int Qw(int id,int l,int r,int tl,int tr)
{
    if(l==tl&&r==tr) return w[id];
    int mid=(l+r)>>1;
    if(tr<=mid) return Qw(id<<1,l,mid,tl,tr);
    else if(tl>mid) return Qw(id<<1|1,mid+1,r,tl,tr);
    else return min(Qw(id<<1,l,mid,tl,mid),Qw(id<<1|1,mid+1,r,mid+1,tr));
}
void up(int id,int l,int r,int v)
{
    if(l==r){
        w[id]=1e8;
        return;
    }
    int mid=(l+r)>>1;
    if(v<=mid) up(id<<1,l,mid,v);
    else up(id<<1|1,mid+1,r,v);
    w[id]=min(w[id<<1],w[id<<1|1]);
}
int q[maxn],top;
int sum[maxn<<2];
bool vis[maxn];
int ans[maxn];
void Debug(int id,int l,int r)
{
    if(l==r){
        printf("%d ",w[id]);
        return ;
    }
    int mid=(l+r)>>1;
    Debug(id<<1,l,mid);
    Debug(id<<1|1,mid+1,r);
}
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);k--;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x[i]);
        p[x[i]]=i;
    }
    init(1,1,n);
    top=0;
    memset(sum,0,sizeof(sum));
    memset(vis,0,sizeof(vis));
    int cnt=1;
    for(int i=1;i<=n;i++)
    {
        if(vis[i]) continue;
        q[top++]=i;
        while(top)
        {
            int i=q[top-1],tmp;
            up(1,1,n,x[i]);
            int t=Qw(1,1,n,1,x[i]);
//            printf("%d top %d  %d %d\n",top,t,i,x[i]);
//            Debug(1,1,n);
//            printf("\n");
            //scanf("%d",&tmp);
            if(t<=i+k){
                q[top++]=t;
                continue;
            }
            ans[cnt++]=i;
            top--;
            vis[i]=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        p[ans[i]]=i;
    }
    for(int i=1;i<=n;i++)
        printf("%d\n",p[i]);
    return 0;
}


Measured memory_bytes: 25472
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            var K = int.Parse(Console.ReadLine());
            var S = ReadLine();
            if(S.Length<=K)
            {
                WriteLine(S);
                return;
            }
                WriteLine(S.Substring(0,K)+"...");

        }

    }
}

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

int main(){
    int h, w, d; cin >> h >> w >> d;
    vector<ll> lis(h*w+1);
    for(int i = 0; i < h; i++){
        for(int l = 0; l < w; l++){
            int mid;
            cin >> mid;
            lis[mid] = i * 1000 + l; //i is x, l is y
        }
    }
    int q; cin >> q;
    vector<ll> ruiseki(h*w+1);
    for(int i = 0; i <= d; i++){
        ruiseki[i] = 0;
    }
    for(int i = d+1; i <= h*w; i++){
        ruiseki[i] = ruiseki[i-d] + abs(lis[i]/1000-lis[i-d]/1000)+abs(lis[i]%1000-lis[i-d]%1000);
        //cout << i << " " << ruiseki[i] << endl;
    }
    for(int i = 0; i < q; i++){
        int l, r; cin >> l >> r;
        cout << ruiseki[r] - ruiseki[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(1e9 + 7)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
const int N = 5005;

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);
	
	int n,k;
	cin >> n >> k;

	string st;
	cin >> st;

	int cnt = 0;
	repA(i,1,n-1) {
		if(st[i] != st[i-1])
			cnt++;
	}

	cout << n-1-max(0ll,cnt - 2*k) << '\n';
}

Measured memory_bytes: 512
import numpy as np
n = int(input())
a1 = np.array([int(i) for i in input().split()])
a2 = np.array([int(i) for i in input().split()])
ans = 0
for i in range(n):
  ans = max(ans,(a1[0:i+1].sum()+a2[i:].sum()))
print(ans)

Measured memory_bytes: 12436
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
const int N=1e5+100;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
struct P{ int a[3]; }p[N];
inline bool operator < (const P &a,const P &b) { return a.a[1]-a.a[0]<b.a[1]-b.a[0]; }
LL pre[N],suf[N];
inline void solve(LL *f,int n,int m,int t) {
	priority_queue<int,vector<int>,greater<int>>q;
	for (int i=1;i<=m;i++) f[m]+=p[i].a[t],q.push(p[i].a[t]-p[i].a[2]);
	for (int i=m+1;i<=n;i++) {
		f[i]=f[i-1]+p[i].a[2];
		if (p[i].a[t]-p[i].a[2]>q.top())
			f[i]-=q.top(),q.pop(),q.push(p[i].a[t]-p[i].a[2]),f[i]+=p[i].a[t]-p[i].a[2];
	}
}
int main()
{
	int x=gi(),y=gi(),z=gi(),i,n=x+y+z;
	LL ans=0;
	for (i=1;i<=n;i++) p[i].a[0]=gi(),p[i].a[1]=gi(),p[i].a[2]=gi();
	sort(p+1,p+1+n);
	solve(pre,n,x,0);
	reverse(p+1,p+1+n);
	solve(suf,n,y,1);
	reverse(suf+1,suf+1+n);
	for (i=x;i<=n-y;i++)
		ans=max(ans,pre[i]+suf[i+1]);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    int max = INT_MAX;
    vector<int> open;
    vector<int> num;
    vector< vector<int> > A;
    int N, M;
    cin >> N >> M;
    
    A.resize(N);
    open.resize(M);
    num.resize(M);
    fill( open.begin(), open.end(), 1 );
    
    for ( int i = 0; i < N; i++ ) {
        for ( int j = 0; j < M; j++ ) {
            int a;
            cin >> a;
            a--;
            A[i].push_back(a);
        }
    }
    
    for ( int i = M; i >= 1; i-- ) {
        
        fill( num.begin(), num.end(), 0 );
        
        for ( int j = 0; j < N; j++ ) {
            
            int k = 0;
            while( k < M ) {
                if ( open[ A[j][k] ] ) {
                    num[ A[j][k] ]++;
                    break;
                }
                k++;
            }
        }
        
        int x = 0;
        int m = 0;
        for ( int j = 0; j < M; j++ ) {
            if ( m < num[j] ) {
                x = j;
                m = num[j];
            }
        }
        
        max = min( max, m );
        open[x] = 0;
        
        // cout << x << endl;
        
    }
    
    
    
    cout << max << endl;
    
    return 0;
}

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

int main()
{
    int X, Y, Z;
    cin >> X >> Y >> Z;
    int tmp;
    tmp = X;
    X = Y;
    Y = tmp;

    tmp = X;
    X = Z;
    Z = tmp;

    cout << X << ' ' << Y << ' ' << Z; 

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

    int a, b,c;
    int temp;
    
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    
    if(0>a || 10000<a){
        return 0;
    }
    
    if(0>b || 10000<b){
        return 0;
    }
    
    if(0>c || 10000<c){
        return 0;
    }

    if(a<b && b<c){
        printf("%d %d %d\n",a,b,c);
    }else if(a<b && b>c){
        printf("%d %d %d\n",a,c,b);
    }else if(b<a && a<c){
        printf("%d %d %d\n",b,a,c);
    }else if(a<b && a>c){
        printf("%d %d %d\n",c,a,b);
    }else if(a>b && b<c){
        printf("%d %d %d\n",b,c,a);
    }else if(a>b && b>c){
        printf("%d %d %d\n",c,b,a);
    }else if(a==b && b<c){
        printf("%d %d %d\n",a,b,c);
    }else if(a==b && b<c){
        printf("%d %d %d\n",c,a,b);
    }else if(b==c && a>b){
        printf("%d %d %d\n",c,b,a);
    }else if(b==c && a<b){
        printf("%d %d %d\n",a,b,c);
    }
    return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
int main(void){ 
    int n; 
    scanf("%d",&n); 
    int a[200005]={0},s[200005]={0}; 
    for(int i=2;i<=n;i++)
      scanf("%d",&a[i]); 
    for(int i=2;i<=n;i++)
      s[a[i]]++; 
    for(int i=1;i<=n;i++)
      printf("%d\n",s[i]); 
  return 0;
}

Measured memory_bytes: 3268
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var h = sc.nextInt();
		var w = sc.nextInt();
		var m = sc.nextInt();
		var c1 = new int[h];
		var c2 = new int[w];
		var set = new HashSet<Long>();
		for (var i = 0; i < m; i++) {
			var h1 = sc.nextInt();
			var w1 = sc.nextInt();
			c1[h1 - 1]++;
			c2[w1 - 1]++;
			set.add((long) (h1 - 1) * w + w1 - 1);
		}
		sc.close();

		var result1 = 0;
		for (var i = 0; i < h; i++) {
			result1 = Math.max(result1, c1[i]);
		}
		var result2 = 0;
		for (var i = 0; i < w; i++) {
			result2 = Math.max(result2, c2[i]);
		}

		var list1 = new ArrayList<Integer>();
		for (var i = 0; i < c1.length; i++) {
			if (c1[i] == result1) {
				list1.add(i);
			}
		}
		var list2 = new ArrayList<Integer>();
		for (var j = 0; j < c2.length; j++) {
			if (c2[j] == result2) {
				list2.add(j);
			}
		}

		boolean check = false;
		if (list1.size() * list2.size() <= m) {
			for (var i : list1) {
				if (check) {
					break;
				}
				for (var j : list2) {
					if (!set.contains((long) i * w + j)) {
						check = true;
						break;
					}
				}
			}
		} else {
			check = true;
		}

		var result = result1 + result2 - (check ? 0 : 1);
		System.out.println(result);
	}
}


Measured memory_bytes: 89280
N, M = map(int, input().split())

store_list = {}
for _ in range(N):
  A, B = map(int, input().split())
  if A not in store_list:
    store_list[A] = 0
  store_list[A] += B
  
store_list = sorted(store_list.items(), key=lambda x:x[0])

ans = 0
for A,B in store_list:
  num = min(M, B)
  ans += A * num
  M -= num
  if M == 0:
    break

print(ans)

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

using namespace std;

int main()
{
    string s,t;
    cin >> s >> t;
    bool isSame = false;
    for(int i = 0; i < s.size(); ++i){
        string tmp(s, i, s.size());
        for(int j = 0; j < i; ++j) tmp += s[j];
        if(tmp == t){
            isSame = true;
            break;
        }
    }
    if(isSame)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
string s;
long long k,n,ans,dp[111][5][3];
int main()
{
	cin>>s>>k;
	n=s.size();
	dp[0][0][0]=1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=k;j++)
		{
			for(int o=0;o<2;o++)
			{
				for(int x=0;x<=9;x++)
				{
					int ni=i+1,nj=j,no=o;
					if(o==0)
					{
						if(x>(s[i]-'0'))
						{
							continue;
						}
						else if(x<(s[i]-'0'))
						{
							no=1;
						}
					}
					if(x!=0)
					{
						nj++;
					}
					dp[ni][nj][no]+=dp[i][j][o];
				}
			}
		}
	}
	cout<<dp[n][k][0]+dp[n][k][1]<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import  deque
import sys
import bisect
# import math
import itertools
from queue import deque
# from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

# def lcm(x, y): return (x * y) // gcd(x, y)

N = inp()
A = [0 for _ in range(N)]
xx = [[] for _ in range(N)]
yy = [[] for _ in range(N)]

for i in range(N):
    A[i] = inp()
    for _ in range(A[i]):
        x, y = inp_list()
        xx[i].append(x)
        yy[i].append(y)

# ↑ inputs
# ↓ main process

honest_count = 0
# {0, 1, ..., N-1} の集合の bit 全探索
ans = 0
for bit in range(1 << N):
    """
        例： bit == 10 のとき、2進数では 001010 
            右から人 1, 2, ..., 6 と対応させる。
    """
    ok = True
    is_honest = [(bit >> i) & 1 for i in range(N)] # bit を 1 右にシフトさせたものの2^0の位が1なら True
    for i in range(N):
        if not is_honest[i]: continue
        for (x, y) in zip(xx[i], yy[i]):
            if is_honest[x - 1] != y:
                ok = False
    if ok:
        ans = max(ans, sum(is_honest))
print(ans)


Measured memory_bytes: 3944
const input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/);
input.pop();

 for (let i = 0; i < input.length; i++) {
     let [m, f, r] = input[i].split(' ').map(Number);
     let exam = m + f;
     if (m === -1 && f === -1 && r === -1) {
         break;
     } else if (m === -1 || f === -1) {
          console.log('F');
     } else if (exam >= 80) {
          console.log('A');
     } else if (80 > exam && exam >= 65) {
          console.log('B');
     } else if (65 > exam && exam >= 50) {
         console.log('C');
     } else if (50 > exam && exam >= 30 && r >= 50) {
         console.log('C');
     } else if (50 > exam && exam >= 30 && r < 50) {
         console.log('D');
     } else if (30 > exam) {
         console.log('F');
     }
 }
 


Measured memory_bytes: 15208
#include<iostream>
#include<string>
using namespace std;
char change(int zurasi,char a)
{
	int x;
	x = ((int)(unsigned char)a - 65
		+ zurasi) % 26;
	return (char)(x+65);
}

 int main()
{
	int zurasi;
	int i, j, k = 0;
	cin >> zurasi;
	string S;
	cin >> S;
	for (j = 0;j < S.size();j++)
	{
		S[j] = change(zurasi, S[j]);
	}
	cout << S <<endl ;
	return 0;
}

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

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
using vvl = vector<vl>;
using pll = pair<ll,ll>;
using vb = vector<bool>;

const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define xx first
#define yy second

#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define FORD(i,a,b) for (int i=int(b)-1; i>=(a); i--)

#define rv(type,name,count) vector<type> name(count); FOR(_i,0,count) cin >> name[_i];
#define grid(type,name,c1,c2) vector<vector<type>> name(c1, vector<type>(c2)); FOR(_i,0,c1)FOR(_j,0,c2)cin >> name[_i][_j];

int main() {
	string s;
	cin >> s;
	vector<int> nextl(s.size()), nextr(s.size());
	FORD(i,0,s.size()) nextl[i] = s[i]=='L' ? i : nextl[i+1];
	FOR(i,0,s.size()) nextr[i] = s[i]=='R' ? i : nextr[i-1];
	vl res(s.size());
	FOR(i,0,s.size())
		if (s[i] == 'L') {
			ll x = nextr[i];
			if ( (i - x) % 2 == 1) x++;
			res[x]++;
		} else {
			ll x = nextl[i];
			if ( (x - i) % 2 == 1) x--;
			res[x]++;
		}
	FOR(i,0,s.size()) cout << res[i] << " ";
	cout << endl;
}


Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

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

  vector<int> h(n);
  for(auto &x : h) cin>>x;
  h.pb(0);
  n++;
  int res=0;
  for(int i=0;i<n;i++){
    int tmp=111;
    int l;
    l=0;
    for(int j=0;j<n;j++){
      if(h[j]==0&&tmp==111){
        l++;
      }
      else if(h[j]==0){
        //printf("%d -> %d : ",l,j);
        for(int m=l;m<j;m++){
          h[m]-=tmp;
        }
        l=j+1;
        res+=tmp;
        tmp=111;
      }
      else{
        tmp=min(tmp,h[j]);
      }
    }
    //for(auto x : h) cout<<x<<" ";cout<<endl;
  }
  cout<<res<<endl;

  return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int sheep = in.nextInt();
        int wolves = in.nextInt();
        System.out.println(sheep <= wolves ? "unsafe" : "safe");
    }
}

Measured memory_bytes: 35940
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        io.r<int>();
        string[] n = io.r<string>(' ');
        io.w(string.Join(" ", n.Reverse().ToArray()));
        io.wflush();
    }
}

namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
    public class memo<Key, Result>
    {
        private Dictionary<Key, Result> R;
        public memo() { R = new Dictionary<Key, Result>(); }
        public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }
    }
}

Measured memory_bytes: 10200