akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>

using namespace std;
typedef long long int ll;



int n,wa;
int w[110],v[110];
ll dp[110][100010];
bool dpf[110][100010];

int main(){
    scanf("%d %d",&n,&wa);
    for(int i=0;i<n;i++)scanf("%d %d",&w[i],&v[i]);
    
    for(int i=0;i<=n;i++){
        if(i){
            for(int j=0;j<=wa;j++){
                
                if(dpf[i][j]){
                    dp[i][j]=max(dp[i][j],dp[i-1][j]);
                }
                else{
                    dp[i][j]=dp[i-1][j];
                    dpf[i][j]=true;
                }
                if(j+w[i-1]<=wa){
                    if(dpf[i][j+w[i-1]]){
                        dp[i][j+w[i-1]]=max(dp[i][j+w[i-1]],dp[i-1][j]+v[i-1]);
                    }
                    else{
                        dp[i][j+w[i-1]]=dp[i-1][j]+v[i-1];
                        dpf[i][j+w[i-1]]=true;
                    }
                }

                
            }
        }
        else{
            for(int j=0;j<wa;j++)dp[i][j]=0;
        }
        /*
        for(int j=0;j<=wa;j++){
            printf("%d ",dp[i][j]);    
        }
        cout<<endl;
        */
    }
    printf("%lld\n",dp[n][wa]);
    
    
}


Measured memory_bytes: 90240
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repi(i,a,b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;

int main() {
  vvc c(3, vc(3));
  rep(i,c.size()) {
    rep(j,c.at(0).size()) {
      cin >> c.at(i).at(j);
    }
  }
  
  cout << c.at(0).at(0) << c.at(1).at(1) << c.at(2).at(2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int MAX_N = 1<<17;
const ll INF = INT_MAX;

class RMQ2{
public : 
  struct data{
    bool type; //0 - empty   , 1 - update
    ll value;
  };
  
  ll n,dat[2*MAX_N-1];
  data td[2*MAX_N-1];
  
  RMQ2(){
    n=MAX_N;
    memset(td,0,sizeof(td));
    for(int i=0;i<2*n-1;i++)dat[i]=INF;
  }
  RMQ2(int n_){
    n=1;
    while(n<n_)n*=2;
    memset(td,0,sizeof(td));
    for(int i=0;i<2*n-1;i++)dat[i]=INF;
  }
  
  ll update(int a,int b,int x,int k=0,int l=0,int r=-1){
    if(r==-1) r=n;
    if(r<=a||b<=l)return dat[k];
    if(a<=l&&r<=b){
      td[k]=(data){1,x};
      return dat[k]=x;
    }
    
    if(td[k].type){
      dat[k*2+1]=dat[k*2+2]=td[k].value;
      td[k*2+1]=td[k*2+2]=(data){1,td[k].value};
    }
    td[k].type=0;
    
    ll vl=update(a,b,x,k*2+1,l,(l+r)/2);
    ll vr=update(a,b,x,k*2+2,(l+r)/2,r);
    return dat[k]=min(vl,vr);
  }
  
  ll find(int a,int b,int k=0,int l=0,int r=-1){
    if(r==-1) r=n;
    if(r<=a||b<=l)return INT_MAX;
    if(a<=l&&r<=b)return dat[k];
    
    if(td[k].type){
      dat[k*2+1]=dat[k*2+2]=td[k].value;
      td[k*2+1]=td[k*2+2]=(data){1,td[k].value};
    }
    td[k].type=0;
    ll vl=find(a,b,k*2+1,l,(l+r)/2);
    ll vr=find(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
};
 
int main(){
  int q,n;
  cin>>n>>q;
  RMQ2 T(n);
  while(q--){
    int cmd;
    cin>>cmd;
    if(cmd==0){
      int s,t,x;
      cin>>s>>t>>x;
      T.update(s,t+1,x);
    }
    else {
      int s,t;
      cin>>s>>t;
      cout <<T.find(s,t+1)<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 9252
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int a,b,k;
	scanf("%d%d%d",&a,&b,&k);
	for(int i=a;i<=min(a+k-1,b);i++)
		printf("%d\n",i);
	for(int i=max(a+k,b-k+1);i<=b;i++)
		printf("%d\n",i);
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

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

using namespace std;

int main()
{
    int Z;           //入力待ち
    int j, k;        //for文用
    string to = ","; //デバッグ用
    int e_count = 0; //演算回数を数える
    int count = 0;   //よくあるカウント
    //----------

    int n;
    cin >> n;
    long nums[200];
    REP(i, n)
    {
        cin >> nums[i];
    }

    //2で割ったものに置き換える
    int flag = 1;
    while (1) //break出抜けるループ
    {
        count++;
        REP(i, n)
        {
            if (nums[i] % 2 == 0)
            {
                nums[i] /= 2; //わって置き換え
            }
            else
            {
                flag = 0;
                count--;
                break;
            }
        }

        if (flag != 1)
            break;
    }
    cout << count << endl;

    //-----------
    cin >> Z;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint a, b, n;
    cin >> a >> b >> n;
    lint xb = min(b - 1, n);
    cout << ((a * xb) / b) - (a * (xb / b)) << "\n";
    // for (lint i = 0; i <= n; ++i) {
    //     lint r = (a * i) / b - a * (i / b);
    //     cout << r << "\n";
    // }
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int dx[] = {0, -1, 0, 1};
int dy[] = {1, 0, -1, 0};
int main()
{
    int H, W;
    cin >> H >> W;
    auto A = make_v<char>(W, H);
    queue<pair<pll, int>> q;
    rep(i, H)
    {
        rep(j, W)
        {
            cin >> A[j][i];
            if (A[j][i] == '#')
                q.push({{j, i}, 0});
        }
    }
    int ans = 0;
    while (!q.empty())
    {
        pll pos = q.front().first;
        int num = q.front().second;
        int x = pos.first, y = pos.second;
        q.pop();
        for (int i = 0; i < 4; i++)
        {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < W and nx >= 0 and ny < H and ny >= 0)
            {
                if (A[nx][ny] == '.')
                {
                    q.push({{nx, ny}, num + 1});
                    A[nx][ny] = '#';
                }
            }
        }
        ans = max(ans, num);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 25524
import java.io.*;
class Main{
    public static void main(String[]args)throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int i,j,k;
        int[][][] list=new int[4][3][10];
        for(i=0;i<4;i++){
            for(j=0;j<3;j++){
                for(k=0;k<10;k++){
                    list[i][j][k]=0;
                }
            }
        }
        String str=br.readLine();
        int n=Integer.parseInt(str);
        for(i=0;i<n;i++){
            String[] house=br.readLine().split(" ");
            int b=Integer.parseInt(house[0])-1;
            int f=Integer.parseInt(house[1])-1;
            int r=Integer.parseInt(house[2])-1;
            int v=Integer.parseInt(house[3]);
             
            list[b][f][r]+=v;
        }
        for(i=0;i<4;i++){
            for(j=0;j<3;j++){
                for(k=0;k<10;k++){
                    System.out.print(" "+ list[i][j][k]);
                }
                System.out.println();
            }
            if(i==3)break;
            System.out.println("####################");
        }
    }
}

Measured memory_bytes: 24660
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  int N, before = 0, c = 0;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++)
  {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  for (int i = 0; i < N; i++)
  {
    if (before != d[i])
    {
      c++;
    }
    before = d[i];
  }
  cout << c << endl;
}


Measured memory_bytes: 3092
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    
    a=list(range(1,n+1))
    m=0
    for i in range(n):
        f=a[i]
        for j in range(n-1):
            if a[j]!=f and a[j]<f:
                g=a[j]
            else: break
            for k in range(n-2):
                if a[k]==f or a[k]==g:
                    break
                if a[k]==x-f-g and a[k]!=f and a[k]!=g:
                    m+=1
                
    print(m)


Measured memory_bytes: 5596
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;

int n, A[1000010], cnt = 0;

void insertionSort(int A[],int n, int g){
  for(int i=g;i<n;i++){
    int v = A[i];
    int j = i - g;
    while(j >= 0 && A[j] > v){
      A[j+g] = A[j];
      j -= g;
      cnt++;
    }
    A[j+g] = v; 
  }
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>A[i];
  int m, G[1000000], i;
  G[0]=1;
  i = 0;
  if(n==1) m = 1;
  else{
    while(G[i]<n){
      G[i+1] = 3 * G[i] + 1;
      i++;
    }
    m = i;
  }
  cout<<m<<endl;
  for(int i=m-1;i>=0;i--){
    insertionSort(A, n, G[i]);
    cout<<G[i];
    if(i) cout<<" ";
  }
  cout<<endl;
  cout<<cnt<<endl;
  for(int i=0;i<n;i++) cout<<A[i]<<endl;
  return 0;
}



Measured memory_bytes: 6940
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  char a[4];
  cin>>a[0]>>a[1]>>a[2]>>a[3];
  bool t = 0;
  if(a[0] == a[1] && a[2] == a[3]){
    t = 1;
  }
  if(a[0] == a[2] && a[1] == a[3]){
    t = 1;
  }
  if(a[0] == a[3] && a[1] == a[2]){
    t = 1;
  }
  if(a[0] == a[1] && a[0] == a[2]){
    t = 0;
  }
  if(t == 1){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
a,b,k = [int(x) for x in input().split()]

num = b-a
l = []
if num > k:
    for i in range(a,a+k):
        l.append(i)
    for i in range(b-k+1, b+1):
        l.append(i)
    for x in sorted(list(set(l))):
        print(x)
else:
    for i in range(a,b+1):
        print(i)


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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX = 16;

VI g[MAX];
int DP[(1<<MAX) + 47];
int n;

int get(int mask)
{
	if (mask == 0) return 1;
	if (DP[mask] != -1) return DP[mask];

	int res = 0;
	int m = mask;
	while(true)
	{
		if (m == 0) break;
		int v1 = (m & 1) > 0;
		int v2 = (m & 2) > 0;
		if (v1 == v2)
		{
			int cur = 1;
			FOR (i, 0, n)
			{
				if (!(mask & (1<<i))) continue;
				if (m & (1<<i)) continue;

				int cnt = 0;
				FOR (j, 0, SZ(g[i]))
				{
					int to = g[i][j];
					if (m & (1<<to)) cnt++;
				}

				cur = (cur * (LL)((1 << cnt) - 1)) % MOD;
			}

			FOR (i, 0, n)
			{
				if (!(m & (1<<i))) continue;

				int cnt = 0;
				FOR (j, 0, SZ(g[i]))
				{
					int to = g[i][j];
					if (mask & (1<<to))
					{
						if (!(m & (1<<to))) cnt++;
					}
				}

				cur = (cur * (LL)(1<<cnt)) % MOD;
			}

			cur = (cur * (LL)get(mask ^ m)) % MOD;

			res = (res + cur) % MOD;
		}

		m = (m - 1) & mask;
	}

	return DP[mask] = res;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int m;
	scanf("%d%d", &n, &m);
	FOR (i, 0, m)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;

		g[x].PB(y);
	}

	FILL(DP, -1);

	int res = get((1<<n) - 1);

	int p2 = 1;
	FOR (i, 0, m)
	{
		p2 *= 2;
		p2 %= MOD;
	}

	res = p2 - res + MOD;
	res %= MOD;

	cout<<res<<endl;
}



Measured memory_bytes: 640
a;b;c;d;e;
main(){
  scanf("%d%d%d",&a,&b,&c);
  if((a+b>=c&&b<=c)||(a+c>=b&&c<=b))
    printf("0\n");
  else{d=b-(a+c);e=c-(a+b);
  printf("%d\n",d>e?d:e);}}

Measured memory_bytes: 128
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<climits>

/*
#include<boost/multiprecision/cpp_long long.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Blong long = mp::cpp_long long;
*/

using namespace std;

#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

int main(){
    int N,A,B,C,D;
    cin>>N>>A>>B>>C>>D;
    A--;
    B--;
    C--;
    D--;
    string S;
    cin>>S;
    S=S+"###";

    bool f=false;

    for(int i=B;i<D;i++){
        if(S[i-1]=='.'&&S[i+1]=='.'&&S[i]=='.') f=true;
        if(S[i]=='.'&&S[i+1]=='.'&&S[i+2]=='.') f=true;
        if(i+1==D||i+2==D) break;
        if(S[i+1]=='.');
        else if(S[i+2]=='.'){
            i++;
        }
        else {
            cout<<"No"<<endl;
            return 0;
        }
    }

    for(int i=A;i<C;i++){
        if(i+1==C||i+2==C) break;
        if(S[i+1]=='.'&&(f||i+1!=D));
        else if(S[i+2]=='.'&&(f||i+2!=D)){
            i++;
        }
        else {
            cout<<"No"<<endl;
            return 0;
        }
    }



    cout<<"Yes"<<endl;


}


Measured memory_bytes: 3420
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = sc.nextInt();
        if(x<a) {
            System.out.println("NO");
        }else if(x>=a && a+b>=x) {
            System.out.println("YES");
        }else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 22736
//
//AOJ volume0 0022
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0022&lang=jp
//20170529
//640009E
//Yang Bo
//

#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    vector<int> a(n, 0); //?´??????¨
    vector<int> b(n, 0); //????????¨
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int k = n - 1;
    while (a[k] < 0)
      k--;
    b[k] = a[k];
    for (int i = k - 1; i > -1; i--) {
      if (a[i] < 0)
	continue;
      else {
	int j = i + 1;
	int s = 0; //?????????????????????????????¨
	while (a[j] < 0) {
	  s += a[j];
	  j++;
	}
	//cout << "s = " << s << " " << "i = " << i << " " << "j = " << j << endl;
	if (s + b[j] >= 0)
	  b[i] += s + b[j] + a[i];
	else // if (a[i] > s + b[j])
	  b[i] += a[i];
	//cout << "b[" << i << "]= " << b[i] << endl;
      }
    }
    /*
    for (int i = 0; i < n; i++)
      cout << "b[" << i << "]= " << b[i] << endl;
    */
    int max = b[0];
    for (int i = 1; i < n; i++)
      if (max < b[i])
	max = b[i];
    if (max < 1) {
      int minus = a[0];
      for (int i = 1; i < n; i++)
	if (minus < a[i])
	  minus = a[i];
      max = minus;
    }
    cout << max << endl;
  }
}

/*
??????????????????????????£???????????§??????????????????wrong answer???????????§??????
????????§?????£???????????¨???????????§?????????????????????????????????
?????????????????§????????§????±?????????????(??????b?????\????????????????????????)?????¨????????°?????????????±?????????¨????????¢?????´?????????????????£???????????????
????????£???????¬??????????????¨?????????¨?¨????????????§???????????????
*/

Measured memory_bytes: 3072
n = int(input())
A = []
for i in range(n):
    x = list(map(int, input().split()))
    
    if x[0] == 0:
        A.append(x[1])
    elif x[0] == 1:
        print(A[x[1]])
    elif x[0] == 2:
        del A[-1]
    


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

int main(){

  int N,M;
  int masu[1005],me[1005];
  int cntmemasu,jj,cnt;
  
  
  
  while(1){
    cntmemasu=1;
    jj=0;
    cnt=1;
    cin >> N >> M;
    if(N == 0 && M == 0) break;
    for(int i = 1; i <= N; i++){
      cin >> masu[i];
    }
    
    for(int i = 1; i <= M; i++){
      cin >> me[i];
    }
    
    for(int j = 1; j <= M; j++){
      jj++;
      cntmemasu+=me[j];
      cnt=cntmemasu;
      // cout << cnt << " ";
      if(cntmemasu >= N){
	cout << jj << endl;
	break;
      }
      cntmemasu+=masu[cnt];
      cnt=cntmemasu;
    //  cout << cnt << " ";
      if(cntmemasu >= N){
	cout << jj << endl;
	break;
      }
    }
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];

  set<string> s2;
  rep(i, n) s2.insert(s[i]);

  cout << s2.size() << endl;
  return 0;
}

Measured memory_bytes: 25004
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int N_MAX = 1e5+20;
int S[N_MAX];
bool prime[N_MAX];

vector<int> eratosthenes(int n){
  list<int> l(1,2);
  //候補
  for(int i = 3; i<=n; i+=2) l.push_back(i);

  //列挙
  for(auto it1 = l.begin(); *it1<=sqrt(n); ++it1){
    auto tmp = it1;
    ++tmp;
    for(auto it2 = tmp, l_end = l.end(); it2 != l_end; ++it2){
      if(*it2 % *it1 == 0){
        tmp = it2;
        --it2;
        l.erase(tmp);
      }
    }
  }
  vector<int> v(l.size());
  int i = 0;
  for(auto it = l.begin(),l_end = l.end(); it != l_end;++it){
    v[i] = *it;
    ++i;
  }
  return v;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int Q;cin >> Q;
  vector<int> v = eratosthenes(N_MAX-1);
  rep(i,v.size()) prime[v[i]] = true;
  repp(x,1,N_MAX){
    S[x] += S[x-1];
    if(prime[x] && prime[(x+1)/2]) S[x] += 1;
  }
  while(Q--){
    int l,r;cin >> l >> r;
    cout << S[r] - S[l-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 2688
#import time

#t1=time.time()
n=int(input())
s=list(input())
info=[]
for i in range(10):
    for j in range(10):
        for k in range(10):
            info.append(str(i)+str(j)+str(k))
ans=0
kind=0
while kind<=999:
    point=0
    check=info[kind]
    for i in range(n):
        if point==0:  
            if check[0]==s[i]:
                point+=1
                continue
        if point==1:
            if check[1]==s[i]:
                point+=1
                continue
        if point==2:
            if check[2]==s[i]:
                point+=1
                break
    if point==3:
        ans+=1
        #print(info[kind])
    kind+=1
print(ans)
#t2=time.time()
#print(t2-t1)

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  sort(p.begin(), p.end());
  int ans = 0;
  rep(i, k) { ans += p[i]; }

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

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

ll dp[3300][3300];
ll dps[3300][3300];

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

  dp[0][0]=1;
  rep(i, n-1){

    dps[i][0]=dp[i][0];
    rep1(j, n){
      dps[i][j] += dps[i][j-1]+dp[i][j];
    }

    rep(j, i+2){
      if(s[i]=='<'){
        if(j)dp[i+1][j] += dps[i][j-1];
      }else{
        dp[i+1][j] += dps[i][n];
        if(j)dp[i+1][j] -= dps[i][j-1];
      }
      while(dp[i+1][j]<0)dp[i+1][j]+=MOD;
      dp[i+1][j] %= MOD;
    }
  }

  ll result = 0;
  rep(i, n)result += dp[n-1][i];
  cout<<result%MOD<<endl;

  return 0;

rep(i, n){
rep(j, n)cout<<dp[i][j]<<' ';cout<<endl;
}

  return 0;
}

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

const int64_t mod = 1000000007;

int64_t power(int64_t n, int64_t k) {
  if (k == 0) return 1;
  int64_t half = power(n, k / 2), ans = half * half % mod;
  if (k % 2) {
    ans *= n;
    ans %= mod;
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) cin >> x.at(i);
  int64_t fact = 1, ans = 0;
  for (int i = 1; i < n; i++) fact = fact * i % mod;
  vector<int64_t> s(n);
  for (int i = 1; i < n; i++) {
    s.at(i) = (s.at(i - 1) + power(i, mod - 2)) % mod;
  }
  for (int i = n - 1; i > 0; i--) {
    int64_t dx = x.at(i) - x.at(i - 1);
    ans += dx * s.at(i) % mod;
    ans %= mod;
  }
  cout << fact * ans % mod << endl;
}


Measured memory_bytes: 1408
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int stepNum = sc.nextInt();
        long k = sc.nextLong();
        
        long[] ownNum = new long[100000];
        
        for(int i=0 ; i< stepNum; i++){
            int intA = sc.nextInt();
            int insertNum = sc.nextInt();
            ownNum[intA-1] += insertNum;
        }
        
        long sum=0;
        for(int i=0 ; i< ownNum.length; i++){
            if(k <= ownNum[i]){
                System.out.println((i+1));
                break;
            }
            k -= ownNum[i];
        }
    }
}

Measured memory_bytes: 64920
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T;
  cin >> S >> T;
  string t;
  
  for (int i = 0; i < S.size(); i++) {
    char C = T.at(0);
    T = T + C;
    t = T.at(1);
    for (int j = 1; j < S.size(); j++) {
      t += T.at(j+1);
    }
    T = t;
    if (S == T){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}



Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n, d[SIZE], m, t[SIZE];
  map<int,int> md, mt;

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

  scanf("%d",&m);
  
  for(int i=0;i<m;i++){
    scanf("%d",t+i);
    mt[t[i]]++;
  }

  for(auto it = mt.begin();it != mt.end(); it++){
    int p = it->first;
    int q = it->second;
    
    if(md[p] < q){
      puts("NO");
      return 0;
    }
  }

  puts("YES");
  
  return 0;
}



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

int N;
double T,A;
double H[1010];

double calc(double T,double x)
{
  return T-x*0.006;
}

int main(void)
{
cin >> N >> T >> A;

double ave=1000010.0;

int ans;

for(int i=1;i<=N;i++)cin >> H[i];

for(int i=1;i<=N;i++)
{
  if(ave>abs(A-calc(T,H[i])))
  {
    ave=abs(A-calc(T,H[i]));

    ans=i;
  }
}

cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
    int N;
    cin >> N;
    
    int C0 = 0;
    int C1 = 0;
    int C2 = 0;
    int C3 = 0;
    
    for (int i = 0; i < N; i++){
        string S;
        cin >> S;
        if (S == "AC"){
            C0++;
        }
        if (S == "WA"){
            C1++;
        }
        if (S == "TLE"){
            C2++;
        }
        if (S == "RE"){
            C3++;
        }
    }
    cout << "AC x " << C0 << endl;
    cout << "WA x " << C1 << endl;
    cout << "TLE x " << C2 << endl;
    cout << "RE x " << C3 << endl;
    
    
    
    
}


Measured memory_bytes: 3604
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int N_candle;
    int K_candle;
    cin >> N_candle;
    cin >> K_candle;

    int tmpx;
    vector<int> x_left;
    vector<int> x_right;

    for( int xi = 0 ; xi < N_candle ; xi++ ){
        cin >> tmpx;
        if(tmpx<0){
            tmpx = tmpx * -1;
            x_left.insert(x_left.begin(),tmpx);
        }
        else{
            x_right.push_back(tmpx);
        }
    }
    x_left.insert(x_left.begin(),0);
    x_right.insert(x_right.begin(),0);
    int mix = 500000000;
    int right_len = x_right.size();
    int value;
    for( int ri = 0 ; ri <= min(K_candle,right_len-1) ; ri++ ){
        if( K_candle <= ri + x_left.size() - 1 ){
            value = x_right[ri] + x_left[K_candle-ri] + min(x_right[ri],x_left[K_candle-ri]);
            if(mix > value){
                mix = value;
            }
//            cout << ri << " : " << value << endl;

        }
    }

    cout << mix;


}

Measured memory_bytes: 1020
n = int(input())
d = []

for i in range(n):
  d.append(list(map(int, input().split())))

cnt = 0
for j in range(n):
  if d[j][0] == d[j][1]:
    cnt += 1
    if cnt >= 3:
      print("Yes")
      exit()
      
  else:
    cnt = 0
    
print("No")

Measured memory_bytes: 9208
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<ll> p(a), q(b), r(c);
	REP(i, a) {
		cin >> p[i];
	}
	REP(i, b) {
		cin >> q[i];
	}
	REP(i, c) {
		cin >> r[i];
	}
	priority_queue<ll,vector<ll>,greater<ll>> pp, pq;
	REP(i, a) {
		pp.push(p[i]);
	}
	REP(i, a - x) {
		pp.pop();
	}
	REP(i, b) {
		pq.push(q[i]);
	}
	REP(i, b - y) {
		pq.pop();
	}
	REP(i, c) {
		int t = pp.top(), u = pq.top();
		if (t < u) {
			pp.push(r[i]);
			pp.pop();
		} else {
			pq.push(r[i]);
			pq.pop();
		}
	}
	ll res = 0;
	while (!pp.empty()) {
		res += pp.top();
		pp.pop();
	}
	while (!pq.empty()) {
		res += pq.top();
		pq.pop();
	}
	put(res);
	
	return 0;
}

Measured memory_bytes: 4980
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;

    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    if(c*2 >= a+b) {
      cout << a*x + b*y << endl;
      return 0;
    }
    if(x == y) {
      cout << c*2*x << endl;
      return 0;
    }

    if(x > y) {
      cout << y*2*c + (x-y)*min(2*c,a) << endl;
      return 0;
    }

    if(x < y) {
      cout << x*2*c + (y-x)*min(2*c,b) << endl;
      return 0;
    }
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

int main() {
  string s;
  cin >> s;
  set<char> st;
  rep(i, s.size()) st.insert(s[i]);
  int ans = 1001001001;
  for (auto c : st) {
    int l = 0, tmp = 0;
    rep(j, s.size()) {
      if (s[j] == c) {
        tmp = max(tmp, j - l);
        l = j + 1;
      }
    }
    tmp = max(tmp, (int)s.size() - l);
    // cerr << c << " " << tmp << endl;
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    int N;
    cin>>N;
    vi A(N),sum(N);
    rep(i,N-1){
        cin>>A[i];
        sum[A[i]-1]++;
    }
    rep(i,N)cout<<sum[i]<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 4844
#include<iostream>
using namespace std;
int main()
{
    int n,m,sum=0;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    int ans=0;
    for(int i=0;i<n;i++)
        if(a[i]>=(double)sum/m/4.0)
            ans++;
    if(ans>=m)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

Measured memory_bytes: 3620
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();
        char m = s.charAt(k-1);

        System.out.println(s.substring(0,k-1)+Character.toLowerCase(m)+s.substring(k));
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N - 1);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 0; i < N - 1; i++) cin >> C[i];
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += B[A[i] - 1];
    if (i >= 1 && A[i - 1] + 1 == A[i]) ans += C[A[i - 1] - 1];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int i,j;
    int antenna[5];	//a,b,c,d,e,k
    
    for(i=0;i<=5;i++){
    scanf("%d",&antenna[i]);
    }
    
    if(antenna[4]-antenna[0]>antenna[5])
    puts(":(");
    
    else
    puts("Yay!");
    
    return 0;
    }


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(テッツセツε」ツ?、テッツスツエテッツセツεッツスツ」テッツセツづ篠エテッツスツサテッツセツεヲツクツ嘉・ツ伉嘉ッツスツ」テッツセツづ篠エテッツスツサ`)(テッツセツε」ツ?、テッツスツエテッツセツεッツスツ」テッツセツづ篠エテッツスツサテッツセツεヲツクツ嘉・ツ伉嘉ッツスツ」テッツセツづ篠エテッツスツサ`)(テッツセツε」ツ?、テッツスツエテッツセツεッツスツ」テッツセツづ篠エテッツスツサテッツセツεヲツクツ嘉・ツ伉嘉ッツスツ」テッツセツづ篠エテッツスツサ`)(テッツセツε」ツ?、テッツスツエテッツセツεッツスツ」テッツセツづ篠エテッツスツサテッツセツεヲツクツ嘉・ツ伉嘉ッツスツ」テッツセツづ篠エテッツスツサ`)(テッツセツε」ツ?、テッツスツエテッツセツεッツスツ」テッツセツづ篠エテッツスツサテッツセツεヲツクツ嘉・ツ伉嘉ッツスツ」テッツセツづ篠エテッツスツサ`)(テッツセツε」ツ?、テッツスツエテッツセツεッツスツ」テッツセツづ篠エテッツスツサテッツセツεヲツクツ嘉・ツ伉嘉ッツスツ」テッツセツづ篠エテッツスツサ`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	REP(j, n) {
		int out = 0, score = 0;
		int cnt = 0;
		vi v(3, 0);
		while (out < 3) {
			string s;
			if (cin >> s)cnt++;

			if (s == "HIT") {
				RREP(i, 3) {
					if (v[i] == 1) {
						if (i == 2)score++;
						else v[i + 1]++;
						v[i]--;

					}
				}
				v[0]++;
			}
			else if (s[0] == 'O') {
				out++;
			}
			else {
				REP(i, 3) {
					if (v[i] == 1) {
						score++;
						v[i] = 0;
					}
				}
				score++;
			}
			assert(cnt <= 100);

		}
		cout << score << endl;
	}
	return 0;
}

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

typedef long long ll;
const int maxn = 1e5 + 5;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

ll n;
int tot;
vector<int> p, q;

void solve(ll n)
{
	if (!n) return ;
	if (~n & 1) p.push_back(tot++), solve(n - 1);
	else q.push_back(tot++), solve(n >> 1);
}

int main()
{
	scanf("%lld", &n);
	solve(n);
	printf("%d\n", tot + 100);
	for (int x : p) printf("%d ", tot - x);
	reverse(q.begin(), q.end());
	for (int x : q) printf("%d ", tot - x);
	for (int i = 1; i <= 100; ++i) printf("%d ", i);
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main() {
    int N;
    scanf("%d", &N);
    int len_n = (int)log10(N) + 1;
    int s = (len_n % 2) ? N - pow(10, len_n - 1) + 1 : 0;
    for (int i=1; i < len_n; i+=2)
        s += 9 * pow(10, i - 1);
    printf("%d\n", s);
}

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

#define MAX 100005
#define NIL -1

using namespace std;

struct Node {int parent, left, right; };
Node Nodes[MAX];


int node_num;
int Depth[MAX] ;


void set_depth(int num, int depth){
	Depth[num] = depth;
 	if (Nodes[num].right != NIL)
 	{
 		set_depth(Nodes[num].right, depth);
 	}
 	if (Nodes[num].left != NIL) 
 	{
 		set_depth(Nodes[num].left, depth+1);
 	}
}


void print_children(int num){
	cout << "[" ;
	int temp_num = NIL;
	if (Nodes[num].left != NIL) {
		temp_num = Nodes[num].left;
		cout << temp_num;
	}
	if (temp_num != NIL) {
		while (Nodes[temp_num].right != NIL) {
			cout << ", " << Nodes[temp_num].right ;
			temp_num = Nodes[temp_num].right;
		}
	}
	cout << "]" << endl; 
}

void print_ans(){
	for (int i = 0; i < node_num; ++i)
	{
		string type;
		if (Nodes[i].parent == NIL) {
			type = "root, ";
		}else if (Nodes[i].left == NIL) {
			type = "leaf, ";
		}else{
			type = "internal node, ";

		}
		cout << "node " << i << ": parent = " << Nodes[i].parent << ", depth = " << Depth[i] << ", " <<  type ;
		print_children(i);
	}
}



int main(){
	int id, k, leaf, child, start;
	cin >> node_num;
	for (int i = 0; i < node_num; ++i)
	{
		Nodes[i].parent = Nodes[i].left = Nodes[i].right = NIL;
	}
	for (int i = 0; i < node_num; ++i)
	{
		cin >> id >> k;
		for (int j = 0; j < k; ++j)
		{
			cin >> leaf;
			if (j == 0)
			 {
			 	Nodes[id].left = leaf;
			 } else {
			 	Nodes[child].right = leaf;
			 } 
			 child = leaf;
			 Nodes[child].parent = id;  
		}
 	}
 	for (int i = 0; i < node_num; ++i)
 	{
 		if (Nodes[i].parent == NIL)
 		{
 			start = i;
 		}
 	}
 	set_depth(start, 0);
 	print_ans();
}

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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a) cout << k << endl;
    else {
        int tmp = k - a;
        if (tmp <= b) cout << a << endl;
        else cout << a - (tmp - b) << endl;
    }
}

Measured memory_bytes: 3604
from fractions import gcd


def lcm(a, b):
    return a * b // gcd(a, b)


N = int(input())
As = list(map(int, input().split()))
ls = [1 for i in range(N + 1)]
for i in range(N):
    ls[i + 1] = lcm(As[i], ls[i])
m = ls[-1] - 1

total = 0
for i in range(N):
    total += m % As[i]
print(total)


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

int main() {
    int N, M;
    cin >> N;

    // cout << N << endl;

    map<string, int> S;
    string c;
    for (int i = 0; i < N; i++)
    {
        cin >> c;
        if (S.count(c))
            S.at(c) += 1;
        else
        {
            S[c] = 1;
        }
    }

    cin >> M;
    for (int i = 0; i < M; i++)
    {
        cin >> c;
        if (S.count(c))
            S.at(c) -= 1;
        else
        {
            S[c] = -1;
        }
    }

    int maxv = 0;
    for (auto i = S.begin(); i != S.end(); i++)
    {
        maxv = max(maxv, i->second);
    }
    cout << maxv << endl;
}

Measured memory_bytes: 384
#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;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

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

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

ll pow(ll a, ll n, ll m) {
	ll ret = 1LL;
	for (; n > 0LL; n >>= 1LL, a = a * a % m) {
		if (n % 2LL == 1LL) {
			ret = ret * a % m;
		}
	}
	return ret;
}

ll cmb(ll x, ll y){
    if(y>x||y<0) return 0LL;
    ll c = 1;
    for(ll i = 0LL; i < y; i++) {
        c *= (x-i)%mod;
        c %= mod;
        c *= pow(i+1,mod-2,mod);
        c%= mod;
    }
    return c;
}

int main() {
    ll S;
    cin>>S;
    ll n = 1;
    S -= 3;
    ll ans = 0;
    while(S>=0){
        ans = (ans + cmb(S+n-1,S))%mod;
        S-=3;
        n++;
    }
    if(ans<0) ans += mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import bisect
 
def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N, K = reads()
a = reads()

ppsum = [0] * (N+1)
psum = [0] * (N+1)

for i in range(N):
  ppsum[i+1] = ppsum[i] + max(0, a[i])
  psum[i+1] = psum[i] + a[i]

ansb = max(ppsum[i] + psum[i+K] - psum[i] + ppsum[N] - ppsum[i+K] for i in range(N-K+1))
answ = max(ppsum[i] + ppsum[N] - ppsum[i+K] for i in range(N-K+1))

print(max(ansb, answ))

Measured memory_bytes: 68460
#pragma optimization_level 3
#pragma GCC optimize("Ofast")   //Comment optimisations for an interatcive problem - use endl
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
 
using namespace std;
 
#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  x                     first                 
#define  y                     second                
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  unordered_map<ll,ll>  um;
typedef  vector<pll>           vpll;
 
const ll   N     =  1e5+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll t=1,d,dp[10008][108][2],dig[10008],sz;
string k;

ll rec(ll ind, ll s, ll f1){
    if(ind == sz){
        if(s == 0) return 1;
        return 0;
    }
    if(dp[ind][s][f1] != -1) return dp[ind][s][f1];
    dp[ind][s][f1] = 0;
    ll j = 9;
    if(f1 == 1) j = dig[ind];
    for(int i = 0; i <= j; i++){
        dp[ind][s][f1] += rec(ind+1,(s+i)%d,f1&(dig[ind]==i));
        dp[ind][s][f1] %= mod;
    }
    return dp[ind][s][f1];
}

ll solve(){
    memset(dp,-1,sizeof(dp));
    cin>>k>>d;
    sz = k.size();
    for(int i = 0; i < sz; i++) dig[i] = k[i] - '0';
    ll ans = rec(0,0,1)-1;
    if(ans < 0) ans += mod;
    cout<<ans<<endl;
}

int main(){
    fastio;
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 17792
def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))

    # 式 f の末尾に "+" を追加するかしないかして次の数字を追加
    return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1])#sは文字列


s = input()
n = len(s)

print(dfs(0, s[0]))

Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
char s[MAXN];
int n, m, l, r, d, len;
int main() {
	int T; read(T);
	while (T--) {
		read(n), read(m); bool flg = n < m;
		read(l), read(r), len = r - l + 1;
		if (flg) {
			swap(n, m);
			l = n + m - l + 1;
			r = n + m - r + 1;
			swap(l, r);
		}
		d = n / (m + 1) + (n % (m + 1) != 0); int j = 0;
		if (n >= m * d) {
			for (int i = l; i <= r; i++)
				if (i % (d + 1) == 0) s[++j] = 'B';
				else s[++j] = 'A';
		} else {
			int ql = 0, qr = n / d - 1;
			while (ql < qr) {
				int mid = (ql + qr + 1) / 2;
		 		int lfta = n - (mid + 1) * d;
				int lftb = m - mid;
				if (1ll * (lfta + 1) * d >= lftb) ql = mid;
				else qr = mid - 1;
			}
			for (int i = l; i <= min(ql * (d + 1) + d, r); i++)
				if (i % (d + 1) == 0) s[++j] = 'B';
				else s[++j] = 'A';
			l -= ql * (d + 1) + d; chkmax(l, 1);
			r -= ql * (d + 1) + d; chkmax(r, 0);
			n -= (ql + 1) * d, m -= ql;
			int p = (m - 1) / d;
			for (int i = l; i <= r; i++)
				if (i == 1) s[++j] = 'B';
				else if (i <= 1 + n - p) s[++j] = 'A';
				else if ((n + m - i + 1) % (d + 1) == 0) s[++j] = 'A';
				else s[++j] = 'B';
		}
		if (flg) {
			reverse(s + 1, s + len + 1);
			for (int i = 1; i <= len; i++)
				if (s[i] == 'A') s[i] = 'B';
				else s[i] = 'A';
		}
		s[len + 1] = 0;
		printf("%s\n", s + 1);
	}
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			int c=0;
			for(int i=0;i<n;i++) if(sc.nextInt()%2==1) c++;
			if(c%2==1) System.out.println("NO");
			else System.out.println("YES");
		}
	}
}

Measured memory_bytes: 48184
/*
	In the name of Allah.
*/

#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define gap ' '
#define INF 99999999
 
const int MAXN = 2 * 1e5 + 5;


int main(){
	char a;
	cin >> a;
	if(isupper(a)){
		cout << "A";
	}
	else{
		cout << "a";
	}

    return 0;
}


Measured memory_bytes: 3036