akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define MOD 1000000007

#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 (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

string s;

signed main()
{
    cin >> s;

    bool ans = true;

    rep(i,s.size()){
        if(i%2==0 && s[i]!='h'){
            ans = false;
            break;
        }else if(i%2==1 && s[i]!='i'){
            ans = false;
            break;
        }
    }

    if(s.size()%2==1){
        ans=false;
    }

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int a = Integer.parseInt(String.valueOf(str.charAt(0)));
		int b = Integer.parseInt(String.valueOf(str.charAt(1)));
		int c = Integer.parseInt(String.valueOf(str.charAt(2)));
		int d = Integer.parseInt(String.valueOf(str.charAt(3)));

		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 2; j++) {
				for (int k = 0; k < 2; k++) {
					int ans = a;
					ans += i == 0 ? b : (-b);
					ans += j == 0 ? c : (-c);
					ans += k == 0 ? d : (-d);

					if (ans == 7) {
						// end
						String out = "";
						out += a;
						out += i == 0 ? "+" : "-";
						out += b;
						out += j == 0 ? "+" : "-";
						out += c;
						out += k == 0 ? "+" : "-";
						out += d + "=7";
						System.out.println(out);
						return;
					}
					
				}
			}

		}
	}

	static double calcDistance(Pair p1, Pair p2) {
		return Math.pow(Math.pow(p1.getX() - p2.getX(), 2) + Math.pow(p1.getY() - p2.getY(), 2), 0.5);
	}

}

class Pair {
	private int x;
	private int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Pair() {

	}

	public Pair(int x, int y) {
		this.x = x;
		this.y = y;
	}

}


Measured memory_bytes: 23764
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize,
        av: [usize; n]
    };
    let mut res = vec![0; n];
    for i in 0..n {
        let a = av[i] - 1;
        res[a] = i + 1;
    }
    println!("{}", res.into_iter().join(" "));
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 3776
#include<stdio.h>
#include<math.h>
int main(){
	int n;
	int i;
	double x1,y1,x2,y2,x3,y3,x4,y4;
	scanf("%d",&n);
	//printf("%llf",1e-10);
	for(i=0;i<n;i++){
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
		if((y2-y1)/(x2-x1)==(y4-y3)/(x4-x3)){
			puts("YES");
		}
		else puts("NO");
	}
	return 0;
}

Measured memory_bytes: 620
public class QQ {
  static void Main(string[] args) {
    for (int first_num = 1; first_num <= 9; first_num++) {
      for (int second_num = 1; second_num <= 9; second_num++) {
        System.Console.WriteLine("{0}x{1}={2}", first_num, second_num, first_num*second_num);
      }
    }
  }
}

Measured memory_bytes: 9048
/*
    Author: aksayushx
*/

#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mod 998244353
using namespace std;
typedef long long ll;
typedef long double ld;

bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
}
ll power(ll x, ll y)  
{  
    ll res = 1; 
    x = x % mod;
    if (x == 0) return 0;
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x)%mod;  
        y = y>>1; 
        x = (x*x)%mod;  
    }  
    return res;  
} 

ll n,w;
vector<ll> wt,v;
vector<vector<ll>> dp;
ll score(ll ind,ll load)
{
    if(ind<0)
    return 0;
    if(load<=0)
    return 0;
    if(dp[ind][load]!=-1)
    return dp[ind][load];
    ll x=score(ind-1,load);
    if(wt[ind]<=load)
    {
        dp[ind][load]=max(x,v[ind]+score(ind-1,load-wt[ind]));
    }
    else
    dp[ind][load]=x;
    return dp[ind][load];
}
void aksayushx()
{
    cin>>n>>w;
    wt.resize(n);
    v.resize(n);
    dp.assign(n,vector<ll>(w+1,-1));
    for(ll i=0;i<n;i++) cin>>wt[i]>>v[i];
    ll ans=score(n-1,w);
    cout<<ans;
    
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    while(test--)
        aksayushx();
    return 0;
}


Measured memory_bytes: 82280
N = int(input())
A = list(map(int, input().split()))
ikutu = [0]*10**5
for i in range(N):
    ikutu[A[i]-1] += 1
Q = int(input())
total = sum(A)
ans = [0]*Q
for i in range(Q):
    B, C = map(int, input().split())
    if ikutu[B-1] == 0:
        ans[i] = total
    else:
        total += (C-B)*ikutu[B-1]
        ikutu[C-1]+= ikutu[B-1]
        ikutu[B-1] = 0
        ans[i] = total
for i in range(Q):
    print(ans[i])
        
    

Measured memory_bytes: 83904
H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

dp = [float("inf")]*H + [0]
ans = float("inf")
for j in reversed(range(H+1)):
    for i in range(N):
        if dp[j] < float("inf"):
            if j - AB[i][0] >= 0:
                dp[j - AB[i][0]] = min(dp[j - AB[i][0]], dp[j] + AB[i][1])
            else:
                ans = min(ans, dp[j] + AB[i][1])

print(min(dp[0], ans))

Measured memory_bytes: 47196
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<cfloat>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P; /* ツ点 */

#define PI (3.1415926535)
#define EPS (1e-10)

//ツ静シツ閉ェ
struct S{
  P p1;
  P p2;
  S(P p,P q) : p1(p), p2(q) {}
};

int ccw(P p0, P p1, P p2){
  P d1 = p1-p0;
  P d2 = p2-p0;
  double dx1 = d1.real(), dx2 = d2.real();
  double dy1 = d1.imag(), dy2 = d2.imag();

  if(dx1*dy2 > dy1*dx2) return  1;//ツ板スツ篠楪計ツ嘉アツづィ
  if(dx1*dy2 < dy1*dx2) return -1;//ツ篠楪計ツ嘉アツづィ
  if((dx1*dx2 < 0) || (dy1*dy2 < 0)) return -1;
  if((dx1*dx1+dy1*dy1) < (dx2*dx2+dy2*dy2)) return 1;
  return 0;
}

bool intersect(const S &s1, const S &s2){
  return ((ccw(s1.p1, s1.p2, s2.p1)
	  *ccw(s1.p1, s1.p2, s2.p2)) <= 0)
       &&((ccw(s2.p1, s2.p2, s1.p1)
	  *ccw(s2.p1, s2.p2, s1.p2)) <= 0);
}

bool inside(P t, P *p, int N){
  int count = 0, j = 0;
  S lt(t, P(DBL_MAX,t.imag()));  

  P pj = p[N-1];
  for(int i=1; i<=N; i++){
    S lp(p[i-1],p[i-1]);
    if(ccw(lt.p1, lt.p2, p[i-1]) != 0){
      if(i == j+1){
	lp.p2 = pj;
	if(intersect(lp,lt)) count++;
      }else if(ccw(lt.p1, lt.p2, p[i-1])*ccw(lt.p1, lt.p2, pj) < 0)
	count++;
      j = i;
      if(j == N) pj = p[0];
      else pj = p[j-1];
    }
  }
  return count & 1 == 1;
}

int main(){
  P p[3];
  P x;
  while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",
	       &p[0].real(),&p[0].imag(),
	       &p[1].real(),&p[1].imag(),
	       &p[2].real(),&p[2].imag(),
	       &x.real(),&x.imag())){
    puts(inside(x,p,3)?"YES":"NO");
  }
  return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
string s;
int h[200010];
int dp[1<<26];

int main(){
	cin>>s;
  int n=s.size();
  rep(i,n){
    h[i+1]=h[i]^(1LL<<(s[i]-'a'));
  }
  rep(i,1<<26)dp[i]=INF;
  dp[0]=0;
  rep(i,n){
    ll a=INF;
    rep(j,26){
      ll tmp=h[i+1]^(1LL<<j);
      minch(a,dp[tmp]+1);
    }
    minch(a,dp[h[i+1]]+1);
    minch(dp[h[i+1]],a);
  }
  if(h[n]==0)cout<<1<<endl;
  else cout<<dp[h[n]]<<endl;
	return 0;
}


Measured memory_bytes: 263556
#include <stdio.h>
#include <string.h>

int main(void) {
	char s[10010];
	int n;
	scanf("%d %s", &n, s);
	int l = strlen(s);
	for (int i = 0;i < l;i++) {
		int x = s[i] - 'A';
		x = (x + n) % 26;
		putchar('A' + x);
	}
	putchar('\n');

	return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 ,-1};
signed main(){
    int N;
    string S;
    cin >> N >> S;
    map<pair<string,string>,int> Mp[2];
    reverse(S.begin()+N,S.end());
    //cabaacba->caba abca
    //左の赤は左から、右の赤は右から
    //左半分の選び方
    for(int bit = 0; bit < (1 << N); bit++) {
        string T = "",R = "";
        for(int i = 0; i < N; i++) {
            if(1 & (bit >> i)) {
                T+=S[i];
            }
            else {
                R+=S[i];
            }
        }
        Mp[0][{T,R}]++;
    }
    //右半分の選び方
    for(int bit = 0; bit < (1 << N); bit++) {
        string T = "",R = "";
        for(int i = 0; i < N; i++) {
            if(1 & (bit >> i)) {
                T+=S[i+N];
            }
            else {
                R+=S[i+N];
            }
        }
        Mp[1][{T,R}]++;
    }
    int ans = 0;
    for(auto p:Mp[0]) {
        ans+=p.second*Mp[1][p.first];
    }
    cout << ans << endl;
}


Measured memory_bytes: 89536
let input = readLine()!.split(separator: " ").map { Int($0)! }

let A = input[0]
let B = input[1]
let C = input[2]
let D = input[3]

let takahashi = C / B + (C % B > 0 ? 1 : 0)
let aoki = A / D + (A % D > 0 ? 1 : 0)
print(aoki >= takahashi ? "Yes" : "No")


Measured memory_bytes: 8152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<int>> vv;
typedef pair<int, int> P;
typedef tuple<int, int, int> tp;

// input
int N, Q;
vector<tp> XST;
vector<int> D;

vector<int> ans;
set<P> ds;


void input() {
    cin >> N >> Q;
    XST = vector<tp>(N);
    rep(i, N) {
        int s, t, x;
        cin >> s >> t >> x;
        XST[i] = tp(x, s, t);
    }
    D = vector<int>(Q);
    rep(i, Q) cin >> D[i];
}


int main() {
    input();
    sort(XST.begin(), XST.end());
    rep(i, Q) ds.insert(P(D[i], i));
    ans = vector<int>(Q, -1);
    rep(i, N) {
        int x, s, t;
        tie(x, s, t) = XST[i];
        auto itr = ds.lower_bound(P(s - x, 0));
        while (itr != ds.end()) {
            if (itr->first >= t - x) break;
            ans[itr->second] = x;
            ds.erase(itr++);
        }
    }
    rep(i, Q) printf("%d\n", ans[i]);
}


Measured memory_bytes: 16432
fun main(args: Array<String>) {
    var N = readLine()!!.toInt()
    var tr = (1..N).map{
                     var (tt,xx,yy) = readLine()!!.split(" ").map(String::toInt)
                     Triple(tt,xx,yy)
                }
    var t = 0
    var x = 0
    var y = 0
    var flag = false
    tr.map{
        var (t_,x_,y_) = it
        var d = Math.abs(x_ - x) + Math.abs(y_ - y)
        var dt = t_ - t
        if(d<=dt && dt%2 == d % 2) flag = true
        else flag = false
        t = t_
        x = x_
        y = y_
    }
    if(flag) println("Yes")
    else println("No")
}



Measured memory_bytes: 56512
#include<stdio.h>

int main()
{
	int h, w, i, j;
	scanf("%d %d", &h, &w);
	while(h && w)
	{
		for (i = 0; i < h; i++)
		{
			for (j = 0; j < w; j++)
			{
				if((i + j) % 2)
					printf(".");
				else
					printf("#");
			}
			printf("\n");
		}
		printf("\n");
		scanf("%d %d", &h, &w);
	}

	return 0;
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

int main() {
    #ifdef LOCAL
    assert(freopen("b.in", "r", stdin));
    #else
    #endif
    int n, a, b;
    string s;
    cin >> n >> a >> b >> s;
    int cur = 0;
    int cur2 = 0;
    forn (i, n) {
        if (s[i] == 'a') {
            if (cur >= a + b) {
                cout << "No\n";
            } else {
                ++cur;
                cout << "Yes\n";
            }
        } else if (s[i] == 'b') {
            if (cur >= a + b || cur2 >= b) {
                cout << "No\n";
            } else {
                ++cur, ++cur2;
                cout << "Yes\n";
            }
        } else
            cout << "No\n";
    }
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define n 500000
#define mem(arr) memset(arr, 0, sizeof(arr))
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
void solve();
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int times = 1;
//	cin >> times;
	for(int i=0; i<times; i++)
	{
		solve();
		cout << '\n';
	}
	return 0;
}

int a, b, c, d, e, f, g, h;
int arr[n + 50], arr1[n + 50], arr2[n + 50];

//type here

void solve()
{
	string str; cin >> str;
	for(int i=0; i<str.size(); i++)
		cout << 'x';
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int a[3];

signed main() {
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if ((a[1] - a[0]) % 2 == 0) {
		cout << (a[2] - a[1]) + (a[1] - a[0]) / 2 << endl;
	}
	else {
		cout << 1 + (a[2] - a[1] + 1) + (a[1] - (a[0] + 1)) / 2 << endl;
	}
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 256
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <numeric>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mod = 1000000007;

#define bs(n) (1ll<<(ll)(n))
#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define rrep(i, n) for(ll (i) = 1;(i) <= (n);(i)++)

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int s = 0;
    s += min(k, a);
    k -= s;
    if (k != 0) {
        k -= min(k, b);
        if (k != 0) {
            s -= min(k, c);
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	ll n;
	cin >> n;
	int len = 1;
	ll val = 0;	
	while(26*(val+1) < n){
		val = 26 * (val+1);
		++len;
	}
	n-=(val+1);
	string res="";
	rep(i,0,len){
		res += 'a' + (n % 26);
		n/=26;
	}
	reverse(all(res));
	cout << res << '\n';
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<a;i++)
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
    long long int h;
    cin>>h;
    long long int ans=0;
    long long int power=1;
    while(h!=0)
    {
        ans+=power;
        h/=2;
        power*=2;
    }
    cout<<ans<<endl;
    return 0;
}

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

int n, A, B, C, l[9], INF = 1e9;

int rec(int i, int a, int b, int c)
{
    if (i == n)
    {
        if (!a || !b || !c)
            return INF;
        return abs(a - A) + abs(b - B) + abs(c - C);
    }

    int res = rec(i + 1, a, b, c);
    return min({rec(i + 1, a, b, c), rec(i + 1, a + l[i], b, c) + (a ? 10 : 0), rec(i + 1, a, b + l[i], c) + (b ? 10 : 0), rec(i + 1, a, b, c + l[i]) + (c ? 10 : 0)});
}

int main()
{
    cin >> n >> A >> B >> C;
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    cout << rec(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (1000000000)
#define linf (1000000000000000000ll)
#define mod (1000000007)

int n;
char s[111111];
int dp[111111][15];

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	scanf("%s",s);
	n=strlen(s);
	//reverse(s,s+n);
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	FOR(i,0,n){
		if(s[i]!='?'){
			FOR(j,0,15){
				dp[i+1][(j*10+(int)(s[i]-'0'))%13]+=dp[i][j];
				if(dp[i+1][(j*10+(int)(s[i]-'0'))%13]>=mod)dp[i+1][(j*10+(int)(s[i]-'0'))%13]-=mod;
			}
		}
		else {
			FOR(k,0,10){
				FOR(j,0,15){
					dp[i+1][(j*10+k)%13]+=dp[i][j];
					if(dp[i+1][(j*10+k)%13]>=mod)dp[i+1][(j*10+k)%13]-=mod;
				}
			}
		}
	}
	cout<<dp[n][5]<<endl;
	
	
	return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> res(n), done(n);
    int cor = 0, pen = 0;
    for (int i = 0; i < m; i++) {
        int p;
        string s;
        cin >> p >> s, p--;
        if (!done[p]) {
            if (s == "AC") {
                pen += res[p], done[p] = 1, cor++;
            } else {
                res[p]++;
            }
        }
    }

    cout << cor << " " << pen << endl;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.function.LongSupplier;

public class Main{ // 

	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

	static LongSupplier now = new LongSupplier() {
		private long t = System.currentTimeMillis();

		@Override
		public long getAsLong() {
			long a = t;
			t = System.currentTimeMillis();
			long ans = t - a;
			return ans;
		}
	};

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	static int tr(Object... objects) {
		System.out.println("tr:" + Arrays.deepToString(objects));
		return 0;
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		// assert solve(1) == 1;

		int n = cin.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < a.length; i++)
			a[i] = cin.nextInt();

		now.getAsLong();

		int ans = solve(n, a);
		cout.println(ans);

		assert 0 == tr("elapsed", now.getAsLong());
	}

	private static int solve(int n, int[] a) {
		int ans = 0;
		for (int i = 1; i < n; i++) {
			if (a[i - 1] == i && a[i] == i + 1) {
				ans += 1;
				int t = a[i - 1];
				a[i - 1] = a[i];
				a[i] = t;
			}
		}
		for (int i = 0; i < n; i++) {
			if (a[i] == i + 1) {
				ans += 1;
			}
		}
		return ans;
	}

}


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

import heapq as hp
from collections import Counter


def main():

    N = int(input())
    A = list(map(int, input().split()))
    graph = [[] for _ in range(1<<N)]

    for l in range(N):
        for n in range(1<<l):
            graph[n].append(n+(1<<l))

    C = Counter(A)
    Keys = sorted(C.keys(), reverse=True)
    
    q = [(-len(graph[0]), 0)]
    for key in Keys:
        num = C[key]
        if num > len(q):
            return False
        use = []
        for _ in range(num):
            _, p = hp.heappop(q)
            use.append(p)
        for p in use:
            for np in graph[p]:
                hp.heappush(q, (-len(graph[np]), np))

    return True

if __name__ == "__main__":
    print("Yes" if main() else "No")

Measured memory_bytes: 124856
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll,ll>;
#define rep(i,n) for(ull i=0;i<(ull)n;++i)
const ull INF = 999999999999999;

vector<vector<ll>> ca;
vector<ll> cst;
ll n,m,x;

void dfs( ll cnt ,vector<ll> now, ll mny ){
  if( cnt == n ){
    sort(now.begin(),now.end());
    if( now.at(0) >= x ){
      cst.push_back(mny);
    }
    return;
  }

  dfs(cnt+1,now,mny);
  mny += ca.at(cnt).at(0);
  rep(i,m) now.at(i) += ca.at(cnt).at(i+1);
  dfs(cnt+1,now,mny);
}

int main(){
  cin >> n >> m >> x;
  ca.resize(n);
  rep(i,n) ca.at(i).resize(m+1);

  rep(i,n){
    rep(j,m+1){
      scanf("%lld",&( ca.at(i).at(j) ) );
    }
  }

  vector<ll> now(m,0);
  dfs(0,now,0);
  
  if( cst.size() == 0 ){
    cout << -1 << endl;
    return 0;
  }
  sort(cst.begin(),cst.end());
  cout << cst.at(0) << endl;

  
  return 0;
}

Measured memory_bytes: 3744
#include <iostream>
#include <algorithm>
using namespace std;
 
int main()
{
    int x;
    long long ans = 0;
    cin >> x;
    ans += 1000 * (x / 500);
    x %= 500;
    ans += 5 * (x / 5);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h> 
int main(void)
{
  int a, b, r, tmp;
  scanf("%d%d", &a,&b);
 
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  printf("%d\n", b);
 
  return 0;
}



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

int po(int k){
	int i=0, ak=abs(k);
	if(ak>0){
		while(ak%2<1){
			ak /= 2;
			++i;
		}
		return i;
	}
	else return 100;
}
int main() {
	int A, B, C; cin >> A >> B >> C;
	if(A%2 || B%2 || C%2) cout << 0 << endl;
	else if(A==B && B==C) cout << -1 << endl;
	else cout << min(po(A-B), po(B-C)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#if LOCAL
#include "../cout.hpp"
#endif
using namespace std;

#define forn(i,n) for (unsigned i = 0; i < n; ++i)
#define foreach(a) for (auto it = a.begin(); it != a.end(); ++it)
#define foreach_r(a) for (auto it = a.rbegin(); it != a.rend(); ++it)

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

    int n;
    cin >> n;

    map<int, int> m;

    forn(i, n) {
	int a;
	cin >> a;
	m.insert(make_pair(a, 0)).first->second++;
    }

    int bigside = -1;
    int smallside = -1;
    foreach_r(m) {
	if(it->second > 1) {
	    if(bigside == -1) {
		bigside = it->first;
		if(it->second > 3) {
		    smallside = it->first;
		    break;
		}
	    } else {
		smallside = it->first;
		break;
	    }
	}
    }
    if(smallside == -1) {
	cout << 0;
    } else {
	cout << ((unsigned long long)bigside * smallside);
    }
}


Measured memory_bytes: 4992
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll n;
vector<vector<P>>v;
bool check(int bit) {
	for (int i = 0; i < n; i++) {
		if (!(bit & (1 << i)))continue;

		for (P id : v[i]) {
			int x = id.first;
			int y = id.second;

			if (y == 1 && !(bit & (1 << x))) {
				return false;
			}

			if (y == 0 && (bit & (1 << x))) {
				return false;
			}
		}
	}
	return true;
}
int main(void) {
	cin >> n;
	v.resize(n);
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		v[i].resize(a);
		for (int j = 0; j < a; j++) {
			cin >> v[i][j].first >> v[i][j].second;
			--v[i][j].first;
		}
	}

	int res = 0;
	for (int bit = 0; bit < (1 << n); bit++) {

		if (check(bit)) {
			int count = 0;
			for (int i = 0; i < n; i++) {
				if (bit & (1 << i)) {
					count++;
				}
			}
			res = max(res, count);
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3552
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int N;
	cin >> N;
	if (N >= 100000) cout << 90909;
	else if (N >= 10000)cout << N - 10000 + 909 + 1;
	else if (N >= 1000)cout << 909;
	else if (N >= 100)cout << N - 100 + 9 + 1;
	else if (N >= 10)cout << 9;
	else cout << N;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int calc(int nowTime, int s, int f){
   if(nowTime <= s) return s - nowTime; 
   else {
       int div = (nowTime + f-1)/f;
       return (div*f - nowTime);
   }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    vector<int> C(N-1), S(N-1), F(N-1);
    for(int i = 0; i < N-1; ++i) cin >> C[i] >> S[i] >> F[i];
    for(int j = 0; j < N; ++j){
        int nowTime = 0;
        for(int i = j; i < N-1; ++i){
            nowTime += calc(nowTime, S[i], F[i]);
            nowTime += C[i];
        }
        cout << nowTime << '\n';
    }
    return 0;
}

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

int main(){
  int n,k,h[100010],dp[100010],t;
  cin>>n>>k;
  fr(i,n) cin>>h[i];
  dp[0]=0;
  for(int i=1;i<n;i++){
    t=dp[i-1]+abs(h[i]-h[i-1]);
    for(int j=i-2;j>=i-k&&j>=0;j--){
      t=min(t,dp[j]+abs(h[i]-h[j]));
    }
    dp[i]=t;
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,x,y;
  cin >> A >> B >> C >> x >> y;
  //枚数の多いほうがA円X枚
  if(x < y){
    int tmp = A;
    A = B;
    B = tmp;
    tmp = x;
    x = y;
    y = tmp;
  }
  
  bool ab,ac,bc;
  ab = ac = bc = false;
  if(A+B > 2*C) ab = true;
  if(A > 2*C) ac = true;
  if(B > 2*C) bc = true;
  if(ab == true){
    if(ac == true) cout << 2*C*x << endl;
    else cout << 2*C*y + A*(x-y) << endl;
  }else{
    cout << A*x + B*y << endl;
  }
}


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

#define ll long long

using namespace std;

const int N = (int)2e5 + 7;

int n, m, k;
int a[N], b[N];
ll pref[N];

main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (i)
      pref[i] = pref[i - 1];
    pref[i] += a[i];
  }
  
  for (int i = 0; i < m; i++) 
    scanf("%d", &b[i]);
  
  ll sum = 0;
  int ans = 0;
  for (int i = 0; i <= m && sum <= k; i++) {
    int pos = upper_bound(pref, pref + n, k - sum) - pref - 1;
    ans = max(ans, i + pos + 1);
    // cout << i + pos + 1 << ' ' << pos << '\n';
    sum += b[i];
  } 
  cout << ans << '\n';
}


Measured memory_bytes: 6788
#include <iostream>

using namespace std;

int main(){
	char s[3], t[3];
	cin >> s[0] >> s[1] >> s[2];
	cin >> t[0] >> t[1] >> t[2];
	int counter = 0;
	for(int i = 0; i < 3; i++){
		if(s[i] == t[i]){
			counter += 1;
		}
	}
	cout << counter;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18

void solve_abc_a() {
	ll n, m;
	ll x, y;
	//ll a, b, d;
	ll c;
	//char c;
	ll h, w;
	ll k;
	string s, t;
	ll l_ans = 0;
	string s_ans = "NG";

	cin >> n;
	V l(n);
	rep(i, n) cin >> l[i];

	rep(i, n)rep2(j, i+1, n)rep2(k, j+1, n) {
		if (l[i] + l[j] > l[k] &&
			l[i] + l[k] > l[j] &&
			l[j] + l[k] > l[i] &&
			l[i] != l[j] && l[j] != l[k] && l[k] != l[i]) {
			l_ans++;
		}
	}

	cout << l_ans << "\n";

	return;
}


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

	solve_abc_a();

	return 0;
}


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

int main(){
	int a,b; cin>>a>>b;
	int ans=0;
	if(a>b){ans+=a; a-=1;}
	else {ans+=b; b-=1;}
	if(a>b){ans+=a; a-=1;}
	else {ans+=b; b-=1;}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
int main(){
	ll n;
	cin>>n;
	vector<ll> h(n),dp(n);
	for(ll i=0;i<n;i++){
		cin>>h[i];
	}
	
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);
	
	for(ll i=2;i<n;i++){
		dp[i] = min(abs(h[i-1]-h[i])+dp[i-1],abs(h[i-2]-h[i])+dp[i-2]);
		
	}
	cout<<dp[n-1]<<"\n";
	
}

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

char a, b;

int main(){
    cin>>a>>b;
    if((a == 'H' && b == 'H' )||(a == 'D' && b == 'D' )) cout<<'H'<<endl;
    else cout<<'D'<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int m,f[10],d[]={0,9,26,50,80,115,154,196,240,285,330};
int g(int a,int b){//printf("%d %d\n",a,b);
  int i,s=0;
  if(m>b+d[a]||b>m)return 0;
  if(b>m)return 0;
  if(a==0)return b-m?0:1;
  for(i=0;i<10;i++){
    if(f[i])continue;
    f[i]=1;
    s+=g(a-1,b+i*a);
    f[i]=0;
  }
  return s;
}
int main(){
  int n,i,j,s;
  while(~scanf("%d %d",&n,&m))printf("%d\n",g(n,0));
  return 0;
}

Measured memory_bytes: 600
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        final int N = Integer.parseInt(sc.next());
        String[] ss = new String[N];
        
        for (int i = 0; i < N; i++) {
            String city = sc.next();
            int point = Integer.parseInt(sc.next()) + 1;
            int index = i + 1;
            ss[i] = city + " " + (1.0 / point) + " " + index;
        }
        Arrays.sort(ss);

        for (String s : ss) {
            out.println(s.split(" ")[2]);
        }
        
        out.flush();
    }
}

Measured memory_bytes: 21844
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

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

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

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

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

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, parser) => {
        $next
    };

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        n: isize, m: isize,
    }

    if n == 1 && m == 1 {
        println!("1");
        return;
    }

    let corner = min(n, 2) * min(m, 2);
    let edge =
        max(n - 2, 0) * if m == 1 { 1 } else { 2 } + max(m - 2, 0) * if n == 1 { 1 } else { 2 };
    let center = n * m - corner - edge;
    if n == 1 || m == 1 {
        println!("{}", max(0, edge));
    } else {
        println!("{}", center);
    }
}


Measured memory_bytes: 2112
import static java.lang.System.*;

import java.util.Scanner;

class Main {
    public static void main(String[]args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt(); // 4
        int c = sc.nextInt(); // 5
        int sum,total = 0;
        int index[][] = new int[r + 1][c + 1];
        for(int a = 0; a < r; a++) {
        	sum = 0;
        	for(int b = 0; b < c; b++) {
        		int x = sc.nextInt();
        		index[a][b] = x;
        		sum += x;
        		if(b == c - 1) {
        			index[a][c] = sum;
        			sum = 0;
        		}
        	}
        } // c 5  r 4
        sum = 0;
        for(int a = 0; a < c; a++) {
        	for(int b = 0; b < r; b++) {
        		sum += index[b][a];
        		if(b == r - 1) {
        			index[b + 1][a] = sum;
        			total += sum;
        			sum = 0;
        		}
        	}
        }
        index[r][c] = total;
        for(int a = 0; a <= r; a++) {
        	for(int b = 0; b <= c; b++) {
        		if(b == c) {
        			out.println(index[a][b]);
        		}else {
        			out.print(index[a][b] + " ");
        		}
        	}
        }
    }
}


Measured memory_bytes: 42008
#include<stdio.h>
#include<math.h>

struct Point{
    double x,y;
};

void koch(int n, struct Point a, struct Point b){
    if(n==0) return;
   struct Point s, t, u;
    double th = M_PI * 60.0 / 180.0; // 度からラジアンへ単位を変換
    
    s.x=(2.0* a.x + 1.0*b.x) /3.0;
    s.y=(2.0* a.y + 1.0*b.y) /3.0;
    t.x=(1.0* a.x + 2.0*b.x) /3.0;
    t.y=(1.0* a.y + 2.0*b.y) /3.0;
    u.x=(t.x -s.x) * cos(th)- (t.y-s.y) * sin(th) + s.x;
    u.y=(t.x -s.x) * sin(th)+ (t.y-s.y) * cos(th) + s.y;
    
    koch(n-1, a,s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n-1, s,u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n-1, u,t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n-1, t,b);
}

int main(){
   struct Point a,b;
    int n;
    scanf("%d", &n);
    
    a.x=0;
    a.y=0;
    b.x=100;
    b.y=0;
    
 printf("%.8f %.8f\n", a.x, b.y);
    koch(n, a,b);
    printf("%.8f %.8f\n", b.x, b.y);
    
    return 0;
}



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

if S[K-1] == 'A':
    S[K-1] = 'a'
elif S[K-1] == 'B':
    S[K-1] = 'b'
elif S[K-1] == 'C':
    S[K-1] = 'c'
    
print("".join(S))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int main(){
  int S[100],top=0;
  string s;
  while(cin>>s){
    if(s=="+") S[--top]+=S[top+1];
    else if(s=="-") S[--top]-=S[top+1];
    else if(s=="*") S[--top]*=S[top+1];
    else S[++top]=atoi(s.c_str());
  }
  cout<<S[top]<<endl;
  return 0;
}

Measured memory_bytes: 3160
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int mod = 998244353;
const int N = 1200000;
int cnt[N], n;
int binpow(int x, int y){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        y /= 2;
        x = x * x % mod;
    }
    return res;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n >> mod;
    string s;
    cin >> s;
    int ans = 0;
    int cs = 0;
    for (int i = 0; i < n; i++){
        int x = s[i] - '0';
        cs = (10 * cs + x) % mod;
        int z = cs * binpow(10, N * (mod - 1) - i) % mod;
        ans += cnt[z];
        cnt[z]++;
        if (z == 0) ans++;
    }
    if (mod == 2 || mod == 5){
        ans = 0;
        for (int i = 0; i < n; i++){
            int x = s[i] - '0';
            if (x % mod == 0) ans += (i + 1);
        }
    }
    cout << ans;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;	
	if(a==0||a<0&&b>0||b==0)
		cout<<"Zero"<<endl;
	if(a<0&&b<0&&(abs(a)-abs(b))%2==0)
		cout<<"Negative"<<endl;
	if(a>0&&b>0||a<0&&b<0&&(abs(a)-abs(b))%2==1)
		cout<<"Positive"<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}


//ここから。
int main(){
    int N,M;
    cin >> N >> M;
    vector<vector<int>> dist(N,vector<int> (N,INF));
    vector<vector<bitset<1000>>> memo(N,vector<bitset<1000>>(N,0));
    
    rep(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        dist[a][b] = c;
        dist[b][a] = c;
        memo[a][b][i] = 1;
        memo[b][a][i] = 1;
    }
    rep(i,N) dist[i][i] = 0;
    rep(k,N)
        rep(j,N)
            rep(i,N){
                if(dist[j][i] > dist[j][k] + dist[k][i]){
                    dist[j][i] = dist[j][k] + dist[k][i];
                    memo[j][i] = memo[j][k] | memo[k][i];
                }
            }
    
    bitset<1000> ans = 0,test = 0;
    rep(i,N){
        rep(j,N){
            ans |= memo[i][j];
        }
    }
    int cnt = ans.count();
    cout << M - cnt << endl;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    auto IN = [&](int x){
        return 0<=x && x<n;
    };

    ll ans = 0;
    for(int w=1; w<n; ++w){
        int a = n-1, b = a-w;
        int l=0,r=n-1;
        ll t=0;
        unordered_set<int> vis;
        while(b>0 && l!=r && IN(l) && IN(r) && !vis.count(l) && !vis.count(r)){
            t += s[l];
            t += s[r];
            ans = max(ans, t);
            vis.insert(l);
            vis.insert(r);

            l += w;
            r -= w;
            b -= w;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5168
#include <cstdio>
#include <utility>
#include <cctype>
#include <deque>
#include <numeric>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n'&&c!=EOF;)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

int j(int n, int k) {
	if (n == 1)
		return 0;
	else if (k == 1)
		return n - 1;
	else if (n < k)
		return (j(n - 1, k) + k) % n;
	else {
		int r = j(n - n / k, k) - n % k;
		return r < 0 ? r + n : r + r / (k - 1);
	}
}

int main() {
	for (int n, k, m; n = in, k = in, m = in;)
		outl((j(n - 1, k) + m) % n + 1);
}


Measured memory_bytes: 2732
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Test | diff Test.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Test.cpp && ./a.out

/*

 6/22/2020

 21:47-

 */

const int MAX_N=1e6+1;
int N,M;

VI G[MAX_N];
void solve() {
  VI ind(N,0);
  REP(u,N) {
    FORR(v,G[u]) ind[v]++;
  }

  queue<int> Q;
  VI res(N,-1);
  REP(u,N) if(ind[u]==0) Q.emplace(u);
  while(SZ(Q)) {
    int u=Q.front(); Q.pop();
    FORR(v, G[u]) {
      ind[v]--;
      if(ind[v]==0) res[v]=u,Q.emplace(v);
    }
  }
  assert(count(ALL(res),-1)==1);
  REP(i,N) cout<<res[i]+1<<endl;
}

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

  cin>>N>>M;
  REP(i,N+M-1) {
    int u,v; cin>>u>>v;
    --u,--v;
    G[u].push_back(v);
  }
  solve();

  return 0;
}


Measured memory_bytes: 30584