akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;
//struct edge { int to, cost; };

int dx[8] = { 1,0,0,-1,1,1,-1,-1 };
int dy[8] = { 0,-1,1,0,-1,1,-1,1 };

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int modinv2(int a, int mod) {
    return mod_pow(a, mod - 2, mod);
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}

signed main() {
    //srand((unsigned)time(NULL));

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

    int a;
    string b;
    cin >> a >> b;
    int x = 0;
    rep(i, b.size()) {
        if (b[i] != '.') {
            x = x * 10 + (b[i] - '0');
        }
    }
    int ab = a * x;
    cout << ab / (int)100 << endl;

    return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int a, b, c, d;
    cin >> a >> b >> c >> d ;

    /*
    if(a - b >= 0){
        cout << b * c + ( a - b ) * d << endl;
    } else {
        cout << a * c << endl;
    }
    */
    
    cout << max(a * b, c * d) << endl;

    return 0; 
}


Measured memory_bytes: 3636
package main

import (
	"fmt"

	"os"
	"io"
	"bufio"
	"bytes"

	"strings"
	"strconv"
	// "sort"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}

// 出力 for 競プロ
type Console struct {
	writer *bufio.Writer
}
func NewConsole() Console {
	return Console{ bufio.NewWriter(os.Stdout) }
}
func (this *Console) Printf(format string, a ...interface{}) {
	fmt.Fprintf(this.writer, format, a...)
}
func (this *Console) Println(s string) {
	fmt.Fprintln(this.writer, s)
}
func (this *Console) Close() {
	this.Flush()
}
func (this Console) Flush() {
	this.writer.Flush()
}

// sort 済み配列からとりあえず一致した要素のindexを返す
func BinarySearch(list []int, key int, compare func(int, int) int) int {
	// func
	// lhs > rhs -> positive
	// lhs < rhs -> negative
	return BinarySearchProc(list, 0, len(list) -1, key, compare)
}

func BinarySearchProc(list []int, begin int, end int, key int, compare func(int, int) int) int {
	cur := (end - begin) / 2 + begin
	// fmt.Printf("b:%d, c: %d, e:%d\n", begin, cur, end)
	cmp := compare(key, list[cur])
	if cmp == 0 {
		return cur
	// to left
	}
	// range check
	if cur == end || end < begin {
		return -1
	}
	// to left
	if 0 < cmp {
		return BinarySearchProc(list, cur + 1, end, key, compare)
	// to right
	} else {
		return BinarySearchProc(list, begin, cur - 1, key, compare)
	}
}

func PrintList(list []int) {
	con := NewConsole()
	defer con.Flush()
	for i := range list {
		if i == 0 {
			con.Printf("%d", list[i])
		} else {
			con.Printf(" %d", list[i])
		}
	}
	con.Println("")
}


func main() {
	con := NewConsole()
	defer con.Flush()

	// create list
	var n int
	fmt.Scanf("%d", &n)

	list := make([]int, n)
	lines, _ := ReadLongLines(1)

	elements := strings.Split(lines[0], " ")
	for i := range elements{
		x, _ := strconv.Atoi(elements[i])
		list[i] = x
	}

	var q int
	fmt.Scanf("%d", &q)
	lines, _ = ReadLongLines(q)
	for i := 0; i < q; i++ {
		x, _ := strconv.Atoi(lines[i])
		res := BinarySearch(list, x, func(lhs, rhs int) int {
			if lhs == rhs {
				return 0
			} else if lhs > rhs {
				// fmt.Printf("%d %d +\n", lhs, rhs)
				return 1
			} else {
				// fmt.Printf("%d %d -\n", lhs, rhs)
				return -1
			}

		})
		if res == -1 {
			con.Println("0")
		} else {
			con.Println("1")
		}
	}
	
}


Measured memory_bytes: 11504
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int ans = 0;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				for(int k = 0; k < N; k++){
					ans++;
				}
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
}

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

int main(void){
  string str;

  while(getline(cin,str) && str!="."){
    string c;
    for(int i=0;i<str.size();i++)
      if(str[i]==')' ||str[i]=='(' ||str[i]=='[' ||str[i]==']')
	c += str[i];

  stack<char> s;
  bool f=true;
    for(int i=0;i<c.length();i++){
      if(s.empty() || c[i]=='(' || c[i]=='[')s.push(c[i]);
      else if((s.top()=='(' && c[i]==')' )||(s.top()=='[' && c[i]==']')){
	s.pop();
      }else{
	f=false;
	break;
      }
      
    }
    cout << (f && s.empty()?"yes":"no") << endl;
  }
  return 0;
}

Measured memory_bytes: 0
package main

import "fmt"

func gcd(a, b int) int {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func main() {
	var k int
	fmt.Scan(&k)
	var ans int
	for a := 1; a <= k; a++ {
		for b := 1; b <= k; b++ {
			for c := 1; c <= k; c++ {
				ans += gcd(gcd(a, b), c)
			}
		}
	}
	fmt.Println(ans)
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;

struct edge { int to,cost; };

int main() {
  int H,W,N;cin>>W>>H>>N;
  vector<P> ps(N);
  vector<int> as(N);
  REP(i,N) {
    int x,y;cin>>x>>y>>as[i];
    ps[i] = {x,y};
  }
  // a=1で最大のx
  ll a1x=0,a2x=W,a3y=0,a4y=H;
  REP(i,N) {
    if (as[i]==1) a1x = max(a1x,ps[i].first);
    if (as[i]==2) a2x = min(a2x,ps[i].first);
    if (as[i]==3) a3y = max(a3y,ps[i].second);
    if (as[i]==4) a4y = min(a4y,ps[i].second);
  }

  if (a1x>=a2x || a3y>=a4y) {
    OUT(0);
  } else {
    OUT((a2x-a1x)*(a4y-a3y));
  }

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
 
using namespace std;
 
char st[10001];
int pos;
int mDepth;
 
int getMini(int depth)
{
    if (depth > mDepth) mDepth = depth;
        vector<int> A;
        while (st[pos] == '['){
                pos++;
                A.push_back(getMini(depth + 1));
                pos++;
        }
        if (st[pos] != 0 && st[pos] != ']'){
                int x;
                sscanf(&st[pos], "%d", &x);
                while ('0' <= st[pos] && st[pos] <= '9') pos++;
                return ((x + 1) / 2);
        }
        else {
                int S = 0;
                sort(A.begin(), A.end());
                for (int i = 0; i < (A.size() + 1) / 2; i++)
                        S += A[i];
                return (S);
        }
}
 
int main()
{
        int T;
        
        scanf("%d", &T);
        
        for (int i = 0; i < T; i++){
                scanf("%s", st);
                pos = 0; mDepth = 0;
                printf("%d\n", getMini(0));
        }
        return (0);
}

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

using namespace std;

typedef long long int ll;

int main(){
	ll a,b,c;
	cin >> a >> b >> c;
	ll lhs = 4 * a * b;
	ll rhs = (c - a - b);
	if(rhs <= 0){
		puts("No");
		return 0;
	}
	rhs *= rhs;
	if(lhs < rhs){
		puts("Yes");
	}else{
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 3640
n, m, c = map(int, input().split())
b = list(map(int, input().split()))

cnt = 0
for i in range(n):
    a = list(map(int, input().split()))
    t = 0
    for j in range(m):
        t += a[j] * b[j]
    t += c
    if t > 0:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,d;
  cin>>n>>d;
  ll ans =0;
  for(ll i=0;i<n;i++){
  	ll t1,t2;
    cin>>t1>>t2;
    if(t1*t1 + t2*t2 <= d*d) 
      ans++;
  }
  cout<<ans;
    }

Measured memory_bytes: 3632
#include <iostream>
#include <string>
using namespace std;
int main() {
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  int a[sa.size()], b[sb.size()], c[sc.size()];
  for (int i = 0; i < sa.size(); i++) {
    switch (sa[i]) {
    case 'a':
      a[i] = 0;
      break;
    case 'b':
      a[i] = 1;
      break;
    case 'c':
      a[i] = 2;
      break;
    }
  }
  
  for (int i = 0; i < sb.size(); i++) {
    switch (sb[i]) {
    case 'a':
      b[i] = 0;
      break;
    case 'b':
      b[i] = 1;
      break;
    case 'c':
      b[i] = 2;
      break;
    }
  }
  for (int i = 0; i < sc.size(); i++) {
    switch (sc[i]) {
    case 'a':
      c[i] = 0;
      break;
    case 'b':
      c[i] = 1;
      break;
    case 'c':
      c[i] = 2;
      break;
    }
  }

  int *player[3];
  player[0] = a;
  player[1] = b;
  player[2] = c;
  int p = 0;
  int i[3] = {0,0,0};
  int size[3] = {sa.size(), sb.size(), sc.size()};
  while (i[p] < size[p]) {
    int temp = p;
    p = player[p][i[p]];
    i[temp]++;
  }
  switch (p) {
  case 0:
    cout << 'A' << endl;
    break;
  case 1:
    cout << 'B' << endl;
    break;
  case 2:
    cout << 'C' << endl;
    break;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <list>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

int main() {
	int a, b; cin >> a >> b;
	if (abs(a - b) >= 2) cout << max(a, b)+ (max(a, b) - 1);
	else cout << a + b;

	cout << endl;
	return 0;
}

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

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

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

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

signed main(){
	int N,K,C; cin>>N>>K>>C;
	string S; cin>>S;
	C++;
	vector<int> sum1(N,0),sum2(N,0);
	int now=0;
	while(now<N){
		if(S[now]=='x'){now++; continue;}
		else {
			if(now!=N-1)sum2[now+1]++;
			now+=C;
		}
	}
	for(int i=0;i<N;i++){
		if(i!=0)sum2[i]+=sum2[i-1];
	//	cout<<sum2[i]<<endl;
	}
	now=N-1;
	while(now>=0){
		if(S[now]=='x'){now--; continue;}
		else{
			if(now!=0)sum1[now-1]++;
			now-=C;
		}
	}
	for(int i=N-1;i>=0;i--){
		if(i!=N-1)sum1[i]+=sum1[i+1];
	}

	// for(int i=0;i<N;i++){
	// 	cout<<"sum1/sum2:  "<<sum1[i]<<";"<<sum2[i]<<endl;
	// }

	vector<int> ans(0);
	for(int i=0;i<N;i++){
		if(S[i]=='o' and sum1[i]+sum2[i]<K)ans.push_back(i+1);
	}
	for(int i=0;i<ans.size();i++){
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 6516
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
hen = []
for i in range(M):
    a, b = map(int, input().split())
    hen.append([a, b])
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

ans = 0
import copy

def dfs(node, visited, gr):
    visited.append(node)
    for cand in gr[node]:
        if cand not in visited:
            dfs(cand, visited, gr)
    return visited

def gcopy(arr):
    new = []
    for a in arr:
        new.append(copy.copy(a))
    return new

for i in range(M):
    a, b = hen[i]
    g = gcopy(graph)
    g[a-1].remove(b-1)
    g[b-1].remove(a-1)
    visited = []
    ans += 1 if len(dfs(0, visited, g)) == N else 0

print(M-ans)


Measured memory_bytes: 42476
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
vector<long long> A;

void solve() {
    long long zero = 0;
    long long cur = zero;
    for (int i = 0; i < N; ++i) {
        cur = A[i] - cur;
    }
    long long start = (cur - zero) / 2;
    cur = start;
    for (int i = 0; i < N; ++i) {
        cout << cur*2 << " ";
        cur = A[i] - cur;
    }
    cout << endl;
}

int main() {
    while (cin >> N) {
        A.resize(N);
        for (int i = 0; i < N; ++i) cin >> A[i];
        solve();
    }
}


















Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=1010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int a[maxn];
int b[maxn];
int c[maxn];
int dp[55][maxn][567];
int n,ma,mb;

int main()
{
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
    gbtb;
    cin>>n>>ma>>mb;
    rep(i,0,n)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    repd(i,0,n)
    {
        repd(j,0,400)
        {
            repd(z,0,400)
            {
                dp[i][j][z]=inf;
            }
        }
    }
    dp[0][0][0]=0;
    rep(i,0,n)
    {
        repd(j,0,400)
        {
            repd(z,0,400)
            {
                if(dp[i][j][z]==inf)
                {
                    continue;
                }
                dp[i+1][j][z]=min(dp[i+1][j][z],dp[i][j][z]);
                dp[i+1][j+a[i]][z+b[i]]=min(dp[i+1][j+a[i]][z+b[i]],dp[i][j][z]+c[i]);
            }
        }
    }
    int ans=inf;
    repd(i,1,400)
    {
        repd(j,1,400)
        {
            if(i*mb==j*ma)
            {
                ans=min(ans,dp[n][i][j]);
            }
        }
    }
    ans=ans==inf?-1:ans;
    cout<<ans<<endl;


    return 0;
}

inline void getInt(int* p) {char ch;do {ch = getchar();}
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9')
{*p = *p * 10 + ch - '0';}}}


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

int main(void){
  string s[3];
  for(int i = 0; i < 3; i ++){
    cin >> s[i];
  	transform(s[i].begin(), s[i].end(), s[i].begin(), ::toupper);
    cout << s[i].front();
  }
  
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 201
#define ll long long
using namespace std;
int n; vector<int> adj[N]; ll int maxx=-1; string s[N];
int main(){
    cin>>n; 
    for (int i=0; i<n; i++){
        cin>>s[i];
        for (int j=0; j<n; j++){
            if (s[i][j]=='1') adj[i].push_back(j);
        }
    }
    bool is_bip=true;
    queue<int> bip; 
    bool is_black[n],spawn[n]; 
    for (int i=0; i<n; i++) is_black[i]=false; 
    for (int i=0; i<n; i++) spawn[i]=false;   
    bip.push(0); is_black[0]=true; spawn[0]=true;
    while (!bip.empty()){
        if (is_bip){
            int b=bip.front(); for (int i=0; i<adj[b].size(); i++){

                if (spawn[adj[b][i]] and is_black[adj[b][i]]==is_black[b]) {
                    is_bip=false; 
                    break;
                }
                if (!spawn[adj[b][i]]){
                    spawn[adj[b][i]]=true;
                    is_black[adj[b][i]]= !is_black[b];
                    bip.push(adj[b][i]);
                }
            }
            bip.pop();
        }
        else break;
    }
    /*for (int i=0; i<n; i++) {
        if (is_black[i]) cout<<i<<':'<<"siah";
        else cout<<i<<':'<<"sefid";
        cout<<endl;
    }*/

    //cout<<endl;
    if (is_bip){
        for (int i=0; i<n; i++){
            queue<int> bfs; 
            bfs.push(i); 
            bool spawn[n]; int dis[n];
            for (int j=0; j<n; j++) spawn[j]=false; 
            for (int j=0; j<n; j++) dis[j]=0;
            spawn[i]=true; 
            //cout<<"bfs"<<i<<endl;


            while (!bfs.empty()){
                //cout<<bfs.front()<<"   ";
                int b=bfs.front();
                //cout<<b<<endl;
                for (int j=0; j<adj[b].size(); j++){
                    if (!spawn[adj[b][j]]){
                        //cout<<b<<" found " <<adj[b][j]<<endl;
                        spawn[adj[b][j]]=true;
                        dis[adj[b][j]]= dis[b]+1;
                        bfs.push(adj[b][j]);
                    }
                }
                bfs.pop();
                
            }
            for (int j=0; j<n; j++){
                if (dis[j]>maxx) maxx=dis[j];
            }
        }

        cout<<maxx+1;
    }
    else cout<<-1;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int dx[2] = {0, 1};
int dy[2] = {1, 0};

int main() {
    int H, W; cin >> H >> W;
    vector<string> A(H);
    REP(i, 0, H) cin >> A[i];

    int dp[H][W] = {};
    dp[0][0] = 1;
    REP(i, 0, H) {
        REP(j, 0, W) {
            if (A[i][j] == '#') continue;
            REP(k, 0, 2) {
                int nx = i + dx[k];
                int ny = j + dy[k];
                if (nx >= H || ny >= W) continue;
                if (A[nx][ny] == '#') continue;
                dp[nx][ny] = (dp[nx][ny] + dp[i][j]) % MOD;
            }
        }
    }
    cout << dp[H - 1][W - 1] << endl;
    return 0;
}

Measured memory_bytes: 5248
import sys
import math
from collections import deque
from itertools import permutations

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N, C = NMI()
    D = [NLI() for _ in range(C)]
    grid = [list(map(lambda x: int(x)-1, NMI())) for _ in range(N)]

    grid_mod = [{i:0 for i in range(C)} for _ in range(3)]
    for h in range(N):
        for w in range(N):
            t = (h+w) % 3
            grid_mod[t][grid[h][w]] += 1

    ans = 10**10
    for colors in permutations(range(C), 3):
        diff = 0
        for i in range(3):
            for c, n in grid_mod[i].items():
                diff += D[c][colors[i]] * n
        ans = min(ans, diff)

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 12052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int H,W,K;
vector< vector<int> > cand;
void DFS(vector<int> now) {
  if ((int)now.size() == W-1) {
    cand.push_back(now);
  } else {
    int c = now.size();
    if (now[c-1] == 1) {
      now.push_back(0);
      DFS(now);
    } else {
      now.push_back(0);
      DFS(now);
      now.pop_back();
      now.push_back(1);
      DFS(now);
    }
  }
  return ;
}
int main() {
  cin >> H >> W >> K;
  if (W == 1) {
    cout << 1 << endl;
    return 0;
  } 
  K--;
  ll table[W][W];
  for (int i = 0; i < W; i++) {
    for (int j = 0; j < W; j++) {
      table[i][j] = 0;
    }
  }
  DFS({0});
  DFS({1});

  for (int i = 0; i < cand.size(); i++) {
    int next[W];
    for (int j = 0; j < W; j++) {
      next[j] = j;
    }
    for (int j = 0; j < W-1; j++) {
      if (cand[i][j] == 1) {
        swap(next[j],next[j+1]);
      }
    }
    for (int j = 0; j < W; j++) {
      table[j][next[j]]++;
    }
  }

  ll DP[H+1][W];
  for (int i = 0; i < H+1; i++) {
    for (int j = 0; j < W; j++) {
      DP[i][j] = 0;
    }
  }
  DP[0][0] = 1;

  for (int i = 1; i <= H; i++) {
    for (int j = 0; j < W; j++) {
      for (int k = 0; k < W; k++) {
        DP[i][j] += table[j][k] * DP[i-1][k];
        DP[i][j] %= Mod;
      }
    }
  }
  cout << DP[H][K] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main(){
    int n;
    while( true ){
        cin >> n;
        if (n == 0) break;
        int a[n];
        for(int i=0;i<n;i++)cin>>a[i];
        sort(a,a+n);
        for(int i=2;i<n-1;i++)a[1]+=a[i];
        cout<<a[1]/(n-2)<<endl;
    }   
    return 0; 
}

Measured memory_bytes: 1172
#include <iostream>
//#include <vector>
//#include <string>

using namespace std;

// ostream & operator<<(ostream & os, const vector<string> & v)
// {
// 	for (auto e : v)
// 		os << e << " ";
// 	return os;
// }

int main()
{
	int n;
	cin >> n;
	bool flag = true;
	if (n > 81)
		cout << "No" << endl;
	else{
		for (int i = 1; i <= 9; ++i){
			if (n % i == 0 && n / i <= 9 && n / i >= 1){
				cout << "Yes" << endl;
				flag = false;
				break;
			}
		}
		if (flag) cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  string S;
  string march = "MARCH";
  int count = 0;
  vector<long> data(5, 0);
  for (int i = 0; i < N; i++){
    count = 0;
    cin >> S;
    for (char a: march) {
      if(S.at(0) == a) data.at(0 + count)++;
      count++;
    }
  }
  cout <<(long) data.at(2) * data.at(3) * data.at(4) + data.at(1) * data.at(3) * data.at(4) + data.at(1) * data.at(2) * data.at(4) + data.at(1) * data.at(2) * data.at(3) + data.at(0) * data.at(3) * data.at(4) + data.at(0) * data.at(2) * data.at(4) + data.at(0) * data.at(2) * data.at(3) + data.at(0) * data.at(1) * data.at(4) + data.at(0) * data.at(1) * data.at(3) + data.at(0) * data.at(1) * data.at(2) << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int,input().split())
E = sorted([list(map(int, input().split())) for _ in range(M)])

c = E[0]
cnt = 0
for i in range(1,M):
	if c[0] <= E[i][0] < c[1]:
		c = [max(c[0],E[i][0]), min(c[1],E[i][1])]
	else:
		cnt += 1
		c = E[i]

print(cnt+1)

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

int h,w,c;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};

bool isin(int x, int y){
  bool ans;
  if(0 <= x and x < h and 0 <= y and y < w) ans = true;
  else ans = false;
  return ans;
}

void changeto(int to,vector<vector<int>> &tmpp){
  queue<pair<int,int>> q;
  int from = tmpp[0][0];
  if(from == to) return;

  q.push(pair<int,int>(0,0));
  tmpp[0][0] = to;

  while(not q.empty()){
    pair<int,int> p = q.front();
    q.pop();

    rep(i, dx.size()){
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if(isin(nx,ny) and tmpp[nx][ny] == from){
	q.push(pair<int,int>(nx, ny));
	tmpp[nx][ny] = to;
      }
    }
  }
}

int area(vector<vector<int>> tmpp){
  queue<pair<int,int>> q;

  q.push(pair<int,int>(0,0));
  int tmpc = tmpp[0][0];
  tmpp[0][0] = -1;
  int res = 1;

  while(not q.empty()){
    pair<int,int> p = q.front();
    q.pop();

    rep(i, dx.size()){
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if(isin(nx,ny) and tmpp[nx][ny] == tmpc){
	q.push(pair<int,int>(nx, ny));
	tmpp[nx][ny] = -1;
	res++;
      }
    }
  }
  return res;
}

int rec(int depth,vector<vector<int>> p){
  if(depth == 4){
    changeto(c,p);
    int res = area(p);
    return res;
  }

  int res = 0;
  FOR(i,1,7){
    vector<vector<int>> tmpp = p;
    changeto(i,tmpp);
    res = max(res, rec(depth+1, tmpp));
  }
  return res;
}
	      
int main(void){
  while(cin >> h >> w >> c, h){
    vector<vector<int>> p(h,vector<int>(w));
    rep(i,h) rep(j,w) cin >> p[i][j];

    int res = rec(0,p);
    cout << res << endl;
  }
}


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

typedef long long ll;
using namespace std;

const int maxn = 200005;
ll found[26];
ll res = 0;

int main(){
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	int n = s.size();

	res = (ll) n * ((ll) n + 1) / 2;

	for(char i : s){
		found[i - 'a']++;
	}

	for(int i = 0; i < 26; i++){
		res -= found[i] * (found[i] + 1) / 2;
	}

	cout << res + 1 << '\n';
}

Measured memory_bytes: 720
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <string.h> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;



int main(){
    //std::ifstream in("resource/input.txt");
    //std::cin.rdbuf(in.rdbuf());
	while(true)
	{
		string a;
		cin >> a;
		if(a == "0")break;

		int res = 0;
		REP(i,a.size())
		{
			res += a[i] - '0';
		}
		cout << res << endl;
	}

    return 0;    
}




Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 100100100100100;
const ll mod = 1000000007;
typedef pair<int,int> P;
#define fi first
#define se second
#define pb push_back
int main(){
   int a,b,c,d,e,f;
   cin>>a>>b>>c>>d>>e>>f;
   vector<int> wat;
for(int i=0;a*100*i<=f;i++){
    for(int j=0;a*100*i+j*b*100<=f;j++){
        if(i==0&&j==0)continue;
        int x=a*100*i+b*j*100;
        wat.pb(x);
    }
}
double ans=0.0;int sug=0,sum=0;
for(int i=0;i<wat.size();i++){
      int x=wat.at(i);
      for(int j=0;x+c*j<=f;j++){
          for(int k=0;x+c*j+d*k<=f;k++){
              if(x/100*e<c*j+d*k)break;
            double rec=double(c*j+d*k)/(double)(x+c*j+d*k);
            if(ans<=rec){//全く溶けていないパターンも考慮する
                   sum=x+c*j+d*k;
                   sug=c*j+d*k;
                   ans=rec;
            }
          }
      }
}
cout<<sum<<" "<<sug<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] S = sc.nextLine().split("");
        int len = 0;
        int r = 0;
        for (String s :
                S) {
            if (s.matches("(A|C|G|T)")) {
                len++;
                if (len > r) r = len;
            } else {
                len = 0;
            }
        }
        System.out.println(r);
    }
}

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

using namespace std;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;

ll mod = 1e9+7;

string solve() {
    int n, m, a; cin >> n >> m;
    vi nums;
    rep(i, n) {
        cin >> a;
        nums.push_back(a);
    }
    sort(nums.rbegin(), nums.rend());
    int sum = accumulate(nums.begin(), nums.end(), 0);
    rep(i, m) {
        if (nums[i] / static_cast<double>(sum) < 1 / static_cast<double>(4 * m)) {
            return "No";
        }
    }

    return "Yes";
}

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

	cout << solve() << endl;
}


Measured memory_bytes: 3636
for i in range(int(input())):
    s = list(map(float,input().split()))
    if s[1] - s[3] == 0 or s[5] - s[7] == 0:
        if s[1] - s[3] == s[5] - s[7] == 0:
            print('YES')
        else:
            print('NO')
    elif abs((s[0] - s[2]) / (s[1] - s[3]) - (s[4] - s[6]) / (s[5] - s[7])) < 1e-10:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 7692
a, b, c, d = map(int, input())
op = "+-"
for i in range(2):
  for j in range(2):
    for k in range(2):
      if a + b*(-1)**i + c*(-1)**j + d*(-1)**k == 7:
        print(str(a) + op[i] + str(b) + op[j] + str(c) + op[k] + str(d) + "=7")
        exit()

Measured memory_bytes: 3060
N,M,X = map(int,input().split())
min_price = -1
C = [0 for i in range(N)]
A = [[0 for _ in range(M)] for i in range(N)]
for i in range(N):
    C[i],*A[i] = list(map(int,input().split()))


for i in range(2**N):
    score = [0 for _ in range(M)]
    price = 0
    for j in range(N):
        if i & 1<<j:
            for k in range(M):
                score[k] += A[j][k]
            price += C[j]    
    if min(score) >= X:
        if min_price == -1 or min_price > price:
            min_price = price

print(min_price)


Measured memory_bytes: 69132
n = int(input())
l = input()
a = l.split(' ')

count = 0

for i in range(len(a)-1):
    if(int(a[i]) > int(a[i+1])):
        count += int(a[i]) - int(a[i+1])
        a[i+1]=a[i]

print(count)




Measured memory_bytes: 25144
#include <iostream>
#include <vector>
using namespace std;
int const s = 100000;
vector< vector<int> > edg(s*2);
vector<bool> vsd(s*2, false);
void f(int v, int& x, int& y){
    vsd[v] = true;
    if(v < s)x++;
    else y++;
    for(int i=0;i<edg[v].size();i++){
        int w = edg[v][i];
        if(!vsd[w]) f(w, x, y);
    }
}
int main() {
    int n;
    long long ans = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        int x, y;
        cin >> x >> y;
        x--;
        y += s-1;
        edg[x].push_back(y);
        edg[y].push_back(x);
    }
    for(int i=0;i<s*2;i++){
        if(vsd[i])continue;
        int x = 0, y = 0;
        f(i, x, y);
        ans += (long long) x*y;
    }
    ans -= n;
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11008
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 19260817
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}

// cf IO: I64d
// atcoder IO: ｌｌｄ
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int Maxn=200005;
const long long mod=1e9+7;
long long fact[Maxn];
long long invf[Maxn];
long long qp(LL x,LL p){
	if (!p) return 1;
	if (p==1) return x;
	if (p%2==0){
		LL y=qp(x,p/2);
		return y*y%mod;
	}
	else{
		LL y=qp(x,p/2);
		return y*y%mod*x%mod; 
	}
}
long long inv(long long x){
	return qp(x,mod-2);
}
long long c(long long x,long long y){
	if (x==0 && y==0) return 1;
	if (x<=0) return 0;
	LL ans=fact[x];
	ans*=invf[y];
	ans%=mod;
	ans*=invf[x-y];
	ans%=mod;
	return ans;
}
void _init(){
	fact[0]=1;
	for (int i=1;i<Maxn;i++){
		fact[i]=(LL)fact[i-1]*(LL)i;
		fact[i]%=mod;
		invf[i]=inv(fact[i]);
	}
	invf[0]=inv(1);
}
LL now[Maxn];
int main(){
	_init();
	//cout<<c(100000,2)<<endl;
	LL h,w,a,b;
	scanf("%lld %lld %lld %lld",&h,&w,&a,&b);
	for (int i=1;i<=w-b;i++){
		// x=h-a ,y=i+b;
		LL x=(LL)h-a,y=(LL)i+b;
		now[i]=c(x+y-2,x-1);
		//cout<<x<<' '<<y<<' '<<now[i]<<endl;
	}
	LL ans=0LL;
	for (int i=1;i<=w-b;i++){
		LL x=a,y=i;
		//cout<<c(x+y-2,x-1)<<endl;
		ans+=c(x+y-2,x-1)*now[w-b-i+1];
		ans%=mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4096
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n, k; cin >> n >> k;
	vector<int> p(n); rep(i, n)cin >> p[i];
	sort(all(p));
	int res = 0;
	rep(i, k)res += p[i];
	cout << res << endl;
}

Measured memory_bytes: 3636
S = input()


table = {}
pairs = [[((i*10 + j)%13, i) for i in range(13)] for j in range(13)]
mod = 10**9 + 7
for i in range(13):
    table[i] = tuple((i + j*13)//10 for j in range(10))

dp =[[0 for i in range(13)] for i in range(len(S))]

if S[0] == "?":
    for i in range(10):
        dp[0][i] = 1
else:
    s = int(S[0])
    dp[0][s] = 1

for i in range(1, len(S)):
    s = S[i]
    if s == "?":
        for j in range(13):
            for k in table[j]:
                dp[i][j] += dp[i-1][k] % mod
    else:
        s = int(s)
        for pair in pairs[s]:
            dp[i][pair[0]] = dp[i-1][pair[1]] % mod

print(dp[len(S)-1][5] % mod)

Measured memory_bytes: 65756
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;


int main(){
  int n;cin >> n;
  int ans = 0;
  for(int i = 3;i <= n;i+=2){
    int cnt = 0;
    for(int j = 1;j <= i;j += 2){
      if(i%j==0){
        cnt++;
      }
    }
    if(cnt == 8) ans++;
  }
  cout << ans << endl;

  
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

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

  map<char,int> mp;
  for(int i = 0; i < s.size(); i++){
    mp[s[i]]++;
    if(mp[s[i]] == 2){
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

#define int ll
void solve()
{
	ll n,k;
	cin>>n>>k;
	vector<ll>p(n),c(n);
	rep(i,n){
		cin>>p[i];
		p[i]--;
	}
	rep(i,n)cin>>c[i];
	ll ans=-INF;
	rep(i,n){
		int cnt=k;
		ll res=0;
		vector<bool>used(n);
		int s=i;
		int nx=s;
		int loop=1;
		vector<ll>v(n),res_v(n);
		ll val=0;
		while(cnt>0){
			nx=p[nx];
			if(used[nx]){
				loop=v[nx]-cnt;
				val=res-res_v[nx]+c[nx];
				break;
			}
			res+=c[nx];
			chmax(ans,res);
			v[nx]=cnt;
			cnt--;
			res_v[nx]=res;
			used[nx]=true;
		}
		//cout<<loop<<"\n";
		if(val>0&&cnt>0){
			if(cnt/loop>=1)res+=(cnt/loop-1)*val,cnt=cnt%loop+loop;
			else res+=cnt/loop*val,cnt=cnt%loop;
			int pos=0;
			chmax(ans,res);
			while(cnt>0&&pos<=2*(loop+1)){
				++pos;
				res+=c[nx];
				chmax(ans,res);
				nx=p[nx];
				--cnt;
			}
		}
		else{
			int pos=0;
			while(cnt>0&&pos<=loop+1){
				++pos;
				res+=c[nx];
				chmax(ans,res);
				nx=p[nx];
				--cnt;
			}
		}
	}
	cout<<ans;
}
#undef int
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

typedef long long int ll;


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

    string s;
    cin>>s;
    map < char , ll > mp;

    for(ll i=0;i<s.size();i++){
        mp[s[i]]++;
    }

    if(mp.size()==2)
    {
        if(mp[s[0]]==2){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    else{
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i < (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.16f\n", a)//少数出力
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

#include <iostream>

using namespace std;

void scans(string & str) {
	char c;
	scanf("%c", &c);
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

/*-----------------------------------------ここからコード-----------------------------------------*/





int main() {

	int n;
	scanf("%d", &n);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	sort(all(a));
	ll ans = 0;
	repr(i, n - 1) {
		for (int j = i - 1; j >= 0; --j) {
			auto ite = lower_bound(all(a), a[i] + a[j]);
			ll dist = distance(ite, a.end());
			ans += (n - 1 - i) - dist;
		}
	}
	printf("%lld\n", ans);

 	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef struct{
    int pos_before;
    long long A;
}INFANT;
bool cmp(INFANT& a, INFANT& b){
    return a.A>b.A;
}
long long absval(long long n){
    return n<0?-n:n;
}
int main(){
    int N;
    cin >> N;
    int afterPos[N]={0};
    INFANT infant[N];
    long long dp[N+1][N+1];
    long long ans=0;
    for(int i=0; i<N; i++){
        cin >> infant[i].A;
        infant[i].pos_before=i;
    }
    sort(infant,infant+N,cmp);
    for(int i=0; i<N; i++){
        //cout << infant[i].pos_before << " " << infant[i].A << endl;
    }
    dp[0][0]=0;
    for(int i=1; i<=N; i++){
        dp[0][i] = dp[0][i-1] + infant[i-1].A*absval((N-i)-infant[i-1].pos_before);
        dp[i][0] = dp[i-1][0] + infant[i-1].A*absval(infant[i-1].pos_before-(i-1));
        //cout << dp[i][0] << " " << dp[0][i] << endl;
    }
    for(int xy=1; xy<=N; xy++){
        for(int x=1; x<=xy-1; x++){
            dp[xy-x][x] = max(
                dp[xy-x][x-1] + infant[xy-1].A * absval( (N-x) - infant[xy-1].pos_before ) ,
                dp[xy-x-1][x] + infant[xy-1].A * absval( infant[xy-1].pos_before - (xy-x-1) )
                );
        }
    }
  /*
    for(int i=0; i<=N; i++){
        for(int j=0; j<=N-i; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    for(int x=0; x<=N; x++){
        ans = max(ans,dp[N-x][x]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 26344
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<"!"<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  if(n%2){
    cout<<n*(n-1)/2-n/2<<endl;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
	if(i+j==n)continue;
	cout<<i<<" "<<j<<endl;
      }
    }
  }else{
    cout<<n*(n-1)/2-n/2<<endl;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
	if(i+j==n+1)continue;
	cout<<i<<" "<<j<<endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256