akhauriyash/Code-Regression huggingface dataset:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint,time,random
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def cal(T):
    res = 0
    last = [0] * 26
    for day in range(D):
        t = T[day]; t -= 1
        last[t] = 0
        res += s[day][t]
        for i in range(26):
            if i == t: continue
            last[i] += 1
            res -= c[i] * last[i]
    return res
def check_change(td,tq):
    global score,res
    old_q = res[td]
    res[td] = tq
    now = cal(res)
    if now > score:
        score = now
    else:
        res[td] = old_q

start_time = time.time()
n = 26
D = inp()
c = inpl()
s = []
max_s = []
for i in range(D):
    tmp = inpl()
    mx = 0; ind = -1
    for j in range(n):
        if tmp[j] > mx:
            mx = tmp[j]
            ind = j
    max_s.append(ind+1)
    s.append(tmp)

last = [0] * n
res = [-1] * D
for d in range(D):
    ans = -1
    mx = -INF
    for i in range(n):
        now = s[d][i]
        for j in range(n):
            if i == j: continue
            now -= s[d][j] * (last[j]+1)
        if now > mx:
            mx = now
            ans = i
    res[d] = ans+1
    for j in range(n):
        last[j] += 1
        if j == ans: last[j] = 0
score = cal(res)
# print(now_score)
for i in range(D):
    if res[i] == max_s[i]: continue
    check_change(i,max_s[i])

while time.time() - start_time < 1.83:
    td,tq = random.randrange(0,D), random.randrange(1,n+1)
    check_change(td,tq)

for x in res:
    print(x)

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

int main() {
    //
    int num;
    int sum=0;

    cin >> num;

    for (int i = 0; i < num; i++) {
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        sum += tmp2 - tmp1 + 1;
    }

    cout << sum << endl;
}


Measured memory_bytes: 3556
import java.io.IOException;
import java.util.Scanner;

/**
 * <pre>
 * NumberOfIsland
 *
 * ??¶?????°???????????????
 * </pre>
 *
 * @author ?????????????????§???
 *
 */
public class Main{

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			//??°??¢???????´???´???
			boolean map[][] = new boolean[12][12];

			for (int cnt = 0; cnt < map.length; cnt++) {
				//????????????
				int tmp_addr=0;
				// ???????????????????????£?????¨???????´?
				char[] tmp_row =sc.next().toCharArray();
				for (char info:tmp_row ) {
					// ????????°??????(???)???true(1)??? ?????? ????????????(???)???false(0)???
					//??°??????????£?
					map[cnt][tmp_addr] = (info == '1')/*(info =='1'? true:false)*/;
					tmp_addr++;
				}
			}
			// ??¶?????°
			int ans = 0;
			for (int cnt1 = 0; cnt1 < map.length; cnt1++) {
				for (int cnt2 = 0; cnt2 < map[0].length; cnt2++) {
					// ?????°??????
					if (map[cnt1][cnt2]/* == true */) {
						// ??¬???
						recursive_landSurvey(cnt1, cnt2, map);
						// ??¬??????????????£????????¶?????°?????????
						ans++;
					}
				}
			}
			// ???????????????
			System.out.println(ans);
		} // ?????????????????????
			// ????????????????????????
		sc.close();
	}// ?????????????????????????????????

	/**
	 * <pre>
	 * ?????°??????????????????
	 * </pre>
	 *
	 * ?????°??¬???
	 *
	 * @param mh
	 *            ??????
	 * @param mw
	 *            ??????
	 * @param map
	 */
	private static void recursive_landSurvey(int mh, int mw, boolean[][] map) {
		// StackOverflowError
		map[mh][mw] = false;
		// ?§??????????????????????
		int move_list1[] = { 1, 0, -1, 0 };
		int move_list2[] = { 0, 1, 0, -1 };
		for (int cnt = 0; cnt < move_list1.length; cnt++) {
			// ??????????????????????§??????????
			int addr_h = mh + move_list1[cnt];
			// ??????????????????????§??????????
			int addr_w = mw + move_list2[cnt];

			// ??°???????????????????????°
			if (0 <= addr_h && 0 <= addr_w && addr_h < map.length && addr_w < map[0].length
					&& map[addr_h][addr_w]/* ==true */)
				// ?????°????¶?????????¬???
				recursive_landSurvey(addr_h, addr_w, map);
		}
	}// recursive_landSurvey????????????????????????

}// ??????????????????????????????

Measured memory_bytes: 26124
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<string> A(H);
  int i,j;
  for (i=0; i< (W+2); i++){
    cout << '#';}
  cout << endl;
  //cout << '#'*(W+2) << endl;
  for (i=0; i<H; i++){
    cout << '#';
      cin >> A.at(i);
    cout << A.at(i);
    cout << '#' << endl;
  }
  for (i=0; i< (W+2); i++){
    cout << '#';}
  cout << endl;
    
}

Measured memory_bytes: 256
n = int(input())
arr = [int(x) for x in input().split()]
dp = [float('inf') for x in arr]
dp[0] = 0
for i in range(n):
    for j in (i+1, i+2):
        if j < n:
            dp[j] = min(dp[j], dp[i] + abs(arr[i] - arr[j]))
print(dp[-1])

Measured memory_bytes: 13928
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define SG getchar()
#define P putchar
using namespace std;
int n,m;
signed main()
{
	scanf("%d%d",&n,&m);
	((n+m)<10)?(printf("%d",(n+m))):(printf("error"));
	return putchar(10),0;
}

Measured memory_bytes: 256
N, M, X = map(int, input().split())

List = []

Max = 10 ** 7

for i in range(N):
    List.append(list(map(int, input().split())))

for i in range(2 ** N):
    Sum = [0] * (M+1)
    for j in range(N):
        if (i >> j) & 1:
            for k in range(M+1):
                Sum[k] += List[j][k]
    if Sum[0] <= Max:
        for a in range(1, M+1):
            if Sum[a] < X:
                break
        else:
            Max = Sum[0]

if Max == 10 ** 7:
    print(-1)
else:
    print(Max)

Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double


int32_t main()
{
	IOS
	int n;cin>>n;
	float ans=0;
	for(int i=1;i<=n;i++)
	{
		float x;string s;cin>>x>>s;
		if(s=="JPY")ans+=x;
		else ans+=x*380000.0;
	}
	cout << fixed << setprecision(20) << ans <<endl;
	
}
	
			
	
	
	
	
	

	

	

	
		


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

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    int C[N], A[N][M];
    rep(i, N) {
        cin >> C[i];
        rep(j, M) {
            cin >> A[i][j];
        }
    }

    int ans = -1;
    rep(bit, 1<<N) {
        int cost = 0;
        vector<int> degree(M, 0);
        rep(i, N) {
            if(bit & (1<<i)) {
                cost += C[i];
                rep(j, M) {
                    degree.at(j) += A[i][j];
                }
            }
        }

        bool flag = true;
        rep(j, M) {
            if(degree.at(j) < X) {
                flag = false;
                break;
            } 
        } 
        if(flag && (ans == -1 || cost < ans)) {
            ans = cost;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3592
import java.util.Scanner;
 class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int x[] = new int[100000], y[] = new int[100000];
		int i = 0,a;
		while(true){
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			if(x[i] == 0 && y[i] == 0) break;
			if(x[i] > y[i]){
				a = x[i];
				x[i] = y[i];
				y[i] = a;
			}
			i++;
		}
		for(int j = 0; j < i; j++){
			System.out.println(x[j]+" "+y[j]);
		}
	}
 }

Measured memory_bytes: 37092
#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

using ld = long double;
using ll = long long;

constexpr int mod = 1000 * 1000 * 1000 + 7;
constexpr int odw2 = (mod + 1) / 2;

void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }
int Pot(int a, int b) { int res = 1; while (b) { if (b % 2 == 1) MnozDo(res, a); a = Mnoz(a, a); b /= 2; } return res; }
int Odw(int a) { return Pot(a, mod - 2); }
void PodzielDo(int& a, int b) { MnozDo(a, Odw(b)); }
int Podziel(int a, int b) { return Mnoz(a, Odw(b)); }
int Moduluj(ll x) { x %= mod; if (x < 0) x += mod; return x; }

template <typename T> T Maxi(T& a, T b) { return a = max(a, b); }
template <typename T> T Mini(T& a, T b) { return a = min(a, b); }

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> A(n);
  for (int& x : A) cin >> x;
  int sum[2] = {0, 0};
  for (int i = 0; i < n; i++) {
    sum[i % 2] += A[i];
  }
  if (n % 2 == 0) {
    cout << max(sum[0], sum[1]) << " " << min(sum[0], sum[1]) << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (i % 2 == 1) A[i] *= -1;
    if (i > 0) A[i] += A[i - 1];
  }
  auto Ok = [n, &A](int x) -> bool {
    int najm = 0;
    for (int i = 1; i < n; i += 2) {
      if (najm <= A[i - 1] - x) {
        Mini(najm, A[i]);
      }
    }
    return najm <= A[n - 1] - x;
  };
  int a = 0, b = n * 1005;
  while (a < b) {
    const int c = (a + b + 1) / 2;
    if (Ok(c)) {
      a = c;
    } else {
      b = c - 1;
    }
  }
  cout << (sum[1] + a) << " " << (sum[0] - a) << endl;
  return 0;
}


Measured memory_bytes: 1408
package main

import "fmt"

func main() {
	var w, h, x, y, r int
	fmt.Scan(&w, &h, &x, &y, &r)
	if x <= w-r && x >= r {
		if y <= h-r && y >= r {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}

	} else {
		fmt.Println("No")
	}

}



Measured memory_bytes: 1128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string> 
#include <map>
#include <iomanip>
#include <list>
#include <stack>

using namespace std;


typedef int INT;
#define int long long

INT main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int n, c;
	cin >> n >> c;
	vector <pair <int, int> > a(n);
	for (int i = 0; i < n; i++)
	{
		int b, d;
		cin >> b >> d;
		a[i] = { b, d };
	}
	sort(a.begin(), a.end());
	vector <int> msudi(n), mtudi(n);
	int mmax = 0;
	int cur = 0, t = 0;
	for (int i = 0; i < n; i++)
	{
		cur += a[i].second;
		cur -= a[i].first - t;
		t = a[i].first;
		mmax = max(mmax, cur);
		msudi[i] = mmax;
	}
	cur = 0, t = c;
	int rmax = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		cur += a[i].second;
		cur -= t - a[i].first;
		t = a[i].first;
		rmax = max(rmax, cur);
		mtudi[i] = rmax;
	}
	mmax = max(mmax, rmax);


	cur = 0; t = 0;
	for (int i = 0; i < n - 1; i++)
	{
		cur += a[i].second;
		cur -= a[i].first - t;
		t = a[i].first;
		int u = cur - a[i].first;
		u += mtudi[i + 1];
		mmax = max(u, mmax);
	}
	cur = 0; t = c;
	for (int i = n - 1; i >= 1; i--)
	{
		cur += a[i].second;
		cur -= t - a[i].first;
		t = a[i].first;
		int u = cur - (c - a[i].first);
		u += msudi[i - 1];
		mmax = max(u, mmax);
	}

	cout << mmax;

	return 0;
}

Measured memory_bytes: 3456
S=input()
flag=0
count=0
begin=0
max_begin=0
max_count=0
for i in range(len(S)):
    if flag==0:
        
        if S[i]=="A" or S[i]=="T" or S[i]=="C" or S[i]=="G":
            begin=i
            count+=1
            flag=1
            
    else:
        if S[i]=="A" or S[i]=="T" or S[i]=="C" or S[i]=="G":
            count+=1
            
        else:
            if max_count<count:
                max_count=count
                max_begin=begin
            flag=0
            count=0
if max_count<count:
    max_count=count
print(max_count)  

Measured memory_bytes: 3064
#!/usr/bin/env python3
from collections import*
n, *d= map(int, open(0).read().split())
c = Counter(d)
if d[0] or c[0] > 1:
    exit(print(0))
MOD = 998244353
m = 1
for i in range(1, max(d)):
    m *= pow(c[i], c[i + 1], MOD)
    m %= MOD
print(m)

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	ll L=in<ll>(),R=in<ll>();
	
	ll LS=L/2019,RS=R/2019;
	if(LS!=RS){
		out(0);
		return 0;
	}

	ll ans = 1LL<<60;
	for(ll i=L;i<R;i++){
		for(ll j=L+1;j<=R;j++){
			ll v = ((i%2019)*(j%2019)%2019);
			ans = min(ans,v);
		}
	}
	
	out(ans);
	return 0;
}


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

#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORS(i, a, b, c) for(int i = a; i < b; i += c)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  unordered_map
#define US  unordered_set
#define PQ  priority_queue

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;

const ll mod = 1e9+7;
ll pow(ll b, ll p){
  ll r = 1;
  while(p){
    if(p&1)r=r*b%mod;
    p>>=1; b=b*b%mod;
  }
  return r;
}
ll rev(ll a, ll b){
  return a*pow(b,mod-2)%mod;
}
ll gcd(ll a, ll b){
  return b ? gcd(b, a%b) : a;
}

int main(){
  IO; int N; cin >> N;
  map<pll, ll> freq;
  ll a, b;
  ll ans = 1;
  ll add = -1;
  while(N--){
    cin >> a >> b;
    if(!a&&!b){
      add ++;
      continue;
    }
    if(!a) b = 1;
    else if(!b) a = 1;
    else{ // b always +
      if(b<0)a=-a,b=-b;
      ll c = gcd(abs(a), abs(b));
      a /= c, b /= c;
    }
    freq[{a,b}]++; freq[{a,b}]%=mod;
  }
  FORE(i,freq){
    if(!i.S) continue;
    ll a = i.F.F, b = i.F.S;
    pll t;
    if(!a)t={1,0}; else if(!b)t={0,1}; else if(a<0) t={b,-a}; else t={-b,a};
    if(IN(freq,t)){
      ans=(pow(2ll,i.S)+pow(2ll,freq[t])-1+mod)%mod*ans%mod;
      freq[t] = 0;
    }else ans = ans*pow(2ll, i.S)%mod;
    i.S = 0;
  }
  cout << (ans+add+mod)%mod << endl;
}


Measured memory_bytes: 16072
import math

def combination(n,r,mod=10**9+7):
    n1 = n+1
    r = min(r,n-r)
    numer = denom = 1
    for i in range(1,r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom,mod-2,mod) % mod

X,Y = map(int,input().split())

ans = 0

if (X+Y)%3 == 0 and 2*Y-X>=0 and 2*X-Y>=0:
    up,right = (2*Y-X)//3,(2*X-Y)//3
    ans = combination(up+right,right)

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i= a ; i < b ; ++i)
#define rep(i,n) fo(i,0,n)
#define pln(n) printf("%lld\n",n)
#define sll(n) scanf("%lld",&n)
#define ss(n) scanf("%s",n)
#define vi vector < int >
#define pii pair < int , int >
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define dbg3(x,y,z) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) <<" , "<< #z <<": "<<(z)<<endl; }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<int>
#define tr(c, it) \
for(decltype(c.begin()) it = c.begin(); it!= c.end(); it++)
#define pis pair<int,string>
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c),x) != c.end())
using namespace std;
int main(){
    int n;
    cin >> n;
    vi h(n);
    for(int i = 0; i < n; i++){
		cin >> h[i];
	}
	int dp[n];
	dp[n-1] = 0;
	for(int i = n-2; i >= 0; i--){
	    int x = dp[i+1] + abs(h[i] - h[i+1]);
		if(i + 2 < n){
			int y = dp[i+2] + abs(h[i] - h[i+2]);
			dp[i] = min(x, y);
		}
		else{
			dp[i] = x;
		}
	}
	cout << dp[0] << endl;
	return 0;
}

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

/*bool is_prime(int x)
{
	if(x<2)
		return false;
	for(int i=2;i*i<=x;i++)
	{
		if(x%i==0)
			return false;
	}
	return true;
} */


int main()
{
	//freopen(" .in","r",stdin);
	//freopen(" .out","w",stdout);
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	int ans=n/2;
	if(n%2==0) 
	{
		ans--;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
  map<ll,ll> mp;
  for(ll i = 0;i <= 9;i++)mp[i] = 1e3;
  mp[1] = 0;

  int H,W;
  cin >> H >> W;
  ll c[10][10];
  for(int i = 0;i < 10;i++){
    for(int j = 0;j < 10;j++){
      cin >> c[i][j];
    }
  }

  vector<ll> perm{0,2,3,4,5,6,7,8,9,1};

  do{
    ll now_sum = 0;
    for(ll i = 8;i>=0;i--){
      now_sum += c[perm[i]][perm[i+1]];
      mp[perm[i]] = min(mp[perm[i]],now_sum);
    }
  }while(next_permutation(perm.begin(),perm.end()-1));


  ll ans = 0;

  for(int i = 0;i < H * W;i++){
    ll a;
    cin >> a;
    if(a != -1)ans += mp[a];
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
d,m=1e9+7,dp[10001][2][100];char s[11111];
f(l,i,k,t,x,L)
{
	int*r=dp[i][t]+k;
	*r=i-l?*r:!k;
	if(!~*r)
		for(L=t?9:s[i]-48,*r=x=0;x<=L;*r%=m)*r+=f(l,i+1,(k+x++)%d,t|x<L);
	return*r;
}
main()
{
	scanf("%s%d",s,&d);
	memset(dp,-1,sizeof dp);
	printf("%d",(f(strlen(s),0,0,0)-1+m)%m);
}

Measured memory_bytes: 8832
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


N,S = map(int,input().split())
table = list(map(int,input().split()))

ans = BIG_NUM

left = 0
right = 0
tmp_sum = table[0]

while left < len(table):
    while True:
        if tmp_sum >= S:
            ans = min(ans,right-left+1)
            break
        if right == len(table)-1:
            break
        right += 1
        tmp_sum += table[right]

    if tmp_sum < S:
        break

    while True:
        if left > right:
            break
        tmp_sum -= table[left]
        left += 1
        if tmp_sum >= S:
            ans = min(ans,right-left+1)
        else:
            break
    right = max(right,left)


if ans == BIG_NUM:
    print("0")
else:
    print("%d"%(ans))




Measured memory_bytes: 17600
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define dump(x) cerr << #x << "=" << x <<endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);

void solve()
{
	/*--------------------------*/

	int H, A; cin >> H >> A;
	cout << (H + A - 1) / A << endl;

	/*--------------------------*/
}

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

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

#define deb(x) cout << #x << " -> " << x << el 
#define db double
#define ll long long int
#define ld long double
#define ull unsigned long long int
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define sclu(x) scanf("%llu", &x)
#define scd(x) scanf("%lf", &x)
#define scld(x) scanf("%Lf", &x)
#define pass cout<<"pass\n"
#define vi vector<int>
#define eb emplace_back
#define pb push_back
#define vec vector
#define el "\n"
#define pii pair<int, int>
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define f(i,x,y) for(int i=x;i<y;++i)
#define ff(i,x,y) for(int i=x;i<=y;++i)
#define mem(x) memset(x, 0, sizeof(x))
#define mems(x,y) memset(x, y, sizeof(x))
#define MOD 1000000007
#define MAX 100005

using namespace std;

int r, g, rapp, gapp, clss;
int red[MAX], green[MAX], lss[MAX];

void solve() {
	cin >> r >> g >> rapp >> gapp >> clss;

	f(i,0,rapp) {
		cin >> red[i];
	}
	f(i,0,gapp) {
		cin >> green[i];
	}
	f(i,0,clss) {
		cin >> lss[i];
	}

	ll ans = 0LL;

	sort(red, red + rapp);
	sort(green, green + gapp);
	sort(lss, lss + clss);

	int total = r + g;
	int ri = rapp - 1, gi = gapp - 1, cli = clss - 1;
	int rem = (r + g) - (rapp + gapp);
	while(cli >= 0 and rem > 0) {
		ans += 1LL * lss[cli--];
		--rem;
		--total;
	}

	vi v;
	while(cli >= 0) {
		v.eb(lss[cli--]);
	}
	while(r > 0 and ri >= 0) {
		v.eb(red[ri--]);
		--r;
	}
	while(g > 0 and gi >= 0) {
		v.eb(green[gi--]);
		--g;
	}
	// for(int s: v) cout << s << " ";
	// cout << el;
	sort(v.begin(), v.end(), greater<int>());
	for(int i = 0; i < (int)v.size() and i < total; ++i) {
		ans += 1LL * v[i];
	}
	cout << ans;
}


int main() {
	// clock_t start = clock();
	// freopen("./input.in", "r", stdin);
	int tt = 1;
	// sc(tt);
	while(tt--) {
		solve();
	}
	// clock_t finish = clock();
	// printf("Time taken: %0.9lf sec\n", (double)((finish - start) / CLOCKS_PER_SEC));
 	
	return 0;
}

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

ll n,k,m,a,b;
string s;

int main() {
  cin >> n;
  cout << (n-2)*180 << endl;
}

Measured memory_bytes: 256
# n 偶数 m 奇数
n, m = list(map(int, input().split()))
n1=0
m1=0
# 2つ選んで偶数になる　奇数＋奇数　もしくは　偶数＋偶数

if n >= 2:
    n1 = (n * (n-1))//2

if m >= 2:
    m1 = (m * (m-1))//2

print(n1 + m1)


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

int binarySearch(vector<int>& v, int n, int t) {
  int lower = 0;
  int upper = n - 1;
  while (lower <= upper) {
    int mid = (lower + upper) / 2;
    if (v[mid] == t) {
      return 1;
    } else if (v[mid] < t) {
      lower = mid + 1;
    } else {
      upper = mid - 1;
    }
  }
  return 0;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n, q, t, cnt = 0;
  cin >> n;
  vector<int> s(n);
  for (auto& e : s) cin >> e;
  cin >> q;
  while (q--) {
    cin >> t;
    cnt += binarySearch(s, s.size(), t);
  }
  cout << cnt << "\n";
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
#define INF 1034567890
int e[1000][1000],cnt[1000],visited[1000][1000];
bool used[SIZE];
int N,H;
int bfs[SIZE];
bool go(int x){
    int v=0,v2=0;
    bfs[0]=x;
    int rr=1;
    used[x]=1;
    REP(i,rr){
        x=bfs[i];
        if(x<=H||x>3*H)v+=cnt[x];
        else v-=cnt[x];
        v2+=cnt[x];
        REPP(j,1,4*H+1){
            if(e[x][j]){
                visited[x][j]=1;
                if(!used[j]){
                    bfs[rr++]=j;
                    used[j]=1;
                }
            }
            if(e[j][x]){
                visited[j][x]=1;
                if(!used[j]){
                    bfs[rr++]=j;
                    used[j]=1;
                }
            }
        }
        int pp=-1;
        if(x>2*H)pp=x-2*H;
        else pp=x+H*2;
        if(pp!=-1){
            if(!used[pp]){
                bfs[rr++]=pp;
                used[pp]=1;
            }
        }
    }
    if(!v2)return 1;
    if(!v)return 0;
    return 1;
}
int main(){
    RII(N,H);
    REP(i,N){
        DRII(A,B);
        DRII(C,D);
        int x,y;
        if(!C)x=A;
        else x=H+C;
        if(!D)y=3*H+B;
        else y=2*H+D;
        
        cnt[x]++;
        cnt[y]++;
        e[x][y]=1;
    }
    REPP(i,1,H+1){
        if(cnt[i]<cnt[i+2*H])return 0*puts("NO");
        if(cnt[H*3+i]<cnt[H+i])return 0*puts("NO");
    }
    REPP(i,1,H+1){
        if(!used[i]){
            if(!go(i))return 0*puts("NO");
        }
    }
    REPP(i,1,4*H+1)REPP(j,1,4*H+1){
        if(e[i][j]&&!visited[i][j]){
            return 0*puts("NO");
        }
    }
    return 0*puts("YES");
}


Measured memory_bytes: 10624
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n;
	cin>>n;
	int streak=0;
	int ans=0;
	while(n--){
		int a,b;
		cin>>a>>b;
		if(a==b)streak++;
		else {
			streak=0;
		}
		ans=max(ans,streak);
	}
	if(ans>=3)
	cout<<"Yes";
	else cout<<"No"; 
	return 0;
}

Measured memory_bytes: 3680
#include <stdio.h> 
main()
{ 
    
  int a,b,c,x,y,z; 
    
  scanf("%d%d%d",&a,&b,&c); 
    
  if(a > b){  
    x = a; 
    a = b; 
    b = x; 
  } 
    
  if(b > c){ 
    y = b; 
    b = c; 
    c = y; 
  } 
    
  if(a > b){ 
    z = a; 
    a = b; 
    b = z; 
  } 
    
  printf("%d %d %d\n",a,b,c); 
    
  return 0; 
}

Measured memory_bytes: 596
// This  Program is made by Jan(Codezebra)
#include<bits/stdc++.h>
//#define int long long
//#define INF 0x3f3f3f3f
using namespace std;
vector<int>num={-1,1,4,8,9,16,25,27,32,36,49,64,81,100,121,125,128,144,169,196,216,225,243,256,289,324,343,361,400,441,484,512,529,576,625,676,729,784,841,900,961,1000,1001};

/*int bs(int a){
	int l=0,r=num.size()-1,m;
	while(l!=r){
		m=(l+r)/2;
		if(num[m]<=a and num[m+1]>a){
			return m;
		}
		else if(num[m]>a){
			r=m-1;
		}
		else if(num[m+1]<a){
			l=m+1;
		}
	}
	return m;
}*/
int ls(int a){
	for(int i=0;i<num.size();i++){
		if(num[i]>a){
			return i-1;
		}
	}
	return num.size()-1;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
//	num.clear();
/*	for(int i=1;i<2;i++){
		for(int j=2;pow(i,j)<=1000;j++){
			num.push_back(pow(i,j));
		}
	}
	sort(num.begin(),num.end());
	for(int i=0;i<num.size();i++){
		if(num[i]!=num[i-1]){//not clean= num[-1]
			cout<<num[i]<<",";	
		}
		
	}*/
	int a;
	cin>>a;
	cout<<num[ls(a)];
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

int Get(int x, int y) { if(x < y) swap(x, y); return (x + y) / (y + 1); }
int Get2(int x, int v) {
	return v % (x+1) == 0;
}

void solve(){
	int A, B, C, D; scanf("%d%d%d%d", &A, &B, &C, &D);
	int N = A + B;
	int x = Get(A, B);
	int f = -1;
	if(x == 1) f = (B > A ? 0 : N);
	else {
		int t = (int)(((ll)x * A - B) / (x - 1));
		for(int i=max(0,t-30);i<=min(t+30, N);i++) {
			int ta = i - (i / (x + 1)) + (N - i) / (x + 1);
			if(ta == A && !(i % (x+1) == x && (N - i) % (x+1) == 0 && i != N) && !(i % (x + 1) == 0 && (N - i) % (x + 1) == x && i != 0)) {
				f = i;
			}
		}
	}
	for(int i=C;i<=D;i++) {
		if(i <= f) printf("%c", 'A' + Get2(x, i));
		else printf("%c", !Get2(x, N + 1 - i) + 'A');
	}
	puts("");
}

int main(){
	int T = 1; scanf("%d", &T);
	while(T--) {
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int gcd(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  while(true) {
    if (b == 0) {
      break;
    }
    int r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }

  for (int i = 0; i < N - 1; i++) {
    vec[i + 1] = gcd(vec[i], vec[i + 1]);
  }
  cout << vec[N - 1] << endl;
  return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  int sum = 0;
  for(int i = a; i <= b; i++){
    int s = i%10; int t = (i/10)%10;
    int u = i/10000; int v = i/1000-u*10;
    if(s == u && t == v)
      sum++;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
use std::io;

/// 一行を読み込んで、空白で区切ったベクタにして返す
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

/// n行を読み込んで、数字を空白で区切って二次元のベクタにして返す
#[allow(dead_code)]
fn read_table<T>(n: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut ret: Vec<Vec<T>> = Vec::new();
    for _ in 0..n {
        ret.push(read::<T>());
    }
    ret
}

/// n行を読み込んで、1文字ずつを二次元のベクタにして返す
#[allow(dead_code)]
fn read_char_table(n: usize) -> Vec<Vec<char>> {
    let mut ret: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let chr = buf.trim().chars().collect();
        ret.push(chr);
    }
    ret
}

/// n行を読み込んで、一次元のベクタにして返す
#[allow(dead_code)]
fn read_array<T>(n: usize) -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut array = Vec::new();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        array.push(buf.trim().parse().unwrap());
    }
    array
}

fn main() {
    // 数値
    let mut n = {
        let i = read::<isize>();
        i[0]
    };

    let mut ans = 0;

    if n % 10 == 1 {
        ans += 9;
    } else if n % 10 == 9 {
        ans += 1;
    } else {
        ans += n % 10;
    }

    n /= 10;

    if n % 10 == 1 {
        ans += 90;
    } else if n % 10 == 9 {
        ans += 10;
    } else {
        ans += (n % 10) * 10;
    }

    n /= 10;

    if n % 10 == 1 {
        ans += 900;
    } else if n % 10 == 9 {
        ans += 100;
    } else {
        ans += (n % 10) * 100;
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
import sys
l,r=map(int,input().split())
anslist=20000000000
for i in range(l,r):
    if r-i>=(2019-i%2019):
        print(0)
        sys.exit()
    for u in range(i+1,r+1):
        ans=min(anslist,i*u%2019)
        anslist=ans
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int N;
int d[312345];

bool solve() {
	for (int i = 0, ma = 0; i <= ma; i++) {
		chmax(ma, d[i] + i);
		if (ma >= N - 1) return true;
	}
	return false;
}

int main() {
	cin >> N;
	REP(i, N) scanf("%d", d + i), d[i] /= 10;
	
	bool ans = solve();
	reverse(d, d + N);
	ans &= solve();
	
	puts(ans ? "yes" : "no");
	
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;
    cin >> n;
    
    vector<int> C(n-1);
    vector<int> S(n-1);
    vector<int> F(n-1);

    rep(i,n-1) cin >> C[i] >> S[i] >> F[i];
    
    for(int i = 0; i < n; i++){
        int t = 0;
        for(int j = i; j < n - 1; j++){
            if(t<S[j]) t = S[j];
            else if (t % F[j]==0);
            else t = t + F[j] - t % F[j];
            t += C[j];
        }
        cout << t << endl;
    }
    
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int H, W, N;
    scanf("%d%d%d", &H, &W, &N);
    int m = H > W ? H : W;
    int ans = N / m;
    if(N % m != 0) ans++;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 384
n = int(input())
list_ = list(map(int,input().split()))
min_ = min(list_)
max_ = max(list_)
num=[]
for a in range(min_,max_):
  _ = []
  for b in range(len(list_)):
    _.append((a - list_[b])**2)
  num.append(sum(_))
if len(list(set(list_))) == 1:
  print(0)
  exit()
print(min(num))

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

int main() {
  int N;
  scanf("%d", &N);

  vector<int> V(N, 0);
  vector<int> C(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &V.at(i));
  }
  for (int i = 0; i < N; i++) {
    scanf("%d", &C.at(i));
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (V.at(i) - C.at(i) > 0) ans += V.at(i) - C.at(i);
  }

  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f1          first
#define f2          second
#define hell        10000007
#define in          for(int i=a;i<b;i++)
using namespace std;
ll a[hell], b[hell];
ll dp[hell];
signed main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	ll i, j, k, l, test, n, c, sum = 0, sum1 = 0, sum2 = 0;
	ll count = 0, count1 = 0, count2 = 0, val = 0, pos = 0, pos1 = 0;
	bool flag = 1;
	
	cin >> n >> k;
	for (i = 1; i <= n; i++) cin >> a[i];

	dp[1] = 0;
	dp[2] = abs(a[2] - a[1]);
	
	for (i = 3; i <= n; i++) {
		val = INT_MAX;
		for (j = 1; j <= k; j++) {
			if (i - j >= 1) {
				if (dp[i - j] + abs(a[i - j] - a[i]) < val) val = dp[i - j] + abs(a[i - j] - a[i]);
			}
		}
		dp[i] = val;
		//if (val == INT_MAX) while (1);
	}
	cout << dp[n];
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <list>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    list<int> lis;
    for(int i = 0; i < n; ++i){
        string s; cin >> s;
        if(s == "deleteFirst") lis.erase(lis.begin());
        if(s == "deleteLast") {
            auto it = lis.end(); it--;
            lis.erase(it);
        }
        if(s == "insert"){
            int x; cin >> x;
            lis.insert(lis.begin(),x);
        }
        if(s == "delete"){
            int x; cin >> x;
            for(auto it = lis.begin(); it != lis.end(); ++it){
                if(*it == x){
                    lis.erase(it);
                    break;
                }
            }
        }
    }
    for(auto it = lis.begin(); it != lis.end(); ++it){
        if(it != lis.begin()) cout << " ";
        cout << *it;
    }
    cout << endl;
    return 0;
}


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

#define IL inline 
IL int read() {
	char ch = getchar(); int u = 0, f = 1;
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { u = (u << 1) + (u << 3) + ch - 48; ch = getchar(); }
	return u * f; 
}
const int maxn = 5005;
int n, len;
char s[maxn];
const int mod = 1e9 + 7;
int f[maxn][maxn];
IL int pls(int x, int y) { x += y; return x >= mod ? x - mod : x; }
IL int dec(int x, int y) { x -= y; return x < 0 ? x + mod : x; }
IL int mul(int x, int y) { return 1ll * x * y % mod; }
IL int fpw(int x, int y) {	
	int r = 1;
	for (; y; y >>= 1, x = mul(x, x)) 	
		if (y & 1) r = mul(r, x);
	return r;
}
int main() {
	n = read();
	scanf("%s", s + 1);
	len = strlen(s + 1);
	
	f[0][0] = 1;	
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= i; ++j) {
			if (j != 0) f[i][j] = pls(f[i][j], mul(2, f[i - 1][j - 1]));
			else f[i][j] = f[i - 1][j];
			f[i][j] = pls(f[i][j], f[i - 1][j + 1]);
		}
	}	
	cout << mul(f[n][len], fpw(fpw(2, len), mod - 2));
	return 0;
}

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

using namespace std;

int mat[110][110];

int main()
{

    int n;

    cin>>n;

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

        cin>>a>>b;

        for(int j=0;j<b;j++)
        {
            int c;

            cin>>c;

            mat[a][c]=1;
        }
    }

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            cout<<mat[i][j];
            if(j==n)
            {
                cout<<endl;
            }else
            {
                cout<<" ";
            }
        }
    }


    return 0;
}



Measured memory_bytes: 3112
///*** author: HM Imu SC ***\\\

#include<bits/stdc++.h>

using namespace std;

#define tillEnd() int t,testCase=1;scanf("%d",&t);while(t--)
#define FEO(container) for(auto ith : container)
#define FEIO(container) for(int i=0; i<container.size();i++)
#define showCase(str) cout<<"Case "<<testCase<<": "<<str<<endl;testCase++
#define read_auto() freopen("in.txt","r",stdin)
#define write_auto() freopen("out.txt","w",stdout)
#define read_write_auto() read_auto();write_auto()
#define to_order() ofstream order("test_cases.txt")
#define space << " " <<
#define get_random(a,b) rand()%(b-a+1)+a
#define lint long long int
#define INF(x) INT_MAX-x
#define boost_io() ios_base::sync_with_stdio(false);cin.tie(false)

int main(){

//    read_auto();

    int n;

    cin>>n;

    vector<int> b;
    int total=0,index=0;

    n--;

    while(n--){
        int x;
        cin>>x;
        b.push_back(x);
    }

    if(b.size()==1){
        total+=(2*b[0]);
        cout<<total<<endl;
        return 0;
    }
    else if(b.size()==2){
        total+=(b[0]+min(b[0],b[1])+b[1]);
        cout<<total<<endl;
        return 0;
    }

    while(index<=b.size()){
        if(index==0){
            total+=b[0];


            index=1;
        }
        else if(index==b.size()){
            total+=b[b.size()-1];
            break;
        }

        total+=min(b[index],b[index-1]);
        index++;
    }

    cout<<total<<endl;

    return 0;
}


Measured memory_bytes: 256
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        x: usize,
        a_s: [usize; m],
    }
    let cost1 = (x..n + 1).filter(|i| a_s.iter().any(|a| i == a)).count();
    let cost2 = (0..x + 1).filter(|i| a_s.iter().any(|a| i == a)).count();
    let ans = *[cost1, cost2].iter().min().unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 4352
n, m = map(int, input().split())
a = []
b = []

ans = 0

for i in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)

sai = sorted(range(len(a)), key=lambda k: a[k])

for i in range(n):
    bsai = min(m,b[sai[i]])
    m -= bsai
    ans += a[sai[i]]*bsai


print(ans)

Measured memory_bytes: 16560
def insertionSort(A,N):
    for i in range(1,N):
        v=A[i]
        j=i-1
        while (j>=0 and A[j]>v):
            c=A[j+1]
            A[j+1]=A[j]
            A[j]=c
            j-=1
        for i in range(len(A)):
            if i!=len(A)-1:
                print(A[i],end=" ")
            else:
                print(A[i])                
a=int(input())
b=list(map(int,input().split()))
for i in range(len(b)):
    if i!=len(b)-1:
        print(b[i],end=" ")
    else:
        print(b[i])   
insertionSort(b,a)


Measured memory_bytes: 5976
// Problem : A - Strings
// Contest : AtCoder Beginner Contest 149
// URL : https://atcoder.jp/contests/abc149/tasks/abc149_a
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#define io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int main () {
	io();
	string s,t;
	cin >> s >> t;
	cout << t+s << endl;
	return 0;
}

Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, M) = read!(usize, usize);
    let T = read![usize, usize; M];

    let mut L = 0;
    let mut R = N;
    for (l, r) in T {
        L = max(L, l - 1);
        R = min(R, r);
    }

    println!("{}", R - min(R, L))
}


Measured memory_bytes: 6396
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n;
    ll ab[100001];
    std::cin >> n;
    ll result = 0;
    for (int i = 0; i < n; i++) {
        ll tmp1,tmp2;
        std::cin >>tmp1>>tmp2;
        ab[i] = tmp1+tmp2;
        result -= tmp2;
    }
    sort(ab,ab+n);
    
    for (int i = 0; i < n; i++) {
        if(i%2==0){
            result += ab[n-i-1];
        }
    }
    std::cout << result << std::endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int c=0;
	char s[200011],t[200011];

	scanf("%s%s",s,t);

	for(int i=0;s[i]!='\0';i++)
		if(s[i]!=t[i])
			c++;

	printf("%d",c);
	return 0;
}

Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n, d[100000], ans = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> d[i];
    }
    sort(d, d+n);
    if(d[n/2-1] == d[n/2]){
        ans = 0;
    }else{
        ans = d[n/2] - d[n/2-1];
    }
    cout << ans << endl;
}


Measured memory_bytes: 640