akhauriyash/Code-Regression huggingface dataset:
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD=998244353;
const ll hell=MOD;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;


void solve()
{
    int n;
    cin>>n;
    int L[n],R[n],l,r;
    for(int i=0;i<n;i++)
    {
        cin>>l>>r;
        L[i]=l;R[i]=r;
    }
    sort(L,L+n);
    sort(R,R+n);
    if(n%2)
    {
        int ans=R[n/2]-L[n/2]+1;
        cout<<ans<<endl;
    }
    else
    {
        int s1=L[(n-1)/2]+L[n/2],s2=R[(n-1)/2]+R[n/2];
        ldb z1=s1/2.0,z2=s2/2.0;
        int ans=0;
        if(s1%2)
        {
            ans++;
            s1=(s1+1)/2;
        }
        else
            s1/=2;
       if(s2%2&&z1!=z2)
           ans++;
        
        s2/=2;
        if(s2>=s1)
        {
            ans=ans+2*(s2-s1)+1;
        }
        cout<<ans<<endl;
        
        
    }
    
    
    
    
    
}


int32_t main()
{
    IOS;
    //pre();
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        
        solve();
    }
    return 0;
}


Measured memory_bytes: 6792
import random
import time
import copy
import math
start=time.time()
d=int(input())
c=list(map(int,input().split()))
s=[]
cli=[]
for i in range(d+1):
  ch=[]
  for j in c:
    ch.append(i*j)
  cli.append(ch)
for i in range(d):
  s.append(list(map(int,input().split())))
last=[0]*26
score=0
solution=[]
for day in range(1,d+1):
  co=[]
  dla=[]
  down=0
  for (i,j) in zip(last,c):
    down+=(day-i)*j
  for (i,j) in zip(last,c):
    dla.append(down-(j*(day-i)))
  for con in range(26):
    co.append(s[day-1][con]-dla[con])
  choice=co.index(max(co))
  score+=co[choice]
  last[choice]=day
  #print(choice+1)
  #print(score)
  solution.append(choice)
#print(score)
stemp=2000
etemp=100
def tem():
  return stemp-((stemp-etemp)*(time.time()-start)/1.9)
while time.time()-start<1.95:
  
  sc=0
  sol=copy.deepcopy(solution)
  for x in [random.randrange(d) for i in range(1)]:
    sol[x]=random.randrange(26)
  last=[0]*26
  for (day,i) in zip(range(1,d+1),sol):
    sc+=s[day-1][i]
    last[i]=day
    for (i,j) in zip(last,range(26)):
      sc-=cli[day-i][j]
  try:
    prob = math.exp((sc-score)/tem())
  except:
    prob=0
  #print("{} {}".format(sc,prob))
  if prob>random.random():
    solution=copy.deepcopy(sol)
    score=sc
    #print(score)
for i in solution:
  print(i+1)
#print(sco)


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


int main(){
  int n;
  cin >> n;
  vector<int> l(2*n);
  int sum =0;
  rep(i,2*n){
    cin >> l[i];
  }
  rep(i,2*n){
    rep(j,2*n-i-1){
      int temp;
      if(l[j]>l[j+1]){
        temp =l[j];
        l[j] = l[j+1];
        l[j+1]=temp;
      }
    }
  }
  rep(i,n){
    sum +=l[2*i];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    long long n, m;
    cin >> n >> m;
    int t=0;
    for (int i=0; i<n; ++i)
    {
        long long f, r;
        cin >> f >> r;
        long long q=f*f+r*r;
        if (q<=m*m)
            t+=1;
    }
    cout << t << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
vector<long long> x;
vector<vector<int>> dp(200010,vector<int>(2,-1));
long long n,m,a,b;

bool ans(long long curr , long long type){
    if(dp[curr][type] != -1){
        return dp[curr][type];
    }
    if(type == 0){
        for(int i = 0 ; i < n ; i += 1){
            if(curr - x[i] >= 0){
                if(ans(curr-x[i],1)){
                    dp[curr][type] = 1;
                    return true;
                }
            }else{
                break;
            }
        }
        dp[curr][type] = 0;
        return false;
    }else{
        for(int i = 0 ; i < n ; i += 1){
            if(curr - x[i] >= 0){
                if(!ans(curr-x[i],0)){
                    dp[curr][type] = 0;
                    return false;
                }
            }else{
                break;
            }
        }
        dp[curr][type] = 1;
        return true;
    }
}

int main(){
    cin >> n >> m;
    x.resize(n);
    for(int i = 0 ; i < n ; i += 1){
        cin >> x[i];
    }
    sort(x.begin(),x.end());
    if(ans(m,0)){
        cout << "First";
    }else{
        cout << "Second";
    }
}

Measured memory_bytes: 15872
fun abs(n:Int):Int{
    if(n<0){
        return -n
    }
    return n
}
fun main(args: Array<String>) {
    var (n, k)= readLine()!!.split(" ").map { it.toInt() }
    var bars= readLine()!!.split(" ").map { it.toInt() }
    var dp= mutableListOf<Int>()
    dp.add(0)
    for (i in 1 until n){
        var tmp=mutableListOf<Int>()
        for(j in 1..k){
            if(i-j<0){
                break
            }
            tmp.add(dp[i-j]+ abs(bars[i]-bars[i-j]))
        }
        dp.add(tmp.min()!!)
    }
    println(dp[n-1])
}

Measured memory_bytes: 123160
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

S = list(input())

ans1 = 0
for i, s in enumerate(S): 
    if i % 2 == 0:
        if s == "0":
            ans1 += 1
    else:
        if s == "1":
            ans1 += 1

ans2 = 0
for i, s in enumerate(S): 
    if i % 2 != 0:
        if s == "0":
            ans2 += 1
    else:
        if s == "1":
            ans2 += 1

ans = min(ans1, ans2)
print(ans)

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    ll N, M;
    cin >> N >> M;

    ll ans = 0;
    rep(i, N) ans += i;
    rep(i, M) ans += i;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    H, W = map(int, input().split())

    graph = [[i for i in list(map(int, input().split()))] for _ in range(10)]
    graph = csr_matrix(graph)

    dist_matrix = floyd_warshall(csgraph=graph, directed=True, return_predecessors=False)
    dist_matrix = list(dist_matrix)

    wall = [[i for i in list(map(int, input().split()))] for _ in range(H)]

    cnt = 0
    for h in range(H):
        for w in range(W):
            val = wall[h][w]
            if val != -1 and val != 1:
                cnt += dist_matrix[val][1]
    print(int(cnt))


resolve()

Measured memory_bytes: 14644
#include<stdio.h>

int main(void)
{
    int N,a,b;

    scanf("%d",&N);

    for(a=1;a<=9;a++)
     for(b=1;b<=9;b++){
       if(a*b==N){
        printf("Yes\n");

     return 0;
}

}
     printf("No\n");    
     
}


Measured memory_bytes: 128
#include<iostream>
#include<string.h>
using namespace std;

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

  int a = stoi(s);
  int jou,kai;

  jou = ((a/1000)*10);
  a %= 1000;
  jou += ((a/100));
  a %= 100;
  kai = a;

  bool ym,my;
  ym = true;
  my = true;

  if(jou == 0){
    my = false;
  }
  if(kai == 0){
    ym = false;
  }
  if(jou > 12){
    my = false;
  }
  if(kai > 12){
    ym = false;
  }

  if(ym && my){
    cout << "AMBIGUOUS" << endl;
  }else if(ym && !my){
    cout << "YYMM" << endl;
  }else if(!ym && my){
    cout << "MMYY" << endl;
  }else{
    cout << "NA" << endl;
  }
}


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

int A[4];
string ans;

void dfs(int n, int sum, string s){
	if(n == 4){
		if(sum == 7){
			ans = s + "=7";
		}
		return;
	}
	dfs(n + 1, sum - A[n], s + "-" + to_string(A[n]));
	dfs(n + 1, sum + A[n], s + "+" + to_string(A[n]));
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	for(int i = 0; i < 4; i++){
		char c;
		cin >> c;
		A[i] = c - '0';
	}

	dfs(1, A[0], to_string(A[0]));
	cout << ans << endl;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=0
for x in range(N):
  ans+=B[A[x]-1]
  if x<N-1:
    if A[x]+1==A[x+1]:
      ans+=C[A[x]-1]
print(ans)

Measured memory_bytes: 9208
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
    	int a, b;
    	
        void solve(InputReader in, PrintWriter out) {
        	a = in.nextInt();
        	b = in.nextInt();
        	
        	if (a <= 0 && 0 <= b) {
				out.println("Zero");
			} else if (0 < a){
				out.println("Positive");
			} else if ((b - a + 1) % 2 == 0){
				out.println("Positive");
			} else {
				out.println("Negative");
			}
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 21460
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
sum = 0
ans = 0
for i in range(N):
    A = list(map(int,input().split()))
    for j in range(M):
        sum += A[j]*B[j]
    if(sum + C > 0):
        ans +=1
    sum = 0
print(ans)

Measured memory_bytes: 9184
def calcDigit(x)
  t = x
  d = 0
  while t > 0
    t = t / 10
    d += 1
  end

  return d
end

input = Array.new()

while (line = gets) != nil
  input.push(line.split())
end

for i, j in input
  puts calcDigit(i.to_i + j.to_i)
end

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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;
typedef vector<int> vi;
typedef vector<ll> vll;

int sieve[1000100];
int gcd(int a, int b) {
	if(b > a) return gcd(b,a);
	if(b == 0) return a;
	else return gcd(b, a % b);
}

int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int n;
	cin >> n;
	for(int i = 2; i < 1000100; i++) {
		if(sieve[i] == 0) {
			for(int j = i; j < 1000100; j += i) {
				sieve[j] = i;
			}
		}
	}
	set<int> primes;
	bool flag = true;
	int GCD = 0;
	M00(i, n) {
		int x;
		cin >> x;
		GCD = gcd(GCD, x);
		if(flag) {
		while(x != 1) {
			int p = sieve[x];
			while(x % p == 0) x /= p;
			if(primes.count(p) > 0) flag = false;
			else primes.insert(p);
		}
		}
	}
	if(flag) cout << "pairwise coprime" << endl;
	else if(GCD == 1) cout << "setwise coprime" << endl;
	else cout << "not coprime" << endl;
}


Measured memory_bytes: 11176
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll K, S;
    cin >> K >> S;

    ll ans = 0;
    rep(i, min(S, K) + 1){
        if(S - i <= 2 * K && S - i > K){
            ans += K - (S - i - K) + 1;
        }else if(S - i <= K){
            ans += S - i + 1;
        }//cout << "x: " << i << ", ans: " << ans << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,L;
    cin >>N>>L;
    vector<string>vec(N);
    for(int i=0;i<N;i++){
        cin >>vec.at(i);
    }
    sort(vec.begin(),vec.end());
    for(int i=0;i<N;i++){
      cout <<vec.at(i);
 } 
 cout <<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#define INF 1000000013
using namespace std;
typedef long long ll;
ll dp[110][100010];

int main(){
  ll n,w;
  cin >> n >> w;
  ll a[n],b[n];
  for(ll i=0;i<n;i++) cin >> a[i] >> b[i];
  for(ll i=1;i<100010;i++) dp[0][i]=INF;
  for(ll i=1;i<=n;i++){
    for(ll j=0;j<100010;j++){
      if(j>=b[i-1]) dp[i][j]=min(dp[i-1][j],dp[i-1][j-b[i-1]]+a[i-1]);
      else dp[i][j]=min(dp[i-1][j],dp[i-1][0]+a[i-1]);
    }
  }
  ll ans=0;
  for(ll i=1;i<100010;i++){
    if(dp[n][i]<=w) ans=i;
  }
  cout << ans << endl;
  //cout << ans << endl;
  /*for(int i=1;i<=n;i++){
    for(int j=0;j<15;j++){
      if(dp[i][j]==INF) cout << "INF" << ' ';
      else cout << dp[i][j] << ' ';
    }
    cout << endl;
  }*/
}   

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

int main() {
    
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int m, d;
    cin >> m >> d;

    int ans = 0;

    for(int i=1; i<=m; i++)
        for(int j=1; j<=d; j++)
        {
            int d1 = j % 10;
            int d2 = j / 10;

            if(d1 >= 2 && d2 >= 2 && d1 * d2 == i)
            {
                ans++;
            }
        }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<set>
#define inf 0x3f3f3f3f
typedef long long ll;

const int maxn=1e5+5;

using namespace std;

ll ans,x,temp;

int main()
{
    scanf("%lld",&x);
    temp=x/500;
    ans+=temp*1000;
    x%=500;
    temp=x/5;
    ans+=temp*5;
    printf("%lld\n",ans);
}


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

typedef struct pos_ {
    long x, y;
} pos;

int main() {
    long n, m;
    scanf("%ld%ld", &n, &m);

    pos ab[n+1];
    pos cd[m+1];
    for (int i = 1; i <= n; i++) {
        scanf("%ld%ld", &(ab[i].x), &(ab[i].y));
    }
    for (int i = 1; i <= m; i++) {
        scanf("%ld%ld", &(cd[i].x), &(cd[i].y));
    }

    for (int i = 1; i <= n; i++) {
        pos a = ab[i];
        long mind = (100000000+1)*2;
        int minj = 1;
        for (int j = 1; j <= m; j++) {
            pos c = cd[j];
            long d = labs(a.x - c.x) + labs(a.y - c.y);
            if (d < mind) {
                mind = d;
                minj = j;
            }
        }
        printf("%d\n", minj);
    }

    return 0;
}

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

int main() {
    int H, W; cin >> H >> W;
    char a[H][W];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> a[i][j];
        }
    }        

    bool canH[H];
    for(int i=0; i<H; i++){
        bool can = false;
        for(int j=0; j<W; j++){
            if(a[i][j] == '#'){
                can = true;
            }
        }
        // cout << can;
        canH[i] = can;
    }

    // cout << endl << endl;

    bool canW[W];
    for(int i=0; i<W; i++){
        bool can = false;
        for(int j=0; j<H; j++){
            if(a[j][i] == '#'){
                can = true;
            }
        }
        // cout << can;
        canW[i] = can;
    }

    // cout << endl << endl;

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(canH[i] && canW[j]){
                cout << a[i][j];
            }
        }
        if(canH[i]) cout << endl;  
    }
}


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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  
  int blue=0,red;
  rep(i,n){
    if(s[i]=='1') blue++;
  }
  red = n - blue;
  
  cout << (min(blue,red)*2) << endl;
  
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

ll max(ll x,ll y){
  if(x > y)return x;
  else return y;
}
int main(){
  ll baggage[2];
  ll i,j,N,capacity;
  cin >> N >> capacity;
  vector<ll> dp(capacity+1);
  for(i=0;i<N;i++){
    cin >> baggage[0] >> baggage[1];
    for(j=capacity;j>=baggage[0];--j){
      dp[j] = max(dp[j],dp[j-baggage[0]]+baggage[1]);
    }
  }
  cout << dp[capacity] << endl;
  return 0;
}

Measured memory_bytes: 3936
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 int n;
 string s, t, ans;
 cin >> n >> s >> t;
 for(int i=0;i<n;i++){
   ans.push_back(s[i]);
   ans.push_back(t[i]);   
 }
 cout << ans;
 return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 100000
#define NIL -1

typedef struct{
  int p;
  int l;
  int r;
}Node;
Node T[MAX];
int n,D[MAX];

void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p==NIL)printf("root, ");
  else if(T[u].l==NIL)printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

int rec(int u,int p){
  D[u]=p;
  if(T[u].r!=NIL)rec(T[u].r,p);
  if(T[u].l!=NIL)rec(T[u].l,p+1);
}

int main(){
  int i,j,d,v,c,l,r;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=T[i].l=T[i].r=NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0)T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL)r=i;
  }
  rec(r,0);
  for(i=0;i<n;i++){
    print(i);
  }
  return 0;
}



Measured memory_bytes: 6384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int INF = (int)(1e+9) + 9;
int N;
vector<int> H;
vector<int> dp;

void input_init(void) {
	cin >> N;
	H.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> H[i];
	dp.resize(N, INF);
}

void solve(void) {
	dp[0] = 0;
	for (int i = 1; i < N; ++i) {
		int step1, step2;
		step1 = dp[i - 1] + abs(H[i - 1] - H[i]);
		if (i > 1)
			step2 = dp[i - 2] + abs(H[i - 2] - H[i]);
		else
			step2 = INF;
		int step = min(step1, step2);
		dp[i] = min(step, dp[i]);
	}
}

int main(void) {
	input_init();
	solve();
	cout << dp[N - 1] << '\n';
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
 
int main(){
  int num[9];
  int atk[9]={0,0,0,0,0,0,0,0,0};
  int N;
  scanf("%d %d %d", &num[0], &num[1], &num[2]);
  scanf("%d %d %d", &num[3], &num[4], &num[5]);
  scanf("%d %d %d", &num[6], &num[7], &num[8]);
  scanf("%d", &N);
  
  int re;
  for(int i=0; i<N; i++){
    //printf("%d %d %d\n", atk[0], atk[3], atk[6]);
    scanf("%d", &re);
    for(int j=0; j<9; j++){
      if(num[j]==re){
        atk[j]=1;
      }
    }
    if(atk[0]==1){
      if(atk[3]*atk[6]==1){
        printf("Yes");
        return 0;
      }else if(atk[4]*atk[8]==1){
        printf("Yes");
        return 0;
      }else if(atk[1]*atk[2]==1){
        printf("Yes");
        return 0;
      }
    }
    if(atk[2]==1){
      if(atk[5]*atk[8]==1){
        printf("Yes");
        return 0;
      }else if(atk[4]*atk[6]==1){
        printf("Yes");
        return 0;
      }
    }
    if(atk[6]*atk[7]*atk[8]==1){
      printf("Yes");
      return 0;
    }
    if(atk[1]*atk[7]*atk[4]==1){
      printf("Yes");
      return 0;
    }
    if(atk[3]*atk[4]*atk[5]==1){
      printf("Yes");
      return 0;
    }
  }
  printf("No");
  
  return 0;
}

Measured memory_bytes: 128
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=tf-8
#

"""
"""

from collections import defaultdict
import bisect

import sys
input = sys.stdin.readline
from decimal import *
from collections import Counter


def solve(n):
    cnt = Counter()
    n_int = 0
    for _ in range(n):
        getcontext().prec = 22
        a = input().rstrip()
        da = Decimal(a)
        ia = int(da.shift(9))
        #print(a,ia)
        if ia%10**9 == 0:
            n_int += 1
        pmul_2 = 0
        pmul_5 = 0
        ia2 = ia
        while ((ia2 & 1) == 0 and pmul_2 < 18): 
            ia2 = ia2 >> 1
            pmul_2 += 1
        ia5 = ia
        while 1:
            if (ia5 % 5 ==0 and pmul_5 < 18):
                pmul_5 += 1
                ia5 = ia5//5
            else:
                break
        cnt[(pmul_2,pmul_5)] += 1
    ans = 0
    #print(cnt)
    for pm2_1 in range(0,19):
        for pm2_2 in range(18-pm2_1,19):
            for pm5_1 in range(0,19):
                for pm5_2 in range(18-pm5_1,19):
                    ans += cnt[(pm2_1,pm5_1)]*cnt[(pm2_2,pm5_2)]
    ans -= n_int
    ans = ans//2
    
    print(ans)
                






def main():
    n = int(input())
    solve(n)


if __name__ == "__main__":
    main()

Measured memory_bytes: 284272
program coins
	implicit none
    integer :: a,b,c,x
    integer :: a5,i,j,k,Total
    integer :: num
    
    read(*,*) a
    read(*,*) b
    read(*,*) c
    read(*,*) x
    
    num=0
    
	do i=0,a
    	do j=0,b
        	do k=0,c
            	Total=i*500+j*100+k*50
                if(Total.eq.x) then
                	num=num+1
                endif
            end do
        end do
    end do
    
    write(*,'(i0)') num

end program coins

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> v;

  for (int i = 1; i <= min(A, B); ++i) {
    if (A % i == 0 && B % i == 0) {
      v.push_back(i);
    }
  }

  cout << v[v.size() - static_cast<size_t>(K)] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
#define MPlus(x,y) {x=(x+y)%M;}
#define MSub(x,y) {x=(x-y+M)%M;}
#define MMul(x,y) {x=(x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  vi a(n);
  rep(i,n){
    cin>>a[i];
    a[i]--;
  }

  int ans=0;
  rep(i,n){
    if(a[a[i]]==i) ans++;
  }

  cout<<ans/2<<endl;


}

Measured memory_bytes: 1024
S = input()
ans = 0
for i in range(2**(len(S)-1)):
    moji = S[0]
    tmp = 0
    for j in range(len(S)-1):
        if ((i >>j) & 1):
            moji = moji + '+' + S[j +1]
        else:
            moji = moji + S[j+1]
    tmp = moji.split('+')
    for k in range(len(tmp)):
        ans += int(tmp[k])
print(ans)


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

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

    vector<ll> h(n);
    rep(i, n) cin >> h.at(i);

    sort(h.rbegin(), h.rend());

    ll ans = 0;
    rep2(i, k, n) {
        ans += h.at(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4788
n,m,c = map(int,input().split())
B = list(map(int,input().split()))
count = 0
for i in range(n):
    A = list(map(int,input().split()))
    ans = c
    for i in range(m):
        ans += A[i]*B[i]
    if ans > 0:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>

#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

/*---------------------------------------------------*/

int prime[150000];
bool is_prime[150000];
vector<ll> v;

void sieve(){
  int p=0;
  rep(i,150000)is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  REP(i,2,150000){
    if(is_prime[i]){
      prime[p++]=i;
      for(int j=2*i;j<150000;j+=i)is_prime[j]=false;
    }
  }
  //rep(i,50)cout<<"DEBUG "<<prime[i]<<endl;
}

void solve(int n,int p){
  ll data[11000];
  int x=0;
  while(prime[x]<=n){
    //cout<<x<<" "<<prime[x]<<endl;
    x++;
  }
  int cnt=0;
  REP(i,x,x+p){
    REP(j,i,x+p){
      data[cnt]=(prime[i]+prime[j]);
      cnt++;
    }
  }
  sort(data,data+cnt);
  //rep(i,p)cout<<i+1<<" "<<v[i]<<endl;
  cout<<data[p-1]<<endl;
}

int main(){
  int n,p;
  sieve();
  while(cin>>n>>p){
    if(n==-1&&p==-1)break;
    solve(n,p);
  }
  return 0;
}

Measured memory_bytes: 3264
program DDCC2020A
    implicit none
    integer(8)::X,Y
    integer(8)::result=0

    read(5,*)X,Y

    if(X==1)then
        result=result+300000
    else if(X==2)then
        result=result+200000
    else if(X==3)then
        result=result+100000
    end if

    if(Y==1)then
        result=result+300000
    else if(Y==2)then
        result=result+200000
    else if(Y==3)then
        result=result+100000
    end if

    if(X==1 .and. Y==1)then
        result=result+400000
    end if

    print'(i0)',result
    
end program DDCC2020A

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = [INT() for _ in range(N)]
ans = 0
for i in range(N-1):
	if A[i]%2==1 and A[i+1]:
		A[i] -= 1
		A[i+1] -= 1
		ans += 1
for a in A:
	ans += a//2
print(ans)


Measured memory_bytes: 9416
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}

int x,n,p[111111];
int Min=INF,ans;
signed main(){
	
	cin>>x>>n;
	rep(i,n)cin>>p[i];
	sort(p,p+n,greater<>());
	
	for(int i=150;i>-100;i--){
		bool flag=true;
		rep(j,n)if(p[j]==i)flag=false;
		if(Min>=abs(i-x) && flag){
			Min=abs(i-x);
			ans=i;
		}
	}
	cout<<ans<<endl;

}

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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

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

  int N;
  string S;

  CIN(N >> S);

  int count = 0;

  map< char, bool > mBefore;

  for (int i = 0; i < N; i++) {
    mBefore[S[i]] = true;

    map< char, bool > mAfter;
    for (int j = i + 1; j < N; j++) {
      mAfter[S[j]] = true;
    }

    // 確認
    int test = 0;

    for (auto b : mBefore) {
      for (auto a : mAfter) {
        if (a.first == b.first) {
          test++;
        }
      }
    }

    count = max(count, test);
  }
  COUT(count);

  return 0;
}


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

using namespace std;

void dfs(int now, int bit, int complete, int &cnt, vector<vector<int>> &g){
  bit |= (1 << now);
  if(bit == complete){
    ++cnt;
    return;
  }
  for(const auto &x : g[now]){
    if((bit >> x) & 1) continue;
    dfs(x, bit, complete, cnt, g);
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for(int i = 0; i < m; ++i){
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int cnt = 0;
  dfs(0, 0, (1 << n) - 1, cnt, g);
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
import math

n=int(input())
s=[input() for i in range(n)]

std=[]
for i in range(n):
    std.append(sorted(s[i]))
stdx=[]
stdx=sorted(std)

cnt=0
k=1
for i in range(n-1):
    if stdx[i]==stdx[i+1]:
        k+=1
        if k>1 and i==n-2:
            cnt+=math.factorial(k)//math.factorial(k-2)//math.factorial(2)
    else:
        if k>1:
            cnt+=math.factorial(k)//math.factorial(k-2)//math.factorial(2)
            k=1

print(cnt)

Measured memory_bytes: 116056
#include <string.h>
#include <iostream>
using namespace std;
int main(void){
    char str[1200];

    cin >> str;
    while( !cin.fail() ){
        for( int cnt = 0; cnt < strlen( str ); cnt++ ){
            if( isalpha( str[cnt] ) ){
                if( islower( str[cnt] ) ) str[cnt] = toupper( str[cnt] );
                else str[cnt] = tolower( str[cnt] );
            }
        };
        cout << str << flush;
        cin >> str;
        if( !cin.fail() ){
            cout << ' ' << flush;
        }
    }
    cout << endl;
}


Measured memory_bytes: 3080
#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>;

const int MX = 2005;
bool d[3][3][MX];

int main() {
  vector<string> s(3);
  rep(i,3) cin >> s[i];
  sort(s.begin(),s.end());
  int ans = MX*3;
  do {
    rep(i,3)rep(j,3)rep(k,s[i].size()) {
      if (i >= j) continue;
      bool ok = true;
      for (int ni = k; ni < s[i].size(); ni++) {
        int nj = ni-k;
        if (nj >= s[j].size()) break;
        if (s[i][ni] == '?' || s[j][nj] == '?') continue;
        if (s[i][ni] != s[j][nj]) ok = false;
      }
      d[i][j][k] = ok;
    }

    auto f = [&](int i, int j, int k) {
      if (k >= s[i].size()) return true;
      return d[i][j][k];
    };

    rep(x,MX)rep(y,MX) {
      if (!f(0,1,x)) continue;
      if (!f(1,2,y)) continue;
      if (!f(0,2,x+y)) continue;
      int now = 0;
      now = max<int>(now, s[0].size());
      now = max<int>(now, x+s[1].size());
      now = max<int>(now, x+y+s[2].size());
      ans = min(ans, now);
    }
  } while (next_permutation(s.begin(), s.end()));
  cout << ans << endl;
  return 0;
}

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

string s,t;
const int INF=1e9+5;
template<typename T> void max_self(T& a,T b){
	a=max(a,b);
}

bool check_first(pair<int,int> p){
	return p.first==0||p.second==0;
}

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	// freopen("input.txt","r",stdin);
	cin>>s>>t;
	vector<vector<pair<int,pair<int,int>>>> dp(s.size()+1,vector<pair<int,pair<int,int>>>(t.size()+1,{-INF,{0,0}}));
	dp[0][0]={0,{0,0}}; 
	for(int i=0;i<(int)s.size();++i){
		for(int j=0;j<(int)t.size();++j){
			if(s[i]==t[j]){
				max_self(dp[i+1][j+1],mp(dp[i][j].first+1,mp(i,j)));
			}
			max_self(dp[i+1][j],mp(dp[i][j].first,mp(i,j)));
			max_self(dp[i][j+1],mp(dp[i][j].first,mp(i,j)));
		}
	}
	pair<int,pair<int,int>> ans={0,{0,0}};
	for(int i=0;i<=(int)s.size();++i){
		for(int j=0;j<=(int)t.size();++j){
			max_self(ans,mp(dp[i][j].first,mp(i,j)));
		}
	} 
	string res="";
	pair<int,int> cur=ans.second;
	while(!check_first(cur)){
		int ff=cur.first;
		int ss=cur.second;
		pair<int,int> pre=dp[ff][ss].second;
		if(pre==mp(ff-1,ss-1)){
			assert(s[ff-1]==t[ss-1]);
			res+=s[ff-1];
		}
		cur=pre;
	}
	reverse(res.begin(),res.end());
	cout<<res;
	return 0;
}
		


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

int main(){
	ll w, h, x, y;
	cin >> w >> h >> x >> y;
	cout << w * h * 0.5 << ' ';
	if(double(x) == w/2.0 && double(y) == h/2.0) cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
S=str(input())
a=S[0]
if a==S[1]:
  if S[2]==S[3]:
    if S[2]==a:
      print("No")
    else:
      print("Yes")
  else:
    print("No")
    
else:
  b=S[1]
  if (a==S[2] or b==S[2]) and (a==S[3] or b==S[3]):
    if S[2]==S[3]:
      print("No")
    else:
      print("Yes")
    
  else:
    print("No")


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

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

int h[3][3], m[3][3], s[3][3];

int main() {
	ios::sync_with_stdio(false);
	
	rep(i, 3)cin >> h[i][0] >> m[i][0] >> s[i][0] >> h[i][1] >> m[i][1] >> s[i][1];
	
	rep(i, 3) {
		s[i][2] = s[i][1] - s[i][0];
		if(s[i][2]<0) {
			s[i][2] += 60;
			m[i][1]--;
		}
		m[i][2] = m[i][1] - m[i][0];
		if(m[i][2]<0) {
			m[i][2] += 60;
			h[i][1]--;
		}
		h[i][2] = h[i][1] - h[i][0];
	}
	
	rep(i, 3) cout << h[i][2] << " " << m[i][2] << " " << s[i][2] << endl;
	
	return 0;
}

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

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int n; cin >> n;
    int k; cin >> k;
    vector <set <int>> tree;
    REP(i, n+1){
        set<int> a;
        tree.push_back(a);
    }
    int a;
    int b;
    REP(i, n-1){
        cin >> a >> b;
        tree[a].insert(b);
        tree[b].insert(a);
    }
    ll ans = k;
    ll div = 1e9 + 7;
    queue <int> nodes;
    nodes.push(1);
    while (!nodes.empty()){
        int node = nodes.front();
        nodes.pop();
        if (node == 1){
            if (tree[node].size() > k-1){
                ans = 0;
                break;
            }
            REP(i, tree[node].size()) {
                ans = ans * (k - 1 - i) % div;
                dump(ans)
            }
            for(auto n: tree[node]){
                nodes.push(n);
                tree[n].erase(node);
            }
            continue;
        }

        if (tree[node].size() > k-2){
            ans = 0;
            break;
        }
        REP(i, tree[node].size()) {
            ans = ans * (k - 2 - i) % div;
        }
        for(auto n: tree[node]){
            nodes.push(n);
            tree[n].erase(node);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15596
import sys
input = sys.stdin.readline

from itertools import groupby

N, K = [int(x) for x in input().split()]
S = list(input().rstrip())

S_groupby = groupby(S)

zero_idx = [] # ゼロが何番目か
value_list = [] # 各インデックスのキーに対する個数
i = -1
for j in S_groupby:
    i += 1
    key, value = j[0], len(list(j[1]))
    value_list.append(value)
    if key == '0':
        zero_idx.append(i)

if len(zero_idx) <= K:
    print(len(S))
    sys.exit()

left = zero_idx[0]
right = zero_idx[K - 1]
if zero_idx[0] == 0:
    ans = [sum(value_list[left:right + 2])]
else:
    ans = [sum(value_list[left - 1:right + 2])]

for i in range(K, len(zero_idx)):
    new_right = zero_idx[i]
    new_left = zero_idx[i - K + 1]
    new_ans = ans[-1] + value_list[new_right] - value_list[left]
    if new_right + 1 < len(value_list):
        new_ans += value_list[new_right + 1]
    if left - 1 >= 0:
        new_ans -= value_list[left - 1]
    ans.append(new_ans)
    right, left = new_right, new_left

print(max(ans))


Measured memory_bytes: 51720
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

typedef double D;
const D EPS = 1e-8;
const D INF = 1e10;
const D PI = M_PI;

struct P {
    D x, y;
    P(D xs, D ys) : x(xs), y(ys) { }
    P() { }
};

P operator +(P a, P b) { return P(a.x + b.x, a.y + b.y); }
P operator -(P a, P b) { return P(a.x - b.x, a.y - b.y); }
P operator *(P p, D s) { return P(p.x * s, p.y * s); }

D inp(P a, P b) { return a.x*b.x + a.y*b.y; }
D outp(P a, P b) { return a.x*b.y - a.y*b.x; }

D norm(P p) { return inp(p, p); }
D abs(P p) { return sqrt(norm(p)); }

bool eq(P a, P b) { return abs(a - b) < EPS; }

D arg(P p) { return atan2(p.y, p.x); }

P rot90(P p) {
    return P(-p.y, p.x);
}

P rot(P p, D radian) {
    P q;
    q.x = cos(radian)*p.x - sin(radian)*p.y;
    q.y = sin(radian)*p.x + cos(radian)*p.y;
    return q;
}

struct L : vector<P> {
    L(P a, P b) { push_back(a); push_back(b); }
    L() { this->resize(2); }
};

struct C {
    P p; D r;
    C(P ps, D rs) : p(ps), r(rs) { }
    C() { }
};

// ??´???l???????????????p?????????
// (l??????p??????????????????????????¨????????????????±???????)
// norm??§?????£?????????(abs??§??????????????????)
P projection(L l, P p) {
    P a = l[1] - l[0];
    P b = p - l[0];
    D t = inp(b, a) / norm(a);
    return l[0] + a * t;
}

// ??´???l???????????????p???????°?
// (l????????????????§°???p??????)
P reflection(L l, P p) {
    return p + (projection(l, p) - p) * 2;
}

int ccw(P a, P b, P c) {
    b = b - a; c = c - a;

    // a - b - c ????????????????????¨???
    if(outp(b, c) > EPS)  return +1; // ???????¨???????
    if(outp(b, c) < -EPS) return -1; // ????¨???????

    // a - b - c ??´??????????????¶??¨???
    if(inp(b, c) < 0)     return +2; // c - a - b
    if(norm(b) < norm(c)) return -2; // a - b - c
    return 0;                        // a - c - b
}

int main() {
    int Q; cin >> Q;
    while(Q--) {
        D x[4], y[4];
        for(int i = 0; i < 4; i++) {
            cin >> x[i] >> y[i];
        }

        P p(x[1] - x[0], y[1] - y[0]), q(x[3] - x[2], y[3] - y[2]);

        int result;
        if(abs(outp(p, q)) < EPS) {
            result = 2;
        }
        else if(abs(inp(p, q)) < EPS) {
            result = 1;
        }
        else {
            result = 0;
        }
        cout << result << endl;
    }
}

Measured memory_bytes: 1236
#include<stdio.h>

int main(void){
    int k;
    scanf("%d",&k);
    int buf[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    printf("%d",buf[k-1]);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
string s;
stack<int>le;// \角? 
stack<pair<int,int> >stk;// /角?，面? 
void solve(){
	int res=0,K=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='\\'){
			le.push(i);
		}else if(s[i]=='/'&&!le.empty()){
			int j=le.top();
			int space=i-j;
			le.pop();
			while(!stk.empty()&&stk.top().first>j){
				space+=stk.top().second;
				stk.pop();
			}
			stk.push(make_pair(i,space));
		}
	}
	vector<int> v;
	while(!stk.empty()){
		v.push_back(stk.top().second);
		res+=stk.top().second;
		stk.pop();
	}
	reverse(v.begin(),v.end());
	printf("%d\n",res);
	if(v.size()!=0){
		printf("%d ",v.size());
		for(int i=0;i<(int)v.size()-1;i++){
			printf("%d ",v[i]);
		}printf("%d\n",v[v.size()-1]);
	}else printf("0\n");
}
int main(){
//	freopen("a.txt","r",stdin);
	cin>>s;	
	solve();
	return 0;
}

Measured memory_bytes: 3336
s=[]
t=[]

n=int(input())
for i in range(n):
    s.append(input())

m=int(input())
for i in range(m):
    t.append(input())

a=[]
for i in range(n):
    a.append(s.count(s[i])-t.count(s[i]))

if max(a)<0:
    print(0)
else:
    print(max(a))


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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main()
{
    int n;
    ll x;
    cin >> n >> x;
    vector<int> to(n);
    REP(i, n)
    {
        cin >> to[i];
        to[i]--;
    }
    vector<vector<int>> root(n, vector<int>(64)); //[from][2^i]
    REP(i, 64)
    {
        REP(j, n)
        {
            if (i == 0) {
                root[j][i] = to[j];
            } else {
                root[j][i] = root[root[j][i - 1]][i - 1];
            }
        }
    }
    int ans = 0;
    REP(i, 64)
    {
        if (x & (1LL << i)) {
            ans = root[ans][i];
        }
    }
    cout << ans + 1 << endl;
}

Measured memory_bytes: 61772
#include "bits/stdc++.h"
using namespace std;
 
int n,t,c[100],x,mn=1001;
int main(){

	cin>>n>>t;
	for(int i=0;i<n;i++){
		cin>>c[i]>>x;
		if(x <= t && c[i] < mn)
			mn = c[i];
	}
	if(mn <= 1000)
		cout<<mn;
	else
		cout<<"TLE";
	return 0;
}


Measured memory_bytes: 256
from collections import deque

n, m = map(int, input().split())
name = ['']*n
time = ['']*n
for i in range(n):
	name[i], time[i] = input().split()
time = list(map(int, time))

Q = deque([i for i in range(n)])
t = 0
while Q!=deque([]):
	q = Q.popleft()
	if time[q]<=m:
		t += time[q]
		print(name[q] + ' ' + str(t))
	else:
		t += m
		time[q] -= m
		Q.append(q)


Measured memory_bytes: 11768
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize
   }

   let mut f = vec![0; n + 1];
   for x in 1.. {
      if x * x >= n {
         break;
      }
      for y in 1.. {
         if x * x + y * y >= n {
            break;
         }
         for z in 1.. {
            let s = x * x + y * y + z * z + x * y + y * z + z * x;
            if s <= n {
               f[s] += 1;
            } else {
               break;
            }
         }
      }
   }
   for i in 1..=n {
      println!("{}", f[i]);
   }
}


Measured memory_bytes: 2120
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    tmp0 = input[0].split(" ");
   // tmp1 = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
    var n = parseInt(tmp0[0], 10);
    var sam=0;
    if(n%2==1){var a=n/2;
               for(i=1;i<=a;i++){
                     sam=sam+i;}
                     console.log(sam*2);
                    }
                    else{var a=n/2;
                        for(i=1;i<=a-1;i++){
                           sam=sam+i;}
                           console.log(sam*2+a)
                        }
                    }

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    if(S[2] == S[3] && S[4] == S[5]){
        cout<<YES<<endl;
    }else{
        cout<<NO<<endl;
    }
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256