akhauriyash/Code-Regression huggingface dataset:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools, random
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right; sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

s = s()
if s[0:2] == "00":
    if "01" <= s[2:4] <= "12":
        print("YYMM")
    else:
        print("NA")
elif "01" <= s[0:2] <= "12":
    if s[2:4] == "00":
        print("MMYY")
    elif "01" <= s[2:4] <= "12":
        print("AMBIGUOUS")
    else:
        print("MMYY")
elif "13" <= s[0:2] <= "99":
    if s[2:4] == "00":
        print("NA")
    elif "01" <= s[2:4] <= "12":
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 7368
#include<stdio.h>
int main(){
   char x[1001];
   while(1){scanf("%s", x);
           int s = 0,i = 0;
           if(x[0] == '0')
             break;
           while(x[i]) s += (x[i++] - '0');
           printf("%d\n", s);}
return 0;}

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

using namespace std;

#define maxn 1000005
#define int long long
#define db(x) cout<<#x<<" ->"<<x<<endl
#define db2(x,y) cout<<#x<<"->"<<x<<", "<<#y<<" -> "<<y<<endl
#define db3(x,y,z) cout<<#x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define db4(w,x,y,z) cout<<#w <<" -> " << w << " , " << #x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define prt(x) for(auto it = x.begin(); it!=x.end(); it++) { cout<<*it<<" "; } cout<< endl
#define IN freopen("input.txt","r",stdin)

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	//	IN;
	int n, k;
	cin >> n >> k;
    if(k==1 || n==k ){
        cout << 0 << endl;
        return 0;
    }
    int ans = n-k;
    cout << ans << endl;

	return 0;
}


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

int findSum(int n){
	int sum=0;
	while(n){
		sum+=n%10;
		n/=10;
	}
	return sum;
}

int main(){
	int n;
	cin >> n;
	cout << (n%findSum(n)==0?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if((a+b) == c || (a+c) == b || (b+c) == a){
      System.out.println("Yes");
    }
    else
      System.out.println("No");
  }
}


Measured memory_bytes: 21076
#include <iostream>
#include <cstring>
#include <cstdlib>

using namespace std;

int dp[201][101],tep[201],a[201],b[201],c[201];
int main(){
    int d,n;
    cin>>d>>n;
    for(int i=0;i<d;++i) cin>>tep[i];
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;++i){
        cin>>a[i]>>b[i]>>c[i];
        if(a[i]<=tep[0]&&b[i]>=tep[0]) dp[0][c[i]]=0;
    }
    for(int i=0;i<d-1;++i){
        for(int j=0;j<101;++j){
            if(dp[i][j]==-1) continue;
            for(int k=0;k<n;++k){
                if(a[k]<=tep[i+1]&&b[k]>=tep[i+1]){
                    dp[i+1][c[k]]=max(dp[i+1][c[k]],dp[i][j]+abs(j-c[k]));
                }
            }
        }
    }
    int ans=0;
    for(int i=0;i<101;++i) ans=max(ans,dp[d-1][i]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3160
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math
import re

sys.setrecursionlimit(10000000)

while True:
    n, m = map(int, raw_input().split())
    if n + m == 0:
        break
    ls = []
    for i in range(n):
        N, M = raw_input().split()
        N = N.replace("*", ".")
        ls.append((N, int(M)))
    ans = 0
    for i in range(m):
        B = raw_input()
        for N, M in ls:
            if re.search(N, B):
                ans += M
    print ans


Measured memory_bytes: 5144
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define loop(i,n) rep(i,0,n)
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    if(n%2==0)cout << 0.5 << endl;
    else cout << setprecision(20) << 1-1.0*(n/2)/n << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq
from sys import stdin
from decimal import *
input = stdin.readline

#入力
# s = input()[0:-1]
# n = int(input())
# a = list(map(int,input().split()))
# a = [int(input()) for i in range()]
# n = int(input())
# a,b = map(float, input().split())
# ab=[]
# for i in range():
#     a,b = map(int, input().split())
#     ab.append([a,b])


     
def main():
    a,b = map(Decimal, input().split())

    print(int(a*b//1))
if __name__ == '__main__':
    main()

Measured memory_bytes: 10068
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

int main() {
   Int n, m;
   std::cin >> n >> m;
   for(Int x = 0; x <= n; ++x) {
      for(Int y = 0; x + y <= n; ++y) {
         Int z = n - x - y;
         if( 10000 * x + 5000 * y + 1000 * z == m ) {
            printf("%ld %ld %ld\n", x, y, z);
            return 0;
         }
      }
   }
   puts("-1 -1 -1");
}



Measured memory_bytes: 256
import java.util.Scanner;

	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int a = n%10;
			int b = (n/10)%10;
			int c = n/100;
			
			if(a==7||b==7||c==7) {
				System.out.println("Yes");
				
			}else {
				System.out.println("No");
			}
			
		}
	}

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

int main(){
    ll k;
    cin >> k;
    queue<ll> number;
    for(int i=1; i<=9;i++){
        number.push(i);
    }
    if(k==1){
        cout << 1 << endl;
        return 0;
    }
    rp(i,k-1){
        ll x=number.front();
        if(x%10==0){
            number.push(x*10);
            number.push(x*10+1);
        }
        else if(x%10==9){
            number.push(x*10+8);
            number.push(x*10+9);
        }
        else{
            number.push(x*10+x%10-1);
            number.push(x*10+x%10);
            number.push(x*10+x%10+1);
        }
        //cout << number.front() << endl;
        number.pop();
    }
    cout << number.front() << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int priority[] = {2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 1};

int found(int x) {
    int sol;
    for (int i = 0 ; i < 13 ; i++)
        if (priority[i] == x) return i;
    return -1;
}

int main() {
    int a,b; scanf("%d%d" , &a , &b);
    int aIdx = found(a), bIdx = found(b);
    if (aIdx > bIdx) printf("Alice\n");
    else if (aIdx < bIdx) printf("Bob\n");
    else printf("Draw\n");
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
int x, y, a, b, c;
ll p[100000], q[100000], r[100000], ans;
priority_queue<ll, vector<ll>, greater<ll>> que;
int main() {
  scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
  for (int i = 0; i < a; i++) {
    scanf("%lld", &p[i]);
  }
  for (int i = 0; i < b; i++) {
    scanf("%lld", &q[i]);
  }
  for (int i = 0; i < c; i++) {
    scanf("%lld", &r[i]);
  }
  sort(p, p + a);
  sort(q, q + b);
  sort(r, r + c);
  for (int i = 0; i < x; i++) {
    ans += p[a - 1 - i];
    que.push(p[a - 1 - i]);
  }
  for (int i = 0; i < y; i++) {
    ans += q[b - 1 - i];
    que.push(q[b - 1 - i]);
  }
  for (int i = 0; i < c; i++) {
    if (que.top() < r[c - 1 - i]) {
      ans -= que.top();
      ans += r[c - 1 - i];
      que.pop();
      que.push(r[c - 1 - i]);
    }
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 4724
i, o, t, j, l, s, z = map(int, raw_input().split())
def f(x, y, z):
    if x >= 0 and y >= 0 and z >= 0 and x % 2 == y % 2 == z % 2:
        return x + y + z
    else:
        return 0
print o + max(f(i, j, l), f(i - 1, j, l), f(i, j - 1, l), f(i, j, l - 1), f(i - 1, j - 1, l), f(i - 1, j, l - 1), f(i, j - 1, l - 1))


Measured memory_bytes: 2568
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <stack>
#include <map>
#include <string> 
#include <set>
#include <iomanip>
#define eps 1e-5
#define N 100005 
#define pi acos(-1)
#define e 2.71828182845904523536
using namespace std;

int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if (a+b>=c) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <cstddef>
#include <cstdint>
#include <vector>

namespace null_null {

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using usize = std::size_t;

constexpr usize operator"" _z(unsigned long long x) noexcept {
  return static_cast<usize>(x);
}

template <typename T>
std::vector<T> make_v(usize a) { return std::vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(usize a, Ts... ts) {
  return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template <typename T, typename V>
typename std::enable_if<std::is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename std ::enable_if<std::is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
  for (auto &e : t) fill_v(e, v);
}

template <typename T, typename V>
inline void chmin(T &a, V b) {
  if (a > b) a = b;
}
template <typename T, typename V>
inline void chmax(T &a, V b) {
  if (a < b) a = b;
}

} // namespace null_null

#include <algorithm>
#include <iostream>
#include <utility>

namespace null_null {

void main_() {
  i32 L, R;
  std::cin >> L >> R;

  if (std::abs(R - L) <= 2019) {
    i32 ans = 3000;
    for (i32 i = L; i <= R; i++) {
      for (i32 j = i + 1; j <= R; j++) {
        ans = std::min(ans, (i * j) % 2019);
      }
    }
    std::cout << ans << std::endl;
  } else {
    std::cout << 0 << std::endl;
  }
}

} // namespace null_null

int main() {
  null_null::main_();
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
using namespace std;
int main(void){
    
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    
    if(x+r>W||y+r>H||x-r<0||y-r<0){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
    
}



Measured memory_bytes: 3096
#include <iostream>
#include <cmath>
#include <complex>
#include <vector>

using namespace std;

const double EPS = 1e-10;

typedef complex<double> P;

double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
int main(){
    double xA,yA,xB,yB,xC,yC,xD,yD;
    while(cin>>xA>>yA>>xB>>yB>>xC>>yC>>xD>>yD){
        P ps[] = {P(xA,yA),P(xB,yB),P(xC,yC),P(xD,yD)};
        double d=dot(ps[0]-ps[1],ps[2]-ps[3]);
        cout<<(abs(d-0) < EPS ? "YES" : "NO")<<endl;
    }
}

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

typedef long long ll;

vector<ll> A;

int solve(int dp[], ll k) {
    // bcout << dp[k] << " : " << k << endl;
    if (dp[k] != 0) {
        return dp[k];
    }

    for (ll i = 0; i < A.size(); i++) {
        if (k - A[i] < 0) {
            continue;
        } else {
            if (solve(dp, k - A[i]) == 2) {
                dp[k] = 1;
                return dp[k];
            }
        }
    }

    dp[k] = 2;
    return dp[k];
}

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

    for (ll i = 0; i < N; i++) {
        ll a;
        cin >> a;
        A.push_back(a);
    }

    int dp[K + 1];
    memset(dp, 0, sizeof(dp));
    dp[0] = 2;


    if (solve(dp, K) == 1) {
        cout << "First";
    } else {
        cout << "Second";
    }
    return 0;
}

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

constexpr int64_t mod = 1000000007;

void dfs(const vector<vector<int>> &to,
            vector<int64_t> &dp_black,
            vector<int64_t> &dp_white,
            int index) {
  dp_black.at(index) = 1;
  dp_white.at(index) = 1;
  for (auto next : to.at(index)) {
    if (dp_black.at(next) != -1) continue;
    dfs(to, dp_black, dp_white, next);
    (dp_black.at(index) *= dp_white.at(next)) %= mod;
    (dp_white.at(index) *= dp_black.at(next) + dp_white.at(next)) %= mod;
  }
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> to(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    to.at(x).push_back(y);
    to.at(y).push_back(x);
  }
  vector<int64_t> dp_black(n, -1), dp_white(n, -1);
  dfs(to, dp_black, dp_white, 0);
  cout << (dp_black.at(0) + dp_white.at(0)) % mod << endl;
}


Measured memory_bytes: 15616
N,x=map(int,input().split())
if x==1 or x==2*N-1:
    print("No")
    exit()
print("Yes")
if N==2:
    for i in range(1,4):
        print(i)
    exit()
x-=1
A=[-1 for i in range(2*N-1)]
B=[0 for i in range(2*N-1)]
if x==1:
    A[N-2]=x+1
    A[N-1]=x
    A[N]=x-1
    A[N+1]=x+2
    for i in range(4):
        B[x-1+i]=1
else:
    A[N-2]=x-1
    A[N-1]=x
    A[N]=x+1
    A[N+1]=x-2
    for i in range(4):
        B[x-2+i]=1

C=[]
for i in range(2*N-1):
    if B[i]==0:
        C.append(i)
for i in range(2*N-1):
    if A[i]!=-1:
        continue
    A[i]=C[-1]
    C.pop()
for i in A:
    print(i+1)

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

using namespace std;

int main(void) {
    string S, T;
    cin >> S >> T;
    T.pop_back();
    if(S == T) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl x(n);
    rep(i, n) {
        cin >> x[i];
    }

    ll ans = INF;
    rep(i, n-k+1) {
        ll now;
        if(x[i]*x[i+k-1] < 0) {
            now = min(abs(x[i]), x[i+k-1]) + (x[i+k-1] - x[i]); 
        }
        else if(0 <= x[i]) {
            now = x[i+k-1];
        }
        else {
            now = abs(x[i]);
        }
        chmin(ans, now);
    }

    out(ans);
    re0;
}

Measured memory_bytes: 1024
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
    I LOVE CLARICE STARLING

     ♥LOVE♥        ♥LOVE♥
  ♥LOVE♥♥LOVE♥  ♥LOVE♥♥LOVE♥
♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
   ♥LOVE♥♥LOVE♥♥LOVE♥♥LOVE♥
      ♥LOVE♥♥LOVE♥♥LOVE♥
         ♥LOVE♥♥LOVE♥
            ♥LOVE♥
               ♥


        EXPLAINATION BELOW->
        Read Editorial first
      
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
ll gcd(ll a,ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
          
} 
ll color(char c)
{
   if(c=='R')return 0;
   if(c=='G')return 1;
   if(c=='B')return 2;
   return 3; 
}
char color(ll c)
{
   if(c==0)return 'R';
   if(c==1)return 'G';
   if(c==2)return 'B';
   return 3; 
}
void solve()
{
  ll n,i,j,k;
  string s;cin>>n>>s;
  ll dp[n+1][3];
  vector<ll>V[3];
  dp[n][0]=dp[n][1]=dp[n][2]=0;
  for(i=n-1;i>=0;i--)
  {
      dp[i][0]=dp[i+1][0];
      dp[i][1]=dp[i+1][1];
      dp[i][2]=dp[i+1][2];
      
      j=color(s[i]);
      dp[i][j]+=1;
      V[j].pb(i);
  }
  fo(i,0,3)
  sort(all(V[i]));
  
  ll ans=0;
  vector<ll> :: iterator it;
  fo(i,0,n)
  {
      ll p1=(color(s[i])+1)%3;
      ll p2=(color(s[i])+2)%3;
      char c;
     //part 1
     it=lower_bound(all(V[p1]),i);
     c=color(p2);
     while(it!=V[p1].end())
     {
         j=(*it);
         ans+=dp[j][p2];
         k=j+(j-i);
         if(k<n&&s[k]==c)ans--;
         it++;
     }
     
     //part 2 
     it=lower_bound(all(V[p2]),i);
     c=color(p1);
     while(it!=V[p2].end())
     {
         j=(*it);
         ans+=dp[j][p1];
         k=j+(j-i);
         if(k<n&&s[k]==c)ans--;
         it++;
     }
  }
  cout<<ans<<"\n";
}
int main()
{
   fastio
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

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


public struct Point
{
	public double X;
	public double Y;
	
	public Point( double x, double y ) { X = x; Y = y; }

}

public class Test
{

	public static void Main( )
	{
		var n = int.Parse( Console.ReadLine().Trim() );
		

		
		Point start = new Point( 0, 0 );
		Point end = new Point( 100, 0 );
		
		Console.WriteLine( "{0:f8} {1:f8}", start.X, start.Y  );
		kock( n, start, end );
		Console.WriteLine( "{0:f8} {1:f8}", end.X, end.Y  );
		return;
	}

	public static void kock( int n, Point p1, Point p2 )
	{
		if( n == 0 ) { return; }

		Point s = new Point( 0, 0 );
		Point u = new Point( 0, 0 );
		Point t = new Point( 0, 0 );
		
		s.X = (2*p1.X+1*p2.X)/3;
		s.Y = (2*p1.Y+1*p2.Y)/3;
		t.X = (1*p1.X+2*p2.X)/3;
		t.Y = (1*p1.Y+2*p2.Y)/3;
		double cos60 = Math.Cos(60 * (Math.PI / 180 ) );
		double sin60 = Math.Sin(60 * (Math.PI / 180 ) );
		u.X = (t.X-s.X)*cos60-(t.Y-s.Y)*sin60+s.X;
		u.Y = (t.X-s.X)*sin60+(t.Y-s.Y)*cos60+s.Y;

		kock(n-1, p1, s);
		Console.WriteLine( "{0:f8} {1:f8}", s.X, s.Y  );
		kock(n-1, s, u);
		Console.WriteLine( "{0:f8} {1:f8}", u.X, u.Y  );
		kock(n-1, u, t);
		Console.WriteLine( "{0:f8} {1:f8}", t.X, t.Y  );
		kock(n-1, t, p2);
		
		
		return;
	}

}


Measured memory_bytes: 18012
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptor/reversed.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

class union_find
{
	std::vector<int> parent, rank;
	std::size_t sz;
public:
	union_find(std::size_t s) :parent(s, -1), rank(s), sz(s)
	{

	}
	int find(int a)
	{
		if (parent[a] == -1)
		{
			return a;
		}
		else
		{
			return parent[a] = find(parent[a]);
		}
	}
	void merge(int a, int b)
	{
		auto x = find(a);
		auto y = find(b);
		if (x != y)
		{
			--sz;
			if (rank[x] < rank[y])
			{
				parent[x] = y;
			}
			else if (rank[y] < rank[x])
			{
				parent[y] = x;
			}
			else
			{
				parent[y] = x;
				++rank[x];
			}
		}
	}
	std::size_t size()const
	{
		return sz;
	}
};

void Main()
{
	int N;
	std::cin >> N;
	std::vector<std::pair<int, int>> balls(N);
	for (auto& p : balls)
	{
		std::cin >> p.first >> p.second;
	}
	std::set<std::pair<int, int>> set;
	for (int i : boost::irange(0, N))
	{
		for (int j : boost::irange(0, N))
		{
			if (i == j)
			{
				continue;
			}
			auto a = balls[i];
			auto b = balls[j];
			set.emplace(a.first - b.first, a.second - b.second);
		}
	}
	std::size_t min = N;
	for (auto&& p : set)
	{
		union_find uf(N);
		for (int i : boost::irange(0, N))
		{
			for (int j : boost::irange(0, N))
			{
				auto a = balls[i];
				auto b = balls[j];
				auto q = std::make_pair(a.first - b.first, a.second - b.second);
				if (p == q)
				{
					uf.merge(i, j);
				}
			}
		}
		min = std::min(min, uf.size());
	}
	std::cout << min << std::endl;
}

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

Measured memory_bytes: 384
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1 << 30
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int MOD = 1000000007;


int main(){
    std::ios_base::sync_with_stdio(false);

    int n; cin >> n;
    std::map<ll, bool> mp;

    REP(i,n){
        ll a; cin >> a;

        if(mp.find(a) == mp.end()){
            mp[a] = true;
        } else {
            mp[a] = mp[a] ^ true;
        }
    }

    ll ans = 0LL;
    for(auto x: mp){
        if(x.second){
            ans++;
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  for (int i = n; i >= 0; i--) {
	if (s.substr(n - i, i) == t.substr(0, i)) {
	  cout << n + n - i << endl;
		return 0;
	}
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
int solve(vector<int> vec,int n,int k)
{
  vector<int> dp(n+1);
  dp[1]=0;
  for(int i=2;i<=n;i++)
  {
    dp[i]=inf;
    for(int j=i-1;j>=1 && (i-j)<=k ; j--)
    {
      dp[i] = min(dp[i],abs(vec[i]-vec[j])+dp[j]);
    }
  }
  return dp[n];
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int n,k;
  cin>>n>>k;
  vector<int> vec(n+1);
  for(int i=1;i<=n;i++)
  {
    cin>>vec[i];
  }
  cout<<solve(vec,n,k);
  return 0;
}


Measured memory_bytes: 1408
from math import gcd

from collections import Counter
from itertools import product


min2 = lambda x,y: x if x < y else y


# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)


# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def chinese_remainder_theorem(R, M, prod):
    """
    returns x s.t.
    all(x%m == r for r,m in zip(R,M))
    """
    s = 0
    for m,r in zip(M,R):
        p = prod//m
        s += r * p * modinv(p,m)
        s %= prod
    return s


# 素因数分解
def prime_factors(n):
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            yield i
    if n > 1:
        yield n



N = int(input())

factors = Counter(prime_factors(N))
if factors[2] > 0:
    factors[2] += 1
    N *= 2
mods = [f**p for f,p in factors.items()]

res = N
for R in product(*((0,m-1) for m in mods)):
    t = chinese_remainder_theorem(R, mods, N)
    if t > 0:
        res = min2(res, t)

print(res)

Measured memory_bytes: 72088
#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

const int MAXN = 1e5 + 10;
string s;
int main(){
	cin >> s;
	for(int i = 0 ; i < s.size() - 1 ; ++ i)
		if(s[i] == s[i + 1]){
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
	for(int i = 0 ; i < s.size() - 2 ; ++ i)
		if(s[i] == s[i + 2]){
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	cout << -1 << " " << -1 << endl;
	return 0;
}

Measured memory_bytes: 512
input_lines = gets.chop.split.map(&:to_i)
input_lines2 = gets.chop.split.map(&:to_i)
input_lines3 = gets.chop.split.map(&:to_i)
input_lines4 = gets.chop.split.map(&:to_i)

count = 0
n = input_lines[0]
for i in 0...n
    count = count + input_lines3[(input_lines2[i] - 1)]
    if i != 0 && input_lines2[i-1] + 1 == input_lines2[i] 
        count = count + input_lines4[(input_lines2[i] - 2)]
    end
end

puts count

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

const long long LINF = 1000000000000000018ll;

struct Edge {
  int dst;
  long long cost;
  Edge() {}
  Edge(int x, int y) : dst(x), cost(y) {}
};

vector<vector<Edge>> graph;

vector<long long> dijkstra(int start_v, int v) {
  vector<long long> dist(v, 1000000000000000018ll);
  dist[start_v] = 0;
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
    greater<pair<long long, int>>> q;

  q.push(make_pair(0, start_v));

  while (!q.empty()) {
    pair<long long, int> t = q.top(); q.pop();
    int cur_v = t.second;
    for (auto nxt: graph[cur_v] ) {
      int next_v = nxt.dst;
      long long cost = nxt.cost;
      if (dist[next_v] > dist[cur_v] + cost) {
        dist[next_v] = dist[cur_v] + cost;
        q.push(make_pair(dist[next_v], next_v));
      }
    }
  }
  return dist;
}

int main () {
  // v: 鬆らせ謨ｰ, e: 霎ｺ縺ｮ謨ｰ, r: 蟋狗せ縺ｨ縺ｪ繧矩?らせ
  int v, e, r;
  cin >> v >> e >> r;

  graph.assign(v, vector<Edge>());
  for (int i = 0; i < e; i++) {
    int s, t, d;
    cin >> s >> t >> d;
    graph[s].push_back(Edge(t, d));
  }

  vector<long long> dist = dijkstra(r, v);
  for (int i = 0; i < v; i++) {
    if ( dist[i] == LINF ) {
      cout << "INF" << "\n";
    } else {
      cout << dist[i] << "\n";
    }
  }
  return 0;
}



Measured memory_bytes: 19452
N=int(input())
s=input()

W=0
R=0
for i in range(N):
    if s[i]=='R':
        R+=1

count = R

for p in range(N):
    if s[p]=='R':
        R-=1
    elif s[p]=='W':
        W+=1
    if max(R, W) < count:
        count = max(R, W)

print(count)


Measured memory_bytes: 9472
// AOJ 3114 Min Element
// 2020.1.14 bal4u

#include <stdio.h>

#define gc() getchar_unlocked()

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void Qsort(int *a, int l, int r) {
	int i, j, m, t;
	
	i = l, j = r, m = a[(l+r) >> 1];
	while (1) {
		while (a[i] < m) i++;
		while (m < a[j]) j--;
		if (i >= j)	break;
		t = a[i], a[i] = a[j], a[j] = t;
		i++, j--;
	}
	if (l+1 < i) Qsort(a, l, i-1);
	if (j+1 < r) Qsort(a, j+1, r);
}

int a[100005];

int main()
{
	int i, N, ans = 1;
	
	N = in();
	for (i = 0; i < N; ++i) a[i] = in();
	Qsort(a, 0, N-1);
	for (i = 1; i < N; ++i) if (a[i] != a[i-1]) ++ans;
	printf("%d\n", ans);
	return 0;
}



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

int main(void)
{
    int n;
    cin >> n;
    
    for (int i = 1; i <= n; ++i) {
        if (i%3 == 0) {
            cout << " " << i;
            continue;
        }
        
        int x = i;
        while (x) {
            if (x%10 == 3) {
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }
    cout << endl;
    return 0;
}


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

int main(){
	int a,b,c,d;
	int ans=0;
	cin>>a>>b>>c>>d;
	ans+=min(a,b);
	ans+=min(c,d);
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun main(args: Array<String>) {
    val N = readInt()
    val v = readIntList().toMutableList()
    v.sort()
    var value = v[0].toFloat()
    for (i in 1 until N) {
        value = (value + v[i].toFloat()) / 2.0F
    }
    println(value)
}

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

using namespace std;

const int N=1e5+10;

int n,a[N],dep[N],t[N];

void Init()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&a[i]),t[a[i]]++;
}

void Solve()
{	
	sort(a+1,a+n+1); reverse(a+1,a+n+1);
	
	int Mx=0,Mx2=0,fl=1,cnt=0;
	
	for (int i=a[n]+1;i<a[1];++i) if (t[i]<2) fl=0;
	
	if (t[a[n]]>2 || (t[a[n]]==2 && !(a[1]%2))) fl=0;
	
	Mx=(a[1]+1)/2; Mx2=a[1]-Mx;
	
	if (a[1]!=a[2]) fl=0;
	
	for (int i=2;i<=n;++i)
	{
		if (a[i]-Mx || !cnt) dep[i]=a[i]-Mx;
		else dep[i]=a[i]-Mx2;
		if (dep[i]<0) fl=0;
		else if (dep[i]==0) cnt++;
	}
	if (cnt>1 || !cnt) fl=0;
	if (fl) printf("Possible\n");
	else printf("Impossible\n");
}

int main()
{
	Init();
	Solve();
	return 0;
}


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

int main() {
  int in;
  cin >> in;
  string out;
  if (in == 25) out = "Christmas";
  if (in == 24) out = "Christmas Eve";
  if (in == 23) out = "Christmas Eve Eve";
  if (in == 22) out = "Christmas Eve Eve Eve";
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<bool> vb;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sq(x) ((x)*(x))
#define fo(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<n;i++)
#define Fo(i,n) for(int i=1;i<=n;i++)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<"\n"
#define fi first
#define se second
const double pi = 3.14159265358979323846;
#define uni(c) (c).resize(unique(all(c))-(c).begin())
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
//pair <int, int> w[4] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)};   // for matrix movement:
void cp()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
void solve()
{
	ll n, k; cin >> n >> k;
	vi a(n);
	fo(i, n)cin >> a[i];
	vi dp(n + 1, 1e9);
	dp[0] = 0;
	for (int i = 0; i <= n; i++)
	{
		for (int j = 1; j <= k; j++)
		{
			if (i + j < n)
				dp[i + j] = min(dp[i + j], dp[i] + abs(a[i] - a[i + j]));
		}
	}
	cout << dp[n - 1];



}
int main()
{
	fast;
	//cp();
	ll t = 1;
	//cin >> t;
	while (t--)
		solve();


	return 0;
}

Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
  
int main(){
  int N,M,count=0,sum=0;
  cin >> N >> M;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    sum+=A.at(i);
  }
  double K=sum/(4.0*M);
  for(int i=0;i<N;i++){
    if(A.at(i)>=(double)K){
      count++;
    }
  }
  if(count>=M){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
      
  

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

string s;
int niz;
int m;
int j;

int main()
{
	cin >> s;
	int a = s.size();
	for (int i = 0; i < a; i = i + 1){
		if (s.substr(i, 1) == "A" || s.substr(i, 1) == "C" || s.substr(i, 1) == "T" || s.substr(i, 1) == "G"){
			niz = 1;
			j = i + 1;
			while ((j < a) && (s.substr(j, 1) == "A" || s.substr(j, 1) == "C" || s.substr(j, 1) == "T" || s.substr(j, 1) == "G")){
				++niz; ++j;
			}
			if (niz > m) m = niz;
			niz = 0;
		}
	}
	cout << m;
	return 0;
}

// 12:08


Measured memory_bytes: 256
N, A, B, C, D, E = [int(input()) for _ in range(6)]

dists = [A, B, C, D, E]
counts = []
total = 0
max_count = 1
for dist in dists:
  count = (N + dist -1) //dist
  counts.append(count)
  total += 1
  if count > max_count:
    total += count - max_count
    max_count = count
print(total)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int a[300010],n;
long long p[300010],q[300010];
struct q1
{
	priority_queue<int,vector<int>,greater<int> >que;
	long long ans;
	void insert(int w)
	{
		if (que.size()<n) {ans+=w;que.push(w);return;}
		if (que.top()>w) return;
		ans-=que.top();que.pop();
		ans+=w;que.push(w);
	}
}q1;
struct q2
{
	priority_queue<int,vector<int>,less<int> >que;
	long long ans;
	void insert(int w)
	{
		if (que.size()<n) {ans+=w;que.push(w);return;}
		if (que.top()<w) return;
		ans-=que.top();que.pop();
		ans+=w;que.push(w);
	}
}q2;

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=3*n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=2*n;i++)
	{
		q1.insert(a[i]);
		p[i]=q1.ans;
	}
	for (int i=3*n;i>n;i--)
	{
		q2.insert(a[i]);
		q[i]=q2.ans;
	}
	long long ans=-1e18;
	for (int i=n;i<=2*n;i++)
	{
		ans=max(ans,p[i]-q[i+1]);
		//cout<<p[i]<<' '<<q[i+1]<<endl;
	}	
	printf("%lld\n",ans);
}
	

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vi c(n);
    vector<vi> a(n, vi(m));
    rep(i, n) {
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }
    int ans = INF;
    rep(i, (1<<n)) {
        int sum = 0;
        vi b(m);
        rep(j, n) {
            if (!((i>>j)&1)) continue;
            rep(h, m) b[h] += a[j][h];
            sum += c[j];
        }
        bool ok = true;
        rep(i, m) {
            if (b[i] < x) ok = false;
        }
        if (ok) ans = min(ans, sum);
    }
    if (ans==INF) ans = -1;
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
	int N, K;
	cin >> N >> K;
	vector<ll> v(N + 1);
	for (int i = 1; i <= N; ++i) { cin >> v[i]; }

	ll res = 0;
	if (N <= K) {
		ll tmp = 0;
		for (int i = 1; i <= N; ++i) { tmp += v[i]; }
		res = max(res, tmp);
	}

	for (int i = 1; i <= N; ++i) {
		if (N - i > K) { continue; }
		for (int j = 1; j + i - 1 <= N; ++j) {
			priority_queue<ll, vector<ll>, greater<ll>> t;
			for (int k = 1; k < j; ++k) { t.push(v[k]); }
			for (int k = j + i; k <= N; ++k) { t.push(v[k]); }
			if (t.size() > K || t.empty()) { continue; }

			int x = K - t.size();
			while (x > 0) {
				if (t.top() < 0) {
					t.pop();
					if (t.empty()) { break; }
				} else {
					break;
				}
				x -= 1;
			}

			ll tmp = 0;
			while (!t.empty()) {
				tmp += t.top();
				t.pop();
			}
			res = max(res, tmp);
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
fn solve() {
    let (n, k): (usize, usize) = (read::<usize>(), read::<usize>());
    let mut lr: Vec<(usize, usize)> = vec![];
    for i in 0..k {
        lr.push((read(), read()));
    }
    let mut dp = vec![0; n + 1];
    dp[1] = 1;
    let mut adp = vec![0, 1];
    for i in 2..n + 1 {
        for j in 0..k {
            let r;
            let l;
            if i <= lr[j].0 {
                r = 0;
                l = 0;
            } else {
                r = i - lr[j].0;
                l = if i > lr[j].1 { i - lr[j].1 - 1 } else { 0 };
            }
            dp[i] += adp[r] + MOD - adp[l];
            dp[i] %= MOD;
        }
        adp.push((adp[i - 1] + dp[i]) % MOD);
    }
    println!("{}", dp[n]);
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 998_244_353;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 4312
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
vector<ll> vec,n2;
vector<P> pv;
vector<bool> kk;
int ma_2(ll a){
  int ret=0;
  ll c=1;
  while(c<a){
    c*=2;
    ret++;
  }
  return ret;
}
int main(){
  int n;
  cin>>n;
  ll k;
  cin>>k;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    vec.push_back(a);
  }
  sort(vec.begin(),vec.end());
  int max_n=max(ma_2(k),ma_2(vec[n-1]));
  pv.resize(max_n+1,P(0,0));
  for(int i=0;i<n;i++){
    ll nm=vec[i];
    for(int j=0;j<max_n;j++){
      if(nm%2==0) pv[j].first++;
      else pv[j].second++;
      nm/=2;
    }
  }
  n2.push_back(1);
  kk.resize(max_n+1,true);
  ll k2=k;
  for(int i=0;i<max_n;i++){
    n2.push_back(n2[i]*2);
    if(k2%2==1) kk[i]=true;
    else kk[i]=false;
    k2/=2;
  }
  ll dp[2][2]={0};
  int id=max_n-1;
  if(kk[id]){
    dp[0][0]=pv[id].second*n2[id];
    dp[0][1]=pv[id].first*n2[id];
  }
  else{
    dp[0][1]=pv[id].second*n2[id];
  }
  for(int i=1;i<max_n;i++){
    int idx=max_n-i-1;
    if(dp[0][0]>0) dp[1][0]=dp[0][0]+max(pv[idx].first,pv[idx].second)*n2[idx];
    if(kk[idx]){
      dp[1][0]=max(dp[1][0],dp[0][1]+pv[idx].second*n2[idx]);
      dp[1][1]=dp[0][1]+pv[idx].first*n2[idx];
    }
    else{
      dp[1][1]=dp[0][1]+pv[idx].second*n2[idx];
    }
    dp[0][0]=dp[1][0];
    dp[0][1]=dp[1][1];
    dp[1][0]=0;
    dp[1][1]=0;
    //cout<<dp[0][0]<<" "<<dp[0][1]<<endl;
  }
  cout<<max(dp[0][0],dp[0][1])<<endl;
}


Measured memory_bytes: 1400
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n;
	string s,t;
	cin>>n>>s>>t;
	FOR(i,0,n){
		int f=0;
		FOR(j,i,n){
			if(s[j]!=t[j-i]){
				break;
			}
			if(j==n-1){
				cout<<n*2-(n-i)<<endl;
				return 0;
			}
		}
	}
	cout<<n*2<<endl;

    return 0;
}


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


char a[1000];
char b[1000];
int main() {
	memset(a, '\0', 1000);
	memset(b, '\0', 1000);
	scanf("%s", a);
	scanf("%s", b);
	int a_num = 0, b_num = 0;
	for(int i = 0; i < 200; i++) {
		if(a_num == 0 && a[i] == '\0') {
			a_num = i;
		}
		if(b_num == 0 && b[i] == '\0') {
			b_num = i;
		}
	}
	if(a_num > b_num) {
		printf("GREATER\n");
	}
	else if(b_num > a_num) {
		printf("LESS\n");
	}
	else {
		for(int i = 0; i < 200; i++) {
			if(a[i] > b[i]) {
				printf("GREATER\n");
				return 0;
			}
			else if(a[i] < b[i]) {
				printf("LESS\n");
				return 0;
			}
		}
		printf("EQUAL\n");
	}
	return 0;
}


Measured memory_bytes: 128
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
ans = 0

for a in A:
    tmp = [i * j for i, j in zip(a, B)]
    if sum(tmp) + C > 0:
        ans += 1

print(ans)

Measured memory_bytes: 3060
from collections import defaultdict

def main():
    n, k = map(int, input().split())
    s = defaultdict(int)

    for _ in range(n):
        a, b = map(int, input().split())
        s[a] += b
    
    print(solve(k, s))

def solve(k, s):
    rank = 0

    for i in sorted(s.keys()):
        j = s[i]
        if rank < k <= rank + j:
            return i
        rank += j

main()


Measured memory_bytes: 10856
#include<stdio.h>
#include<string.h>

int count(int x,int y);

char board[20][22];

int main(void){
    int w,h,i,j;
    while(scanf("%d%d%*c",&w,&h) && w && h){
        for(i=0;i<20;i++) for(j=0;j<22;j++) board[i][j]=0;
        for(i=0;i<h;i++){
            fgets(board[i],sizeof(board[i]),stdin);
        }
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if(board[i][j]=='@')
                    break;
            }
            if(j<w) break;
        }
        printf("%d\n",count(i,j));
    }
    return 0;
}

int count(int x,int y){
    int ret=1;
    if(x!=0 && board[x-1][y]=='.'){
        board[x-1][y]='@';
        ret+=count(x-1,y);
    }
    if(y!=0 && board[x][y-1]=='.'){
        board[x][y-1]='@';
        ret+=count(x,y-1);
    }
    if(x<20 && board[x+1][y]=='.'){
        board[x+1][y]='@';
        ret+=count(x+1,y);
    }
    if(y<22 && board[x][y+1]=='.'){
        board[x][y+1]='@';
        ret+=count(x,y+1);
    }
    return ret;
}

Measured memory_bytes: 632
#include <stdio.h>
#include <string.h>
char s[110];
int main(){
	int k,n,i;
	scanf("%d%s",&k,s+1);
	n=strlen(s+1);
	if(n<=k)printf("%s\n",s+1);
	else{
		for(i=1;i<=k;i++)printf("%c",s[i]);
		printf("...\n");
	}
}

Measured memory_bytes: 3168
h, w = map(int, input().split())
s = [list(map(lambda x:x=="#", list(input())))for i in range(h)]
f=0
for i in range(h):
    for j in range(w):
        if s[i][j]:
            s[i][j] ^= 1
            if 1^(s[max(0,i-1)][j]or s[i][max(0,j-1)]or s[i][min(w-1,j+1)]or s[min(h-1,i+1)][j]):f=1
            s[i][j] ^= 1
print("YNeos"[f::2])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
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; }
using namespace std;

//ABC130
signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    int n,x; cin>>n>>x;
    vector<int> l(n);
    rep(i,n)cin>>l[i];
    int ans=1,now=0;
    rep(i,n){
        now+=l[i];
        if(now<=x)ans++;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
N = int(input())
A = [0]
A += list(map(int,input().split()))
Res = [0] * (N+1)

for i in range(N):
    Res[N-i] = A[N-i] ^ (sum(Res[::N-i]) % 2)

print(sum(Res))
ResN = []
for i,r in enumerate(Res):
    if i==0:
        continue
    if r == 1:
        ResN.append(str(i))

if ResN:
    print(' '.join(ResN)) # ここの空白を忘れてはならない



Measured memory_bytes: 22724
N = int(input())
W = list(map(int, input().split()))
R = [0]*N
R[0] = W[0]

for i in range(1, N):
  R[i] = R[i-1] + W[i]

#print(R)
m = sum(W) / 2
#print(m)
e = 10000

for i in range(N):
  e_new = abs(R[i] - m)
  if e >= e_new:
    e = e_new
    #print(e)
  else:
    ans_index = i - 1
    #print(ans_index, e)
    break

print(int(2 * abs(R[ans_index] - m)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

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

    cout << 24+(24-M) <<endl;

    return 0;
}


Measured memory_bytes: 256
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    # dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
    N, K = read_ints()
    h = read_ints()
    dp = [0, abs(h[1]-h[0])]
    for i in range(2, N):
        dp.append(min(abs(h[i]-h[i-k])+dp[i-k] for k in range(1, K+1) if i >= k))
    return dp[-1]


if __name__ == '__main__':
    print(solve())


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll H, W;
  cin >> H >> W;
  ll diff = 1 << 29, sa, sb, sc, nh, nw;
  for (ll h = 1; h < H; h++) {
    nw = W / 2;
    sa = h * W;
    sb = (H - h) * nw;
    sc = (H - h) * (W - nw);
    diff = min(diff, max({sa, sb, sc}) - min({sa, sb, sc}));

    nh = (H - h) / 2;
    sb = nh * W;
    sc = (H - h - nh) * W;
    diff = min(diff, max({sa, sb, sc}) - min({sa, sb, sc}));
  }
  for (ll w = 1; w < W; w++) {
    nh = H / 2;
    sa = w * H;
    sb = (W - w) * nh;
    sc = (W - w) * (H - nh);
    diff = min(diff, max({sa, sb, sc}) - min({sa, sb, sc}));

    nw = (W - w) / 2;
    sb = nw * H;
    sc = (W - w - nw) * H;
    diff = min(diff, max({sa, sb, sc}) - min({sa, sb, sc}));
  }
  cout << diff << '\n';
  return 0;
}


Measured memory_bytes: 256
n=int(input())
d=list(map(int,input().split()))
b=sorted([[i+1,h] for i,h in enumerate(d)],key=lambda x:(x[1],x[0]))
c=[]
while len(b)>0:
    for i in range(len(b)-1,-1,-1):
        if 0<b[i][1]<=len(b) and 0<b[i][0]<=len(b) and b[i][0]==b[i][1]:
            c.append(b[i][1])
            d.pop(b[i][0]-1)
            b=sorted([[i+1,h] for i,h in enumerate(d)],key=lambda x:(x[1],x[0]))
            break
    else:
        print(-1)
        break
else:
    for i in c[::-1]:
        print(i)

Measured memory_bytes: 3064