akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9 + 7;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int N, arr[200000];
ll dp[200000][3];

ll go(int idx, int rest) {
	if (idx + rest >= N) return 0;

	ll &ret = dp[idx][rest];
	if (ret != -1) return ret;

	ret = -0x3f3f3f3f3f3f3f3fll;
	for (int i = 0; i <= rest; ++i)
		ret = max(ret, arr[idx + i] + go(idx + i + 2, rest - i));

	return ret;
}
int main() {
	fastio; ini(dp, -1);
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> arr[i];

	if (~N & 1) cout << go(0, 1);
	else cout << go(0, 2);

	return 0;
}


Measured memory_bytes: 16948
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max(a,b) (((a)>(b)) ? (a):(b))
#define min(a,b) (((a)<(b)) ? (a):(b))

int cp(const int *a,const int *b){
    return *a-*b;
}

int main(void){
    int r,g,b,n;
    scanf("%d %d %d %d",&r,&g,&b,&n);
    int cnt=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            int bb=n-(i*r+j*g);
            int s=bb+i*r+j*g;
            if(bb<0)continue;
            if(s==n&&bb%b==0)cnt++;
            if(j*g>n||i*r>n)break;
        }
        if(i*r>n)break;
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
private static Scanner s;
public static StringBuilder sb = new StringBuilder();
public static void main(String[] args) {
	s = new Scanner(System.in);
	int a = s.nextInt();
	int[] b = new int[a];
	int l = Integer.MIN_VALUE;
	int[] c = new int[10001];


	for(int i = 0;i < a;i++) {
		int tmp = s.nextInt();
		b[i] = tmp;
		l = Math.max(l, b[i]);
		c[tmp]++;
	}

	for(int i = 1;i < c.length;i++){
			c[i] += c[i-1];
	}
	int[] d = new int[a];

	for(int i = a - 1;i >= 0;i--) {
		d[--c[b[i]]] = b[i];
	}

	for(int i = 0;i < a-1;i++) {
		sb.append(d[i] + " ");
	}
	System.out.println(sb.toString() + d[a-1]);
}
}



Measured memory_bytes: 565204
N = int(input())
S = list(input())

WHITE = '.'
BLACK = '#'

white_dp = [0 for _ in range(N)]
black_dp = [0 for _ in range(N)]

black2white = 0
for i in range(N):
    black2white += 1 if S[i] == BLACK else 0
    white_dp[i] = black2white
white_dp = [0] + white_dp

white2black = 0
for i in range(N-1, -1, -1):
    white2black += 1 if S[i] == WHITE else 0
    black_dp[i] = white2black
black_dp.append(0)

ans = N
for i in range(N+1):
    ans = min(ans, white_dp[i]+black_dp[i])
print(ans)


Measured memory_bytes: 20744
def main():
    s = input()
    s = sorted(s)
    ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
    ans = 'None'
    for chr_alpha in ascii_lowercase:
        if chr_alpha not in s:
            ans = chr_alpha
            break
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 10008
#include <cstdio>
#include <algorithm>
#include <vector>

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<int> a(n);
  for (auto& ai: a) scanf("%d", &ai);

  int res = 1;
  int cur = a[0];
  int sign = 0;
  for (size_t i = 0; i < n; ++i) {
    bool valid = (cur <= a[i] && sign >= 0);
    valid |= (cur >= a[i] && sign <= 0);
    if (!valid) {
      fprintf(stderr, "%zd\n", i);
      ++res;
      cur = a[i];
      sign = 0;
    } else {
      if (sign == 0 && cur != a[i])
        sign = a[i]-cur;
      cur = a[i];
    }
  }
  printf("%d\n", res);
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
    int n;
    int l[105];
    int i,j,k;
    int count = 0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&l[i]);
    }
    for(i=0;i<n-2;i++){
        for(j=i+1;j<n-1;j++){
            for(k=j+1;k<n;k++){
                if(l[i] != l[j] && l[j] != l[k] && l[k] != l[i]){
                    if(l[i]+l[j]>l[k] && l[j]+l[k]>l[i] && l[k]+l[i]>l[j]){
                        count++;
                    }
                }
            }
        }
    }    
    printf("%d\n",count);
    return 0;
}

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

int main() {
	int a, b;

	while(cin >> a >> b) {
		a += b;
		int t = 1, cnt = 0;
		while(1) {
			if( a < t ) {
				break;
			} else {
				t *= 10;
				++cnt;
			}
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 0
s=int(input())

def f(x):
    if x%2==0:
        return x/2
    else:
        return 3*x+1
list_a=[s,f(s)]
i=1
while i>0:
    if f(list_a[-1]) in list_a:
        print(len(list_a)+1)
        i=-1
    else:
        list_a.append(f(list_a[-1]))

Measured memory_bytes: 3060
#include<cstdio>

int main(){
    int X, Y;
    scanf("%d %d", &X, &Y);
    int a,b;
    int ans;
    if((Y-2*X) % 2 != 0) ans = 0;
    else{
        b = (Y-2*X)/2;
        if(b<0 || b>X) ans = 0;
        else ans = 1;
    }
    if(ans == 0) printf("No");
    else printf("Yes");
    return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k,count=2,e,f,ans=0,l,m,n;
  string s;
  cin >>s>>k;
  char a,b='0',c='C';
  a = s.at(0);
  for(int i=1;i<s.size();i++){
    if(s.at(i)!='0'&& b=='0'){
      b = s.at(i);
      e = s.size()-count+1;
    }
    else if(s.at(i)!='0'&& b!='0' &&c=='C'){
      c = s.at(i);
      f = s.size()-count+1;
    }
    count++;
  }
  a = a-'0';
  m = b-'0';
  n = c-'0';
  l = s.size()-1;
  if(k==1){
    ans += 9*l+a;    
  }
  else if(k==2){
    ans += l*(l-1)/2*81;
    ans += 9*l*(a-1);
    if(b!='0'){
      ans += 9*(e-1)+m;
    }
  }
  else if(k==3){
    ans += l*(l-1)*(l-2)/2*243;
    ans += l*(l-1)/2*81*(a-1);
    if(b!='0'){
     ans += (e-1)*(e-2)/2*81;
     ans += (m-1)*(e-1)*9;
    }
    if(b!='0'&&c!='C'){
     ans += 9*(f-1)+n;
    }
  }
  else if(k==2  && l==1){
    ans += 9*(a-1)+m;
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 256
W, H, N = map(int, input().split())

xmin, xmax, ymin, ymax = 0, W, 0, H
for i in range(N):
  x,y,a = map(int, input().split())
  if a==1:
    xmin = max(xmin, x)
  elif a==2:
    xmax = min(xmax, x)
  elif a==3:
    ymin = max(ymin, y)
  else:
    ymax = min(ymax, y)
    
print( max(0, xmax-xmin) * max(0, ymax-ymin) )

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC061_B();
        }

        static void ABC061_B()
        {
            var NM = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var road = new int[51, 51];

            for (var i = 1; i <= NM[1]; i++)
            {
                var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                road[ab[0], ab[1]] += 1;
                road[ab[1], ab[0]] += 1;
            }

            for (var i = 1; i <= NM[0]; i++)
            {
                var count = 0;
                for (var j = 1; j <= NM[0]; j++)
                {
                    if (road[i, j] > 0)
                        count += road[i, j];
                }
                Console.WriteLine(count);
            }
        }
    }
}

Measured memory_bytes: 13376
#D in [S_i-X_i,T_i-X_i) → Xiで止まる
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
from collections import defaultdict

N,Q = map(int,input().split())
task = []

STX = [[int(x) for x in input().split()] for _ in range(N)]
for s,t,x in STX:
  task.append((t-x,0,x)) # xで止まらなくなる
  task.append((s-x,1,x)) # xで止まる

for i in range(Q):
  d = int(input())
  task.append((d,2,i)) # 止まる位置を答える
answer = [-1]*Q

task.sort()

# 引っかかってる場所の管理
se = set()
se_hp = [] # heapで最小値を先頭に保つ

# 小さい時刻から順に見ていく
for a,b,c in task:
  if not b: # b == 0
    se.remove(c)
  elif b&1: # b == 1
    se.add(c)
    heappush(se_hp,c)
  else: # b == 2
    while se_hp and se_hp[0] not in se:
      heappop(se_hp)
    answer[c] = se_hp[0] if se_hp else -1

print('\n'.join(map(str,answer)))


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

int main()
{
    long long int k,n,temp=INT_MIN,total=0;
    cin>>k>>n;
    
    long long int a[n],ans[n];
    for(long long int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    
    for(int i=1;i<n;i++)
    {
        ans[i-1]=a[i]-a[i-1];
        temp=max(temp,ans[i-1]);
        total=total+ans[i-1];
    }
    
    ans[n-1]=k+a[0]-a[n-1];
    temp=max(temp,ans[n-1]);
    total=total+ans[n-1];
    
    total=total-temp;
    
    cout<<total;
    
    return 0;
}

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

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

Measured memory_bytes: 3604
// Dynamic Programming implementation of LCS problem in Java 
import java.io.*; 
import java.util.*;
class Main 
{ 
	// Returns length of LCS for X[0..m-1], Y[0..n-1] 
	static void lcs(String X, String Y, int m, int n) 
	{ 
		int[][] L = new int[m+1][n+1]; 

		// Following steps build L[m+1][n+1] in bottom up fashion. Note 
		// that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] 
		for (int i=0; i<=m; i++) 
		{ 
			for (int j=0; j<=n; j++) 
			{ 
				if (i == 0 || j == 0) 
					L[i][j] = 0; 
				else if (X.charAt(i-1) == Y.charAt(j-1)) 
					L[i][j] = L[i-1][j-1] + 1; 
				else
					L[i][j] = Math.max(L[i-1][j], L[i][j-1]); 
			} 
		} 

		// Following code is used to print LCS 
		int index = L[m][n]; 
		int temp = index; 

		// Create a character array to store the lcs string 
		char[] lcs = new char[index+1]; 
		lcs[index] = ' '; // Set the terminating character 

		// Start from the right-most-bottom-most corner and 
		// one by one store characters in lcs[] 
		int i = m;
		int j = n; 
		while (i > 0 && j > 0) 
		{ 
			// If current character in X[] and Y are same, then 
			// current character is part of LCS 
			if (X.charAt(i-1) == Y.charAt(j-1)) 
			{ 
				// Put current character in result 
				lcs[index-1] = X.charAt(i-1); 
				
				// reduce values of i, j and index 
				i--; 
				j--; 
				index--;	 
			} 

			// If not same, then find the larger of two and 
			// go in the direction of larger value 
			else if (L[i-1][j] > L[i][j-1]) 
				i--; 
			else
				j--; 
		} 

		// Print the lcs 
		for(int k=0;k<=temp;k++) 
			System.out.print(lcs[k]); 
	} 
	
	// driver program 
	public static void main (String[] args) 
	{ 
	    Scanner scn = new Scanner(System.in);
		String X = scn.nextLine();
		String Y = scn.nextLine();
		int m = X.length(); 
		int n = Y.length(); 
		lcs(X, Y, m, n); 
	} 
}

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

using namespace std;

int main()
{
    int H, W;

    while (true)
    {
        cin >> H >> W;
        if (H == 0 && W == 0)
            break;
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if ((i + j) % 2 == 0)
                    cout << "#";
                else
                    cout << ".";

                if (j + 1 == W)
                    cout << endl;
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;
	
	int x = tx - sx - 1;
	int y = ty - sy - 1;
	
	string s="",t="";
	if(y!=0){
		s += string(y,'U');
	}
	if(x!=0){
		s += string(x,'R');
	}
	if(y!=0){
		t += string(y,'D');
	}
	if(x!=0){
		t += string(x,'L');
	}
	
	cout << "U" + s + "R";
	cout << "D" + t + "L";
	cout << "LUU"+s+"RRD";
	cout << "RDD"+t+"LLU" << endl;
	
	
	
	return 0;
}

Measured memory_bytes: 3596
N,D=map(int,input().split())
table=[input().split() for i in range(N)]
k=0
	
for i in range(N):
	for j in range(N):
		if ((sum((int(table[i][l])-int(table[j][l]))**2 for l in range(D))**0.5).is_integer())==True:
			k=k+1
		
print(int((k-N)/2))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int n,x;cin >> n >> x;
  int m = INF32;
  for(int i = 0; i < n; ++i){
    int a;cin >> a;
    x -= a;
    m = min(m, a);
  }
  cout << n + x/m << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;



int main(int argc, const char * argv[]) {
    
   
    cin.tie(0);
    ios::sync_with_stdio(false);
   
    int n,k; cin >> n >> k;
    int ans = 1;
    for (int i = 0; i < n; i++) {
        ans = min(ans*2,ans+k);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
#define mod2 1000000006
#define inf 100000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<lli>
#define vii vector<int>
#define is indexed_set
#define eps 0.000001
#define endl '\n'
#define mo 998244353
#define pi 3.141592653589793
 
using namespace std ;
 
typedef tree<pair<pll,lli>,null_type,less<pair<pll,lli>>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
 
#define MAXN 200000
#define ll lli
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
 
ll lcm(ll a, ll b){
    return ((a/gcd(a, b)) * b);
}
 
 
int main()
{
    
/////////////////////////////////////
 
/////////////////////////////////////  
  
    ll n, m;
    cin>>n>>m;
    ll b[n];
    
    loop(i,0,n)
    {
        cin>>b[i];
        b[i] = b[i] >> 1ll;
    
    }
    ll lcm = b[0];
    for(ll i=1; i<n; i++)
    lcm = ((lcm/gcd(lcm, b[i])) * b[i]);
    
    for(ll i=0; i<n; i++)
    {
        ll ooi = lcm/b[i];
        if(ooi % 2 == 0){
            cout<<0;
            return 0 ;
        }
    }
 
    ll ans = m/lcm;
    if(ans%2 == 1) ans = (ans+1)/2;
    else ans = ans/2;
    cout<<ans;

}
        
 


Measured memory_bytes: 1024
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(x...) cerr << __LINE__ << ": " << #x << " = "; DBG::_print(x)
#else
#define DEBUG(x...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

int N;
VVI tree;
VI color;
void dfs(int u, int p = -1, int c = 0) {
   color[u] = c;
   for (int v : tree[u]) {
      if (v == p) continue;
      dfs(v, u, c^1);
   }
}


int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   cin >> N;
   tree = VVI(N);
   REP(j, N-1) {
      int u, v;
      cin >> u >> v;
      --u, --v;
      tree[u].push_back(v);
      tree[v].push_back(u);
   }

   color = VI(N, -1);
   dfs(0);

   int ncolors[2] = {0, 0};
   REP(u, N) {
      int c = color[u];
      assert(c >= 0);
      ncolors[c]++;
   }

   if (ncolors[0] > ncolors[1]) {
      swap(ncolors[0], ncolors[1]);
      REP(u, N)
         color[u] ^= 1;
   }

   queue<int> mods[3];
   FOR(n, 1, N)
      mods[n % 3].push(n);

   VI P(N);
   if (ncolors[0] <= SZ(mods[0])) {
      REP(u, N) {
         if (color[u] == 0) {
            assert(!mods[0].empty());
            P[u] = mods[0].front();
            mods[0].pop();
         }
         else {
            if (!mods[1].empty()) {
               P[u] = mods[1].front();
               mods[1].pop();
            }
            else if (!mods[2].empty()) {
               P[u] = mods[2].front();
               mods[2].pop();
            }
            else {
               assert(!mods[0].empty());
               P[u] = mods[0].front();
               mods[0].pop();
            }
         }
      }
   }
   else {
      REP(u, N) {
         if (color[u] == 1) {
            if (!mods[2].empty()) {
               P[u] = mods[2].front();
               mods[2].pop();
            }
            else {
               assert(!mods[0].empty());
               P[u] = mods[0].front();
               mods[0].pop();
            }
         }
         else {
            if (!mods[1].empty()) {
               P[u] = mods[1].front();
               mods[1].pop();
            }
            else {
               assert(!mods[0].empty());
               P[u] = mods[0].front();
               mods[0].pop();
            }
         }
      }
   }

   for (int x : P)
      cout << x << ' ';
   cout << "\n";

   return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 110

int W, a, b;

signed main()
{
    cin >> W >> a >> b;
    int a_l = a + W;
    int b_l = b + W;
    if( (a <= b && b <= a_l) || (a <= b_l && b_l <= a_l) ||
        (b <= a && a <= b_l) || (b <= a_l && a_l <= b_l)
      ) {
        printf("0\n");
        return 0;
    }
    if(a_l < b) {
        printf("%lld\n", b - a_l);
    } else {
        printf("%lld\n", a - b_l);
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
xs = []
ys = []

for _ in range(N):
    a, b = map(int, input().split())
    xs.append((a, b))

for _ in range(N):
    c, d = map(int, input().split())
    ys.append((c, d))
ys.sort(key=lambda l: l[0])

used = []
ret = 0
for (c, d) in ys:
    ab = None
    for (a, b) in xs:
        if a < c and b < d and used.count((a, b)) == 0:
            if ab is None:
                ab = (a, b)
            elif ab[1] < b:
                ab = (a, b)

    if ab is not None:
        used.append(ab)
        ret += 1

print(ret)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
 
#define N 100000
#define INF 1000000
 
int main(void){
  long long sum, x, ans;
  int n, q, l, r, a[N];
   
  cin >> n >> q;
  for (int i=0; i<n; i++){
    cin >> a[i];
  }
  for (int i=0; i<q; i++){
    cin >> x;
    ans = 0;
    l = r = 0;
    sum = a[0];
    while (true){
      while (r<n && sum <= x){
        sum += a[++r];
      }
      ans += r-l;
//      cout << l << " to " << r << " = " << sum;
//      cout << " (" << ans << ")" << endl;
      if (l==n) break;
      sum -= a[l++];
    }
    cout << ans << endl;
  }
  return 0;
}


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

int gcd(int a, int b) {
    if (a%b==0) return b;
    else return gcd(b, a%b);
}

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

    ll ans = 0;
    for (int a=1; a<=K; a++) {
        for (int b=1; b<=K; b++) {
            for (int c=1; c<=K; c++) {
                ans += gcd(gcd(a, b), c);
            }
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3596
import math
X=int(input())
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
while True:
    if is_prime(X):
        ans = X
        break
    X += 1
print(ans)

Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n;
Vi p;
bool ck(Vi v,Vi u){
    bool ans = true;
    rep(i,v.size()){
        if(v[i]!=u[i]){
            ans = false;
            break;
        }
    }
    return ans;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n;
    p.resize(n);
    rep(i,n){
        cin>>p[i];
    }
    ll tmp = 0;
    Vi v = p;
    sort(all(v));
    rep(i,n){
        repi(j,i,n){
            Vi tp = p;
            swap(tp[i],tp[j]);
            if(ck(v,tp)){
                tmp = 1;
                break;
            }
        }
    }
    YES(tmp>=1);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    double a,b;
    cin>>a>>b;
    cout<<a/b<<endl;
    return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;
int H, W;
vector<string> A;
vector<vector<bool>> homon;
bool ans = true;
int dx[] = {0, 1};
int dy[] = {1, 0};
void dfs(int h, int w){
  homon[h][w] = true;
  if(h==H-1 && w==W-1) return;
  REP(i, 2){
    int nh = h + dy[i], nw =w + dx[i];
    if(nh >= H || nw >= W) continue;
    if(A[nh][nw] == '#'){
      dfs(nh, nw);
      return;
    }
  }
}
int main(){
  cin >> H >> W;
  A.resize(H);
  homon.resize(H, vector<bool>(W, false));
  REP(i, H){
    cin >> A[i];
  }
  dfs(0, 0);
  REP(i, H){
    REP(j, W){
      if(A[i][j] == '#' && !homon[i][j]){
        ans = false;
      }
    }
  }
  if(ans){
    cout << "Possible" << endl;
  }
  else{
    cout << "Impossible" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=0
w=0
t=0
r=0
for i in range(n):
  s=input()
  if s=="AC":
    a+=1
  if s=="WA":
    w+=1
  if s=="TLE":
    t+=1
  if s=="RE":
    r+=1
print("AC x "+str(a))
print("WA x "+str(w))
print("TLE x "+str(t))
print("RE x "+str(r))


Measured memory_bytes: 9136
#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
using namespace std;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int OFF = (1 << 20);

int n, k, a;
vector<ll> hi;
vector<ll> lo;

int main () {

	cin >> n >> k;
	int poc = k;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a >= 0) hi.push_back(a);
		else lo.push_back(abs(a));
	}
	
	sort(lo.begin(), lo.end());
	sort(hi.begin(), hi.end());
	
	int ph = (int)hi.size()-1, pl = (int)lo.size()-1;
	while (k > 0) {
		if (ph >= 0 && pl >= 0) {
			if (hi[ph] > abs(lo[pl])) ph--;
			else pl--; 
		}
		else if (ph >= 0) {
			ph--;
		}
		else if (pl >= 0) {
			pl--;
		}
		k--;
	}
	
	if ((lo.size()-pl-1) % 2 == 1) {
		if ((ph >= 0) && (pl >= 0 && ph+1 < hi.size())) {
			if (hi[ph]*hi[ph+1] > lo[pl]*lo[pl+1]) {
				ph--;
				pl++;
			}
			else {
				pl--;
				ph++;
			}
		}
		else if (ph >= 0) {
			ph--;
			pl++;	
		}
		else if (pl >= 0 && ph+1 < hi.size()) {
			pl--;
			ph++;
		}
		else {
			pl = 0, ph = 0;
			while (poc > 0) {
				if (pl < lo.size() && ph < hi.size()) {
					if (lo[pl] < hi[ph]) pl++;
					else ph++;
				}
				else if (pl < lo.size()) {
					pl++;
				}
				else {
					ph++;
				}
				poc--;
			}
			
			ll sol = MOD-1;
			for (int i = 0; i < ph; i++) {
				sol *= hi[i];
				sol %= MOD;
			}
			
			for (int i = 0; i < pl; i++) {
				sol *= lo[i];
				sol %= MOD;
			}
			
			cout << sol;
			return 0;
		}
		
		ll sol = 1;
		for (int i = ph+1; i < hi.size(); i++) {
			sol *= hi[i];
			sol %= MOD;
		}
		
		for (int i = pl+1; i < lo.size(); i++) {
			sol *= lo[i];
			sol %= MOD;
		}
		
		cout << sol;
	}
	else {
		ll sol = 1;
		for (int i = ph+1; i < hi.size(); i++) {
			sol *= hi[i];
			sol %= MOD;
		}
		
		for (int i = pl+1; i < lo.size(); i++) {
			sol *= lo[i];
			sol %= MOD;
		}
		
		cout << sol;
	}

	return 0;
}


Measured memory_bytes: 5352
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[3010];
ll s[3010];
int main(){
    ll n, sm;
    while(cin>>n>>sm){
        ll ans=0, mod=998244353;
        for(ll i=0; i<n; ++i){
            // a[i]=i+1;
            scanf("%d",a+i);
        }
      int cnt=0;
      s[0]=1;
        for(ll i=0; i<n; ++i){
          // cout<<i<<":::"<<endl;
            for(int j=sm; j>a[i]; --j){
                s[j]+=s[j-a[i]];
                s[j]%=mod;


            //   cout<<j-a[i]<<" "<<s[j-a[i]].size()<<endl;
            //     for(auto it:s[j-a[i]]){
            //         cout<<"#"<<it.fs<<" "<<it.sc<<endl;
            //         s[j][it.fs]+=it.sc;
            //        ++cnt;
            //         if(j==sm){
            //             ll tmp=(it.fs+1)*(n-i);
            //             tmp*=it.sc;
            //             tmp%=mod;
            //             ans+=tmp;
            //             while(ans>=mod){
            //                 ans-=mod;
            //             }
            //         }
            //     }
            // }
            // s[a[i]][i]+=(n-i);
            // if(a[i]==sm){
            //     ans+=(n-i)*(i+1);
            //     while(ans>=mod){
            //         ans-=mod;
            //     }
            }
            s[a[i]]+=(i+1);
            s[a[i]]%=mod;
            ans+=s[sm];
            ans%=mod;
        }
        ans%=mod;
        // for(int i=0; i<=sm; ++i){
        //     //cnt+=s[i].size();
        // }
      // cout<<cnt<<endl;
        printf("%lld\n",ans);
    }
  return 0;
}




Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n;
	cin >> n;
	if(n == 2){
		cout << 1 << endl;
		return 0;
	}
	set<ll> ans;
	ans.insert(n);
	ans.insert(n - 1);
	for(ll i = 2; (i * i) <= n; i++){
		if(n % i == 0){
			ll rep = n;
			while(rep % i == 0) rep /= i;
			if(rep % i == 1) ans.insert(i);
			if((n / i) != i){
				ll rep1 = n;
				while(rep1 % (n / i) == 0) rep1 /= (n / i);
				if(rep1 % (n / i) == 1) ans.insert(n / i);
			}
		}
	}
	n--;
	for(ll i = 2; (i * i) <= n; i++){
		if(n % i == 0){
			ll rep = n;
			if(rep % i == 0 && (n + 1) % i == 1) ans.insert(i);
			if((n / i) != i){
				ll rep1 = n;
				if(rep1 % (n / i) == 0 && (n + 1) % (n / i) == 1) ans.insert(n / i);
			}
		}
	}
	cout << ans.size() << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int a[100002][3] = {};
int dp[100002][3] = {};

int main() {
	int n;
	cin >> n;
	for(int i=1;i<=n;i++) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	for(int i=1;i<=n;i++) {
		for(int j=0;j<3;j++) {
			dp[i][j] = max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) + a[i][j];
		}
	}
	cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
}

Measured memory_bytes: 2560
#include <stdio.h>
int main (){
	
	int a, b, max = 0;
	
	scanf("%d %d", &a, &b );
	
	if((a + b) > max){
		max = a +b;
	}
	if((a + a - 1) > max){
		max = a + a - 1;
	}
	if((b + b -1) > max){
		max = b + b -1;
	}
	
	printf("%d", max);
	
	
	
	
	
	
	
	return 0;
}

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

int main(){
    int i = 0;
    int n, k;
    int *A = malloc(sizeof(int) * 200000);

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

    for (i = k; i < n;i++){
        if(A[i-k]<A[i]){
            puts("Yes");
        }else{
            puts("No");
        }
    }
    return 0;
}

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


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl			'\n'

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

vector<bool> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	vector<bool> primes(n + 1);
	primes[0] = false;
	primes[1] = false;
	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes[i] = true;
	}
	return primes;
}



set<int> primeFactors(int  n)
{
	set<int> factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors.insert(2);

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		while (n % i == 0)
		{
			factors.insert(i);
			n /= i;
		}
	}
	if (n > 2)
		factors.insert(n);
	return factors;
}
bool func(int n)
{
	while (n % 2 == 0)
		n /= 2;

	while (n % 3 == 0)
		n /= 3;


	return (n == 1);
}





// Graph------------------------------------------------------------------------

int32_t main()
{
	FIO;
	// c_p_c();
	// --------------------------------------------------

	int a, b;
	cin >> a >> b;
	cout << a*b << endl;


}


Measured memory_bytes: 3680
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector<int> ss(n), ts(n), xs(n);
    for(int i = 0; i < n; i++){
        cin >> ss[i] >> ts[i] >> xs[i];
    }
    // vector<int> ds(q); cin >> ds;
    set<pair<int, int>> ds2;
    for(int i = 0; i < q; i++){
        int d; cin >> d;
        ds2.emplace(d, i);
    }
    vector<int> is(n);
    iota(is.begin(), is.end(), 0);
    sort(is.begin(), is.end(), [&](int i, int j){ return xs[i] < xs[j]; });
    vector<int> anss(q, -1);
    for(auto i : is){
        int l = ss[i] - xs[i], r = ts[i] - xs[i];
        printde(ss[i], ts[i], xs[i], l, r);
        if(ds2.empty()){ break; }
        auto ite = ds2.lower_bound(pair<int, int>(l, 0));
        if(ite == ds2.end()){ continue; }
        while(ite->first < r){
            anss[ite->second] = xs[i];
            ite = ds2.erase(ite);
            if(ite == ds2.end()){ break; }
        }
    }
    for(auto& ans : anss){
        cout << ans << '\n';
    }
}


Measured memory_bytes: 15232
package main

import (
	"fmt"
)


func main() {
	var s string
	fmt.Scanf("%s", &s)

	if s[0] == 'R' && s[1] == 'R' && s[2] == 'R' {
		fmt.Println(3)
	} else if s[0] == 'R' && s[1] == 'R' ||
		s[1] == 'R' && s[2] == 'R' {
		fmt.Println(2)
	} else if s[0] == 'R' ||
		s[1] == 'R' ||
		s[2] == 'R' {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

int P[100100];
int main(){
    int N;
    cin >> N;
    REP(i,N){
        int p;
        cin >> p;
        P[i] = p;
    }

    ll ans = 0;
    for(int i = 0; i < N; i++){
        int p = P[i];
        if(p == i+1){
            ans++;
            if(i+1 < N){
                P[i] = P[i+1];
                P[i+1] = p;
            }
        }
    }

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



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

using namespace std;

int solve() {
    int n; cin >> n;
    vector<int> nums(n);
    for (int i = 0; i < n; ++i) {
        cin >> nums[i];
    }
    
    int res{0};
    for (int i = 1; i < n - 1; ++i) {
        if ((nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) 
            || (nums[i - 1] > nums[i] && nums[i] > nums[i + 1])) {
            res++;
        }
    }
    
    return res;
}

int main() {
    cout << solve() << endl;
}

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

int main()
{
    int n;
    long long l_current, l_prev_1, l_prev_2;
    cin >> n;
    if(n == 0)
    {
        cout << "2" << endl;
    }
    else if(n == 1)
    {
        cout << "1" << endl;
    }
    else
    {
        l_prev_2 = 2;
        l_prev_1 = 1;
        for(int i=2; i<=n; i++)
        {
            l_current = l_prev_2 + l_prev_1;
            l_prev_2 = l_prev_1;
            l_prev_1 = l_current;
        }
        cout << l_current << endl;
    }
    return 0;
}

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

int parent(int i) {return i/2; }
int left(int i) {return i*2; }
int right(int i) {return i*2+1; }

int main(){
  int H,tree[100001];
  scanf("%d",&H);
  for(int i=1;i<=H;++i) scanf("%d",&tree[i]);
  for(int i=1;i<=H;++i){
    printf("node %d: key = %d, ",i,tree[i]);
    if(parent(i)>=1) printf("parent key = %d, ",tree[parent(i)]);
    if(left(i)<=H) printf("left key = %d, ",tree[left(i)]);
    if(right(i)<=H) printf("right key = %d, ",tree[right(i)]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

 
int main() {
    ll ans = 0;
    ll a, b, c;
    cin >> a >> b >> c;

    (b + c > a) ? (cout << b + c - a << endl) : (cout << 0 << endl);

    
}

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define pli pair<long long,int>
#define pil pair<int,long long>
#define ll long long
#define el '\n'

using namespace std;

const int N = 2e5 + 10;

int n, k;
int ar[N];

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

    cin >> n >> k;
    for (int i=1;i<=n;i++){
        cin >> ar[i];
    }
    for (int i=1;i<=k;i++){
        int ton[n + 2];
        fill(ton, ton + n + 2, 0);

        for (int j=1;j<=n;j++){
            int l = max(1, j - ar[j]);
            int r = min(n, j + ar[j]);
            ton[l]++;
            ton[r + 1]--;
        }
        int cur = 0;
        int cnt = 0;
        for (int i=1;i<=n;i++){
            cur += ton[i];
            ar[i] = cur;
            if (cur == n) cnt++;
        }
        if (cnt == n) break;
    }
    for (int i=1;i<=n;i++){
        cout << ar[i] << " ";
    }
    cout << el;

    return 0;
}

Measured memory_bytes: 5124
# 累積和
from sys import exit

N, K = map(int, input().split())
S = input()

p = '1'
count = 0
cs = []
for c in S:
  if c != p:
    cs.append(count)
    p = c
    count = 1
  else:
    count += 1
cs.append(count)
if p == '0':
  cs.append(0)

if len(cs) < 2 * K:
  print(N)
  exit()

for i in range(1, len(cs)):
  cs[i] += cs[i - 1]

result = cs[2 * K]
for i in range(2, len(cs) - 2 * K, 2):
  t = cs[2 * K + i] - cs[i - 1]
  if t > result:
    result = t
print(result)


Measured memory_bytes: 7164
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

const double ZERO = 1e-9;

const double PI = 3.1415926535;

double a, b, x;

double calcV(double h, int type)
{
	double v;
	if (1 == type) {
		v = a * a * b - a * h * a / 2;
//		v = a * a * b - a * h / 2.0;
	} else if (2 == type) {
		v = a * b * h / 2.0;
	}
	
	return v;
}

double doSearch(int type, double l, double t)
{
	double head = l;
	double tail = t;
	double result = -1;
	double mid;
	
	while (true)
	{
		mid = (head + tail) / 2;
		
		double cv = calcV(mid, type);
//		printf("%llf\n", cv);

 		if (fabs(cv - x) <= ZERO)
 		{
 			result = mid;
 			break;
		}
		
		if (cv >= x)//角度太大，要变小 
		{
			result = mid;
			tail = mid;			
		}
		else	//角度太大，要变小 
		{
			head = mid;
		}
	}
	
	return result;
}

double doSearch2(int type, double l, double t)
{
	double head = l;
	double tail = t;
	double result = -1;
	double mid;
	
	while (true)
	{
		mid = (head + tail) / 2;
		
		double cv = calcV(mid, type);
//		printf("%llf\n", cv);

 		if (fabs(cv - x) <= ZERO)
 		{
 			result = mid;
 			break;
		}
		
		if (cv >= x)//角度太大，要变小 
		{
			head = mid;			
			result = mid;
		}
		else	//角度太大，要变小 
		{
			tail = mid;
		}
	}
	
	return result;
}

int main()
{
	scanf("%lf%lf%lf", &a, &b, &x);
	
	double halfV = a * a * b / 2;
	
	if (fabs(halfV - x) < ZERO)	//==
	{
		double lengthAB = sqrt(a * a + b * b);
		double ratio = b / lengthAB;
		
		double rad = asin(ratio);
		double result = rad * 180.0 / PI;
		printf("%.12lf\n", result);
		
		return 0;
	} else if (halfV > x)	//在之后的段位里，公式V = a * b * h / 2 
	{
		double h = doSearch(2, 0, a);
		
		double lengthAB = sqrt(h * h + b * b);
		double ratio = b / lengthAB;
		double rad = asin(ratio);
		double result = rad * 180.0 / PI;
		printf("%.12lf\n", result);
		
		return 0;
	} else //在之前的段位里，公式V = a * a * b - a * h * a / 2;
	{
		double h = doSearch2(1, 0, b);
		
		double lengthAB = sqrt(h * h + a * a);
		double ratio = h / lengthAB;
		double rad = asin(ratio);
		double result = rad * 180.0 / PI;
		printf("%.12lf\n", result);
		
		return 0;
	}
	
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	int ans=0;
	for(int i=0;i<k;i++)
	ans+=a[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
int a[150005];
int main()
{
    ll x,y;
    cin>>x>>y;
    ll t=y/x;
    int cnt=0;
    while(t>0)
    {
        cnt++;
        t>>=1;
    }
    cout<<cnt<<'\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <cmath>

using namespace std;

void c_special_trains(void) {
	int n;
	cin >> n;
	vector<int> c(n);
	vector<int> s(n);
	vector<int> f(n);
	for (int i = 1; i <= n - 1; i++) {
		cin >> c[i] >> s[i] >> f[i];
	}

	for (int i = 1; i <= n - 1; i++) {
		int total = 0;
		total += (s[i]+c[i]);
		for (int j = i + 1; j <= n-1; j++) {
			int wait_time;
			if (total < s[j]) wait_time = s[j] - total;
			else if (total % f[j] == 0) wait_time = 0;
			else wait_time = f[j] - total % f[j];

			total += (wait_time + c[j]);
		}
		cout << total << endl;
	}
	cout << "0" << endl;
}

int main()
{
    c_special_trains();
    return 0;
}

Measured memory_bytes: 3640
h, w = map(int, input().split())
s = [input() for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            continue
        if i-1 >= 0 and s[i-1][j] == '#':
            continue
        if i+1 <= h-1 and s[i+1][j] == '#':
            continue
        if j-1 >= 0 and s[i][j-1] == '#':
            continue
        if j+1 <= w-1 and s[i][j+1] == '#':
            continue
        print('No')
        break
    else:
      continue
    break
else:
    print('Yes')

Measured memory_bytes: 3064
import java.io.*;

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

	String   input1 = br.readLine();
	String[] input2 = br.readLine().split(" ");

	int size = Integer.parseInt(input1);
	int[] a = new int[size];

	for(int i = 0; i < size; i++) {
		a[i] = Integer.parseInt(input2[i]);
	}

	long min = a[0], MAX = a[0], sum = 0;

	for(int j = 0; j < size; j++) {
		if(a[j] >= MAX) MAX = a[j];
		if(a[j] <= min) min = a[j];
		sum += a[j];
	}
	System.out.println(min + " " + MAX + " " + sum);
	}
}

Measured memory_bytes: 28440
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    string s;

    cin >> s;
    sort(s.begin(), s.end());

    if(s[0] == s[1] && s[0] != s[2] && s[2] == s[3]) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define allR(x) (x).rbegin(), (x).rend()
using ll = long long;
using P = pair<int, int>;
const int INF (1<<30);

int main() {
  string S, T;
  cin >> S >> T;

  int ans = 0;
  rep(i, S.length()) {
    if (S[i] != T[i]) ans++;
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    if(b == 1){
        cout << "0" << endl;
    }
    else {
        int c = 1;
        int d = a;
        while(d < b){
            d += a-1;
            c++;
        }
        cout << c << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
    #include <cstdio>
    using namespace std;
     
    int main() {
    long long n,res=1,mod= 1e9+7;
    scanf("%lld",&n);
    for(long long i=1;i<=n;i++)
    {
    res*=i;
    res=res%mod;
    }
     
     
    printf("%lld",res);
    }

Measured memory_bytes: 256
from itertools import product
from bisect import bisect_right

n = int(input())
m = len(str(n))

ans = 0
for i in range(3, m+1):
    candidates = []
    for v in product(['3', '5', '7'], repeat=i):
        if '3' in v and '5' in v and '7' in v:
            candidates.append(int(''.join(v)))
    candidates.sort()
    ans += bisect_right(candidates, n)

print(ans)

Measured memory_bytes: 45164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
public class MainClass
{
	public const long Giri = 1000000007;
 
	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		Console.WriteLine((p[0]+p[1])%24);
	}
	
 
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}
 
public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 13140