akhauriyash/Code-Regression huggingface dataset:
def main():
    s = input()
    op = ["-", "+"]

    for i in range(2 ** 3):
        lst = [0] * 3
        for j in range(3):
            if (i >> j) & 1 == 1:
                lst[2 - j] = 1

        res = int(s[0])
        for j in range(3):
            if lst[j] == 0:
                res -= int(s[j + 1])
            if lst[j] == 1:
                res += int(s[j + 1])
        if res == 7:
            print(f"{s[0]}{op[lst[0]]}{s[1]}{op[lst[1]]}{s[2]}{op[lst[2]]}{s[3]}=7")
            break


if __name__ == "__main__":
    main()


Measured memory_bytes: 9072
N = int(input())
A = list(map(int, input().split()))
count = 0

for i in range(N):
  min_j = i
  flag = False

  for j in range(i+1, N):
    if (A[min_j] > A[j]):
      min_j = j
      flag = True
  
  #print("min_j:{} j:{}".format(min_j, j))
  A[min_j], A[i] = A[i], A[min_j]

  if flag == True:
    count += 1

print(str(A).replace('[', '').replace(']', '').replace(',', ''))
print(count)



Measured memory_bytes: 5600
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let mut vec = vec![];
    let mut dp = vec![0; n as usize];
    for _ in 0..n {
        vec.push(read::<i32>());
    }
    dp[1] = (vec[0] - vec[1]).abs();
    for i in 2..n as usize {
        dp[i] = std::cmp::min(
            dp[i - 1] + (vec[i - 1] - vec[i]).abs(),
            dp[i - 2] + (vec[i - 2] - vec[i]).abs(),
        );
    }
    println!("{}", dp[n as usize - 1 ]);
}


Measured memory_bytes: 4352
# -*- coding: utf-8 -*-

import os
import sys

class Main(object):

    def __init__(self):
        pass

    def some_method(self):
        a, op, b = input().split()
        a = int(a)
        b = int(b)
        if op == '+':
            print(a + b)
        else:
            print(a - b)

        return None

if __name__ == '__main__':
    m = Main()
    m.some_method()


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

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

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  string n;
  cin >> n;
  for (auto e : n) {
    if (e == '1')
      cout << 9;
    else
      cout << 1;
  }
  cout << endl;
}


Measured memory_bytes: 256
/*-----------------------------------
                -----------MEHEDI HASAN--------------
                -----CSE,JAHANGIRNAGAR UNIVERSITY----
                -----------------------------------*/
//--------------------------------------------------------------------//
#include<bits/stdc++.h>
#include <cassert>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
//--------------------------------------------------------------------//
#define FAST        ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define cc(x)       cout<<#x<<"="<<x<<" ";
#define ccc(x)      cout<<x<<" ";
#define ccp(x)      cout<<#x<<"="<<"("<<x.ff<<" "<<x.ss<<") ";
#define CC(x)       for(auto xx: x) cout<<xx<<" ";
#define CCp(x)      for(auto xx: x) cout<<"("<<xx.ff<<" "<<xx.ss<<") ";
#define ee          cout<<"\n";
#define OK          cout<<"Ok"<<"\n";
//--------------------------------------------------------------------//
#define ff          first
#define ss          second
#define ll          long long
#define ull         unsigned long long
#define pii         pair<int,int>
#define mp          make_pair
#define ps          push
#define psb         push_back
#define psf         push_front
#define pp          pop
#define ppb         pop_back
#define ppf         pop_front
#define all(x)      x.begin(),x.end()
#define TESTS       int t;cin>>t;for(int tcase=1;tcase<=t;tcase++)
#define ordered_set tree< int, null_type, less_equal< int >, rb_tree_tag, tree_order_statistics_node_update>
//--------------------------------------------------------------------//
#define MAX (int)(3e6)
#define MOD (ll)(1e9+7)


int main()
{
    FAST
    int n,x,y;cin>>n>>x>>y;
    vector <int> D(n,0);
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            int d=j-i;
            int m=0;
            if(i<=x and j>=y) m=y-x-1;
            d=d-m;
            int d1=(int)abs(j-y)+1+(int)abs(i-x);
            d=min(d,d1);
            D[d]++;

        }

    }
    for(int i=1;i<n;i++) cout<<D[i]<<endl;


    return 0;
}
//--------------------------------------------------------------------//
/*
>Check Corner Cases (n==1 or T==1)
>Overflow issues?
>LB / UB !!not found!! check?
*/
//--------------------------------------------------------------------//
/* ---INPUT---
--------(1)------
2
1 2 4

-------(2)-------


-------(3)-------
4
1 2 2
1 3 4
3 4 5

-------(4)-------



--------------
*/
//--------------------------------------------------------------------//


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		long K = sc.nextLong();
		int N = sc.nextInt();

		long[] A = nextLongArray(sc, N);

		sc.close();

		long[] b = new long[N];
		b[0] = A[0] + K - A[N - 1];
		for (int i = 1; i < N; i++) {
			b[i] = A[i] - A[i - 1];
		}

		Arrays.sort(b);

		long ans = 0;
		for (int i = 0; i < N - 1; i++) {
			ans += b[i];
		}

		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private long[] nextLongArray(Scanner sc, int n) {
		long[] result = new long[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextLong();
		}
		return result;
	}
}


Measured memory_bytes: 78948
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0; i<n; i++)
#define loop(i, j, n) for(int i=j; i<n; i++)
using namespace std;
int main()
{
	bool ans = true;
	int n;
	cin >> n;
	vector<string> w(n);
	rep(i,n) cin >> w[i];

	rep(i,n-1){
		if(w[i].back() != w[i+1].front()) ans = false;
	}

	rep(i,n){
		size_t cnt = count(w.begin(), w.end(), w[i]);
		if(cnt >= 2) ans = false;
	}

	if(ans) cout << "Yes" <<endl;
	else cout << "No" <<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
#define vec2(a,y,x) vector<vector<int>> a(y,vector<int>(x))
#define vec1(a,n) vector<int> a(n);rep(i,n)cin>>a[i]

int main(){
  int n,m;
  cin>>n>>m;
  int x;
  vector<int> k(m);
  vec2(s,m,0);
  rep(i,m){
    cin>>k[i];
    rep(j,k[i]){
      cin>>x;
       s[i].push_back(x-1);
    }
  }
  vec1(p,m);
  
  int cnt=0;
  int ans=0;
  bool flag=false;
  
  for (int tmp = 0; tmp < (1 << n); tmp++) {
     bitset<11> a(tmp);
    rep(i,m){
       rep(j,k[i]){
          if(a.test(s[i][j])) cnt ++;
       }
      if(cnt%2!=p[i]){flag=true;break;}
      cnt =0;
    }
    cnt=0;
    if(flag){flag=false; continue;}
    ans ++;
  }
  //rep(i,11-m) ans/=2;
  cout<<ans;
}


Measured memory_bytes: 256
/*
  AtCoder Beginner Contest 079
  D - Wall

  方針
    マスに書いてある数字Aが1もしくは-1でなければ、1にする必要がある。
    したがって、Aを1に変換する最小のコストを計算すればよい。

  実装
    Warshall-Floyd法を用いて最小コストを計算する。
*/

#include<iostream>
#include<vector>
using namespace std;

int H, W;
vector<vector<int>> cost(10, vector<int>(10));

void floyd_warshall() {
  for (int k = 0; k < 10; ++k) {
    for (int i = 0; i < 10; ++i) {
      for (int j = 0; j < 10; ++j) {
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      }
    }
  }
}

int main() {
  scanf("%d%d", &H, &W);
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      scanf("%d", &cost[i][j]);
    }
  }

  floyd_warshall();

  int total = 0;
  for (int h = 0; h < H; ++h) {
    for (int w = 0; w < W; ++w) {
      int A;
      scanf("%d", &A);

      if (A == -1) continue;
      total += cost[A][1];
    }
  }

  printf("%d\n", total);
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AtCoder_Project_CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = ab[0], b = ab[1];
            if(a <= b)
            {
                Console.WriteLine(a);
            }
            else
            {
                Console.WriteLine(a - 1);
            }
        }
    }
}


Measured memory_bytes: 11220
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
	long long n, q;
	std::vector<long long> aList;
	std::vector<long long> bList;
	std::vector<long long> cList;

	std::cin>>n;
	aList.resize(n);

	for(int i=0; i< n; i++)
		std::cin>>aList[i];

	std::cin>>q;

	bList.resize(q);
	cList.resize(q);

	for(int i=0; i< q; i++)
		std::cin>>bList[i]>>cList[i];


	std::vector<long long> numList(100001, 0);

	long long sum=0;
	for(int i=0; i< n; i++){
		numList[aList[i]]++;
		sum+= aList[i];
	}


	for(int i=0; i<q; i++){
		long long bIdx= bList[i];
		long long cIdx= cList[i];

		long long tmp= numList[bIdx];

		sum+= numList[bIdx] * (cIdx - bIdx);
		numList[bIdx]=0;
		numList[cIdx]+= tmp;

		std::cout<<sum<<std::endl;
	}


	return 0;
}

Measured memory_bytes: 6356
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main(void)
{
    int N, W;
    cin >> N >> W;
    long weight[N + 10];
    long value[N + 10];
    long ans = 0;

    map<long, long> mp;

    for (int i = 0; i < N; i++)
    {
        cin >> weight[i] >> value[i];
    }

    for (int i = 0; i < N; i++)
    {
        map<long, long> tmp_mp;
        tmp_mp[weight[i]] = value[i];
        for (pair<long, long> p : mp)
        {
            tmp_mp[p.first + weight[i]] = value[i] + p.second;
        }
        for (pair<long, long> p : tmp_mp)
        {
            if (mp[p.first] < p.second)
                mp[p.first] = p.second;
        }
    }

    for (pair<long, long> p : mp)
    {
        if (p.first <= W)
            ans = max(ans, p.second);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

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

    int N = sc.nextInt();
    int acCount[] = new int[N];
    int Q = sc.nextInt();
    String S = sc.next();
    String s[] = S.split("");
    int l[] = new int[Q];
    int r[] = new int[Q];
    for (int i = 0; i < Q; i++) {
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }

    for (int i = 0; i < N; i++) {
      if (i > 0) {
        acCount[i] = acCount[i-1];
      }
      if (i >= N-1) {
        break;
      }
      if (S.charAt(i) == 'A' && S.charAt(i+1) == 'C') {
        acCount[i] += 1;
      }
    }
    for (int i = 0; i < Q; i++) {
      int ans = acCount[r[i]-1] - acCount[l[i]-1] + 1;
      if (l[i]-1 > 0) {
        if (acCount[l[i]-1] == acCount[l[i]-2]) {
          ans--;
        }
      }
      else if (!(S.charAt(0) == 'A' && S.charAt(1) == 'C')) {
        ans--;
      }

      if (r[i] < S.length() && acCount[r[i]-2] != acCount[r[i]-1]) {
        ans--;
      }
      System.out.println(ans);
    }
    //System.out.println(Arrays.toString(acCount));
  }
}


Measured memory_bytes: 108648
def foo(infile, outfile, n):
    ax = 0
    bx = 0
    for i in range(n):
        a, b = infile.readline().split()
        a = int(a)
        b = int(b)
        if a > b:
            ax += (a + b)
        elif a < b:
            bx += (a + b)
        elif a == b:
            ax += a
            bx += b
        else:
            assert False
    print >> outfile, ax, bx


def run(infile, outfile):
    while True:
        n = int(infile.readline())
        if n == 0:
            break
        foo(infile, outfile, n)


if __name__ == "__main__":
    import sys
    run(sys.stdin, sys.stdout)

Measured memory_bytes: 4988
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
  		int c500=a/500;
		a=a-c500*500;
  		int c5=a/5;
  		long ans=c500*1000+c5*5;
  	
    	System.out.println(ans);
    }
}

Measured memory_bytes: 23124
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int x = int.Parse(str[2]);
            double h = x * 2 / (a * a * 1.0) - b;
            if (h >= 0)
            {
                double theta = Math.Atan(a / (b - h));
                Console.WriteLine(90-theta * 180 / Math.PI);
            }
            else
            {
                h = x * 2*1.0 / (b*a);
                double theta = Math.Atan(h / b);
                Console.WriteLine(90-theta * 180 / Math.PI);
            }

        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.fn", "r", stdin);
	string str = "";

	getline (cin, str );
	stringstream ss(str);
	vector <int> num(5, 0);

	int i;
	for (i = 0; i < 5; ++i){
		ss >> num[i];
	} // end for

	sort (num.begin(), num.end(), greater<int>() );

	for (i = 0; i < 5; ++i){
		cout << num[i];
		if (i != 4){
			cout << ' ';
		} // end if
	} // end for
	cout << endl;
		
	return 0;
}

Measured memory_bytes: 0
#AGC047-A Integer Product
"""
小数または整数が与えられるので、その積が整数となるペアの個数を求めよ。

まず入力に10**9をかけることで、
問題を「その積が10**18の倍数となるペアの個数を求めよ」
とする。
その場合、とりあえず10**18を素因数分解すると2**18と5**18なので、
片方が因数分解済みであるとした時に、
dp[i][j] : 2**iかつ5**jの個数
として、もう片方を2**aかつ5**bであると考えた時に、
2**(i+a)>=18かつ5**(j+b)>=18となるならば、それは条件を満たす
と考えられる。

よってこの個数を数えることで問題が解けた。
"""
import sys
from decimal import Decimal
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1  = [] 
for i in range(n):
    s = readline().rstrip().decode('utf-8')
    lst1.append(int(Decimal(s)*(10**9)))

dp = [[0]*20 for _ in range(45)]

ans = 0

for i in range(n):
    res = lst1[i]
    t,f = 0,0
    while True:
        if res%2==0:
            res //= 2
            t += 1
        else:
            break
    while True:
        if res%5==0:
            res //= 5
            f += 1
        else:
            break
    #i+t>=18かつj+f>=18であるような場所からカウント
    for i in range(18-t,45):
        for j in range(18-f,20):
            ans += dp[i][j]
    dp[t][f] += 1

print(ans)


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

int main()
{
    int n,k,d,x;
    cin>>n>>k;

    int snack[n];

    for(int i=0;i<n;i++)
        snack[i]=0;

    for(int i=0;i<k;i++)
    {
        cin>>d;
        for(int j=0;j<d;j++)
        {
            cin>>x;
            snack[x-1]++;
        }
    }

    int sum=0;

    for(int i=0;i<n;i++)
    {
        if(snack[i]==0)
            sum++;
    }

    cout<<sum;

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>
#include <ios>
#include <iomanip>
#include <functional>
#include <queue>

#define int long long

int inf = (1LL <<  62);
using namespace std;

signed main(){
    int n;
    cin >> n;
    vector<int> v1;
    vector<int> v2;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        v1.push_back(x);
    }
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        v2.push_back(x);
    }
    int sum = 0;;
    for(int i = 0; i < n; i++){
        if(v1[i] - v2[i] > 0){
            sum += v1[i] - v2[i];
        }
    }
    
    cout << sum;

    
    
}

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

using namespace std;
typedef double D;
const D EPS= (1e-10);

#define X real()
#define Y imag()
#define SZ size()
#define PB(x) push_back(b)
#define PREV(x,i)  (x[(i+x.SZ-1)%x.SZ])
#define NEXT(x,i) (x[(i+1)%x.SZ])

template<class T> using CR=const  T&;
using P=complex<D>;
using G=vector<P>;

int sgn(D a,D b=0){
    if(a>b+EPS)return 1;
    if(a<b-EPS)return -1;
    return 0;
}

D dist(P a,P b){
    return abs(a-b);
}

tuple<P,P> normal_direction(P v){
    D x=v.X,y=v.Y;
    return tuple<P,P>(P(y,-x),P(-y,x));
}

P normalize(P v){
    D x=v.X,y=v.Y;
    D d=abs(v);
    return P(x/d,y/d);
}

tuple<P,P> getC(P a,P b){
    auto v=b-a;
    auto pq=normal_direction(v);
    P p,q;tie(p,q)=pq;
    D d=sqrt(1-(dist(a,b)/2)*(dist(a,b)/2));
    return tuple<P,P>(a+0.5*v+d*normalize(p),a+0.5*v+d*normalize(q));
}

int cnt(G& g,P c){
    int n=g.size(),res=0;
    for(int i=0;i<n;i++)
	if(sgn(dist(c,g[i]),1.0)<=0){
	    res++;
	}
    return res;
}

int main(){
    for(int n;cin>>n,n;){
	G g(n);
	for(int i=0;i<n;i++){\
	    D x,y;
	    cin>>x>>y;
	    g[i]=P(x,y);
	}
	int res=1;
	for(int i=0;i<n;i++)
	    for(int j=i+1;j<n;j++)
		if(sgn(dist(g[i],g[j]),2.0)<=0){
		    auto pq=getC(g[i],g[j]);
		    P p,q;tie(p,q)=pq;
		    res=max({res,cnt(g,p),cnt(g,q)});
		}
	cout<<res<<endl;
    }
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction
 
///using namespace __gnu_pbds;
using namespace std;
 
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    int n,m,x;
    while(cin>>n>>m>>x)
    {
        int c[n+5],ara[n+5][m+5];
        for(int i=0;i<n;i++)
        {
            cin>>c[i];
            for(int j=0;j<m;j++)cin>>ara[i][j];
        }

        int mn=INT_MAX;
        for(int i=1;i<(1<<n);i++)
        {
            int mara[m+5];
            memset(mara,0,sizeof mara);
            int sum=0;
            for(int j=0;j<n;j++)
            {
                if(i & (1<<j))
                {
                    for(int k=0;k<m;k++)
                    {
                        mara[k]+=ara[j][k];
                    }
                    sum+=c[j];
                }
            }

            bool f=true;
            for(int j=0;j<m;j++)
            {
                if(mara[j]<x)
                {
                    f=false;
                    break;
                }
            }
            if(f)mn=min(mn,sum);
        }
        if(mn==INT_MAX)puts("-1");
        else cout<<mn<<"\n";
    }
    return 0;
}
 









 




























Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  // そのままでは100->1,000,000の場合に1e+06になる
  cout << fixed << setprecision(0);
  cout << (a * b) << " " << (a + b) * 2 << endl;
  return 0;
}



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

int main(){
	int n,q,f,x;
	deque<int> DQ;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>q;
		switch(q){
			case 0:
				cin>>f>>x;
				if(f) DQ.push_back(x);
				else DQ.push_front(x);
				break;
			case 1:
				cin>>f;
				cout<<DQ[f]<<endl;
				break;
			case 2:
				cin>>f;
				if(f) DQ.pop_back();
				else DQ.pop_front();
		}
	}
	return 0;
}



Measured memory_bytes: 4644
import collections

n = int(input())
A = list(map(int, input().split()))

C = collections.Counter(A).values()

even = 0
for c in C:
    if c % 2 == 0:
        even += 1

if even % 2 == 0:
    print(len(C))
else:
    print(len(C) - 1)


Measured memory_bytes: 18656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,m,n) for(int i=m;i<(int)(n);i++)
#define INF 999999999

    /*Solve*/
int main(){
    string st;
    cin >> st;
    int n=sizeof(st);
    int x[4]={0,0,0,0};
    rep(i,n){
        if(st[i]=='N'){x[0]+=1;
        }else if(st[i]=='S'){x[1]+=1;
        }else if(st[i]=='E'){x[2]+=1;
        }else if(st[i]=='W'){x[3]+=1;
        }
    }
    int cnt=0;
    rep(i,4)if(x[i]!=0)cnt++;
    bool NS,EW;
    NS=((x[0]!=0&&x[1]!=0)||(x[0]==0&&x[1]==0));
    EW=((x[2]!=0&&x[3]!=0)||(x[2]==0&&x[3]==0));
    if(NS && EW){cout << "Yes";
    }else cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

int main()
{
	int32_t N, M;
	cin >> N >> M;

	vector<int32_t> X(M);
	for (int32_t i = 0; i < M; i++) {
		cin >> X[i];
	}

	int32_t res = 0;

	if (N < M) {
		sort(X.begin(), X.end());
		vector<int32_t> diff(M - 1);
		for (int32_t i = 0; i < M - 1; i++) {
			diff[i] = X[i + 1] - X[i];
		}
		sort(diff.begin(), diff.end(), greater<int32_t>());

		for (int32_t i = N - 1; i < M - 1; i++) {
			res += diff[i];
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1024
def main():
    import sys
    from bisect import bisect_left
    N,K=list(map(int,sys.stdin.readline().split()))
    A=[0]*N
    for i in range(N):
        A[i]=int(sys.stdin.readline())

    dp=[0]*(N+1)
    dp[0]=1
    if abs(A[0]-A[1])<=K:
        dp[1]=2
    else:
        dp[1]=1
    
    for i in range(2,N):
        mx=1
        for j in range(1,105):
            if i-j<0:
                break
            if abs(A[i-j]-A[i])<=K:
                mx=max(mx,dp[i-j]+1)

        dp[i]=mx

    print(max(dp))


main()

Measured memory_bytes: 73236
n=int(input())
a=list(map(int, input().split()))
a_abs=[abs(x) for x in a]
cnt=[1 for x in a if x<0]
if cnt.count(1)%2>0:
    print(sum(a_abs)-2*min(a_abs))
else:
    print(sum(a_abs))

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

#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;

int main() {
    constexpr int C_MAX = 100000;
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R), inv_r(N, -1);
    REP(i, R) {
        cin >> r[i];
        --r[i];
        inv_r[r[i]] = i;
    }
    vector<vector<pii>> g(N);
    REP(i, M) {
        int A, B, C;
        cin >> A >> B >> C;
        --A; --B;
        g[A].push_back(pii(B, C));
        g[B].push_back(pii(A, C));
    }

    const ll INF = (N << R) * C_MAX;
    ll result = INF;
    int mask = (1 << R) - 1;
    REP(start, R) {
        vector<int> dp(N << R, INF);
        priority_queue<pli, vector<pli>, greater<pli>> q;
        dp[(r[start] << R) ^ (1 << start)] = 0;
        q.push(pli(0, r[start] << R ^ 1 << start));
        while (!q.empty()) {
            ll d;
            int state;
            tie(d, state) = q.top();
            q.pop();
            if (dp[state] < d) {
                continue;
            }
            int u = state >> R;
            int visited = state & mask;
            if (visited == mask) {
                result = min(result, d);
                break;
            }
            for (const pii &edge: g[u]) {
                int v = edge.first;
                int cost = edge.second;
                int visited_next;
                if (inv_r[v] == -1) {
                    visited_next = visited;
                } else {
                    visited_next = visited | 1 << inv_r[v];
                }
                int state_next = v << R ^ visited_next;
                if (dp[state_next] > d + cost) {
                    dp[state_next] = d + cost;
                    q.push(pli(dp[state_next], state_next));
                }
            }
        }
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 4192
#include<stdio.h>
#include<stdlib.h>

#define N 100
#define WHITE 0
#define GRAY  1
#define BLACK 2


void makenode(int,int);
void dfs(int);
void visit(int,int);

int G[N][N];

int color[N];
int d[N];
int f[N];
int times;

int main()
{
  int n,i,k,u,v,j;
  
  scanf("%d", &n);

  for(i=0;i<n;i++)
    {
      scanf("%d%d", &u, &k);
      for(j=0;j<k;j++)
	{
	  scanf("%d", &v);
	  G[u-1][v-1]=1;
	}
    }
  
  dfs(n);
  
  for(i=0;i<n;i++)
    {
      printf("%d %d %d\n", i+1, d[i], f[i]);
    }

  return 0;
}

void dfs(int n)
{
  int i;
  for(i=0;i<n;i++)
    {
      color[i]=WHITE;
    }
  times=0;

  for(i=0;i<n;i++)
    {
      if(color[i]==WHITE)
	visit(i,n);
    }
}
void visit(int u,int n)
{
  int i;
  color[u]=GRAY;
  d[u]=++times;

  for(i=0;i<n;i++)
    {
      if(G[u][i]==1)
	{
	  if(color[i]==WHITE)
	    visit(i,n);
	}
    }
  color[u]=BLACK;
  f[u]=++times;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
const int N=200005;
int h[N],dp[N],n;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&h[i]);
	memset(dp,0x3f,sizeof(dp));
	dp[1]=0;
	for (int i=1;i<=n;i++){
		dp[i+1]=std::min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
		dp[i+2]=std::min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
	}
	printf("%d\n",dp[n]);
} 

Measured memory_bytes: 1408
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define L 100
#define Gard NULL

struct Tree{
  int nodekey;
  struct Tree *parent;
  struct Tree *leftch;
  struct Tree *rightch;
};

typedef struct Tree  *Search;
Search road;

void Insert(int );
void Pre(Search );
void In(Search );


int main(){
  int loop,numnode;
  char order[L];
  int i;
    
  scanf("%d",&loop);
  
  for(i=0;i<loop;i++){
    scanf("%s",order);
    
    if(order[0]=='i'){
      scanf("%d",&numnode);
      Insert(numnode);
    }
    
    else if(order[0]=='p'){
      In(road);
      printf("\n");
      Pre(road);
      printf("\n");
    }
  }
  
  return 0;
}

void Insert(int numnode){
  Search xnode,ynode,znode;
  
  xnode=road;
  ynode=Gard;
  znode=(struct Tree *)malloc(sizeof(struct Tree));
  znode->nodekey=numnode;
  znode->leftch=Gard;
  znode->rightch=Gard;
  
  while(1){
    if(xnode==Gard)break;
    ynode=xnode;
    
    if(znode->nodekey<xnode->nodekey){
      xnode=xnode->leftch;
    }
    
    else{
      xnode=xnode->rightch;
    }
  }
  
  znode->parent=ynode;
  
  if(ynode==Gard){
    road=znode;
  }
  
  else if(znode->nodekey<ynode->nodekey){
    ynode->leftch=znode;
  }
  
  else{
    ynode->rightch=znode;
  }
    
}

void Pre(Search road){

  if(road==Gard){
    return;
  }
  
  printf(" %d",road->nodekey);
 
  Pre(road->leftch);
  Pre(road->rightch);
  
}

void In(Search road){

  if(road==Gard){
    return;
  }
  
  In(road->leftch);
  
  printf(" %d",road->nodekey);
  
  In(road->rightch);
}



Measured memory_bytes: 25128
#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()
using namespace std;

const double EPS = 1e-3;
const double PI = 3.1415926535897932384626433832795028841971;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

int main(int argc, char const *argv[])
{
    deque<int> b;
    vector<int> ans;
    int n;
    cin >> n;
    rep(i, n)
    {
        int a;
        cin >> a;
        if (i % 2 == 0)
            b.push_back(a);
        else
            b.push_front(a);
    }
    while (!b.empty())
    {
        ans.push_back(b.front()), b.pop_front();
    }
    if (n % 2 == 1)
        reverse(ALL(ans));
    rep(i, n) cout << ans[i] << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 3960
#include <stdio.h>
int main()
{
    long long int n, i, sum = 0;
    long long int a[100005];
    scanf("%lld", &n);
    for (i = 0; i < n; i++)
        scanf("%lld", &a[i]);
    sum = a[0];
    for (i = 1; i < n; i++)
    {
        if (a[i] > sum)
            sum = a[i];
        if (a[i] <= sum - 2)
            break;
    }
    if (i != n)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 896
#include <stdio.h>

int n,k,x,y;

int main()
{
	scanf("%d %d %d %d", &n, &k, &x, &y);
	
	if(n<=k) printf("%d\n", n*x);
	else	printf("%d\n", k*x+(n-k)*y);

	return 0;
}

Measured memory_bytes: 128
S = input()
if S == 'SUN':
  print(7)
elif S == 'MON':
  print(6)
elif S == 'TUE':
  print(5)
elif S == 'WED':
  print(4)
elif S == 'THU':
  print(3)
elif S == 'FRI':
  print(2)
elif S == 'SAT':
  print(1)  

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

struct team{
    int cor,pen,id;
    vector<int>AC;
    vector<int>correct;
    vector<int>penalty;
};
bool com(team t1,team t2){
    return t1.cor==t2.cor?t1.pen==t2.pen?t1.id>t2.id:t1.pen<t2.pen:t1.cor>t2.cor;
}
bool com2(team t1,team t2){
    return t1.cor==t2.cor?t1.pen<t2.pen:t1.cor>t2.cor;
}
int main(){
    int M,T,P,R,m,t,p,j;
    while(cin>>M>>T>>P>>R,M){
        vector<team>vec(T);
        for(int i=0;i<T;i++){
            vec[i].id=i;
            vec[i].correct.resize(P,0);
            vec[i].penalty.resize(P,0);
            vec[i].AC.resize(P,0);
            vec[i].cor=0;
            vec[i].pen=0;
        }
        for(int i=0;i<R;i++){
            cin>>m>>t>>p>>j;
            t--;p--;
            if(j==0){
                vec[t].correct[p]=vec[t].penalty[p]+m;
                vec[t].AC[p]=1;
            }
            else{
                vec[t].penalty[p]+=20;
            }
        }
        for(int i=0;i<T;i++){
            for(int a=0;a<P;a++){
                if(vec[i].AC[a]>0){
                    vec[i].cor++;
                    vec[i].pen+=vec[i].correct[a];
                }
            }
        }
        sort(vec.begin(),vec.end(),com);
        
        for(int i=0;i<T-1;i++){
            if(com2(vec[i],vec[i+1]))
                cout<<vec[i].id+1<<",";
            else
                cout<<vec[i].id+1<<"=";
        }
        cout<<vec[T-1].id+1<<endl;
        vec.clear();
    }
    
}

Measured memory_bytes: 1256
using System.Collections.Generic;
using static System.Console;
class Z
{
	static void Main()
	{
		var N = int.Parse(ReadLine());
		var S = ReadLine();
		var T = ReadLine();
		var same = new List<bool>();
		for (var i = 0; i < N; i++)
			if (S[i] == T[i]) same.Add(true);
			else { same.Add(false); i++; }
		var dp = same[0] ? 3L : 6;
		for (var i = 1; i < same.Count; i++) dp = dp * (same[i - 1] ? 2 : same[i] ? 1 : 3) % 1000000007;
		WriteLine(dp);
	}
}


Measured memory_bytes: 13268
#include <stdio.h>
int n, i;
int a, b;
char s[200001], c;
int main(void){
  while((c=getchar())!=10){s[n++]=c;}
  scanf("%s",&s);
  for(i=0; i<n; i++){
    if(b>0){
      if(s[i]=='S'){
        b++;
      }else{
        b--;
      }
    }else{
      if(s[i]=='T'){
        a++;
      }else{
        b++;
      }
    }
  }
  printf("%d\n", a*2);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll gcd(ll a, ll b);
ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int n;
  cin >> n;
  if (n >= 1000)
    cout << "ABD" << endl;
  else
    cout << "ABC" << endl;

  return 0;
}

ll gcd(ll a, ll b){
  if (a < b)
    return gcd(b, a);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int A, B;
    cin >> A >> B;

    cout << A * B << endl;
	
	return 0;
}

Measured memory_bytes: 3592
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	for i := 0; i <= 10000; i++ {
		if a%2 != 0 || b%2 != 0 || c%2 != 0 {
			fmt.Println(i)
			return
		}
		a, b, c = b/2+c/2, a/2+c/2, a/2+b/2
	}
	fmt.Println(-1)
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

typedef long long int ll;

int comp(const void* a, const void* b){
  return *(int*)a - *(int*)b;
}

ll gcd(ll x, ll y) {
  return y? gcd(y, x%y): x; 
}

ll a, b, g;
int c;
int main(void){
  scanf("%lld%lld", &a, &b);
  g = gcd(a, b);
  // printf("gcd(a, b)= %lld\n", g);
  for (ll i = 2; i*i<= g; ++i) {
    if (g%i==0) {
      ++c;
      while (g%i==0) g/=i; 
    }
  }
  if (g!=1) c++;
  printf("%d", c+1);
  return 0*printf("\n");
}


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

using namespace std;
typedef long long ll;

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

  int n; cin >> n;

  vector<int> v;
  for (int i = 0; i < 4; ++i) {
    v.push_back(n % 10);
    n /= 10;
  }

  if (v[0] == v[1] && v[1] == v[2]) cout << "Yes" << "\n";
  else if (v[1] == v[2] && v[2] == v[3]) cout << "Yes" << "\n";
  else cout << "No" << "\n";
}


Measured memory_bytes: 3660
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    A, B, Q = LI()
    s = [I() for _ in range(A)]
    t = [I() for _ in range(B)]

    # xから一番近い神社に行く→その神社から一番近い寺に行く、またはその逆の2パターン

    # 各神社に対する一番近い寺の距離を求めておく
    len_of_nearest_t = [INF] * A
    for i in range(A):
        idx = bisect.bisect_left(t, s[i])
        len_r = t[idx] - s[i] if 0 <= idx < B else INF
        len_l = s[i] - t[idx-1] if 0 <= idx - 1 < B else INF
        len_of_nearest_t[i] = min(len_l, len_r)
    # print(len_of_nearest_t)

    # 各寺に対する一番近い神社の距離を求めておく
    len_of_nearest_s = [INF] * B
    for i in range(B):
        idx = bisect.bisect_left(s, t[i])
        len_r = s[idx] - t[i] if 0 <= idx < A else INF
        len_l = t[i] - s[idx-1] if 0 <= idx - 1 < A else INF
        len_of_nearest_s[i] = min(len_l, len_r)
    # print(len_of_nearest_s)

    for _ in range(Q):
        x = I()
        # 神社→寺
        idx = bisect.bisect_left(s, x)
        len_r = s[idx] - x + len_of_nearest_t[idx] if 0 <= idx < A else INF
        len_l = x - s[idx-1] + len_of_nearest_t[idx-1] if 0 <= idx - 1 < A else INF
        len_x_s_t = min(len_r, len_l)
        # 寺→神社
        idx = bisect.bisect_left(t, x)
        len_r = t[idx] - x + len_of_nearest_s[idx] if 0 <= idx < B else INF
        len_l = x - t[idx-1] + len_of_nearest_s[idx-1] if 0 <= idx - 1 < B else INF
        len_x_t_s = min(len_r, len_l)
        print(min(len_x_s_t, len_x_t_s))

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 26052
import sys
input = sys.stdin.readline

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

    tmp_max = sum(P[:K])
    tmp = sum(P[:K])
    for i in range(N-K):
        tmp += P[i+K]
        tmp -= P[i]

        if tmp > tmp_max:
            tmp_max = tmp

    print((tmp_max + K) / 2)

main()

Measured memory_bytes: 24404
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=998244353;
const int siz=1e5;
const long inf=1e9;
int main(){
	int T; cin>>T;
	rep(_,0,T){
		int N; cin>>N;
		long A[N]; string s;
		rep(i,0,N) cin>>A[i];
		cin>>s;
		set<long> st;
		bool flag = 0;
		for(int i = N-1; i >= 0; i--){
			while(A[i] > 0){
				long t = 1;
				while(2 * t <= A[i]) t *= 2;
				auto it = st.lower_bound(t);
				if(it != st.end() && *it < 2 * t){
					A[i] ^= *it;
				}else{
					if(s[i] == '0') st.insert(A[i]);
					else{ flag = 1; break; }
				}
			}
		}cout<<flag<<endl;
	}
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define db double
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vpi vector<pi>
#define vpl vector<pl>
#define pb push_back
#define er erase
#define SZ(x) (int) x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mkp make_pair
#define dmin(x, y) ((x) < (y) ? (x) : (y))
#define dmax(x, y) ((x) > (y) ? (x) : (y))
#define checkmax(x, y) ((x) < (y) ? ((x) = (y)) : (x))
#define checkmin(x, y) ((x) > (y) ? ((x) = (y)) : (x))
#define pls(x, y) ((x) + (y) >= mod ? (x) + (y) - mod : (x) + (y))
#define sub(x, y) ((x) - (y) < 0 ? (x) - (y) + mod : (x) - (y))
#define mul(x, y) (1ll * (x) * (y) % mod)
#define ms(data_name) memset(data_name, 0, sizeof(data_name))
#define msn(data_name, num) memset(data_name, num, sizeof(data_name))
#define For(i, j) for(reg int (i) = 1; (i) <= (j); ++(i))
#define For0(i, j) for(reg int (i) = 0; (i) < (j); ++(i))
#define Forx(i, j, k) for(reg int (i) = (j); (i) <= (k); ++(i))
#define Forstep(i , j, k, st) for(reg int (i) = (j); (i) <= (k); (i) += (st))
#define fOR(i, j) for(reg int (i) = (j); (i) >= 1; (i)--)
#define fOR0(i, j) for(reg int (i) = (j) - 1; (i) >= 0; (i)--)
#define fORx(i, j, k) for(reg int (i) = (k); (i) >= (j); (i)--)
#define tour(i, u) for(reg int (i) = head[(u)]; (i) != -1; (i) = nxt[(i)])
using namespace std;
char ch, B[1 << 20], *S = B, *T = B;
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T) ? 0 : *S++)
#define isd(c) (c >= '0' && c <= '9')
int rdint() {
  int aa, bb;
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
ll rdll() {
  ll aa, bb;
  while(ch = getc(), !isd(ch) && ch != '-');
  ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1);
  while(ch = getc(), isd(ch))
    aa = aa * 10 + ch - '0';
  return bb ? aa : -aa;
}
const int MAXN = 1e5 + 10;
const int mod = 1e9 + 7;
char s[MAXN];
int len, dp[MAXN][13];
inline void work() {
  scanf("%s", s + 1);
  len = strlen(s + 1);
  dp[0][0] = 1;
  For(i, len) {
    if(s[i] == '?') {
      For0(k, 10) {
        For0(j, 13) {
          dp[i][(j * 10 + k) % 13] = pls(dp[i][(j * 10 + k) % 13], dp[i - 1][j]);
        }
      }
    } else {
      s[i] -= '0';
      For0(j, 13) {
        dp[i][(j * 10 + s[i]) % 13] = pls(dp[i][(j * 10 + s[i]) % 13], dp[i - 1][j]);
      }
    }
  }
  printf("%d\n", dp[len][5]);
}
int main() {
  // freopen("input.txt", "r", stdin);
  work();
  return 0;
}


Measured memory_bytes: 6400
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

// vars
lint x;

void input(){
    cin >> x;
}

void solve(){
    for (lint a=0; a<=1000; ++a){
        for (lint b=-10000; b<=10000; ++b){
            lint k = a * a * a * a * a - b * b * b * b * b;
            if(k == x){
                cout << a << " " << b << endl;
                return;
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
int main()
{
    float a,b,c;
    cin>>a>>b>>c;
    if(a/c<=b)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}


Measured memory_bytes: 3716
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main(void){
	
	string s;
	int i,cnum=0,check=0;
	cin>>s;
	if(s[0]=='A')check++;
	else{
		cout<<"WA"<<endl;
		return 0;
	}
	for(i=2;i<s.length()-1;i++){
		if(s[i]=='C')cnum++;
	}
	if(cnum==1)check++;
	else{
		cout<<"WA"<<endl;
		return 0;
	}
	for(i=1;i<s.length();i++){
		if((s[i]<'a'||s[i]>'z')&&s[i]!='C'){
			cout<<"WA"<<endl;
			return 0;
		}
	}
	cout<<"AC"<<endl;
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;


int main(){
	int a,b;
	while(cin >> a >> b){
		a = a + b;
		cout << (int)log10(a)+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1204
const main = (inputs) => {
  var N = inputs[0].split(" ")[0]-0;
  var arr = inputs[1].split(" ").map(v=>v-0);
  var tmp = arr[0];
  var ans = true;
  arr.forEach(v=>{
    if(v+1<tmp) ans = false;
    tmp = Math.max(tmp, v);
  });
  console.log(ans?"Yes":"No");
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


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

#define rep(i, first, to) for(ll i = first; i < to; ++i)

using namespace std;
typedef long long ll;

const int MAXN = 100;

int a[MAXN];
int color[8];

bool nuru(int v) {
	for (int i = 0; i < 8; ++i) {
		if (v < 400 * (i + 1)) {
			color[i] = 1;
			return true;
		}
	}
	return false;
}
void solve() {
	int n;
	cin >> n;
	rep(i, 0, n) {
		cin >> a[i];
	}

	int ans = 0;
	rep(i, 0, n) {
		if (!nuru(a[i])) {
			ans++;
		}
	}
	int ans1 = 0;
	rep(i, 0, 8) {
		ans1 += color[i];
	}
	cout << (ans1 == 0 ? 1 : ans1) << " ";
	ans += ans1;
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;


int ans[1 << 17];
void solve() {
	string s; cin >> s;
	int n = s.length();
	rep(i, n) {
		int le = i;
		while (i + 1 < n&&s[i] == s[i + 1]) {
			i++;
		}
		int len = i - le + 1;
		if (s[i] == 'L') {
			ans[le] += (len + 1) / 2;
			ans[le - 1] += len / 2;
		}
		else {
			ans[i] += (len + 1) / 2;
			ans[i + 1] += len / 2;
		}
	}
	rep(i, n) {
		if (i > 0)cout << " ";
		cout << ans[i];
	}
	cout << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
	//stop
	return 0;
}


Measured memory_bytes: 1104
#include <iostream>
#include <algorithm>
using namespace std;
int v[5];
int main()
{
    cin>>v[1]>>v[2]>>v[3];
    sort(v+1,v+4);
    if(v[1]==v[2]&& v[3]!=v[2])
        cout<<"Yes"<<'\n';
    else if(v[2]==v[3] && v[1]!=v[2])
        cout<<"Yes"<<'\n';
    else cout<<"No"<<'\n';
    return 0;
}


Measured memory_bytes: 256