akhauriyash/Code-Regression huggingface dataset:
// Problem : B - Postdocs
// Contest : AtCoder - NOMURA Programming Competition 2020
// URL : https://atcoder.jp/contests/nomura2020/tasks/nomura2020_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

void solve(){
    string s;
    cin>>s;
    string t = s;
    for(int i=0;i<sz(s);i++){
        if(s[i] == '?') t[i] = 'D';
    }
    cout<<t<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int t;
    //cin>>t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3776
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
int inf = 1e9;

int main() {
  int n; cin >> n;
  vector<long long int> a(n);
  vector<long long int> b(n);
  vector<long long int> c(n);
  for(int i=0; i<n; i++) {
    cin >> a[i] >> b[i];
    c[i] = a[i] + b[i];
  }

  sort(c.begin(), c.end());
  reverse(c.begin(), c.end());

  long long int ans = 0;
  for(int i=0; i<n; i++) {
    if(i%2 == 0) ans += c[i];
  }
  for(int i=0; i<n; i++) {
    ans -= b[i];
  }
  cout << ans << endl;

  return 0;
}


//EOF


Measured memory_bytes: 2560
a,b,c,d=map(int,input().split())
m=10**9+7
s=[pow(i,m-2,m)for i in range(10**6+2)]
def f(x,y):
    p,q=x,x
    for i in range(2,y+1):
        q=(q*(x+i-1)*s[i])%m
        p=(p+q)%m
    return p
print((f(c+1,d+1)-f(a,d+1)-f(c+1,b)+f(a,b))%m)

Measured memory_bytes: 114032
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    ans = 0
    if K == 0:
        print(N * N)
        return 0
    for i in range(1, N+1):
        if i <= K:
            continue
        if N % i < K:
            ans += (N // i) * (i - K)
        else:
            ans += (N // i ) * (i - K) + (N % i - K + 1)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
//rohitkaushal
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
template<typename T> using id_setp = tree<pair<T,T>,null_type,less<pair<T,T>>,rb_tree_tag,tree_order_statistics_node_update> ;

#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e5+1;
 
typedef long long ll;
typedef long double ld;
 
int main()
{
   IOS();
   ll n,m,i,j;
   cin>>n>>m;
   vector<pair<ll,ll>> v(n+1);
   f(i,0,n+1)
   {
      v[i].F=0;v[i].S=0;
   }
   ll c[n+1]={0};
   f(i,0,m)
   {
      string s;
      ll x;
      cin>>x>>s;
      if(v[x].S==0 && s=="WA")
      {
         v[x].F++;
      }
      else if(s=="AC")
      {
         v[x].S=1;
         c[x]=1;
      }
   }
   ll p=0,ca=0;
   f(i,1,n+1)
   {
      if(c[i])
         ca++;
      if(v[i].S==1)
         p+=v[i].F;
   }
   cout<<ca<<' '<<p<<'\n';

   return 0;
}

Measured memory_bytes: 2560
N, Q = gets.split(" ").map(&:to_i)
S= gets.chomp.chars
nums = [0]
count = 0
N.times do |i|
    if S[i] == "A" && S[i + 1] == "C"
        count += 1
    end
    nums << count
end
Q.times do 
    l, r = gets.split(" ").map(&:to_i)
    puts nums[r - 1] - nums[l - 1]
end



Measured memory_bytes: 10876
#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    int n,i;
    cin>>n;
    i=n%10;
    if(i==2 || i== 4|| i==5 || i==7|| i==9)
    {
        cout<<"hon";
    }
    else if(i==0||i==1||i==6||i==8)
    {
        cout<<"pon";
    }
    else
    {
        cout<<"bon";
    }
    
}



Measured memory_bytes: 3624
s = input()
t = input()
ans = 1001
if len(s)-len(t)==0:
    temp = 0
    for j in range(len(t)):
        if s[j]!=t[j]:
            temp+=1
    ans = min(ans, temp)
else:
    for i in range(len(s)-len(t)):
        temp = 0
        for j in range(len(t)):
            if s[i+j]!=t[j]:
                temp+=1
        ans = min(ans, temp)
print(ans)

Measured memory_bytes: 67188
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n,m) for(int i=n;i<m;i++)
#define repn1(i,n,m) for(int i=n;i<=m;i++)
#define pb push_back
using namespace std;
typedef long long ll;
const int INF = 1e+8;

int main(){

    int N, W;
    int v[1001];
    int w[1001];
    int dp[101][10001];
    cin >> N >> W;
    memset(dp, 0, sizeof(dp));
    rep(i, N)cin >> v[i] >> w[i];
    rep(i,N){
        rep(j,W+1){
            if(j < w[i]){
                dp[i+1][j] = dp[i][j];
            }else{
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]);
            }
        }
    }
    cout << dp[N][W] << endl;
 
    return 0;	
}

Measured memory_bytes: 5120
#include <stdio.h>


int main(void)
{
    int x=0,A,B;
    scanf("%d %d %d",&x,&A,&B);

    if(A>=B)
    {
        printf("delicious\n");
    }
    else
    {
        if(x>=(B-A))
        {
            printf("safe\n");
        }
        else
        {
            printf("dangerous\n");
        }
    }
    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define endl "\n"

#define aim_cpo do{ios::sync_with_stdio(false);\
cin.tie(nullptr);cout.precision(10);cout<<fixed;}while(0)

#define LOCAL_INPUT do{FILE *stream1;\
stream1=freopen("/Users/aim_cpo/CLionProjects/competitive/in.txt","r",stdin);\
if(stream1==nullptr)return 0;}while(0)

#define LOCAL_OUTPUT do{FILE *stream2;\
stream2 = freopen("out.txt", "w", stdout);\
if (stream2 == nullptr) return 0;}while(0)

#ifdef LOCAL_DEFINE
#define show(x) cerr << #x << " = " << x << endl
#else
#define show(x)
#endif

typedef long long ll;
typedef unsigned long long ull;

constexpr const int INT_INF=0x3f3f3f3f; // 1061109567
constexpr const ll LL_INF=0x3f3f3f3f3f3f3f3f; // 4557430888798830399

template <typename T> bool chmin(T &a, T b) {
    if (a > b) {a = b;return true;}return false;
}

template <typename T> bool chmax(T &a, T b) {
    if (a < b) {a = b;return true;}return false;
}

// INT
#define GCD(a, b) __gcd(a, b)
template <typename T> T LCM(T a, T b) {return a / GCD(a, b) * b;}
template <typename T> T EXTGCD(T a, T b, T& x, T& y) {
    T d = a;
    if (b != 0) {d=EXTGCD(b,a%b,y,x);y-=(a/b)*x;}
    else x=1,y=0;
    return d;
}
template <typename T> bool is_prime(T a) {
    for(int i=2;i*i<=a;i++)if(a%i==0)return 1;
    return 0;
}

// MOD
const ll MOD = (ll)1e9 + 7;
#define add(a, b) ((a % MOD) + (b % MOD)) % MOD
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define sub(a, b) ((a % MOD) + MOD - (b % MOD)) % MOD
template <typename T> T mod_inverse(T a, T mod, bool prime){ // if mod is prime, "prime" is true.
    if(prime){
        T tmp=mod-2,now=a,res=1;while(tmp){if(tmp&1)res=mul(res,now);now=mul(now,now);tmp>>=1;}
        return res;
    }else{T x,y;EXTGCD(a,mod,x,y);return (mod+x%mod)%mod;}
}
#define divide(a, b) ((a % MOD) * (mod_inverse(b, MOD, true))) % MOD

//LLの数値をつかう時は最後にLをつける癖をつけよう
//
//  ┏┓┏┓　┓　┏┓
//  ┏┛┃┃　┃　┗┫
//  ┗┛┗┛　┻　┗┛
//
//   謹┃賀┃新┃年┃
//   ━┛━┛━┛━┛
//WWWWWWWWWWWWWWWWWWWWWW

int n, k;
ll a[100001];
ll b[100001];
ll c[100001];
ll dp[101][100001];

int main() {
    aim_cpo; // インタラクティブのときは消すように.
#ifdef LOCAL_DEFINE
    LOCAL_INPUT; // インタラクティブのときは消すように.
//    LOCAL_OUTPUT; // ファイルに出力したいときのみ
    show(MOD);
#endif
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < 100001; j++) {
            dp[i][j] = LL_INF;
        }
    }
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 100000; j++) {
            if (dp[i][j] + a[i] <= k) dp[i + 1][j + b[i]] = min(dp[i + 1][j + b[i]], dp[i][j] + a[i]);
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }
    ll ans = 0;
    for (int i = 0; i < 100001; i++) {
        if (dp[n][i] != LL_INF) ans = i;
    }
    cout << ans << endl;
#ifdef  LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s." << endl;
#endif
    return 0;
}

Measured memory_bytes: 80128
#include <stdio.h>

int main(int argc, char *argv[])
{
	int n;
	scanf("%d",&n);
	int a[n],i,j,temp,good=0,k;
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
			if(a[i]>a[j]){
				temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			if(a[i]==a[j])continue;
			for(k=j+1;k<n;k++){
				if(a[i]!=a[k]&&a[k]!=a[j]){
				if(a[i]+a[j]>a[k])
					good++;
				}
			}
		}
	}
	printf("%d\n",good);
}

Measured memory_bytes: 2156
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    V=[tuple(map(int,input().split())) for _ in range(n)]
    C=[tuple(map(int,input().split())) for _ in range(m)]
    ans=[0]*n
    for i in range(n):
        dist=INF
        ind=0
        for j in range(m):
            d=abs(V[i][0]-C[j][0])+abs(V[i][1]-C[j][1])
            if d<dist:
                ind=j
                dist=d
        print(ind+1)
resolve()

Measured memory_bytes: 39152
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	ans := make([]int, n+1)
	for x := 1; x*x < n; x++ {
		for y := 1; x*x+y*y < n; y++ {
			for z := 1; x*x+y*y+z*z+x*y+y*z+z*x < n+1; z++ {
				a := x*x + y*y + z*z + x*y + y*z + z*x
				if a < n+1 {
					ans[a]++
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, ans[i+1])
	}
}


Measured memory_bytes: 1968
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}
void print(vector<int> v){rep(i,0,v.size()){if(i)cout<<" ";cout<<v[i];}cout<<endl;}

signed main (){
    vector<int> v(26,0);
    int n;cin>>n;
    string s;cin>>s;
    rep(i,0,n){
        v[s[i]-'a']++;
    }
    int ans=1;
    rep(i,0,26){
        ans*=(v[i]+1);
        ans%=MOD;
    }
    cout<<(ans-1)%MOD<<endl;
}

/*

*/


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

using namespace std;
#define ll long long
#define ld long double

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    string s;
    cin >> s;
    int ans = 0;
    if(s == "SUN") ans = 7;
    else if(s == "SAT") ans = 1;
    else if(s == "FRI") ans = 2;
    else if(s == "THU") ans = 3;
    else if(s == "WED") ans = 4;
    else if(s == "TUE") ans = 5;
    else if(s == "MON") ans = 6;
    cout << ans <<endl;
    return 0;
}



Measured memory_bytes: 256
class Node:
    __slots__ = ["string", "index"]
    def __init__(self, string, index):
        self.string = string
        self.index = index

    def get_children(self):
        parent = self.string
        out = [None]*(self.index+1)
        for i, c in enumerate(s[:self.index]):
            out[i] = Node(parent+c, self.index)
        out[i+1] = Node(parent+s[self.index], self.index+1)
        return out

def main():
    n = int(input())
    root = Node("a", 1)
    children = [root]
    for _ in range(n-1):
        parents, children = children, []
        for parent in parents:
            children.extend(parent.get_children())
    for child in children:
        print(child.string)

if __name__ == "__main__":
    s = "abcdefghij"
    main()

Measured memory_bytes: 21820
#/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

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

N, Q = map(int, input().split())

adj = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b = map(int, input().split())
    a, b = (a - 1, b - 1)
    adj[a].append(b)
    adj[b].append(a)
    
values = [0 for _ in range(N)]
    
for _ in range(Q):
    p, x = map(int, input().split())
    values[p - 1] += x

def dfs(node, parent):
    for child in adj[node]:
        if child == parent: continue
        values[child] += values[node]
        dfs(child, node)

dfs(0, -1)

print(" ".join(map(str, values)))
    

Measured memory_bytes: 232224
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
#define pb push_back
#define F first
#define S second

const ll MX=1e5+100, mod=1e9+7;
ll n, arr[MX];
ll fac=1, cnt, sum;

ll pn(ll a, ll b){
	if(b==0)return 1;
	ll nsf=pn(a, b/2);
	nsf*=nsf;
	nsf%=mod;
	if(b&1)nsf*=a;
	return nsf%mod;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	for(int i=1; i<=n; i++){
		fac*=i;
		fac%=mod;
	}
	for(int i=0; i<n; i++){
		cnt+=(ll)fac*pn((ll)i+1, mod-2)%mod;
		cnt%=mod;
	}
	sum+=cnt*arr[0]%mod;
	for(int i=1; i<n; i++){
		cnt+=(ll)fac*pn(i+1, mod-2);
		cnt%=mod;
		cnt-=(ll)fac*pn(n-i+1, mod-2)%mod;
		cnt+=(ll)mod;
		cnt%=(ll)mod;
		sum+=(ll)cnt*arr[i]%mod;
		sum%=(ll)mod;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  ll a,b;
  cin >> a >> b;
  if((a+b)%2 == 0)cout<<(a+b)/2<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
  return 0;
}

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

using namespace std;
using ll = long long int;
using lc = complex<double>;

int main(void) {
    constexpr ll MOD = 998244353;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);


    ll n, s;
    cin >> n >> s;
    vector<ll> a(n);
    for(auto &e: a) cin >> e;
    vector<vector<ll>> dp(n+1, vector<ll>(s+1));
    vector<vector<ll>> dq(n+1, vector<ll>(s+1));
    dp[0][0] = 1;
    for(ll i=1; i<=n; i++)
        for(ll j=0; j<=s; j++) {
            (dp[i][j] = dp[i-1][j] * 2) %= MOD;
            if(j-a[i-1]>=0)
                (dp[i][j] += dp[i-1][j-a[i-1]]) %= MOD;
        }
    cout << dp[n][s] << endl;
}


Measured memory_bytes: 144176
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    string S, T, U;
    ll A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if ( S == U ) A--;
    else B--;
    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
template <class T1, class T2>
void vadd(vector<T1> &v, T2 x);

#define int long long int
lli po[200005] = {};
lli inv(lli p)
{
  lli n = 2017;
  lli ret = 1;
  while (n)
  {
    if (n & 1)
      ret *= p;
    p *= p;
    p %= 2019;
    ret %= 2019;
    n /= 2;
  }
  return ret;
}
void solve(string S)
{
  map<lli, lli> m;
  int n = S.size();
  lli mod = 0;
  po[0] = 1;
  rep(i, n + 1) po[i + 1] = (po[i] * 10) % 2019;
  lli ret = 0;
  rrep(i, n)
  {
    mod += lli(S[i] - '0') * po[n - 1 - i];
    mod %= 2019;
    ret += m[mod];
    m[mod]++;
  }
  ret += m[0];
  // m[0]++;
  // rep(i, 2019)
  // {
  //   ret += m[i] * (m[i] - 1) / 2;
  // }
  // lli ret = m[0];
  // lli base = 0;
  // rrep(i, n)
  // {
  //   base += lli(S[i] - '0') * po[n - 1 - i];
  //   base %= 2019;
  //   ret += m[base] * (m[base] - 1) / 2;
  //   // ret += m[inv(po[i + 1])] * m[inv(po[i + 1])];
  // }
  cout << ret;
}

signed main()
{
  string S;
  cin >> S;
  solve(S);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2>
void vadd(vector<T1> &v, T2 x)
{
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 5300
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n in O(log(n)) time

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
lng X;
/**********************************/


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

    lng ans = (X/11)*2;
    if(X%11>6) ans += 2;
    else if(X%11>0) ans++;
    cout << ans << endl;
}


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

int main(){
    int a[4][13], n, num;
    char ch;
    cin >> n;
    for(int row=0; row<4; row++){
        for(int col=0; col<13; ++col){
            a[row][col] = 0;
        }
    }
    for(int i=0; i<n; ++i){
        cin >> ch >>num;
        if(ch=='S') a[0][num-1]=1;
        if(ch=='H') a[1][num-1]=1;
        if(ch=='C') a[2][num-1]=1;
        if(ch=='D') a[3][num-1]=1;
    }
    for(int row=0; row<4; row++){
        for(int col=0; col<13; ++col){
            if(a[row][col] != 1){
                if(row == 0) cout<<"S "<<col+1<<endl;
                if(row == 1) cout<<"H "<<col+1<<endl;
                if(row == 2) cout<<"C "<<col+1<<endl;
                if(row == 3) cout<<"D "<<col+1<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3088
import java.util.*;

import static java.lang.System.*;

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

        switch(b){
            case "A":
                out.println("T");
                break;
            case "C":
                out.println("G");
                break;
            case "G":
                out.println("C");
                break;
            case "T":
                out.println("A");
                break;

        }
    }
}

Measured memory_bytes: 21460
n = int(input())
m = list(map(int, input().split()))

count = 0
for i in range(n-1):
    minj =i
    for j in range(i+1, n):
        if m[j] < m[minj]:
            minj = j
    if m[i] != m[minj]:
        m[i], m[minj] = m[minj], m[i]
        count += 1


print(" ".join(str(x) for x in m))
print(count)

Measured memory_bytes: 7720
#ITP1_3_C
while True:
    x, y = input().split()
    x, y = int(x), int(y)
    if x == 0 and y == 0:
        break
    else:
      if x < y:
        print("{} {}".format(x, y))
      else:
        print("{} {}".format(y, x))


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll> >
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define prll(a)                 cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,cur)               lower_bound(all(v),cur)-v.begin()
#define ub(v,cur)               upper_bound(all(v),cur)-v.begin()
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD){if(m == 1)return 0;ll m0=m,y=0,x=1;while(a>1){ll q=a/m,t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0) x+=m0;return x;}
int main()
{
fastIO
ll n,m,i,j,k,x,y,z,t,e,f,p,q,g,l,r,w,h,count1=0,prod=1,a,b,c,d,index,x1,x2,y1,y2,diff,ans=0,sum=0,sum1=0,sum2=0,flag=0,flag1=0,flag2=0;
string s1,s2;
ld rad;
cin>>rad;
ld pi=3.14159265359;
ld cir=2*pi*rad;
cout<<fixed<<setprecision(10)<<cir;
}


Measured memory_bytes: 3788
from collections import deque
H,W = map(int,input().split())
m = []
for i in range(H):
	s = list(input())
	m.append(s)

def validPoint(i,j):
	if i < 0 or i >= H:
		return False
	if j < 0 or j >= W:
		return False
	return True

def wfs(start):
	search = deque([(start, 0)])
	dist = [[-1 for j in range(W)] for i in range(H)]
	#searched = [[False for j in range(W)] for i in range(H)]
	#searched[start[0]][start[1]] = True
	v = [(0,-1), (0,1), (-1,0), (1,0)]
	dist[start[0]][start[1]] = 0
	while len(search) > 0:
		s = search.popleft()
		i,j = s[0][0], s[0][1]
		d = s[1]
		if dist[i][j] < d:
			continue
		for (x,y) in v:
			if validPoint(i+x, j+y):
				if m[i+x][j+y] == "#":
					continue
				if dist[i+x][j+y] == -1 or dist[i+x][j+y] > d+1:
					dist[i+x][j+y] = d+1
					search.append(((i+x,j+y),d+1))
	return max([max(dist[i]) for i in range(H)])

ans = 0
for i in range(H):
	for j in range(W):
		if m[i][j] == "#":
			continue
		ans = max(ans, wfs((i,j)))
print(ans)

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

template <typename T> inline void read (T &x) {bool b = 0; char c; while (!isdigit (c = getchar()) && c != '-');
if (c == '-') c = getchar(), b = 1; x = c - 48; while (isdigit(c = getchar())) x = (x<<3) + (x<<1) + c - 48; if (b)x=-x;}
template <typename T> inline void wrip(T x) {if (x > 9) wrip(x / 10); putchar(x%10 + 48); }

template <typename T> inline void write(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar(' ');}
template <typename T> inline void writeln(T x) {if (x < 0) putchar('-'), x = -x; wrip(x); putchar('\n');}
inline char readch() {char c; do c = getchar(); while (c == '\n' || c == ' '); return c;}
inline void reads(string &s) {char c; while((c=getchar())==' '||c =='\n'); s=c; while((c=getchar())!=' '&&c!='\n') s+=c;}
inline void getlines(string &s) {char c; while((c=getchar())=='\n'); s=c; while((c=getchar())!='\n') s+=c;}
typedef const int csint;

#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;

const ld pi = acos(-1);
const ll inf = 1e9;
const int mod = 1e9 + 7,
N = 2e5 + 11;

int n, m;
int main() {
    #ifdef makacha
        freopen("m.inp", "r", stdin);
        freopen("m.out", "w", stdout);
    #endif // makacha
    int n, m, res = 0;
    cin >> n >> m;
    while (n) {
        n -= n % m;
        n /= m;
        res++;
    }
    cout << res;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

vector<int> a;
const int K = 1e5 + 5;
int memo[K];

int rec(int curr)
{
  int& ret = memo[curr];
  if (ret != -1) return ret;
  if (curr < a[0]) return 0;
  
  int mx = 0;
  each (i, a) {
    if (0 <= curr - i) {
      setmax(mx, rec(curr - i) ^ 1);
    }
  }
  
  return ret = mx;
}

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

  int n, k;
  while (cin >> n >> k) {
    a.resize(n);
    fill(memo, memo + K, -1);
    cin >> a;
    cout << (rec(k) ? "First" : "Second") << endl;    
  }
  
  return 0;
}


Measured memory_bytes: 5376
def main():
    N, Z, W = map(int, input().split())
    A = list(map(int, input().split()))
    if N >= 2:
        print(max(abs(W - A[-1]), abs(A[-2] - A[-1])))
    else:
        print(abs(W - A[-1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include <stdio.h>
#define N 10000

typedef struct{
  int p;
  int l;
  int r;
}Node;

Node T[N];
int n, D[N], H[N];

void setDepth(int u, int d){
  if(u == -1) return;
  D[u] = d;
  setDepth(T[u].l, d+1);
  setDepth(T[u].r, d+1);
}

int setHeight(int u){
  int h1=0, h2=0;
  if(T[u].l != -1) h1 = setHeight(T[u].l) + 1;
  if(T[u].r != -1) h2 = setHeight(T[u].r) + 1;
  return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u){
  if(T[u].p == -1) return -1;
  if(T[T[u].p].l != u && T[T[u].p].l != -1) return  T[T[u].p].l;
  if(T[T[u].p].r != u && T[T[u].p].r != -1) return T[T[u].p].r;
  return -1;
}

int main(){
  int i, v, l, r, deg, root=0;

  scanf("%d", &n);

  for(i=0; i<n; i++) T[i].p = -1;

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

  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }

  setDepth(root, 0);
  setHeight(root);

  for(i=0; i<n; i++){
    printf("node %d: ", i);
    printf("parent = %d, ", T[i].p);
    printf("sibling = %d, ", getSibling(i));
    deg = 0;
    if(T[i].l != -1) deg++;
    if(T[i].r != -1) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[i]);
    printf("height = %d, ", H[i]);

    if(T[i].p == -1) printf("root\n");
    else if(T[i].l == -1 && T[i].r == -1) printf("leaf\n");
    else printf("internal node\n");
  }
  
  return 0;
}

Measured memory_bytes: 624
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  long long dp[101][21]={0};
  int N;
  cin>>N;
  N--;
  int array[101];
  int sum;
  REP(i,N) cin>>array[i];
  cin>>sum;
  dp[0][array[0]] = 1;
  for(int i=1; i<N; i++){
    int k = array[i];
    for(int j = 0; j+k<=20; j++){
      dp[i][j+k] += dp[i-1][j];
    }
    for(int j= 20; j-k>=0; j--){
      dp[i][j-k] += dp[i-1][j];
    }
  }
  cout<<dp[N-1][sum]<<endl;
  return 0;
}

Measured memory_bytes: 0
import numpy as np

#%%
N, M, X = [int(i) for i in input().split()]
CA = [[] for i in range(N)]
for i in range(N):
    k = list(map(int, input().split()))
    CA[i] = k[:]
CA = np.array(CA)
#%%
cnt = (10 ** 5) * N + 1

for i in range(2 ** N):
    score = np.zeros(M + 1)
    for j in range(N):
        if (i >> j) & 1:
            score += CA[j]
    for k in range(1, M + 1):
        if score[k] < X:
            break
    else:
        if score[0] < cnt:
            cnt = score[0]
            
if cnt != (10 ** 5) * N + 1:
    print(int(cnt))
else:
    print(-1)

Measured memory_bytes: 27092
h, w, k = map(int, input().split())
board = [list(input()) for _ in range(h)]

ans = 0
for i in range(1 << h):
    for j in range(1 << w):
        black = 0
        for y in range(h):
            for x in range(w):
                if i >> y & 1:
                    continue
                if j >> x & 1:
                    continue
                if board[y][x] == '#':
                    black += 1
        if black == k:
            ans += 1
print(ans)

# print(bin(5>>1&1))


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

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

    int n = s.size();
    int cnt_odd_0 = 0;
    int cnt_even_0 = 0;
    for(int i=0;i<n;++i)
    {
        if(s[i] == '0')
        {
            if(i%2==0)
                ++cnt_odd_0;
            else
                ++cnt_even_0;
        }
        else
        {
            if(i%2==0)
                ++cnt_even_0;
            else
                ++cnt_odd_0;
        }
    }
    cout << min(cnt_odd_0, cnt_even_0) << endl;
    return 0;
}

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

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 123;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 9;
const double eps = 1e-9;

inline void boost () {
	ios_base::sync_with_stdio (0);
	cin.tie (0), cout.tie (0);
}
int n, a[N], c, k, ans;

int main () {
	boost ();
	cin >> n >> c >> k;
	for (int i = 1;i <= n;i ++) cin >> a[i];
	sort (a + 1, a + n + 1);
	bool st = 0;
	int l = 0, kol = 0;
	for (int i = 1;i <= n;i ++) {
		if (st == 1) {
			if (a[i] - a[l] <= k && i - l < c) {
				continue;
			}
			i --;
			st = kol = 0;
		} else {
			st = 1; l = i;
			ans ++;
		}
	}
	cout << ans;

	return 0;
}

                

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long a, b, d[1000005], book[1000005], cnt, ans, g, num;
long long gcd(long long a, long long b) {
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}
int main() {
	cin >> a >> b;
	long long dx = min(a, b);
	long long g = max(a, b);
	long long c = min(sqrt(a), sqrt(b));
	if (g == 0) {
		cout << "0";
		return 0;
	}
	else if (dx == 0) {
		for (int i = 1; i <= sqrt(g); i++) {
			if (g % i == 0) {
				d[++cnt] = i;
				if (g / i != i)
					d[++cnt] = g / i;
			}	
		}
	}
	else {
		for (long long i = 1; i <= c; i++) {
			if (dx % i == 0) {
				if (g % i == 0)
				d[++cnt] = i;
				if (g % (dx / i) == 0 && dx / i != i)
				d[++cnt] = dx / i;
			}
		}
	}
//	for (int i = 1; i <= cnt; i++)
//		cout << d[i] << " ";
//	cout << endl;
	sort(d + 1, d + cnt + 1);
	for (long long k = 2; k <= cnt - 1; k++) {
		if (book[k] == 1)	continue;
		for (long long j = k + 1; j <= cnt; j++) {
			if (book[j] == 0 && gcd(d[j], d[k]) != 1) {
				book[j] = 1;
				ans--;
			}
		}
	}
//	cout << endl;
	cout << ans + cnt;
	return 0;
}


Measured memory_bytes: 2304
#include <iomanip>
#include <iostream>
using namespace std;
bool S[13], H[13], C[13], D[13];
int main(void) {
  for(int i = 0; i < 13; i++) {
    S[i] = false;
    H[i] = false;
    C[i] = false;
    D[i] = false;
  }

  int n;
  cin >> n;
  for(int i = 0; i < n; i++) {
    char st;
    int m;
    cin >> st >> m;
    if(st == 'S')
      S[m - 1] = true;
    if(st == 'H')
      H[m - 1] = true;
    if(st == 'C')
      C[m - 1] = true;
    if(st == 'D')
      D[m - 1] = true;
  }
  for(int i = 0; i < 13; i++) {
    if(!S[i])
      cout << "S " << i + 1 << endl;
  }
  for(int i = 0; i < 13; i++) {
    if(!H[i])
      cout << "H " << i + 1 << endl;
  }
  for(int i = 0; i < 13; i++) {
    if(!C[i])
      cout << "C " << i + 1 << endl;
  }
  for(int i = 0; i < 13; i++) {
    if(!D[i])
      cout << "D " << i + 1 << endl;
  }

  return 0;
}



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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll H,W;
ll X,Y;
char grid[55][55];
struct edge{ll to,cost;};
ll V; 
vector<edge> G[2505];
ll d[2505];
void dijkstra(ll s){
	priority_queue<P,vector<P>,greater<P> > que;
	fill(d,d+V,mod);
	d[s]=0;
	que.push(P(0,s));
	while(!que.empty()){
		P p=que.top(); que.pop();
		ll v=p.second;
		if(d[v]<p.first) continue;
		for(ll i=0; i<G[v].size(); i++){
			edge e=G[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>H>>W;
V=H*W;

rep(i,H){
	rep(j,W){
		cin>>grid[i][j];
		if(grid[i][j]=='#') Y++;
	}
}

ll n=0;
rep(i,H){
	rep(j,W){
		if(j-1>=0) if(grid[i][j-1]!='#') if(n-1>=0) G[n].pb((edge){n-1,1});
		if(j+1<W) if(grid[i][j+1]!='#') if(n+1<V) G[n].pb((edge){n+1,1});
		if(i-1>=0) if(grid[i-1][j]!='#') if(n-W>=0) G[n].pb((edge){n-W,1});
		if(i+1<H) if(grid[i+1][j]!='#') if(n+W<V) G[n].pb((edge){n+W,1});
		n++;
	}
}

dijkstra(0);
if(d[V-1]==mod){
	cout<<-1<<endl; return 0;
}
X=d[V-1];
cout<<V-(X+1)-Y<<endl;

}
	


Measured memory_bytes: 512
N, K = map(int, input().split())
S = input()

before = S[0]
cnt = 0
same_nums = []
if S[0] == '0':
  same_nums.append(0)
for i in range(N):
  if S[i] == before:
    cnt += 1
  else:
    same_nums.append(cnt)
    before = S[i]
    cnt = 1
same_nums.append(cnt)
if S[-1] == '0':
  same_nums.append(0)
  
sum_nums = sum(same_nums[:2*K+1])
ans = sum_nums
for i in range(0, len(same_nums)-2*K, 2):
  sum_nums = sum_nums - sum(same_nums[i:i+2]) + sum(same_nums[i+2*K+1:i+2*K+3])
  ans = max(ans, sum_nums)
print(ans)
  


Measured memory_bytes: 4596
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;

    bool seven = false;
    while(N) {
        seven |= (N % 10 == 7);
        N /= 10;
    }
    cout << (seven ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3632
A = list(map(lambda x: int(x),input().split()))
N = A[0]
K = A[1]
s = input()
s_1 = s[:K-1]
s_2 = s[K-1:].lower().capitalize().swapcase()
#print(s_1)
#print(s_2)

print(s_1 + s_2)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s[999];
int n;
int dx[]={1,0,-1},dy[]={1,1,1};
int ful(int y,int x){
    int sum=0;
    while(1){
        x++;
        if(s[y].size()<=x){
            x--;
            break;
        }
        if(s[y][x]==' '){
            x--;
             break;
        }
    }
    s[y][x]='#';sum++;
        if(y+1<n){
          if(x+1<s[y+1].size()&&x-1>=0){
           if(s[y+1][x+1]=='*'&&s[y+1][x-1]=='*'){
              sum+=ful(y+1,x+1);
            }
            else goto L;
         }
          else{L:;int ppp=0;
          r(i,3){
          int yy=y+dy[i];
          int xx=x+dx[i];
           if(yy>=0&&yy<n&&xx>=0)
             if(xx<s[yy].size())
                 if(s[yy][xx]=='*')
                    if(!ppp)
                     sum+=ful(yy,xx),ppp++;}}
           }

    //cout<<y<<x<<endl;r(k,n)cout<<s[k]<<endl;
    return sum;
}
int con(int y,int x){
    int sum=0,p=x,pp=x;
    for(;x<s[y].size();){
        if(s[y][x]=='#'){
            break;
        }
        if(p==pp)s[y][x]='#';
        if(x-1>=0)if(s[y][x-1]=='#'&&s[y][x]=='*')s[y][x]='#';
        sum++;
        x++;p++;
    }
    r(i,3){
        int yy=y+dy[i];
        int xx=pp+dx[i];
        if(yy>=0&&yy<n&&xx>=0)
            if(xx<s[yy].size())
                if(s[yy][xx]=='*')
                    sum+=con(yy,xx);
    }
    return sum;
}
void del(){
    r(i,n)r(j,s[i].size())
      if(s[i][j]=='#')s[i][j]=' ';
}
int main(){

    int ppp=0;

    while(cin>>n,n){

        if(ppp)cout<<"----------"<<endl;

        ppp++;

        string t;

        getline(cin,t);

        r(i,n){

            getline(cin,t);

            s[i]=t;

            //cout<<t<<endl;
        }

        map<int,int>m;

        for(int i=0;i<n;i++){

            for(int j=0;j<s[i].size();j++){

                int sum=0;

                if(s[i][j]=='*'){

                    sum+=ful(i,j);//r(k,n)cout<<s[k]<<endl;

                    sum+=con(i,j);

                    del();

                    m[sum]++;//cout<<sum<<endl;
                }
                
            }

        }

        for(map<int,int>::iterator it=m.begin();it!=m.end();it++)
            cout<<(*it).first<<' '<<(*it).second<<endl;
        
    }
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL n,a,b,lst,ans,x;
inline LL mn(LL k,LL l){return k<l?k:l;}
int main(){
	scanf("%lld%lld%lld%lld",&n,&a,&b,&lst);
	for(--n;n--;){
		scanf("%lld",&x);
		ans+=mn(b,a*(x-lst));lst=x;
	}printf("%lld\n",ans);return 0;
}

Measured memory_bytes: 256
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 1000005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

bool isPossible(ll n,ll k)
{
    while(n%k == 0)
    {
        n = n/k;
    }

    return (n%k) == 1;
}

int main()
{
    fast
/*

    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/


    ll n;
    cin>>n;
    n--;

    ll count = 0;

    ll i = 1;
    for(; i*i <= n; i++)
    {
        if(n%i) continue;
        count++;
        if(i*i != n) count++;
    }


    i = 2;
    n++;
    for(; i*i <= n; i++)
    {
        if(n%i) continue;
        count += isPossible(n,i);
        if(i*i != n) count += isPossible(n,n/i);
    }

    cout<<count<<endl;



    return 0;
}   






Measured memory_bytes: 256
/*
[abc127] B - Algae
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

int r, D, x;

void solve() {
    for (int i = 0; i < 10; i++) {
        x = r * x - D;
        cout << x << endl;
    }
}

int main() {
    cin >> r >> D >> x;

    solve();

    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int main() {
	int n;
	vector<int>d;
	int a;
	cin >> n;
	lp(n) {
		cin >> a;
		d.push_back(a);
	}
	sort(d.begin(), d.end());
	d.erase(unique(d.begin(), d.end()), d.end());
	cout << d.size() << endl;
	return 0;
}

Measured memory_bytes: 256