akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        // ans: 二分木の頂点数の最大値(但し、深さiにA[i]個だけ葉がある)
        long ans = 0;
        
        // ・言い換え
        // 深さiにおける頂点数(count[i])の最大値を考える。
        
        // 下から見る時、count[i]はarray[i]個だけ増やせる
        // -> count[i]のmax = arrayの後ろからの累積和。
        // 上から見る時、頂点数は葉を引いた数の2倍にできる
        // <- オーバーフローしそう。 (深さの最大値は10^5)
        // -> 上から見るのを都度、下からのmaxでカットしてやる。
        
        int n = sc.nextInt();
        // array[i]: 深さiの葉の個数
        int[] array = new int[n+1];
        for (int i = 0; i < n+1; i++) {
            array[i] = sc.nextInt();
        }
        
        // sum[i]: 下から見たときのcount[i]の最大値
        long[] sum = new long[n+1];
        sum[n] = array[n];
        for (int i = n-1; i >= 0; i--) {
            sum[i] = sum[i+1] + array[i];
            
        }
        // System.out.println(Arrays.toString(sum));
        
        // count[i]: 深さiにおける頂点数
        long[] count = new long[n+1];
        long now = 1;
        for (int i = 0; i < n+1; i++) {
            // 葉を引いた数の2倍にしたいが、
            // sum[i]が上限ならそれにする
            count[i] = Math.min(sum[i], now);
            
            // 次見るときは葉を引いた数の2倍にする
            now = count[i] - array[i];
            if (now < 0) {
                System.out.println(-1);
                return;
            }
            now *= 2;
        }
        
        for (int i = 0; i < n+1; i++) {
            ans += count[i];
        }
        System.out.println(ans);
        
    }
}

Measured memory_bytes: 59200
def main():
  n,m,q = map(int,input().split())
  
  a = [1]*n
    
  a_list = []
  while True:
    a_list.append([0, a[:]])
    end = True
    for i in range(n):
      index = n-1-i
      if a[index] < m:
        a[index] = a[index] + 1
        for j in range(i):
          a[index+1+j] = a[index]
        end = False
        break
    
    if end:
      break
  
  for _ in range(q):
    tmp = list(map(int, input().split()))
    for a in a_list:
      if a[1][tmp[1]-1] - a[1][tmp[0]-1] == tmp[2]:
        a[0] = a[0] + tmp[3]
  
  max = 0
  for a in a_list:
    if max < a[0]:
      max = a[0]
  
  return max

print(main())

Measured memory_bytes: 99292
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
//#define repitr(itr, st) for(auto itr = st.begin(); itr != st.end(); ++itr)
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define M_P make_pair
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl
//#define print(x) printf("%d\n", x)

using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
//const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;
//int:±2*10^9くらい　ll:±9*10^18くらい



void Main(){
	int N;
	cin >> N;
	vector<pair<string, int> > a(N);
	map<int, int> M;
	rep(i, N){
		string S;
		int P;
		cin >> S >> P;
		P = 100 - P;
		a[i] = (M_P(S,P));
		M[P] = i+1;
	}
	sort(all(a));
	rep(i, N){
		cout << M[a[i].se] << endl;
	}




}

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

  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
  string s;
  cin >> s;

  int res = 1000000;
  for (int i = 2; i < s.size(); ++i) {
    int x = 100 * (s[i - 2] - '1' + 1) + 10 * (s[i - 1] - '1' + 1) + (s[i] - '1' + 1);
    res = min(res, abs(753 - x));
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1212030],v[1000005];
int main()
{
    ll i,ans=0,ans2,w,t,flag=0,n,k,N,x,q,c,b,j;
    scanf("%lld",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%lld",&a[i]);
    }
    ans2=a[1];
    for(i=2; i<=n; i++)
    {
        ans2^=a[i];
        //swap(a[i],a[i+1]);
    }
    for(i=1; i<=n; i++)
    {
        ans=ans2;
        ans^=a[i];
        printf("%lld\n",ans);
    }
// printf("%c",N+'a'-1);



}


Measured memory_bytes: 5248
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

LL n, x;
LL a[101010];
LL b[101010];
int main() {
	cin >> n >> x;
	REP(i, n) {
		cin >> a[i];
		b[i] = a[i];
	}
	LL ans = INF<LL>();
	REP(i, n) {
		LL sum = x*i;
		REP(j, n)sum += b[j];
		ans = min(ans, sum);
		REP(j, n) {
			int k = (j - i - 1 + n) % n;
			b[j] = min(b[j], a[k]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
ans=0
currentpower=0
for i in range(1,n+1):
  if i>=10**(currentpower+1):
    currentpower+=1
  b=i%10
  a=(i-i%(10**currentpower))//(10**currentpower)
  if b==0:
    continue
  if a==b:
    ans+=1
    if currentpower>0:
      ans+=2
    r=max(0,((i-(a*(10**currentpower))-b)//10))
    ans+=2*r
    for j in range(0,currentpower-1):
      ans+=2*(10**j)
  elif a<b:
    for j in range(0,currentpower-1):
      ans+=2*(10**j)
  else:
    for j in range(0,currentpower):
      ans+=2*(10**j)
print(ans)

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\contests\\stdout", "w", stdout);
    }

    int N;
    cin >> N;
    vector<pii> A(N);

    FOR(i, N) {
        cin >> A[i].first;
        A[i].second = i+1;
    }
    sort(A.begin(), A.end());
    FOR(i, N)
        cout << A[i].second << " ";

    if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define mod 1000000009
#define int long long
#define garou ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int pow(int p,int r){
	int ans=1;
	while(r>0){
     if(r&1){
		 ans=((ans%mod)*(p%mod))%mod;
	 }
	 r=r>>1;
     p=((p%mod)*(p%mod))%mod;
	}
	return ans;
}
signed main() {
	 garou;
	 int l,r,d;
	 cin>>l>>r>>d;
	 int re=0;
	 for(int i=l;i<=r;i++){
		 if(!(i%d))
		 re++;
	 }
	 cout<<re;

}

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

int main() {
  char C;
  cin >> C;
  
  C = C+1;
  
  cout << C << endl;
  
  
  return 0;
}

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

#define all_of(x) std::begin(x), std::end(x)
#ifdef _GLIBCXX_DEBUG
    #define debug(x) cerr << #x << ": " << x << endl
#else
    #define debug(x) 
#endif

using namespace std;

using LL = long long;

template<typename T>
ostream& operator << (ostream& out, const vector<T>& v) {
    out << "[";
    for(const auto& x : v) {
        out << x << ", ";
    }
    return out << "]";
}
template<typename T>
istream& operator >> (istream& in, vector<T>& v) {
    for(auto& x : v) {
        in >> x;
    }
    return in;
}

template<typename S, typename T>
ostream& operator << (ostream& out, const pair<S, T>& p) {
    return out << "{" << p.first << ", " << p.second << "}";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    cin >> A >> B;
    vector<int> s(N + 1);
    for(int i = 0; i < N; ++i) {
        auto [b, e] = equal_range(all_of(B), A[i]);
        if(b == e) {
            continue;
        }
        int r = (i - int(b - B.begin()) + N) % N;
        int l = (i - int(e - B.begin()) + N) % N;
        if(l < r) {
            s[l + 1] += 1;
            s[r + 1] -= 1;
        } else {
            s[0] += 1;
            s[r + 1] -= 1;
            s[l + 1] += 1;
            s[N] -= 1;
        }
        debug(l);
        debug(r);
        debug(s);
    }
    debug(s);
    for(int n = 0; n < N; ++n) {
        s[n + 1] += s[n];
        if(s[n] == 0) {
            cout << "Yes\n";
            rotate(B.begin(), B.end() - n, B.end());
            for(auto b : B)  {
                cout << b << " ";
            }
            cout << "\n";
            return 0;
        }
    }
    debug(s);
    cout << "No\n";
    
    
    
    return 0;
}


Measured memory_bytes: 5568
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz size()
#define endl "\n"
#define ll long long int
#define llu unsigned long long int
#define freverse(str) reverse(str.begin(),str.end())
#define Allah_Hafez return 0;
void solve(){
    int N,ne=1000;
    cin>>N;
    if(N%ne==0)
    {
        cout<<"0"<<endl;
    }
    else
    {
        while(N>=ne)
        {
            ne+=1000;
        }
        cout<<ne-N<<endl;
    }
}
int main(){
    int T=1;
    //cin>>T;
    while(T--)solve();
    Allah_Hafez;
}




Measured memory_bytes: 3628
#include <cstdio>
#include <complex>
#include <vector>

using namespace std;

typedef complex<double> Vector;

double cross(const Vector &v1, const Vector &v2) {
    return v1.real()*v2.imag() - v1.imag()*v2.real();
}

int main() {
    vector<Vector> v;
    double X, Y;
    while(scanf("%lf,%lf", &X, &Y) != -1) {
        v.push_back(Vector(X, Y));
    }
    const int N = v.size();
    double area = 0;
    for(int i = 0; i < N; ++i) {
        const int next = (i+1) % N;
        area += fabs(cross(v[i], v[next]));
    }
    printf("%f\n", area/2);
    return 0;
}

Measured memory_bytes: 1084
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#include<string>
#include<cmath>
#include<tuple>
#define INF 1111111
using namespace std;
typedef pair<int,int> P;
typedef tuple<int,int,int> tup;
typedef long long ll;

int main() {
  int h,w;
  cin >> h >> w;
  char map[110][110] = {};
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      cin >> map[i][j];
  int erase[110][110] = {};
  
  for(int i=0;i<h;i++){
    bool flag = true;
    for(int j=0;j<w;j++){
      if(map[i][j] == '#')
        flag = false;
    }
    if(flag){
      for(int j=0;j<w;j++)
        erase[i][j] = 1;
    }
  }
  
  for(int j=0;j<w;j++){
    bool flag = true;
    for(int i=0;i<h;i++){
      if(map[i][j] == '#')
        flag = false;
    }
    if(flag){
      for(int i=0;i<h;i++)
        erase[i][j] = 1;
    }
  }
  
   for(int i=0;i<h;i++){
      bool flag = false;
    for(int j=0;j<w;j++){
      if(erase[i][j] == 0){
      cout << map[i][j];
      flag = true;
      }
    }
     if(flag)
     cout << endl;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
int X[maxn];
LL P[maxn];

int main() {
    int N, S;
    scanf("%d %d", &N, &S);
    for(int i = 1; i <= N; ++i) scanf("%d %lld", X + i, P + i);
    int p1 = 1, p2 = N, d = 0;
    LL ans = 0;
    while(1){
        if(X[p1] >= S) {ans += X[p2] - S; break;}
        if(X[p2] <= S) {ans += S - X[p1]; break;}
        if(P[p1] < P[p2]) {
            if(d != -1) ans += X[p2] - X[p1], d = -1;
            P[p2] += P[p1], p1++;
        }
        else {
            if(d != 1) ans += X[p2] - X[p1], d = 1;
            P[p1] += P[p2], p2--;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1408
import java.io.PrintWriter;
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int[] price = new int[n];
        int[][] books = new int[n][m];

        for (int i = 0; i < n; i++) {
            price[i] = sc.nextInt();
            for (int j = 0; j < m; j++) {
                books[i][j] = sc.nextInt();
            }
        }

        int min = Integer.MAX_VALUE;
        for (int bit = 0; bit < (1 << n); bit++) {
            Set<Integer> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                if ((bit & (1 << i)) != 0) {
                    set.add(i);
                }
            }

            int[] arr = new int[m];
            int p = 0;
            for (int i : set) {
                p += price[i];
                for (int j = 0; j < m; j++) {
                    arr[j] += books[i][j];
                }
            }

            boolean isOk = true;
            for (int i = 0; i < m; i++) {
                if (arr[i] < x) {
                    isOk = false;
                    break;
                }
            }

            if (isOk) {
                min = Math.min(min, p);
            }
        }
        System.out.println(min == Integer.MAX_VALUE ? -1 : min);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 40228
#include<bits/stdc++.h>
#define ll long long

const ll mod = 1000000007 ;

using namespace std ;

int main()
{
	string n;
	cin>>n;
	int sum = 0 ;
	for(int i=0 ;i<n.length() ; i++)
	{
		sum+=(n[i]-(int)'0');
	}
	if(sum%9==0)
		cout<<"Yes"<<"\n";
	else
		cout<<"No"<<"\n";
}


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

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)

int main(void){
    int N; cin >> N;
    int a[N+10];
    rep(i, N)cin >> a[i];

    sort(a,a + N);
    map<int,int> mp;
    rep(i, N)mp[a[i]]++;

    int diameter = *max_element(a, a + N);
    int ok;
    rrrep(i, diameter, diameter / 2){
        ok = i;
        if(diameter % 2 == 0){
            if(i == diameter / 2){
                if(mp[i] <= 0){
                    cout << "Impossible" << "\n";
                    return 0;
                }
                mp[i] -= 1;
                break;
            }
        }
        else{
            if(i == diameter / 2){
                ok++;
                break;
            }
        }
        if(mp[i] <= 1){
            cout << "Impossible" << "\n";
            return 0;
        }
        mp[i] -= 2;
    }

    rrep(i, ok + 1, a[N - 1] + 1){
        mp[i] = 0;
    }

    rrep(i, 1, N + 10){
        if(mp[i] != 0){
            cout << "Impossible" << "\n";
            return 0;
        }
    }
    
    cout << "Possible" << "\n";
    return 0;
}


Measured memory_bytes: 256
//b棟f階のr番目の部屋にv人が追加で入居したことを示します。vが負の値の場合、v人退去したことを示します。 

import java.util.Scanner;

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

        int n = sc.nextInt();
        
        int [][][] bill = new int[4][3][10];
        
        int b ;
        int f ;
        int r ;
        int v = 0;
        
        for( int i = 0 ; i < n ; i++ ){
	        
	        b = sc.nextInt();//棟
	        f = sc.nextInt();//階
	        r = sc.nextInt();//番目
	        v = sc.nextInt();//人数
	        
	        bill[b-1][f-1][r-1] = bill[b-1][f-1][r-1] + ( v );
	        
	        /*for(int j = 0 ; j < 4 ; j++ ){
	        	for( int k = 0 ; k < 3 ; k++ ){
	        		for( int l = 0 ; l < 10 ; l++ ){
	        			
	        			if( bill[j][k][l] != v){
	        				bill[j][k][l] = 0;
	        			}
	        		}
	        	}
	        }*/  
        }
	        
        for(int j = 0 ; j < 4 ; j++ ){
        	for( int k = 0 ; k < 3 ; k++ ){
        		for( int l = 0 ; l < 10 ; l++ ){
        			
        			
        			System.out.print(" " + bill[j][k][l]);
        			
        		}
        		System.out.println();
        	}
        	if( j != 3){
        	System.out.println("####################");
        	}
        }     
    }
}

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

void dfs(string s, char mx){
    if(s.length() == N){
        cout << s <<endl;
    }else{
        for (char c = 'a'; c <= mx; c++) {  //char型の比較は辞書順
            dfs(s+c, ((c==mx) ? (char)(c+1) : mx)); //s_iが最大値mxの時, s_{i+1}が取りうる最大値はmx+1
        }
    }
}

int main() {
    cin >> N;
    dfs("",'a');
    return 0;
}

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

int main() {
  int N;
  int l;
  int r;
  int SUM = 0;
  
  cin >> N;
  for (int i = 0; i<N; i++){
    cin >> l >> r; 
    SUM += r - l + 1;
  }
  cout << SUM;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
const int N=5050;
inline ll qpow(ll x,ll y,ll ans=1){
	for(;y;y>>=1,x=x*x%mod) if(y&1) ans=ans*x%mod;
	return ans;
}
int n,siz[N];
ll ans,js[N],f[N][N],tmp[N];
vector<int> g[N];
void dfs(int x,int fa){
	siz[x]=1; f[x][1]=1;
	for(int i=0;i<g[x].size();++i) if(g[x][i]!=fa){
		int y=g[x][i];
		dfs(y,x);
		for(int j=1;j<=siz[y];++j){
			for(int k=1;k<=siz[x];++k){
				(tmp[j+k]+=f[x][k]*f[y][j])%=mod;
				if(~j&1) (tmp[k]-=f[x][k]*f[y][j]%mod*js[j])%=mod;
			}
		}
		siz[x]+=siz[y];
		for(int j=1;j<=siz[x];++j) f[x][j]=tmp[j],tmp[j]=0;
	}
}
int main(){
	cin>>n; js[0]=1;
	for(int i=2;i<=n;i+=2) js[i]=js[i-2]*(i-1)%mod;
	for(int i=1,x,y;i<n;++i) cin>>x>>y,g[x].push_back(y),g[y].push_back(x);
	dfs(1,0);
	for(int i=2;i<=n;i+=2) (ans+=js[i]*f[1][i])%=mod;
	cout<<(ans%mod+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 92868
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder s = new StringBuilder(sc.next());
        int ans = 0;
        while (s.length() > 0) {
            if (s.charAt(0) == s.charAt(s.length() - 1)) {
                s.deleteCharAt(s.length() - 1);
                if (s.length() == 0) {
                    break;
                }
                s.deleteCharAt(0);
            } else {
                if (s.charAt(0) == 'x') {
                    s.append('x');
                    ans++;
                } else if (s.charAt(s.length() - 1) == 'x') {
                    s.insert(0, 'x');
                    ans++;
                } else {
                    System.out.println(-1);
                    return;
                }
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 28036
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#endif

using namespace std;


typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) {
  v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t) {
  stringstream ss;
  ss << f;
  ss >> t;
}


#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back


#define MOD 1000000007LL
#define EPS 1e-8

int main() {
  string s;
  cin >> s;
  replace(s.begin(), s.end(), ',', ' ');
  cout << s << endl;
  return 0;
}

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


public class Main{
    static long []pre1;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        // Start writing your solution here. -------------------------------------
        long MOD = 1000000007;
        //int t = sc.nextInt();
        int t = 1;
        Main sol = new Main();
        while(t -- > 0)
        {
            long n = sc.nextLong(), k = sc.nextLong(), res = 0;
            for(long i = k; i <= n + 1; i++)
                res += (n - i + 1) * i + 1;
            out.println(res % MOD);
            //for(int ii = 0; ii <= n; ii++) System.out.println(Arrays.toString(dp[ii]));
        }
        out.close();
    }
    public static Long solve(Long[] a, int k){
        int n = a.length;
        long res = pre1[n] - 2 * pre1[k + 1];
        Long a1[] = new Long[k + 1];
        Long a2[] = new Long[n - k - 1];
        for(int i = 0; i <= k; i ++) a1[i] = a[i];
        for(int i = k + 1; i < n; i ++) a2[i - k - 1] = a[i];
        Arrays.sort(a1);
        Arrays.sort(a2);
        int tmp1 = n - k - 1, tmp2 = n - k - 2;
        for(int i = 0; i <= k; i ++) res += (tmp1 + i) * a1[i];
        for(int i = 0; i < n - k - 1; i ++) res -=  (tmp2 - i) * a2[i];
        return res;
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    //--------------------------------------------------------
}

Measured memory_bytes: 33048
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number_input = Integer.parseInt(sc.next());
    int number_upper = number_input / 100;
    int number_lower = number_input % 100;
    if((1 <= number_upper && number_upper <= 12) && (1 <= number_lower && number_lower <= 12)) {
      System.out.println("AMBIGUOUS");
    } else if(1 <= number_upper && number_upper <= 12) {
      System.out.println("MMYY");
    } else if(1 <= number_lower && number_lower <= 12) {
      System.out.println("YYMM");
    } else {
      System.out.println("NA");
    }
  }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main()
{
    lli n,k;
    cin>>n>>k;
    vector<lli> a(n),multi;
    lli mul=0;
    for(lli i=0;i<n;i++)
    {
        cin>>a[i];
    }

    for(lli i=0;i<n;i++)
    {
        if(i>=(k-1))
        {
            if(i+1<n && a[i-(k-1)]<a[i+1])
            { 
                cout<<"Yes"<<"\n";
            }else if(i+1<n)
            {
                cout<<"No"<<"\n";
            }
            
        }
    }

    return 0;
    
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define debug(...)
#endif
#define FOR(i,a,b) 	for(ll i=a;i<b;++i)
#define RFOR(i,a,b) 	for(int i=a;i>=b;--i)
#define ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
#define init(a, x) memset(a,x,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
// ordered_set X
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
const int L=1e7+7;
ll dp[L], cur;
bool solve(ll n)
{
	if(n == 1)return 1;
	if(n < cur)return 0;
	if(n%cur == 0)return solve(n/cur);
	else return solve(n%cur);

}
void fff()
{
	ll n;
	cin >> n;
	set<ll> v;
	ll tmp = sqrt(n) + 1;
	FOR(i,1,tmp)
	{
		if(n%i == 0)
		{
			v.insert(i);
			if(n != i*i)v.insert(n/i);
		}
	}	
	tmp = sqrt(n-1) + 1;
	FOR(i,1,tmp)
	{
		if((n-1)%i == 0)
		{
			v.insert(i);
			if(n != i*i)v.insert((n-1)/i);
		}
	}	
	v.erase(1);
	init(dp,-1);
	ll ans = 0;
	trace(v,x)
	{
		cur = x;
		// debug(cur, solve(n));
		ans += solve(n);
	}
	cout<<ans<<ln;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//int t;cin >> t;while(t--)
	fff();
	return 0;
}

Measured memory_bytes: 78720
import java.util.*;
    import java.io.*;
    class Program{
     
    }
    class Main{
        public static void main(String args[]) throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(), count = 0,M = sc.nextInt(), C = sc.nextInt(),sum = C;
        int B[] = new int[M], A[] = new int[M];
        //System.out.println(N+" "+M+" "+C);
        for(int i = 0;i < M; i++) B[i] = sc.nextInt();
        for(int m = 0;m<N;m++){
            for(int i = 0; i<M;i++)A[i] = sc.nextInt();
            sum = C;
            for(int i = 0; i<M;i++)sum+=A[i]*B[i];
            if (sum>0) count++;
            }
        System.out.println(count);
        }
    }

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

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            //

            var N = GetInt();
            var A = GetIntArray();

            var memo = Enumerable.Repeat(0, (int)Math.Pow(10, 5) + 2).ToArray();
            foreach(var a in A)
            {
                memo[a]++;
                memo[a + 1]++;
                memo[a + 2]++;
            }
            var ans = memo.Max();

            Console.WriteLine(ans);

            //
            Console.Out.Flush();
            Console.ReadKey();
        }

        static void Solve()
        {

        }





        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c, out V d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<V>(ar[3]);
        }
    }
}

Measured memory_bytes: 19552
#include <stdio.h>
int main(void){
	int n, m, s[5], c[15],i, j, a[4]={};
  a[0]=1;

  scanf("%d %d",&n, &m);
  
    if(m==0&&n==1){
    a[0]=0;
  }
	
	for(i=0; i<m;i++){
		scanf("%d %d", &s[i], &c[i]);
	}
	for(i=0; i<m;i++){
		for(j=0; j<m; j++){
			if(s[i]==s[j]){
				if(c[i]!=c[j]){
					printf("-1\n");
					return 0;
				}
			}
		}
	}
	for(i=0; i<m;i++){
		if(s[i]==1){
			a[0]=c[i];
		}
		if(s[i]==2){
			a[1]=c[i];
		}
		if(s[i]==3){
			a[2]=c[i];
		}
	}
  
  if(a[0]==0 && n==1){
    printf("0\n");
    return 0;
  }
  if(a[0]==0){
    					printf("-1\n");
					return 0;
				}
    
	for(i=0;i<n;i++){
		printf("%d", a[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
import sys

def main():
    input = sys.stdin.readline

    MOD = pow(10, 9) + 7

    n, k = map(int, input().split())
    A = sorted(map(int, input().split()))
    B = A[::-1]
    fact = [1]
    for i in range(1, n+1):
        fact.append((fact[i-1]*i)%MOD)
    now = k-2
    S = []
    while now <= n-2:
        tmp = ((fact[now] % MOD * pow(fact[now-(k-2)], MOD-2, MOD)) % MOD * pow(fact[k-2], MOD-2, MOD)) % MOD
        S.append(tmp)
        now += 1
    cumsum = [0, ]
    for i, s in enumerate(S):
        cumsum.append((cumsum[i]+s) % MOD)
    ans = 0
    for i, a in enumerate(A):
        ans = (ans - a*cumsum[-(i+1)])%MOD
        if cumsum[-(i+1)] == 0:
            break
    for i, b in enumerate(B):
        ans = (ans + b*cumsum[-(i+1)])%MOD
        if cumsum[-(i+1)] == 0:
            break
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62632
a = []
13.times do |i|
  a << ["S", i+1]
end
13.times do |i|
  a << ["H", i+1]
end
13.times do |i|
  a << ["C", i+1]
end
13.times do |i|
  a << ["D", i+1]
end

n = gets.to_i
n.times do
  h = gets.split
  h[1]=h[1].to_i
  a.delete(h) if a.include?(h)
end
a.size.times do |i|
  puts "#{a[i][0]} #{a[i][1]}"
end


Measured memory_bytes: 6876
import math

N,K=map(int,input().split())
ans=0
ans2=0
if K%2==1:
    for i in range(1,N+1):
        if i%K==0:
            ans+=1


else:
    for i in range(1,N+1):
        if i%K==0 :
            ans+=1
        if i%K==K/2:
            ans2+=1


print(ans**3+ans2**3)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define eps 1e-3
#define pi acos(-1.0)
#define inf 0x3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define debug1 cout<<"&&";
#define debug2 cout<<"**";
#define ms(a, x) memset(a, x, sizeof(a))
#define for0(i, n) for(int i = 0; i < n; ++i)
#define for1(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, int> pli;
typedef pair<long long, long long> pll;
const int mod = 1e9 + 7;
const int N = 21;
const int M = 3e6 + 10;
/*=================================================================================*/

int n, mp[N][N];
ll dp[M];

int main() {
   cin>>n;
   for0(i, n) for0(j, n) {
      scanf("%d", &mp[i][j]);
   }
   dp[0] = 1;
   for0(i, (1<<n)) {
      int cnt = 0;
      for0(j, n) {
         if((i >> j) & 1) {
            cnt++; // 记录已经匹配完成的人数
         }
      }
      cnt--;
      for0(j, n) {
         if(mp[cnt][j] && (i & (1<<j))) {
            dp[i] = (dp[(1<<j)^i] + dp[i]) % mod;
            // debug1 printf("%d %d %d %d\n", i, j, mp[cnt][j], cnt);
         }
      }
   }
   cout<<dp[(1<<n)-1]<<endl;
}

Measured memory_bytes: 20048
# coding: utf-8
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = [0] * (N+1)
ans = 1
for i in range(1, N+1):
    D[i] = D[i-1] + L[i-1]
    if D[i] <= X:
        ans += 1
print(ans)

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

lli h, w;

int main(void){
	cin >> h >> w;
	lli c = 0;
	rep(i, h){
		string s;
		cin >> s;
		rep(j, s.size()){
			if(s[j] == '#') c++;
		}
	}
	if(c == h+w-1) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}


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

#define int long long int
#define ull unsigned long long int
#define for0(i, n) for (int i = 0; i < (int)(n); i++) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); i++) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); i++) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; i--) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; i--) // reverse 1 based


#define pb push_back
#define fi first
#define se second

#define I_max (int)1e9+7
#define size6 (int)1e6


#define all(x) (x).begin(), (x).end() 
#define rall(x) (x).rbegin, (x).rend() 
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define sz(a) int((a).size())


using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef double ld;

//-----------------------------------------------------------------------------------END-------------------------------------------------------------------------------------//

int a[size6];


bool inc(vi vec){
	for1(i,vec.size()-1){
		if(vec[i]<vec[i-1])return 0;
	}
	return 1;
}


void solve(){
	int n;cin>>n;
    string ac="AC",wa="WA",tle="TLE",re="RE";
	int a=0,w=0,t=0,r=0;

	while(n--){
		string temp;cin>>temp;
		if(temp==ac)a++;
		else if(temp==wa)w++;
		else if(temp==tle)t++;
		else if(temp==re)r++;
	}  

	cout<<"AC x "<<a<<'\n';
	cout<<"WA x "<<w<<'\n';
	cout<<"TLE x "<<t<<'\n';
	cout<<"RE x "<<r<<'\n';
}



int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout.precision(10);
	//cout << fixed;
	//int tt;cin>>tt;
	//while(tt--){
		solve();
	//}
	return 0;
}




Measured memory_bytes: 3592
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        int N = sc.nextInt();
        System.out.println(N+N*N+N*N*N);
    }

    public static void main(String[] args) {
        new Main();
    }
}


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

int main()
{
    int W,H,X,Y;
    cin >> W >> H >> X >> Y;
    int flag = 0;
    if((double)W/2 == (double)X && (double)H/2 == (double)Y) flag = 1;
    double ans = (double)W*H/2;
    printf("%.10lf %d\n", ans, flag);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string.h>
using namespace std;

int main(){
  string s;
  int i,j,n,flag=0,flag2=0;

  getline(cin,s);
  for(i=0;i<s.length();i++){
    
    if(s[i]=='a' && s[i+1]=='p'&& s[i+2]=='p' && s[i+3] == 'l' && s[i+4] == 'e'){
      s[i]='p';
      s[i+1]='e';
      s[i+2]='a';
      s[i+3]='c';
      s[i+4]='h';
    }
    else if(s[i]=='p' && s[i+1]=='e'&& s[i+2]=='a' && s[i+3] == 'c' && s[i+4] == 'h'){
      s[i]='a';
      s[i+1]='p';
      s[i+2]='p';
      s[i+3]='l';
      s[i+4]='e';
    }
    
  }
  cout << s << endl;
  
  
  
}

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


int main(){
                                                                     

    int n, i, j;

    int s = 0;


    cin >> n;


    for( i = 1 ; s < n ; i = i + 1 ){

         s += i;
 
         }


    for( j = 1 ; j < i ; j = j + 1 ){

         if( j != s - n ) cout << j << endl;
 
         }


    return 0;

    }

Measured memory_bytes: 384
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

public class Main{    
    static int n;
    static int[] x = new int[n];
    static int[] y = new int[n];
    static int[] z = new int[n];
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int k = sc.nextInt();
        int n = sc.nextInt();

        String s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            if (i == n-1) {
                String a = s.substring(n-1, n);
                a = a.toLowerCase();
                System.out.print(a);
            }else{
                System.out.print(s.charAt(i));
            }
        }
        System.out.println("");

        sc.close();
    }

}


Measured memory_bytes: 23764
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"No", "Yes"};
string ANS[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}

int A[505][505];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = 0;
    forn(i, 4) n += s[i] == '2';
    cout << n;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"
int arr[5][105];
int dp[5][105];
int main()
{
    //freopen(file".inp","r",stdin);
    //freopen(file".out","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=2;i++)
	    for(int j=1;j<=n;j++)
	    	cin>>arr[i][j];
    for(int i=1;i<=2;i++)
    	for(int j=1;j<=n;j++)
    		dp[i][j] = max(dp[i-1][j],dp[i][j-1])+arr[i][j];
    cout<<dp[2][n];
//   for(int i=1;i<=2;i++)
//   {
//   	for(int j=1;j<=n;j++)
//   		cout<<dp[i][j]<<" ";
//	cout<<endl;
//   }
}


Measured memory_bytes: 3572
#include<stdio.h>
int main(void)
{
	int n,a,b;
	int t;
	int i;
	int c=0;
	scanf("%d %d %d",&n,&a,&b);
	for(i=0;i<n;i++){
		scanf("%d",&t);
		if(t<a || t>=b)
			c++;
	}
	printf("%d\n",c);
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  if(N<10){
    cout<<N<<endl;

  }else if(N<100){
    cout<<9<<endl;

  }else if(N<1000){
    cout<<N-99+9<<endl;

  }else if(N<10000){
    cout<<909<<endl;

  }else if(N<100000){
    cout<<N-9999+909<<endl;

  }else if(N==100000){
    cout<<90909<<endl;
  }
}


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

typedef long long LL;
const int MN = 100005;

int N, K, A[MN];
LL S1p[MN], S1s[MN];
LL S2p[MN], S2s[MN];
LL Sum[MN], Ans;

int main() {
	scanf("%d%d", &N, &K);
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]), Sum[i] = Sum[i - 1] + A[i];
	for (int i = 1; i <= N; ++i)
		S1p[i] = S1p[i - 1] + (A[i] > 0 ? A[i] : 0),
		S2p[i] = S2p[i - 1] + (A[i] < 0 ? A[i] : 0);
	for (int i = N; i >= 1; --i)
		S1s[i] = S1s[i + 1] + (A[i] > 0 ? A[i] : 0),
		S2s[i] = S2s[i + 1] + (A[i] < 0 ? A[i] : 0);
	for (int i = K; i <= N; ++i)
		Ans = std::max(Ans, Sum[i] - Sum[i - K] + S1p[i - K] + S1s[i + 1]),
		Ans = std::max(Ans, Sum[N] - (Sum[i] - Sum[i - K] + S2p[i - K] + S2s[i + 1]));
	printf("%lld\n", Ans);
	return 0;
}

Measured memory_bytes: 6028
import java.util.*;
 
class Main {
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int nam[] = new int[4]; int w = 1000;
        int flag = 0;
      
      for(int i = 0; i<4 ;i++){
        nam[i] = S/w;S%=w;w /= 10;
      }
      for(int i = 1;i<4;i++){
       if(nam[i]==nam[i-1]){flag=1;} 
      }
	  if(flag==1){System.out.print("Bad");}
      else{System.out.print("Good");}
      
    }
}

Measured memory_bytes: 25300