akhauriyash/Code-Regression huggingface dataset:
def main():

    N_machi, K_teleport = map(int, input().split())
    to_teleport = list(map(int, input().split()))

    visited_city = [1]
    order = [-1 for i in range(N_machi + 1)]
    order[1] = 0
    next_city = 1
    
    for i in range(N_machi):
        next_city = to_teleport[next_city - 1]
        tmp = order[next_city]
        
        if (tmp == -1):
            visited_city.append(next_city)
            order[next_city] = i + 1
        else:
            break
    
    first = order[next_city]
    len_loop = len(visited_city) - first
    
    if (K_teleport < first):
        ans = visited_city[K_teleport]
    else:
        mod = (K_teleport - first) % len_loop
        ans = visited_city[first + mod]
    
    print(ans)
        

if __name__ == '__main__':
    main()

Measured memory_bytes: 33384
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> v(N);

	for (int i = 0; i < N; i++) {
		cin >> v.at(i);
	}
	sort(v.begin(), v.end());

	int sum = 0;
	for (int i = v.size() - 1; i >= 0; i--) {
		int n = N - K - 1;
		if (n == i) break;
		sum += v.at(i);
	}

	cout << sum << endl;
}

Measured memory_bytes: 3612
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , a[N] , q ;
int tony[10] ;
int main ( ){
cin >> n ;
int last =1;
int cnt =0 ;
while ( n ){

if ( last == -1 ){ last = n%10 ; cnt = 1 ; n/=10; continue;}
if ( last == n%10 ){
    cnt++ ;
}else {
  cnt = 1 ;
  last = n%10 ;
}
n/= 10 ;
if ( cnt == 3 ) {
    cout <<"Yes";
    return 0;
}
}
cout << "No";
return 0 ;
}


Measured memory_bytes: 384
from collections import deque

n,p=map(int ,input().split())
que=deque([])

for i in range(n):
    name,time=input().split()
    time=int(time)
    que.append([name,time])

t=0
while len(que)>0:
    atop=que.popleft()
    spend=min(atop[1],p)
    atop[1]-=spend
    t+=spend
    if(atop[1]==0):
        print(atop[0],t)
    else:
        que.append(atop)

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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;

#define MOD 1000000007
#define times(n) rep(_idx, n)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mk make_pair
#define out(x) cout << (x) << endl;
#define DU(x) cerr << #x << " = " << (x) << endl;

template<typename _Ty>ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "[]";return ostr;}ostr << "[" << v.front();for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}ostr << "]";return ostr;}

int main() {
    string S, T;
    cin >> S >> T;
    int ans = 0;
    rep(i, 3) if (S[i] == T[i]) ans++;
    out(ans);
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
P = list(map(int, input().split()))

m = prev = sum(P[:k])
s = 0
for i in range(1, n - k + 1):
    tmp = prev - P[i - 1]+ P[i + k - 1]
    prev = tmp
    if tmp > m:
        s = i
    m = max(tmp, m)

ans = 0
d = dict()
for i in range(s, s + k):
    p = P[i]
    if p not in d.keys():
        tmp = sum(range(p + 1)) / p
        ans += tmp
        d[p] = tmp
    else:
        ans += d[p]
print(ans)

Measured memory_bytes: 32296
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string S;
    cin >> S;

    int cnt = 0;
    REP(i, S.size() / 2) {
        if (S[i] != S[S.size() - i - 1]) cnt++;
    }

    print(cnt);
    
}


Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
using namespace std;
int main(void){
   int h,w,dx[8]={0,1,1,1,0,-1,-1,-1},dy[8]={1,1,0,-1,-1,-1,0,1};
   cin>>h>>w;
   int ans[h][w];
   for(int i=0;i<h;i++){
       for(int j=0;j<w;j++){
           char c;
           scanf(" %c",&c);
           if(c=='.')ans[i][j]=0;
           else ans[i][j]=-1;
       }
   }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(ans[i][j]==0){
                for(int k=0;k<8;k++){
                    if(j+dx[k]>=0&&j+dx[k]<w&&i+dy[k]>=0&&i+dy[k]<h&&ans[i+dy[k]][j+dx[k]]==-1)ans[i][j]++;
                }
            }
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(ans[i][j]==-1)cout<<'#';
            else cout<<ans[i][j];
        }
        cout<<endl;
    }
}

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

using namespace std;

typedef long long ll;
#define INF (1<<29)
#define INFF 0x7fffffff
#define LINF (1ll<<60)
#define LINFF 0x7fffffffffffffff
#define PI 3.14159265359
#define _fi(n) for(int i = 0;i < n;i++)
#define _fj(n) for(int j = 0;j < n;j++)
#define _fk(n) for(int k = 0;k < n;k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define YESNO(ans) cout << (ans?"YES":"NO") << endl;
#define pqueue priority_queue
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'

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

    int n, k;cin>>n>>k;
    ll r, s, p;cin>>r>>s>>p;
    string t;cin>>t;
    string f(n, 'x');

    ll ans = 0;
    for(int i = 0;i < k;i++){
        if (t[i] == 'r') ans += p, f[i] = 'p';
        if (t[i] == 's') ans += r, f[i] = 'r';
        if (t[i] == 'p') ans += s, f[i] = 's';
    }

    for(int i = k;i < n;i++){
        if (t[i] == 'r'){
            if (f[i-k] != 'p'){
                ans += p;
                f[i] = 'p';
            }
        }
        if (t[i] == 's'){
            if (f[i-k] != 'r'){
                ans += r;
                f[i] = 'r';
            }
        }
        if (t[i] == 'p'){
            if (f[i-k] != 's'){
                ans += s;
                f[i] = 's';
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: usize = read();
    let mut a: Vec<i32> = read_vec();
    let mut max = a[0];
    let mut idmax = 0;
    let mut min = a[0];
    let mut idmin = 0;
    for i in 1..n {
        let t = a[i];
        if t > max {
            max = t;
            idmax = i;
        }
        if t < min {
            min = t;
            idmin = i;
        }
    }

    println!("{}", 2 * n - 1);

    if max + min > 0 {
        for i in 0..n {
            a[i] += max;
            println!("{} {}", idmax + 1, i + 1);
        }
        for i in 1..n {
            a[i] += a[i - 1];
            println!("{} {}", i - 1 + 1, i + 1);
        }
    } else {
        for i in 0..n {
            a[i] += min;
            println!("{} {}", idmin + 1, i + 1);
        }
        for i in (0..n - 1).rev() {
            a[i] += a[i + 1];
            println!("{} {}", i + 1 + 1, i + 1);
        }
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<algorithm>
using namespace std;
long long h[1100];
char s[1100];
char t[1100];
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		for(int i=0;i<b;i++)h[i]=(1LL<<a)-1;
		long long val=0;
		for(int i=0;i<c;i++){
			scanf("%s%s",s,t);
			long long key=0;
			for(int j=0;j<a;j++){
				if(s[j]=='1')key+=(1LL<<j);
			}
			val^=key;
			for(int j=0;j<b;j++){
				if(t[j]=='1'){
					h[j]&=val;
				}else {
					h[j]&=~val;
				}
			}
		}
		for(int i=0;i<b;i++){
			if(__builtin_popcountll(h[i])>1)printf("?");
			else{
				int at=0;
				for(int j=0;j<a;j++)if(h[i]==(1LL<<j))at=j;
				if(at<10)printf("%d",at);
				else printf("%c",'A'+at-10);
			}
		}
		printf("\n");
	}
}

Measured memory_bytes: 1048
from bisect import bisect_right

N=int(input())
S=input()
pos=[[] for _ in range(10)]
ans=0
for i in range(N):
  pos[int(S[i])].append(i)
for i in range(10**3):
  digit1, digit2, digit3=i//100, (i%100)//10, i%10
  if not pos[digit1] or not pos[digit2] or not pos[digit3]:
    continue
  pos1=pos[digit1][0]
  if pos1>=pos[digit2][-1]:
    continue
  idx2=bisect_right(pos[digit2], pos1)
  if idx2>=len(pos[digit2]):
    continue
  pos2=pos[digit2][idx2]
  if pos2>=pos[digit3][-1]:
    continue
  idx3=bisect_right(pos[digit3], pos2)
  if idx3>len(pos[digit3]):
    continue
  else:
    ans+=1
print(ans)

Measured memory_bytes: 39920
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll H, W, N=0;
    ll a[600][600], b[600][600];
    cin>>H>>W;
    rep(i, H) rep(j, W) cin>>a[i][j], b[i][j]=a[i][j];
    rep(i, H) rep(j, W){
        if(b[i][j]%2==1 && j<W-1){
            N++;
            b[i][j]--;
            b[i][j+1]++;
        }
        if(b[i][j]%2==1 && i<H-1 && j==W-1){
            N++;
            b[i][j]--;
            b[i+1][j]++;
        }
    }
    cout<<N<<endl;
    rep(i, H) rep(j, W){
        if(a[i][j]%2==1 && j<W-1){
            cout<<i+1<<sp<<j+1<<sp<<i+1<<sp<<j+2<<endl;
            a[i][j]--;
            a[i][j+1]++;
        }
        if(a[i][j]%2==1 && i<H-1 && j==W-1){
            cout<<i+1<<sp<<j+1<<sp<<i+2<<sp<<j+1<<endl;
            a[i][j]--;
            a[i+1][j]++;
        }
    }
    return 0;
}


Measured memory_bytes: 7680
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int vis[110][110][110];
struct node
{
	int a,b,c,s;
	node (int aa,int bb,int cc,int ss):a(aa),b(bb),c(cc),s(ss){}
};
int bfs(int a,int b,int c)
{
	queue<node>q;
	q.push(node(a,b,c,0));
	while(!q.empty())
	{
		node t=q.front();
		q.pop();
		if(t.a==t.b&&t.b==t.c)
			return t.s;
		int x,y,z;
		x=t.a+2;y=t.b;z=t.c;
		if(x<110&&y<110&&z<110&&vis[x][y][z]==0)
		{
			q.push(node(x,y,z,t.s+1));
			vis[x][y][z]=1;
		}
		x=t.a;y=t.b+2;z=t.c;	
		if(x<110&&y<110&&z<110&&vis[x][y][z]==0)
		{
			q.push(node(x,y,z,t.s+1));
			vis[x][y][z]=1;
		}
		x=t.a;y=t.b;z=t.c+2;
		if(x<110&&y<110&&z<110&&vis[x][y][z]==0)
		{
			q.push(node(x,y,z,t.s+1));
			vis[x][y][z]=1;
		}if(x<110&&y<110&&z<110&&vis[x][y][z]==0)
		{
			q.push(node(x,y,z,t.s+1));
			vis[x][y][z]=1;
		}	
		x=t.a+1;y=t.b+1;z=t.c;
		if(x<110&&y<110&&z<110&&vis[x][y][z]==0)
		{
			q.push(node(x,y,z,t.s+1));
			vis[x][y][z]=1;
		}
		x=t.a;y=t.b+1;z=t.c+1;
		if(x<110&&y<110&&z<110&&vis[x][y][z]==0)
		{
			q.push(node(x,y,z,t.s+1));
			vis[x][y][z]=1;
		}
		x=t.a+1;y=t.b;z=t.c+1;
		if(x<110&&y<110&&z<110&&vis[x][y][z]==0)
		{
			q.push(node(x,y,z,t.s+1));
			vis[x][y][z]=1;
		}		
	}
	return -1;
}
int main()
{
	int x,y,z,ans;
	cin>>x>>y>>z;
	memset(vis,0,sizeof(vis));
	vis[x][y][z]=1;
	ans=bfs(x,y,z);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5504
#include <climits>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int v[5];
  for (int i = 0; i < 5; ++i) {
    std::cin >> v[i];
  }

  int k; std::cin >> k;
  if (k >= v[4] - v[0]) std::cout << "Yay!" << std::endl;
  else                  std::cout << ":(" << std::endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli x;
    cin >> x;
    YES(x == 7 || x == 5 || x == 3);
}

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

#define fast ios_base::sync_with_stdio; cin.tie(0); cout.tie(0)
#define ll          long long
#define ull         unsigned long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define Mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)      (a).rbegin(),(a).rend()
#define ff           first
#define ss           second
#define sz(x)       (int)x.size()
//#define endl        '\n'
#define mod        1000000007
//#define mod        998244353
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define INF         numeric_limits<ll>::max();
#define NINF        numeric_limits<ll>::min();
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))
const long double pi=3.14159265359;

int main()
{fast;
 #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
 #endif
 int t=1,n,k,a,b;
 //cin>>t;
 while(t--)
 {cin>>k>>a>>b;
  rep(i,a,b+1){
    if(i%k==0){
        cout<<"OK";
        return 0;
    }
  }
  cout<<"NG";
 }
 return 0;
}


Measured memory_bytes: 3624
import numpy as np
N = int(input())
A = np.array([0 for i in range(N)], np.int64)
B = np.array([0 for i in range(N)], np.int64)
TA = 0
AO = 0
for i in range(N):
    A[i], B[i] = map(int, input().split())
AmB = np.array([A[i] + B[i] for i in range(N)])
# sort_index = A.argsort()[::-1]
# A = A[sort_index]
# B = B[sort_index]
# AmB = AmB[sort_index]
index = np.argsort(AmB)[::-1]
print(np.sum(A[index[::2]]) - np.sum(B[index[1::2]]))


Measured memory_bytes: 19024
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  ll n, a, b;
  cin >> n >> a >> b;
  ll s = n / (a+b);
  ll m = n % (a+b);
  cout << (s*a) + min(m, a) << endl;
  return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define MOD 1000000007
#define vec vector
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int h[n], i=0;
	for(i=0;i<n;i++)
		cin>>h[i];
	int dp[n];
	i=0;
	while(i<=k&&i<n)
	{
		dp[i] = abs(h[i] - h[0]);
		i++;
	}
	while(i<n)
	{
		int ans = dp[i-1]+abs(h[i]-h[i-1]);
		for(int j=2;j<=k;j++)
		{
			ans = min(ans, dp[i-j]+abs(h[i] - h[i-j]));
		}
		dp[i] = ans;
		i++;
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 4312
N, K = map( int, input().split())
A = list( map( int, input().split()))
# 1の個数をそれぞれの桁でカウントしたい
V = [0]*41
for a in A:
    for i in range(40,-1,-1):
        if a%2 == 0:
            pass
        else:
            V[i] += 1
        a //= 2
        if a == 0:
            break
W = [0]*41
for i in range(40,-1,-1):
    if K%2 == 0:
        pass
    else:
        W[i] += 1
    K //= 2
    if K == 0:
        break
ans = 0
check = 0
dp = [[-1]*2 for _ in range(42)]
dp[0][0] = 0
for i in range(41):
    if dp[i][1] != -1:
        dp[i+1][1] = dp[i][1] + (2**(40-i))*max(V[i], N-V[i])
    if dp[i][0] != -1:
        if W[i] == 1:
            dp[i+1][1] = max( dp[i+1][1], dp[i][0]+(2**(40-i))*V[i] )
    if dp[i][0] != -1:
        if W[i] == 1:
            dp[i+1][0] = dp[i][0] + (2**(40-i))*(N-V[i])
        else:
            dp[i+1][0] = dp[i][0] + (2**(40-i))*V[i]
print( max( dp[-1][0], dp[-1][1]))


Measured memory_bytes: 68696
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    string s;
    cin >> s;
    int ans = 0;
    rep(i,s.size())ans+= s[i]-'0';
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
int k;
cin >> k;
string s;
cin >> s;
int m=s.length();
if(m>k){
for(int i=0;i<k;i++){
cout << s[i];
}
cout <<"...";
}
else{
cout << s;
}
     
}

Measured memory_bytes: 3624
// abc167_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
  string s,t;
  cin>>s>>t;
  if (s==t.substr(0,(int)t.size()-1)) {
    cout<<"Yes"<<endl;
  } else {
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3632
use std::ops;

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim_right().to_owned()
}

fn read_stdin() -> String {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

fn new_jobs() -> Vec<Vec<u64>> {
    let jobs = read_stdin().lines()
        .map(|line: &str| line.split_whitespace().map(|s| s.parse().unwrap()).collect())
        .collect::<Vec<Vec<u64>>>();
    
    let mut v = vec![Vec::new(); 100_000];
    for job in jobs {
        v[(job[0] - 1) as usize].push(job[1]);
    }
    v
}

trait Sorted {
    fn position_quick(&self, n: u64, range: ops::Range<usize>) -> usize;
    fn sorted_insert(&mut self, n: u64);
}

impl Sorted for Vec<u64> {
    fn position_quick(&self, n: u64, range: ops::Range<usize>) -> usize {
        let len = range.end - range.start;
        let i = range.start + len / 2;
        
        if len == 1 {
            return i + (self[i] < n) as usize;
        }
        
        if n < self[i] {
            self.position_quick(n, range.start..i)
        } else {
            self.position_quick(n, i..range.end)
        }
    }
    
    fn sorted_insert(&mut self, n: u64) {
        if self.is_empty() {
            self.push(n);
            return;
        }
        
        let i = self.position_quick(n, 0..self.len());
        self.insert(i, n);
    }
}

fn main() {
    let nums: Vec<usize> = read_line().split_whitespace().map(|x| x.parse().unwrap()).collect();
    let (_, m) = (nums[0], nums[1]);
    let jobs = new_jobs();
    
    let mut current = Vec::new();

    let mut total = 0;
    for day in 0..m {
        for &reward in &jobs[day] {
            current.sorted_insert(reward);
        }
        
        if current.is_empty() { continue; }
        
        let index = current.len() - 1;
        total += current[index];
        current.swap_remove(index);
    }
    
    println!("{}", total);
}


Measured memory_bytes: 14280
/*
    By Prabal Aggarwal
*/
#include <bits/stdc++.h>
#define fastIo                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
using namespace std;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
#define ll long long
#define MOD 1000000007
const int N = 100005;

int main()
{
    fastIo;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;

    ll x,y;
    ll mx = a*c;

    mx = max(a*c,max(a*d,max(b*c,b*d)));
    cout<<mx;
    return 0;
}

Measured memory_bytes: 3648
// Main maut ko takiya, aur kafan ko chadaar banakar audhta hoon!

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define len(a) ll(a.size())
#define endl "\n"

#define vll vector< ll >
#define pll pair< ll, ll >
#define vvll vector< vll >
#define vpll vector< pll >

#define umsll unordered_map<string,ll>
#define umll unordered_map<ll,ll>
#define sll set<ll>
#define minpqll priority_queue<ll,vector<ll>,greater<ll>>

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1)
    {
        cerr << name << " : " << arg1 << endl;
    }

    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args)
    {
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1 << "  ";
        __f(comma + 1, args...);
    }

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

const double pi=3.141592653589793238462643383279502884197169399375105820974944;
const double e=2.71828182845904523536028747135266249775724709369995;
const ll mod=1e9+7;
const ll inf=2e18;
const ll ninf=-2e18;
const ll nax=1e6;

ll power(ll x, ll y, ll mod)
{
    ll ans=1;
    x=x%mod;
    while(y)
    {
        if(y&1)
            ans=(x*ans)%mod;

        x=(x*x)%mod;
        y>>=1;
    }
    return ans;
}

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

    int n,a;
    cin>>n>>a;

    if(n%500 <= a)
        cout<<"Yes";
    else cout<<"No";

    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<utility>
#include<sstream>
#define mem0(x) memset(x,0,sizeof x)
#define mem1(x) memset(x,-1,sizeof x)
#define dbug cout<<"here"<<endl;
//#define LOCAL

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e6+10;
const int MOD = 1000000007;

ull n,m;

ull gcd(ull a, ull b){
    if(b == 0)
        return a;
    return gcd(b, a%b);
}

int main(){
    #ifdef LOCAL
        freopen("C:\\Users\\asus-z\\Desktop\\input.txt","r",stdin);
        freopen("C:\\Users\\asus-z\\Desktop\\output.txt","w",stdout);
    #endif
    while(cin >> n >> m){
        ull tmp = gcd(n, m);
        cout << tmp << " " << n*m/tmp << endl;
    }
    return 0;
}

Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int>h(n);
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  vector<int>dp(n,INT_MAX);
  dp[0]=0;
  dp[1]=abs(h[0]-h[1]);
  for(int i=2;i<n;i++){
    int j=1;
    while(j<=k&&(i-j)>=0){
      dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
      j++;
    }
  }
  cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include <climits>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

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

	int n;
	cin >> n;

	vector<int> p(n);
	for(int i = 0; i < n; ++i)
		cin >> p[i];

	vector<int> dist(n, INT_MAX);
	dist[0] = 0;

	typedef pair<int, int> pInt;
	priority_queue<pInt, vector<pInt>, greater<pInt> > que;
	que.push(pInt(0, 0));

	while(!que.empty()) {
		const pInt tmp = que.top();
		que.pop();

		const int pos = tmp.second;
		if(dist[pos] < tmp.first)
			continue;

		if(p[pos]) {
			const int next = pos + p[pos];
			if(dist[pos] < dist[next]) {
				dist[next] = dist[pos];
				que.push(pInt(dist[next], next));
			}
		}

		else {
			for(int i = 1; i <= 6; ++i) {
				const int next = pos + i;
				if(next >= n)
					break;

				if(dist[pos] + 1 < dist[next]) {
					dist[next] = dist[pos] + 1;
					que.push(pInt(dist[next], next));
				}
			}
		}
	}

	cout << dist[n - 1] << endl;

	return EXIT_SUCCESS;
}

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

static int cmp(const void *a, const void *b);

int main(int argc, char *argv[])
{
    int i, N, K, t = 0;
    int l[50];
    scanf("%d %d", &N, &K);
    for ( i = 0; i < N; i++ ){
        scanf("%d", &l[i]);
    }
    qsort(l, N, sizeof(int), cmp);
    for ( i = 0; i < K; i++ ){
        t += l[i];
    }
    printf("%d\n", t);
    return 0;
}

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

Measured memory_bytes: 128
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Stones
 */

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

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

/* global variables */

char s[MAX_N + 4];
int dp[MAX_N][2];

/* subroutines */

inline void setmin(int &a, int b) { if (a > b) a = b; }

/* main */

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

  if (s[0] == '.')
    dp[0][0] = 0, dp[0][1] = 1;
  else
    dp[0][0] = 1, dp[0][1] = 0;

  for (int i = 1; i < n; i++) {
    int d0 = 0, d1 = 0;
    if (s[i] == '.') d1 = 1;
    else d0 = 1;

    dp[i][0] = dp[i - 1][0] + d0;
    dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + d1;
  }

  printf("%d\n", min(dp[n - 1][0], dp[n - 1][1]));
  return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <cmath>

#define PI 3.14159265358979323

using namespace std;

int main() {
	double a, b, C;
	double S, L, h;
	cin >> a >> b >> C;
	double rad = C * PI / 180.0;
	S = 0.5 * a * b * sin(rad);
	L = a + b + sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * cos(rad));
	h = b * sin(rad);
	printf("%.8f\n", S);
	printf("%.8f\n", L);
	printf("%.8f\n", h);
	return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#define rep(i,m,n) for(int i=m; i<(n); i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
typedef long long ll;
using namespace std;

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


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll all = b - a + 1;
    ll roku = b/c - (a-1)/c;
    ll hati = b/d - (a-1)/d;
    ll kousa = c*d/gcd(c,d);
    ll kousa2 = b/kousa - (a-1)/kousa;
    ll ans = all - roku - hati + kousa2;
    cout << ans << endl;
}


Measured memory_bytes: 256
//28
#include<iostream>

using namespace std;

#define T(X) ((X)*(X)*(X))

int main(){
  for(int n;cin>>n,n;){
    int m=0;
    for(int a=1;T(a)<=T(n);a++){
      for(int b=1;T(a)+T(b)<=T(n);b++){
	if(m<T(a)+T(b)){
	  m=T(a)+T(b);
	}
      }
    }
    cout<<T(n)-m<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int BinarySearch(int key,int n,int S[]){
  int l=0,r=n;
  while(r-l>1){
    int mid=(l+r)/2;
    if(S[mid]>key)r=mid;
    else l=mid;
  }
  return S[l]==(key?1:0);
}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
  ll N;
  cin >> N;
  cout << ((N-1)/111+1)*111 << endl;
}

Measured memory_bytes: 380
cnt = [0, 0, 0, 0]

for i in range(3):
    ab = list(map(int, input().split()))
    for j in ab:
        cnt[j-1] += 1

ans = 'YES'
if (cnt.count(2) == 2) and (cnt.count(1) == 2):
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include <stdio.h>
 
int main(void)
{
    int xs[2], ys[2], eqs[2];
    float x, y;
 
    while (~scanf("%d %d %d %d %d %d", xs, ys, eqs, xs + 1, ys + 1, eqs + 1)){
        x = 1.*(eqs[0] * ys[1] - eqs[1] * ys[0]) / (xs[0] * ys[1] - xs[1] * ys[0]);
        y = 1.*(eqs[1] * xs[0] - eqs[0] * xs[1]) / (xs[0] * ys[1] - xs[1] * ys[0]);
 
        if (x == 0.0) x = 0.0;
        if (y == 0.0) y = 0.0;

        printf("%.3f %.3f\n", x, y);
    }
 
    return (0);
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {

	int n;
	ll d;
	cin >> n >> d;
	d *= d;
	int cnt = 0;
	rep(i, n) {
		ll x, y;
		cin >> x >> y;
		if (x * x + y * y <= d)cnt++;
	}

	cout << cnt << endl;

}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
	int n, m;
	cin >> n >> m;
	int res = 1;
	for (int i = 1; i * i <= m; i++) {
		if (m % i == 0) {
			if (i >= n) {
				res = max(m / i, res);
			}
			if (m / i >= n) {
				res = max(i, res);
			}
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long int llint;

int main(){
	int n, k, i, ans=0;
	int a[200010];
	int num[200010]={};
	cin>>n>>k;
	for(i=0; i<n; i++) cin>>a[i];
	for(i=0; i<n; i++) num[a[i]]++;
	sort(num+1, num+n+1);
	if(k==n){
		cout<<0<<endl;
		return 0;
	}
	for(i=1; i<=n-k; i++) ans+=num[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
S = input()
if S.isupper() == True:
    if  (S[0]==S[1] and S[2]==S[3] and S[1]!=S[2]) or (S[0]==S[2] and S[1]==S[3] and S[0]!=S[1]) or (S[0]==S[3] and S[1]==S[2] and S[0]!=S[1]):
        print('Yes')
    else:
        print('No')
else:
    print('No')



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

typedef long long LL;
typedef long double LD;
typedef string ST;



void func()
{
  LL N;
  cin >> N;
  priority_queue<LL, vector<LL>,greater<LL>> A;
  for (LL i = 0; i < N; ++i) {
    LL a;
    cin >> a;
    A.push(a);
  }

  
  while (A.size()>1) {
    LL a1 = A.top();
    A.pop();
    LL a2 = A.top();
    A.pop();
    LL d = a1*((LL)ceil(a2 / a1));
    a2 -= d;
    if (a2 > 0) {
      A.push(a2);
    }
    A.push(a1);
  }
  cout << A.top();
}


#ifdef CALC_TIME 
#include <windows.h>
int main()
{
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  LARGE_INTEGER start, end;
  QueryPerformanceCounter(&start);
  // 何かの処理
  func();
  QueryPerformanceCounter(&end);
  double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart;
  fprintf(stderr, "%lf[ms]\n", time);
  return 0;
}
#else 
int main()
{
  func();
  return 0;
}
#endif





Measured memory_bytes: 1400
from collections import deque
s = input()
rev = s[::-1]
curs = [deque(list(s)), deque(list(rev))]
f = 0
b = 1
q = int(input())
for _ in range(q):
    stuff = input().split()
    if stuff[0] == '1':
        f, b = b, f
    else:
        op, fi, c = stuff
        fi = int(fi)
        if fi == 1:
            curs[f].appendleft(c)
            curs[b].append(c)
        else:
            curs[f].append(c)
            curs[b].appendleft(c)
print(''.join(curs[f]))

Measured memory_bytes: 11108
// Try AtCoder
// author: Leonardone @ NEETSDKASU
package main

import "fmt"

func grouping(k int) int {
	switch k {
	case 1, 3, 5, 7, 8, 10, 12:
		return 0
	case 4, 6, 9, 11:
		return 1
	case 2:
		return 2
	default:
		return -1
	}
}

func main() {
	var x, y int
	fmt.Scan(&x, &y)
	if grouping(x) == grouping(y) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res;}

int main()
{
	lli n,a,b;
	cin>>n>>a>>b;
	if(a>b)
		swap(a,b);
	lli k=abs(b-a);
	lli ans=0;
	if(k==0)
	{cout<<0;return 0;}
	k-=1;
	if(k%2LL==0)
	{
		k-=1;
		if(n-b<a-1)
			ans=(n-b)+1+(k+1LL)/2LL;
		else
			ans=a+(k+1LL)/2LL;
	}
	else
		ans=(k+1LL)/2LL;
	cout<<ans;

}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void) {
    string s, t;
    cin >> s >> t;

    int ans = 0;
    for(int in=0;in<=s.size()-t.size();++in) {
        int st = in, cnt = 0;
        for(int it=0;it<t.size();++it) { 
            if(t[it]==s[st+it]) cnt++;
        }
        chmax(ans, cnt);
    }

    cout << t.size()-ans << endl;
    return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

using ll = int64_t;

using namespace std;

/*
 * Modint struct
 * library author : @snuke
 * */
const int mod = 1e9 + 7;
struct mint {
  long long x; // typedef long long ll;
  mint(long long x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) { if((x+=a.x)>=mod)x-=mod;return *this;}
  mint& operator-=(const mint a) { if((x+=mod-a.x)>=mod)x-=mod; return *this;}
  mint& operator*=(const mint a) { (x *=a.x)%=mod; return *this;}
  mint operator+(const mint a) const { mint res(*this);return res+=a;}
  mint operator-(const mint a) const { mint res(*this);return res-=a;}
  mint operator*(const mint a) const { mint res(*this);return res*=a;}
  mint pow(ll t) const {
    if (!t) return 1;mint a = pow(t>>1);a*=a;
    if (t&1) a *= *this;return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return (*this) *= a.inv();}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

string s;
int64_t n;

mint dp[100010][13];

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

    cin >> s;
    reverse(all(s));

    n = s.size();

    int64_t ten = 1;
    const int64_t M = 13;

    dp[0][0] = 1;

    REP(i,n){
        if(s[i] == '?'){
           REP(j,10){
               int64_t step = (ten * j) % M;
               REP(from,13){
                   int to = (from + step) % M;
                   dp[i + 1][to] += dp[i][from];
               }
           }
        }else{
           int64_t step = (ten * (s[i] - '0')) % M;
           REP(from,13){
               int to = (from + step) % M;
               dp[i + 1][to] += dp[i][from];
           }
        }
        ten = (ten * 10) % M;
    }
    cout << dp[n][5] << '\n';
}



Measured memory_bytes: 13836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define lPair pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
ll dp[101][100100] = {0};
ll N,W;
ll w[101],v[101];
int main(){
    cin >> N >> W;
    for(ll i = 1; i <= N; i++){
        cin >> w[i] >> v[i];
    }
    dp[0][0] = 0;
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j <= W; j++){
            dp[i+1][j] = dp[i][j];
            if(j >= w[i+1]){
                dp[i+1][j] = max(dp[i+1][j],dp[i][j-w[i+1]] + v[i+1]);
            }
        }
    }
    ll mx = 0;
    for(ll i = 0; i <= W; i++){
        mx = max(mx,dp[N][i]);
    }
    cout << mx << endl;
}

Measured memory_bytes: 78464
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                int[,] dp = new int[n + 1, n + 1];
                int max = 0;

                for (int i = 1; i <= n; i++)
                {
                    string input = Console.ReadLine();

                    for (int j = 1; j <= n; j++)
                    {
                        if (input[j - 1] == '.')
                        {
                            dp[i, j] = 1;

                            dp[i, j] = Math.Min(dp[i - 1, j], dp[i, j - 1]);
                            dp[i, j] = Math.Min(dp[i, j], dp[i - 1, j - 1]) + 1;
                            max = Math.Max(max, dp[i, j]);
                        }
                    }
                }
                sb.AppendLine(max.ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 22960
//dp
#include<cstdio>
#include<iostream>
using namespace std;

int W,N,value[1000],weight[1000],cost;
int dp[1001][1001],data=0,w;
int main(){

  while(cin >>W){
    if(W==0)break;
    cin >>N;
    for(int i=0;i<=N;i++){
      for(int j=0;j<=W;j++){
	dp[i][j]=0;
      }
    }
    data++;
    for(int i=0;i<N;i++) scanf("%d,%d",&value[i],&weight[i]);
   
    for(int i=0;i<N;i++){ //どのお宝を選んでいるか
      for(int j=0;j<=W;j++){
	dp[i+1][j] = max (dp[i+1][j],dp[i][j]);
	if(j+weight[i]<=W)
	dp[i+1][j+weight[i]] = max(dp[i+1][j+weight[i]],dp[i][j]+value[i]);
      }
    }
    cost=dp[N][W];
    w=-1;
   
	for(int j=0;j<=W;j++){
	  if(dp[N][j] == cost){
	    w=j;
	    break;
	  }	  
	  //      cout <<weight[i]<<endl;
    }
      cout <<"Case "<<data<<":\n"<<cost<<endl<<w<<endl;
  }

  return 0;
}

Measured memory_bytes: 5164
#include<cstdio>
#include<algorithm>
const int N=1005,M=2e5+5;
const int Z=205;
using namespace std;
int n,h;
int rudu[N],chudu[N];
bool vis[N];
struct node{
    int u,v,nxt;
}edge[M];
int head[N],mcnt;
void add_edge(int u,int v){
	mcnt++;
	edge[mcnt].u=u;
    edge[mcnt].v=v;
    edge[mcnt].nxt=head[u];
    head[u]=mcnt;
    rudu[v]++;
    chudu[u]++;
}
void dfs(int u){
	vis[u]=true;
	for(int i=head[u];i;i=edge[i].nxt){
        int v=edge[i].v;
		if(!vis[v])
            dfs(v);
	}
}
int main()
{
	scanf("%d%d",&n,&h);
	for(int i=1;i<=n;i++){
		int a,b,c,d,l,r;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		l=c?(-c):a;
		r=d?d:(-b);
		add_edge(l+Z,r+Z);
	}
	for(int i=Z-h;i<Z;i++)
		if(rudu[i]<chudu[i]){
            puts("NO");
            return 0;
        }
	for(int i=Z+1;i<=Z+h;i++)
		if(rudu[i]>chudu[i]){
            puts("NO");
            return 0;
        }
	for(int i=Z-h;i<=Z+h;i++)
		if(chudu[i]>rudu[i]&&!vis[i])
            dfs(i);
	for(int i=Z-h;i<=Z+h;i++)
		if((rudu[i]||chudu[i])&&!vis[i]){
            puts("NO");
            return 0;
        }
	puts("YES");
}


Measured memory_bytes: 1408
n, k = map(int, input().split())

if k % 2 != 0:
    print((n//k)**3)
else:
    kk = k//2
    a = 0
    b = 0
    for i in range(1, n+1):
        if i % kk == 0 and (i//kk) % 2 == 0:
            a += 1
        elif i % kk == 0 and (i//kk) % 2 != 0:
            b += 1
    print(a**3+b**3)


Measured memory_bytes: 38896
def main():
    N = int(input())
    ab = [tuple(int(j) for j in input().split()) for i in range(N)]
    cd = [tuple(int(j) for j in input().split()) for i in range(N)]
    # y 降順
    ab.sort(key=lambda x:x[1], reverse=True)
    # x 昇順
    cd.sort()
    # ペアになった赤
    done = [False] * N
    for bx, by in cd:
        for k, ((rx, ry), d) in enumerate(zip(ab, done)):
            if not d and rx < bx and ry < by:
                done[k] = True
                break
    print(sum(done))
    return


main()


Measured memory_bytes: 3064
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val A = new Array[Long](N+1)
  for(i <- (1 to N).reverse) {
    A(i) = in.next().toLong
  }

  ///
  if (A(1) != 2)
    println(-1)
  else {
    var flag = true
    var l = 2L; var r = 3L
    breakable {
      for(i <- 2 to N) {
        val now = A(i)

        l =
          if(l % now != 0)
            (l / now + 1) * now
          else
            (l / now) * now
        r = (r / now)*now

        if(l > r) { // invalid
          flag = false
          break
        }
        else {
          r += now - 1
        }

      }
    }

    if(flag)
      println(s"$l $r")
    else
      println(-1)
  }
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}



Measured memory_bytes: 43240
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ll N;

    while (cin >> N, N) {
        ll S = 0;

        for (ll i = 1; i * i <= N; ++i) {
            if (N % i == 0 && i != N) {
                S += i;
                if (i != N / i && N / i != N)
                    S += N / i;
            }
        }

        if (N == S)
            cout << "perfect number\n";
        else if (N > S)
            cout << "deficient number\n";
        else
            cout << "abundant number\n";
    }

    return 0;
}

Measured memory_bytes: 1116
n = int(input())
x = input()

original_pop_count = x.count('1')
one_pop_count = original_pop_count - 1 # 0になりうる
zero_pop_count = original_pop_count + 1

# X mod p(X) += 1 の前計算
one_mod = 0
zero_mod = 0
for b in x:
    if one_pop_count != 0:
        one_mod = (one_mod * 2 + int(b)) % one_pop_count
    zero_mod = (zero_mod * 2 + int(b)) % zero_pop_count

# f の前計算
f = [0] * 220000
pop_count = [0] * 220000
for i in range(1, 220000):
    # pop_count[i] = pop_count[i // 2] + i % 2
    pop_count[i] = bin(i)[2:].count('1')
    f[i] = f[i % pop_count[i]] + 1

for i in range(n-1, -1, -1):
    if x[n-i-1] == '1':
        if one_pop_count != 0:
            nxt = one_mod
            nxt -= pow(2, i, one_pop_count)
            nxt %= one_pop_count
            print(f[nxt] + 1)
        else:
            print(0)
    elif x[n-i-1] == '0':
        nxt = zero_mod
        nxt += pow(2, i, zero_pop_count)
        nxt %= zero_pop_count
        print(f[nxt] + 1)

Measured memory_bytes: 81744