akhauriyash/Code-Regression huggingface dataset:
#include<vector>
#include<algorithm>
#include<iostream>
#include<utility>
#include<climits>
using namespace std;



class RMQ{//RangeMinimumQuery
	int n;
	std::vector<int> dat,idx;
	static int calcsize(int n){
		int res=1;
		while(res<n)res<<=1;
		return res;
	}
	int query(int a,int b,int k,int l,int r)const{
		if(r<=a||b<=l)return dat.size()-1;
		if(a<=l&&r<=b)return idx[k];
		else{
			int vl=query(a,b,k*2+1,l,(l+r)/2);
			int vr=query(a,b,k*2+2,(l+r)/2,r);
			return dat[vl]<dat[vr]?vl:vr;
		}
	}
public:
	RMQ(){}
	~RMQ(){}
	void build(const std::vector<int> &a){
		n=calcsize(a.size());
		idx.resize(2*n-1);
		for(int i=0;i<(int)a.size();i++)idx[n-1+i]=i;
		for(int i=a.size();i<n;i++)idx[n-1+i]=a.size();
		dat=a;
		dat.push_back(INT_MAX);
		for(int i=n-2;i>=0;i--){
			idx[i]=dat[idx[i*2+1]]<dat[idx[i*2+2]]?idx[i*2+1]:idx[i*2+2];
		}
	}
	int query(int a,int b)const{//[a,b)の最小値
		return query(a,b,0,0,n);
	}
};


class LCA{
	vector<int> eulertour;
	vector<int> vertex;
	//SparseTableRMQ rmq;
	RMQ rmq;
	void dfs(const vector<int> edge[],int n,vector<int> &depth,int d,int u){
		eulertour[u]=vertex.size();	
		vertex.push_back(u);
		depth.push_back(d);
		for(int i=0;i<edge[u].size();i++){
			dfs(edge,n,depth,d+1,edge[u][i]);
			vertex.push_back(u);
			depth.push_back(d);
		}
	}
public:
	LCA(const vector<int> edge[],int n,int root):eulertour(n){
		vector<int> depth;
		dfs(edge,n,depth,1,root);
		vertex.push_back(root);
		depth.push_back(0);
		rmq.build(depth);
	}
	int query(int u,int v)const{
		if(u==v)return u;
		if(eulertour[u]>eulertour[v])swap(u,v);
		return vertex[rmq.query(eulertour[u], eulertour[v])];
	}
};


vector<int> edge[100000];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int k,v;
		cin>>k;
		for(int j=0;j<k;j++){
			cin>>v;
			edge[i].push_back(v);
		}
	}
	LCA lca(edge,n,0);
	int q,u,v;
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>u>>v;
		cout<<lca.query(u,v)<<endl;
	}
	return 0;
}

Measured memory_bytes: 14948
def calctime(w,dist):
    time=dist/(2000/(70.0+w))
    return time

n=int(raw_input())
s={}
d={}
v={}
for i in xrange(n):
    S,D,V=map(int,raw_input().split())
    s[i]=S
    d[i]=D
    v[i]=V

dist=[[None]*n for _ in xrange(n)]
for i in xrange(n):
    for j in xrange(n):
        if i==j:
            dist[i][j]=float('inf')
        else:
            dist[i][j]=abs(d[i]-d[j])

w=[float('inf')]*(1<<n)
time=[[float('inf')]*n for _ in xrange(1<<n)]
last=[[0]*n for _ in xrange(1<<n)]
for i in xrange(n):
    time[1<<i][i]=0
    w[1<<i]=v[i]*20

for i in xrange(1,1<<n):
    for j in xrange(n):
        if w[i]==float('inf'):continue
        for k in xrange(n):
            if not i>>k&1:
                nexti=i|(1<<k)
                w[nexti]=w[i]+v[k]*20
                if time[nexti][k]>calctime(w[i],dist[j][k])+time[i][j]:
                    time[nexti][k]=calctime(w[i],dist[j][k])+time[i][j]
                    last[nexti][k]=j

ans=[]
now=(1<<n)-1
last_index=time[now].index(min(time[now]))
while now!=0:
    ans.append(s[last_index])
    nx=last[now][last_index]
    now=now^(1<<last_index)
    last_index=nx
ans.reverse()
print(' '.join(map(str,ans)))

Measured memory_bytes: 27408
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    double ans = 0.0;
    REP(i,n) {
        cin>>a[i];
    }
    SORT(a);
    ans = (a[0] + a[1]) / 2.0;
    REP(i,n-2) {
        ans = (ans + a[i+2]) / 2.0;
    }

    printf("%9f\n", ans);

    return 0;
}


Measured memory_bytes: 256
<?php
  	$str = explode(' ', fgets(STDIN));
  	$strS = $str[0];
	$strT = $str[1];
	$num = explode(' ', fgets(STDIN));
	$numS = (int)$num[0];
	$numT = (int)$num[1];
	$strU = trim(fgets(STDIN));

	if ($strU === $strS) {
      	$numS --;
    } else {
      	$numT --;
    }

	print($numS . ' ' . $numT);

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

#define int long long

signed main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int> > A(N);
	vector<int>  cur(N, 0);
	vector<int>  used(M, 0);
	vector<int>  num(M, 0);

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		A[i].resize(M);
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
			A[i][j]--;
		}
	}
	for (int i = 0; i < N; i++) {
		num[A[i][cur[i]]]++;
	}
	int res = N + 1;
	for (int k = 0; k < M; k++) {
		/*
		for (int i = 0; i < M; i++) {
			cerr << num[i] << " ";
		}
		cerr << endl;
		*/
		int maxi;
		maxi = -1;
		int maxl;
		
		maxl = -1;
		for (int i = 0; i < M; i++) {
			if (used[i] == 0) {
				if (maxi < num[i]) {
					maxi = num[i];
					maxl = i;
				}
			}
		}
		//cerr << maxi << " " << maxl << endl;
		res = min(maxi, res);
		used[maxl] = 1;
		if (k < M - 1) {
			for (int i = 0; i < N; i++) {
				if (A[i][cur[i]] == maxl) {
					while (cur[i] < M && used[A[i][cur[i]]] == 1) {
						cur[i]++;
					}
					num[maxl]--;
					if (cur[i] < M) {
						num[A[i][cur[i]]]++;
					}
					else {
						cerr << "ERROR" << endl;
					}
				}
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1024
S = input()
T = input()

s = len(S)
t = len(T)

counter = 10**8
for i in range(s-t+1):
    cnt = 0
    for j in range(t):
        if S[i+j] != T[j]:
            cnt += 1
    if counter > cnt:
        counter = cnt

print(counter) 
        

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll MAXN = 

/********** Good Luck :) **********/
int main()
{
    IOS();
    ll n,k;
    cin >> n >> k;
    if ((n+1)/2 >= k) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    string s;
    cin >> s;
    int n = size(s);

    int ans = 0;

    string pre = "", cur = "";

    REP(i, n){
        cur += s[i];
        if(pre != cur){
            ans++;
            pre = cur;
            cur = "";
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N;
	cin >> N;
	vector<tuple<string, int, int>>A(N);
	rep(i, N) {
		cin >> get<0>(A[i])>>get<1>(A[i]);
	}
	rep(i, N) {
		get<2>(A[i]) = i + 1;
		get<1>(A[i]) = get<1>(A[i]) * (-1) + 100;
	}
	sort(A);
	rep(i, N) {
		cout << get<2>(A[i]) << endl;
	}
}

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

using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Pair vector<pair<ll,ll>>
#define vec vector <ll> 
#define all(a) a.begin(),a.end()
#define mo 1000000007
#define decimal(i,n) fixed << setprecision(i) << n
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define show_nl(a) for(auto xyz:a)cout<<xyz<<endl;


void eea(ll a,ll b,ll &x,ll &y)
{
    if (a == 1)
    {
        x = 1; y = 0;
        return;
    }
    ll x1, y1;
    eea(b%a,a,x1,y1);
    x=y1-(b/a)*x1;
    y=x1;
}
ll mi(ll a,ll m)
{
    ll x,y;
    eea(a,m,x,y);
    x= (x%m+m)%m;
    return x;
}

/*
Enter the test case


Some helpful points
1.) Calm yourself
2.) check for semicolon or data type mismatch
*/


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);    
    ll t=1;
    // cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        for(int i=0;i<s.size();i++)
        cout<<"x";
        cout<<"\n";
    }
}



Measured memory_bytes: 3608
import bisect
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

a, b, q = map(int, input().split())
s = sorted([int(input()) for _ in range(a)])
t = sorted([int(input()) for _ in range(b)])

for _ in range(q):
    x = int(input())
    s_i = bisect.bisect_left(s, x)
    t_i = bisect.bisect_left(t, x)

    s0, s1, t0, t1 = None, None, None, None
    ans = 10 ** 11
    if s_i > 0:
        s0 = x - s[s_i-1]
    if s_i < a:
        s1 = s[s_i] - x
    if t_i > 0:
        t0 = x - t[t_i-1]
    if t_i < b:
        t1 = t[t_i] - x

    if s0 is not None and t0 is not None:
        ans = min(ans, max(s0, t0))
    if s1 is not None and t1 is not None:
        ans = min(ans, max(s1, t1))
    if s0 is not None and t1 is not None:
        ans = min(ans, s0*2 + t1, t1*2 + s0)
    if s1 is not None and t0 is not None:
        ans = min(ans, s1*2 + t0, t0*2 + s1)

    print(ans)

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;

int count_digits(ll val)
{
  int ret = 0;
  while (val != 0) {
    ++ret;
    val /= 10;
  }
  return ret;
}

int main()
{
  ll N; scanf("%lld", &N);
  int ans = INF;
  for (ll i = 1; i * i <= N; ++i) {
    if (N % i != 0) { continue; }
    int digits = max(count_digits(i), count_digits(N / i));
    ans = min(ans, digits);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{

    clock_t starttime = clock();
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(n - 1));
    vector<int> ind(n, 0);
    vector<bool> isok(n, true);
    int ans = 0;
    int cnt = 0;
    bool f = true;
    rep(i, n)
    {
        rep(j, n - 1)
        {
            scanf("%d", &v[i][j]);
            v[i][j]--;
        }
    }
    while (cnt < n * (n - 1) / 2 && f)
    {
        if (double(clock() - starttime) / CLOCKS_PER_SEC >1.9)
        {
            printf("%d\n", n * (n - 1) / 2);
            return 0;
        }
        f = false;
        vector<bool> usedturn(n, false);
        vector<vector<bool>> used(n, vector<bool>(n - 1, false));
        rep(i, n)
        {
            int cur = i;

            if (ind[cur] == n - 1)
            {

                continue;
            }
            int next = v[cur][ind[cur]];

            if (usedturn[cur] == true || usedturn[next] == true)
            {
                continue;
            }
            if (ind[next] == n - 1)
            {
                continue;
            }

            if (v[next][ind[next]] != cur)
            {
                continue;
            }
            //cerr << "turn " << ans << " " << cur + 1 << "," << next + 1 << " " << cnt << endl;

            usedturn[next] = true;
            usedturn[cur] = true;
            used[next][next] = true;
            used[cur][next] = true;
            ind[cur]++;
            ind[next]++;
            cnt += 1;
            f = true;
        }
        ans++;
    }
    if (f == false)
    {
        printf("-1\n");
        return 0;
    }
    printf("%d\n", ans);
    return 0;
}


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

int main()
{
    // freopen("input01.txt", "r", stdin);
    // freopen("output01.txt", "w", stdout);
    int x;
    cin>>x;
    if(x>=30)
        cout<<"Yes";
    else
    {
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3588
#![allow(unused_imports, dead_code)]
use std::f64::*;
use std::cmp::*;
use std::collections::*;

macro_rules! dump{
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const INF: i64 = 0x3f3f3f3f3f3f3f3f;
const MOD: i64 = 1000000007;
const NOTHING: usize = std::usize::MAX;
const DX: [usize; 4] = [1, 0, std::usize::MAX, 0];
const DY: [usize; 4] = [0, 1, 0, std::usize::MAX];

fn main() {
    let n: usize = readln();
    let xs: Vec<usize> = readln();
    let mut m2 = 0;
    let mut m4 = 0;
    let mut m = 0;
    for x in xs {
        if x % 4 == 0 {
            m4 += 1;
        } else if x % 2 == 0 {
            m2 += 1;
        } else {
            m += 1;
        }
    }

    if m <= m4 && (!(m2 % 2 == 1) || m4 > 0) {
        println!("Yes")
    } else if m2 == 0 && m == m4 + 1 {
        println!("Yes")
    } else {
        println!("No")
    }

}

trait Read {
    fn read(s: &str) -> Self;
}

fn readln<T: Read>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    T::read(buf.trim_right())
}

macro_rules! read_impl{
    ($($t:ty)*) => ($(
        impl Read for $t {
            fn read(s: &str) -> $t{
                s.parse().unwrap()
            }
        }
    )*)
}
read_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }

impl Read for String {
    fn read(s: &str) -> Self {
        s.to_string()
    }
}

impl Read for Vec<char> {
    fn read(s: &str) -> Self {
        s.chars().collect()
    }
}

impl<T: Read> Read for Vec<T> {
    fn read(s: &str) -> Self {
        s.split_whitespace().map(T::read).collect()
    }
}

impl<A: Read, B: Read> Read for (A, B) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]))
    }
}

impl<A: Read, B: Read, C: Read> Read for (A, B, C) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))
    }
}

impl<A: Read, B: Read, C: Read, D: Read> Read for (A, B, C, D) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]), D::read(tokens[3]))
    }
}


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


void solve(){
    int n;cin>>n;
    vector<unsigned ll int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];

    if(n==1){cout<<0;return;}
 
    unsigned ll int ans=0;
    for(int i=1;i<n;i++){
        if(a[i-1]>a[i]){
            ans+=(a[i-1]-a[i]);
            a[i]=a[i-1];
        }
    }
    cout<<ans;
}


int main(){
    //ll tt;cin>>tt;
    //while(tt--){
        solve();
    //}
    return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);

main(){
    INCANT;
    int n, res = 0;
    map<int, int> cnt;
    cin >> n;
    int a[n];
    
    for(auto& i: a){
        cin >> i;
    }
    sort(a, a + n, greater<int>());

    for(auto& i: a){
        if(cnt[i]){
            cnt[i]--;
            res++;
        }else{
            cnt[(1<<(32 - __builtin_clz(i))) - i]++;
        }
    }

    cout << res;
}


Measured memory_bytes: 19840
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    odd_product = 1
    for a in A:
        if a % 2 == 0:
            count = 2
        else:
            count = 1
        odd_product *= count

    ans = 3 ** N - odd_product
    print(ans)


if __name__ == "__main__":
    main()


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
ll N, M;
ll A[100100];
ll B[100100];
ll p[100100];
map<ll, ll> roots;

pair<ll, ll> root(ll a){
  ll atmp = a;
  ll acnt = 1;
  while(p[atmp]!=atmp){
    atmp = p[atmp];
    acnt++;
  }
  p[a]=atmp;
  return {atmp, acnt};
}

void con(ll a, ll b){
  P ap = root(a);
  P bp = root(b);
  ll an = ap.first;
  ll bn = bp.first;
  ll root;
  if(an==bn)return;
  if(ap.second>bp.second){
    roots[an]=roots[an] + roots[bn];
    roots.erase(bn);
    root = an;
  }else{
    roots[bn]=roots[an] + roots[bn];
    roots.erase(an);
    root = bn;
  }
  p[an]=root;
  p[bn]=root;
  return;
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  cin >> N >> M;
  rep(i, N){
    p[i]=i;
    roots[i]=1;
  }
  rep(i, M){
    cin >> A[i] >> B[i];
    A[i]--;B[i]--;
  }

  llvec ans(M, 0);
  ll tmp =  N*(N-1)/2;
  for(int i=M-1;i>=0;i--){
    ans[i]=tmp;
    ll a;
    if(root(A[i]).first == root(B[i]).first){
      a=1;
    }else{
      ll b = roots[root(A[i]).first];
      ll c = roots[root(B[i]).first];
      tmp += b*(b-1)/2 + c*(c-1)/2;
      con(A[i], B[i]);
      a = roots[root(A[i]).first];
    }
    tmp = tmp - a*(a-1)/2;
  }
  //ans[0]=tmp;
  rep(i, M){
    cout << ans[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 10752
#include<bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v) cerr<<#v":[ ";for (auto macro_vi:v){cerr<<macro_vi<< " ";}cerr<<"]"<<endl;
#define ddump(v) cerr<<#v":"<<endl;for(auto macro_row:v) {cerr<<"["; for (auto macro__vi:macro_row){cerr<<macro__vi<< " ";}cerr<<"]"<<endl;}
#define damp(m) for(auto macro_pair:m){cerr<< macro_pair.first<<":"<<macro_pair.second<<endl;}
#define dpair(p) cerr << #p":"<<"(" << p.first << "," << p.second << ")" << endl;
// iterate
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define itr(macro_v,i) macro_v.begin()+i
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double a,b,x;
    cin >> a >> b >> x;
    ll M = a*a*b/2;
    if(M<=x){
        cout << setprecision(11) << 90.0-atan(a*a*a/(2*(a*a*b-x)))*(180.0/M_PI) << endl;
        // cout << atan(1)*(180/M_PI) << endl;
    }
    else{
        cout << setprecision(11) <<90.0-atan(2*x/(a*b*b))*(180.0/M_PI) << endl;   
    }
    return 0;
}

Measured memory_bytes: 256
a = input()
b = input()
c = input()

turn = 'a'
for i in range(len(a)+len(b)+len(c)):
    if turn == 'a':
        if len(a) == 0:
            print('A')
            break
        turn = a[0]
        a = a[1:]
    elif turn == 'b':
        if len(b) == 0:
            print('B')
            break
        turn = b[0]
        b = b[1:]
    else:
        if len(c) == 0:
            print('C')
            break
        turn = c[0]
        c = c[1:]

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

int main(){
  int N;
  cin >> N;
  vector<int> a(100009);
  for(int i=1;i<=N;i++)cin >> a[i];
  int count=0;
  for(int i=1;i<=N;i++){
    if(a[a[i]]==i){count++;}
  }
  cout << count/2 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll modpow(ll b, ll i){
  ll s=1;
  while(i){
    if(i%2) s=(s*b)%MOD;
    b=(b*b)%MOD; i/=2;
  }
  return s;
}
int main(){
  int n,a,b; cin >>n >>a >>b;
  ll fa=1,ga=1,fb=1,gb=1;
  for(int i=0; i<a; i++){
    fa=(fa*(n-i))%MOD; ga=(ga*(a-i))%MOD;
  }
  for(int i=0; i<b; i++){
    fb=(fb*(n-i))%MOD; gb=(gb*(b-i))%MOD;
  }
  cout <<(modpow(2,n)-(fa*modpow(ga,MOD-2))%MOD-(fb*modpow(gb,MOD-2))%MOD-1+2*MOD)%MOD;
return 0;}

Measured memory_bytes: 256
<?php

$n = trim(fgets(STDIN));

for($i=0; $i<$n; $i++){
  $t = str_split(trim(fgets(STDIN)));
  sort($t);
  $s[$i] = implode($t);
}

$sc = array_count_values($s);

$sum = 0;
foreach($sc as $k => $v){
  for($i=$v-1; $i>=1; $i--){
  	$sum += $i;
  }
}

echo $sum;

?>

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

int main(){
    
    // 1. 入力情報.
    char c[101010];
    scanf("%s", c);
    int l = strlen(c);
    
    // 2. 'a', 'b', 'c' を カウント.
    rep(i, l) abc[c[i] - 'a']++;
    
    // 3. 'a', 'b', 'c' の 個数を比較して, 
    // 最大のものと最小のものの差が, 2以上なら, "NO" に見える.
    // ex.
    // babacccabab
    // 'a': 4, 'b': 4, 'c': 3
    // -> YES (例えば, abcabcabcab と 並び替えることが出来る)
    // 
    // ex.
    // abcaba
    // 'a': 3, 'b': 2, 'c': 1
    // -> NO (2文字以上の回文を解消できないように見える)
    sort(abc, abc + 3);
    
    // 4. 出力.
    if(abc[2] - abc[0] < 2) puts("YES");
    else                    puts("NO");
    return 0;
    
}

Measured memory_bytes: 384
def calc(a,op,b):
    if op == "+":
        r = a + b 
    if op == "-":
        r = a - b 
    if op == "*":
        r = a * b 
    if op == "/":
        r = a // b
    return r

if __name__ == '__main__':
    while True:
        a,op,b = input().split()
        if op == "?":
            break
        print(calc(int(a),op,int(b)))

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

int main()
{
	int n;
	cin>>n;
	int ans=0;
	for(int i = 1; i<=n ; i++)
	{
		int a_last = i % 10;
		int a_first = i;
		if(a_last==0||a_first==0)
			continue;
		while(a_first/10>0)
		{
			a_first/=10;
		}
		int tem=0;
		int t=10,s=1;
		if(a_first==a_last)
		{
			tem = a_last;
			ans++;
			//cout<<i<<" "<<tem<<"\n";
		}	
	
		while(tem <=n)
		{
			tem=a_last*t+a_first;
			for(int j=0;j<s;j++)
			{
				if(tem <=n)
				{	
					ans++;
					//cout<<i<<" "<<tem<<"\n";
				}
				tem+=10;
			}
			t*=10;
			s*=10;
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <set>

using namespace std;

const int H = 5, W = 4;

inline int countZero(const string &str) {
  int ret = 0;
  for(int i=0; i<H*W; i++) {
    ret += str[i] == '0';
  }
  
  return ret;
}

void rearrange(string &str) {
  int pos = 0;
  for(int i=0; i<H*W; i++) {
    if(str[i] == '0') continue;
    char ch = str[i];
    str[i] = '0';
    str[pos++] = ch;
  }
}

int main() {
  
  int Tc;
  cin >> Tc;
  
  while(Tc--) {
    
    string initial;
    for(int i=0; i<H; i++) {
      for(int j=0; j<W; j++) {
        char ch; cin >> ch;
        initial += ch;
      }
    }
    
    int ans = 0;
    
    set<string> used;
    queue<string> Q;
    Q.push(initial);
    while(!Q.empty()) {
      const string now = Q.front(); Q.pop();
      ans = max(ans, countZero(now));
      for(int pos=0; pos<H*W; pos++) {
        if(now[pos] == '0') continue;
        int x = pos%W, y = pos/W;
        for(int k=0; k<=1; k++) {
          for(int l=-1; l<=1; l++) {
            if(k == 0 && l == 0) continue;
            const int ny = y+k, nx = x+l;
            if(nx<0 || W<=nx || ny<0 || H<=ny) continue;
            const int npos = ny*W+nx;
            if(now[pos] != now[npos]) continue;
            string next;
            for(int i=0; i<H*W; i++) {
              if(i == pos || i == npos) continue;
              next += now[i];
            }
            next += "00";
            if(used.count(next)) continue;
            used.insert(next);
            Q.push(next);
          }
        }
      }
    }
    cout << 20-ans << endl;
  }
  
  return 0;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    ll ans = 0;
    ll tmp = 0;
    REP(i, n) {
        if(a[i] != 0) {
            tmp += a[i];
        } else {
            ans += tmp / 2;
            tmp = 0;
        }
    }

    ans += tmp / 2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    int cnt=0;
    
	
	    int[] insertionSort(int[]lst,int g){
        int n=lst.length;
        for(int i=g;i<n;i++){
            int v=lst[i];
            for(int j=i-g;j>=0;j-=g){
                if(lst[j]>v){
                    lst[j+g]=lst[j];lst[j]=v;cnt++;
                }
                else{break;}
            }
        }
        return lst;
    }
	
	static List<Integer> g_lst = new LinkedList<Integer>();
	
	int[] shellSort(int[] lst){
		for(int i:g_lst){
			insertionSort(lst,i);
		}
		return lst;
	}
	
	public static void main(String[] args){
	    Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),x=1;
        g_lst.add(1);
        while(3*x+1<n){x=3*x+1;g_lst.add(0,x);}
	    int[] lst = new int[n];
	    for(int i=0;i<n;i++){lst[i]=sc.nextInt();}
	    Main m= new Main();
	    lst=m.shellSort(lst);
	    System.out.println(g_lst.size());
	    for(int i=0;i<g_lst.size();i++){
	        if(i==0){System.out.printf("%d",g_lst.get(i));continue;}
	        System.out.printf(" %d",g_lst.get(i));
		}
		System.out.println();
	    System.out.println(m.cnt);
	    for(int i=0;i<n;i++){System.out.println(lst[i]);};
	}
}


Measured memory_bytes: 299372
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using ll = int64_t;

int main() {
  string s;
  cin>>s;
  int n=s.size();
  if (s.back() == '1') {
    cout << -1 << endl;
    return 0;
  }
  if (s.front() == '0') {
    cout << -1 << endl;
    return 0;
  }
  int root = 2;
  vector<pair<int,int>> vp;
  vp.emplace_back(root, 1);
  bool ok = true;
  FOR(i,1,n-1) {
    vp.emplace_back(root, i+2);
    if (s[i] == '1') {
      root = i+2;
    }
    if (s[i] != s[n-i-2]) {
      ok = false;
    }
  }
  if (ok) {
    for (auto p : vp) {
      int u,v;
      tie(u, v) = p;
      cout << u << ' ' << v << endl;
    }
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 2420
#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>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    int ans = b /a;
    if(ans >= c){
        cout << c << endl;
    }else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 3640
from collections import deque

n, m = (int(x) for x in input().split())
list_load=[[0] for i in range(n)]
for i in range(m):
    a, b = (int(x) for x in input().split())
    list_load[a-1].append(b)
    list_load[b-1].append(a)
list_ans=[0]*n

que=deque()
que.append(1)
while que:
    now = que.pop()
    for i in list_load[now-1]:
        if i!=0:
            if list_ans[i-1]==0:
                list_ans[i-1]=now
                que.appendleft(i)
bool = True
for i in range(1,n):
    if list_ans[i]==0:
        bool=False
if bool:
    print("Yes")
    for i in range(1,n):
        print(list_ans[i])
else:
    print("No")






Measured memory_bytes: 97544
#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pii pair<ll,ll>
#define mod 1000000007 //998244353
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define PI 3.141592653589793238
#define pq priority_queue<ll>
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}
void solve()
{
   ll n;
   cin>>n;
   
   vector<ll>adj[n+1];
   
   for(ll i=2;i<=n;i++){
       ll x;
       cin>>x;
       adj[x].pb(i);
       adj[i].pb(x);
   }
   
   
   ll sz[n+1]={0};
   
   ll mx=0;
   
   function<void(ll,ll)>dfs=[&](ll s,ll p){
       
       
       vector<ll>v;
       for(auto a:adj[s])
       {
           if(a==p)
           continue;
           
           dfs(a,s);
           v.pb(a);
       }
       
       if(v.empty()){
           if(s==1)
           sz[s]=adj[s].size();
           else
           sz[s]=(ll)adj[s].size()-1;
       }
       
       else{
         vector<pii>p;
          
          for(ll i=0;i<(ll)v.size();i++)
           p.pb(mk(sz[v[i]],v[i]));
           
           sort(p.begin(),p.end(),[&](pii aa,pii bb){
               return aa.ff>bb.ff;
           });
           
           for(ll i=0;i<(ll)p.size();i++){
               
              
               ll node=p[i].ss;
               
               sz[s]=max(sz[s],i+1+sz[node]);
           }
       }
   };
   
   
   dfs(1,-1);
    
    cout<<sz[1]<<endl;
   
}
int32_t main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     
//Start from Here.

  ll t;
  t=1;
 // cin>>t;
  while(t--)
  solve();
  
//Good Bye!
    return 0;
}

Measured memory_bytes: 27036
#include <stdio.h>

int main(void) {
  int n,a,b;
  int sum[10001];
  int ans = 0;
  scanf("%d%d%d",&n,&a,&b );
  for (int i = 1; i <= n; i++) {
    sum[i] = i % 10;
    sum[i] += (i / 10) % 10 ;
    sum[i] += (i / 100) % 10 ;
    sum[i] += (i / 1000) % 10 ;
    sum[i] += (i / 10000) % 10;
    if (a <= sum[i] && sum[i] <= b) {
      ans += i;
    }
  }
  printf("%d\n",ans );
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
constexpr ll MOD = 998244353LL;
class ModCombination
{
public:
    ModCombination(const int n, const ll mod = MOD) : size{n + 1}, mod{mod}, fact(n + 1, 1), inv(n + 1, 1), inv_fact(n + 1, 1)  // mod should be prime
    {
        for (ll i = 2; i <= n; i++) {
            fact[i] = (fact[i - 1] * i) % mod;
            inv[i] = ((mod - (mod / i)) * inv[mod % i]) % mod;
            inv_fact[i] = (inv_fact[i - 1] * inv[i]) % mod;
        }
    }
    ll factorial(const int n) const
    {
        assert(n < size);
        return fact[n];
    }
    ll inverse(const int n) const
    {
        assert(n < size);
        return inv[n];
    }
    ll inverseFactorial(const int n) const
    {
        assert(n < size);
        return inv_fact[n];
    }
    ll permutation(const int n, const int k) const
    {
        assert(n < size);
        assert(k <= n);
        return (fact[n] * inv_fact[n - k]) % mod;
    }
    ll combination(const int n, const int k) const
    {
        assert(n < size);
        assert(k <= n);
        return (((fact[n] * inv_fact[k]) % mod) * inv_fact[n - k]) % mod;
    }
    ll homogenious(const int n, const int k) const { return (n == 0 and k == 0 ? 1 : combination(n + k - 1, k)); }

private:
    const int size;
    const ll mod;
    vector<ll> fact;
    vector<ll> inv;
    vector<ll> inv_fact;
};
template <typename T>
T gcd(const T a, const T b) { return (b != 0) ? gcd(b, a % b) : a; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll A, B, K;
    cin >> N >> A >> B >> K;
    ll x0 = 0, y0 = N + 1;
    for (; x0 <= N and A * x0 <= K; x0++) {
        if ((K - A * x0) % B == 0) {
            const ll y = (K - A * x0) / B;
            if (y <= N) {
                y0 = y;
                break;
            }
        }
    }
    if (y0 >= N + 1) { return (cout << 0 << endl), 0; }
    const ll g = gcd(A, B);
    vector<ll> X, Y;
    ll ans = 0;
    ModCombination mod(N + 2, MOD);
    for (ll x = x0, y = y0; x <= N and y >= 0; x += B / g, y -= A / g) {
        (ans += mod.combination(N, x) * mod.combination(N, y) % MOD) %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
const int N = 4e5 + 10;
ll n, k, a[N], nxt[N], lst[N], stk[N], top;
bool vis[N], used[N];

void bao(int x, int step) {
    rep(i, 1, step) {
        if (!used[a[x]]) used[a[x]] = 1, stk[++top] = a[x];
        else {
            while (stk[top] != a[x]) used[stk[top]] = 0, --top;
            used[a[x]] = 0; --top;
        }
        x = x % n + 1;
    }
    rep(i, 1, top) printf("%lld ", stk[i]); puts("");
}

void solve(int st, ll step) {
    while (nxt[st] - st + 1 <= step) {
        step -= nxt[st] - st + 1;
        st = nxt[st] % n + 1;
    }
    bao(st, step);
}

int main() {
    cin >> n >> k;
    rep(i, 1, n) scanf("%lld", &a[i]);
    for (int i = n; i >= 1; i--) lst[a[i]] = i + n;
    for (int i = n; i >= 1; i--) nxt[i] = lst[a[i]], lst[a[i]] = i;

    int x = 1;
    ll sum = 0;
    while (!vis[x]) {
        vis[x] = 1, sum += nxt[x] - x + 1;
        x = nxt[x] % n + 1;
    }

    int y = x;
    ll len = 0;  // 循环节长度
    while (1) {
        len += nxt[x] - x + 1;
        x = nxt[x] % n + 1;
        if (x == y) break;
    }

    if (n * k <= sum) solve(1, n * k);
    else solve(y, (n * k - sum) % len);
    return 0;
}


Measured memory_bytes: 13440
#include<stdio.h>
int main(void){
	
	int a[5],k=99999,x,i,m=0,w,o,y;
	
	scanf("%d",&a[0]);
	scanf("%d",&a[1]);
	scanf("%d",&a[2]);
	scanf("%d",&a[3]);
	scanf("%d",&a[4]);
	
	for(i=0;i<5;i++){
		w=a[i]%10;
		if(w<=k){
			if(w!=0){
				k=w;
				o=a[i];
				y=i;
			}
		}
	}
	
	for(x=0;x<5;x++){
		if(x!=y){
			if(a[x]%10!=0){
				a[x]=(a[x]/10)+1;
				a[x]=a[x]*10;
			}
			m+=a[x];
		}
	}
	m+=o;
	printf("%d",m);
	return(0);
}

Measured memory_bytes: 2124
s = list(input())
n = len(s)

mod = 10**9+7
dp = [[0]*13 for i in range(n+1)]
dp[0][0] = 1

for i in range(n):
    flag = 1 if s[i]=='?' else 0 #?だったら1
    if flag==1:
        for a in range(10):#i+1桁目の数字(0-9)
            for j in range(13): #あまり(0-12)
                dp[i+1][(j*10+a)%13] += dp[i][j] #i桁目の余りの10倍とi桁目を足して余りをだす
    else:
        for j in range(13):
            a = int(s[i])
            dp[i+1][(j*10+a)%13] += dp[i][j]
    for j in range(13):
        dp[i+1][j]%=10**9+7
        
print(dp[n][5])

Measured memory_bytes: 64760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++){
        string s;
        cin>>s;
        cout<<s<<endl<<s<<endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int n,a[201],i,j,flag=1,s=0;
int main()
{
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	while(1)
	{
		for(i=0;i<n;i++)
		{
			if(a[i]%2!=0)
			{
				flag=0;
			}
		}
		if(flag==0)
		{
			printf("%d",s);
			return 0; 
		}
		for(i=0;i<n;i++)
		{
			a[i]/=2;
		}
		s+=1;
	}
	return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 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 (a>b) { a=b; return 1; } return 0; }

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

  int h, w, n, sr, sc;
  string s, t;
  cin >> h >> w >> n >> sr >> sc >> s >> t;
  sr--, sc--;

  int res = sr;
  rep(i, n) {
    if (s[i] == 'U') res--;
    if (res < 0) {
      cout << "NO\n";
      return 0;
    }
    if (t[i] == 'D' && res < h - 1) res++;
  }
  res = sr;
  rep(i, n) {
    if (s[i] == 'D') res++;
    if (res >= h) {
      cout << "NO\n";
      return 0;
    }
    if (t[i] == 'U' && res > 0) res--;
  }
  res = sc;
  rep(i, n) {
    if (s[i] == 'L') res--;
    if (res < 0) {
      cout << "NO\n";
      return 0;
    }
    if (t[i] == 'R' && res < w - 1) res++;
  }
  res = sc;
  rep(i, n) {
    if (s[i] == 'R') res++;
    if (res >= w) {
      cout << "NO\n";
      return 0;
    }
    if (t[i] == 'L' && res > 0) res--;
  }
  cout << "YES\n";
  
  



  
  return 0;
}

Measured memory_bytes: 920
#[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 ) * } } ; }
#[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 , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        train: [u64;2],
        bus: [u64;2]
    }

    let mut trainm = train;
    let mut busm = bus;
    trainm.sort();
    busm.sort();
    println!("{}", trainm[0] + busm[0]);
}

Measured memory_bytes: 4352
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
const double pi=acos(-1.0);
const double eps=1e-11;
template<class T> inline void ckmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void ckmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> ipair;
#define SIZE(A) ((int)A.size())
#define LENGTH(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) for(int i=0;i<(a);++i)
#define ALL(A) A.begin(),A.end()

const int maxn=200000+16;

int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
int n;
int a[maxn];

int main()
{
#ifdef _MSC_VER
	freopen("input.txt","r",stdin);
#endif
	std::ios::sync_with_stdio(false);
	int k;
	cin>>n>>k;
	REP(i,n) cin>>a[i];
	int m1=a[0],m2=a[0];
	REP(i,n)
	{
		ckmin(m1,a[i]);
		ckmax(m2,a[i]);
	}
	if (k>m2)
		printf("IMPOSSIBLE\n");
	else
	{
		int d=0;
		REP(i,n) d=gcd(d,a[i]);
		if (k%d==0)
			printf("POSSIBLE\n");
		else
			printf("IMPOSSIBLE\n");
	}
	return 0;
}



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

int main(){
  int N, K, Q;
  vector<int> A;

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

  vector<int> count(N, 0);
  for(int i=0; i < Q; i++){
    count[A[i]-1] += 1;
  }
  for(int i=0; i< N; i++){
    if(K-(Q-count[i]) > 0){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

}


Measured memory_bytes: 1528
import scala.math._

object Main extends App {

  val YES = "YES"
  val Yes = "Yes"
  val NO = "NO"
  val No = "No"

  val input: Array[Array[Int]] = Array.ofDim(6, 6000000)
  ///////////////////////////////////////////

  val sc = new java.util.Scanner(System.in)
  val s = sc.next
//  val t = List.fill(n)(sc.nextInt)

  val (odd, even) = s.zipWithIndex.partition{ case (c, i) => i % 2 == 0}
  val ans = odd.forall{ case (c, i) => Seq('R', 'U', 'D').contains(c) } && even.forall{ case (c, i) => Seq('L', 'U', 'D').contains(c) }
  println(if (ans) Yes else No)

  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

Measured memory_bytes: 167368