akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

// 

public class Program_ABC114_C_2 // ←Class名変更！！
{
    public static void Main()
    {
        var n = Ri();


        if (n < 357)
        {
            WriteLine(0);
            return;
        }

        var ans = 1;
        for (int i = 358; i <= n; i++)
        {
            var s = i.ToString().ToCharArray();
            var b = true;
            var b3 = false;
            var b5 = false;
            var b7 = false;
            for (int k = 0; k <s.Length; k++)
            {

                switch (s[k])
                {
                    case '3':
                        b3 = true;
                        break;
                    case '5':
                        b5 = true;
                        break;
                    case '7':
                        b7 = true;
                        break;
                    default:
                        b = false;
                        break;
                }

                if (!b)
                {
                    i += (int)(Math.Pow(10, s.Length - k-1)) - 1;
                    break;
                }
            }



            if (b & b3 & b5 & b7)
            {
                ans++;
            }
        }

        WriteLine($"{ans}");
        return;

    } // Main

    public static string Rs() { return ReadLine(); }
    public static int Ri() { return int.Parse(ReadLine()); }
    public static long Rl() { return long.Parse(ReadLine()); }
    public static int[] Ria() { return Array.ConvertAll(ReadLine().Split(' '), int.Parse); }
    public static long[] Rla() { return Array.ConvertAll(ReadLine().Split(' '), long.Parse); }
    public static char[] Rca() { return ReadLine().ToCharArray(); }
}     // Class


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

int main()
{
    int n;
    cin >> n;
    if (n / 10 % 111 == 0 || n % 1000 % 111 == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

ll mod = 998244353;
ll bin_pow(ll a, ll p) {
  ll r = 1;
  while (p) {
    if (p&1) r = r*a%mod;
    a = a*a%mod;
    p >>= 1;
  }
  return r;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<int> count(n);
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    if (i == 0 && d) {
      cout << 0 << endl;
      return 0;
    }
    count[d]++;
  }
  ll ans = 1;
  if (count[0] != 1) ans = 0;
  for (int i = 1; i < n; i++) {
    if (count[i] && !count[i-1]) ans = 0;
    ans = (ans*bin_pow(count[i-1], count[i]))%mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
 
int main()
{
    int n;
    cin >> n;
    vector<int> p(n + 1);
    for(int i = 0; i <= n; i++){
        int a,b;
        cin >> a >> b;
        if(!i) {
         p[i] = a;
         i++;
        }
        p[i] = b;
    }
    
    vector<vector<int>> m(n + 1, vector<int>(n + 1, 0));
    for(int l = 2; l <= n; l++){
        for(int i = 1; i <= n - l + 1; i++){
            int j = i + l - 1;
            m[i][j] = (1 << 21);
            for(int k = i; k <= j - 1; k++){
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1]*p[k]*p[j]);
            
            }
        
        }
    
    }
    cout << m[1][n] << endl;
    return 0;
}


Measured memory_bytes: 3152
/*  ex6_2
    supercomputerjoi    */

#include <stdio.h>
#include <string.h>

int main(void){

    char text[101];
    int length = 0;

    // input s
    scanf("%s", text);

    // calculate text length
    length = strlen(text);

    // output answer
    printf("%c%d%c\n", text[0], length - 2, text[length - 1]);

    return 0;
}

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

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> c(10, vector<int>(10));
    int div = 1;
    for (int i = 1; i <= N; i++)
    {
        if (i / div >= 10)
        {
            div *= 10;
        }
        int left = i / div;
        int right = i % 10;
        if (left != 0 && right != 0)
        {
            c[left][right] += 1;
        }
    }

    int ans = 0;
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            ans += c[i][j] * c[j][i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
void Debug(auto a);


signed main(){
    int n,m,l;
    cin >> n >> m >> l;
    if(n == m && m == l){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }


    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
B=[A[i]-(i+1) for i in range(n)]
C=sorted(B)
b=C[n//2]
import functools
x=functools.reduce(lambda x,y:abs(x)+abs(y),[C[i]-b for i in range(n)])
print(x)


Measured memory_bytes: 30288
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <limits>
#include <array>

using namespace std;

vector<long long> v;
vector<long long> calc;

int main(){
	int n;cin>>n;
	v.resize(n);
	calc.resize(n);
	for(int i=0;i<n;i++) cin>>v[i];
	for(int i=0;i<n;i++) calc[i] = v[i] + v[n-i-1];

	long long ans = 0;

	for(int i=1;i<n;i++){
		long long tmp = 0;
		for(int j=i;j<n;j+=i){
			if((n-j-1) <= i) break;
			if(j >= n-j-1){
				if(((n-j-1)%i) == 0) break;
			}
			tmp += calc[j];
			ans = max(ans,tmp);
		}
	}
	cout<<ans<<endl;
	return 0;

}

Measured memory_bytes: 1792
#include <iostream>
#include <string>

using namespace std;

int main(){

string s;
int n,q,counts=0;
  
  cin >> n >> q;
  cin >> s;
 
int sum[n+1];
  
  for(int i=0;i<=n;i++){
    sum[i]=counts;
    if(s.substr(i,2)=="AC"){
    counts++;
    }
    
    }  
  
  for(int i=0;i<q;i++){
    int l,r;
    cin >> l >> r;
    cout << (sum[r-1]-sum[l-1]) <<  endl;
  }
  
 
}

Measured memory_bytes: 1472
import time
start = time.time()
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
s = [0 for i in range(n)] #それぞれ何試合目か
ans = 0
need = n*(n-1)//2
while need:
    c = [0 for i in range(n)] #今日試合をするかどうか
    ans += 1
    for first in range(n):
        if c[first] == 0 and s[first] < n-1:
            second = a[first][s[first]]-1 # firstが対戦したい相手
            second_num = s[second] # #secondの対戦番号
            if c[second] == 0 and a[second][second_num]-1 == first:
                c[first] = 1
                c[second] = 1
                s[first] += 1
                s[second] += 1
                need -= 1
    if sum(c) == 0:
        print(-1)
        exit()
    now = time.time()-start
    if now > 1.8:
        print(n*(n-1)//2)
        exit()
print(ans)

Measured memory_bytes: 60120
#include <iostream>
#include <algorithm>

#define REP(id, num) for (auto id = 0; id < num; id++) 
#define FOR(id, num) for (auto id = 1; id <= num; id++) 

#define MAX_NUM (int)1e5 + 10
#define INF (int)1e9

using namespace std;

int dp[MAX_NUM];
int h[MAX_NUM];

void chmin(int &a, int b);

int main()
{
  REP(id, MAX_NUM)
    dp[id] = INF;

  int N, K;
  cin >> N >> K;

  REP(id, N)
    cin >> h[id];

  //cin >> h[0];
  dp[0] = 0;

  // 配るDP
  REP(id, N)
  {
    FOR(kId, K)
      chmin(dp[id + kId], dp[id] + abs(h[id + kId] - h[id]));
  }

  cout << dp[N - 1] << endl;
}

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll N,M; cin >> N >> M;
  priority_queue<ll> Q;
  for(ll i = 0; i < N; i++){ ll a; cin >> a; Q.push(a);}
  
  while(M--){
    ll b = Q.top(); Q.pop(); b /=2; Q.push(b);}
  ll ans = 0;

   while(!Q.empty()){
     ans += Q.top(); Q.pop();}
  cout << ans << endl; return 0;}
  

Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>

int main(){
    int i,j;
    int h,w;

    for(;;){
        std::cin>>h>>w;

        if(h==0 && w==0){
            break;
        }
        else {
            for(i=1;i<=h;i++){
                
                for(j=1;j<=w;j++){
                    
                    if(j==1){
                        printf("#");
                        }
                    else if(j==w){
                        printf("#\n");
                        break;
                    }
                    else{
                        if(i==1||i==h){
                            printf("#");
                        }
                        else{
                            printf(".");
                        }
                    }
                }
            
            }
            printf("\n");
        }

    }
    return 0;
}


Measured memory_bytes: 3076
#include <cstdio>
#include <algorithm>

int N, M, X, Y;

int main(int argc, char const *argv[]) {
  scanf("%d %d %d %d\n", &N, &M, &X, &Y);
  int x[N+1];
  int y[M+1];
  for (int i = 0; i < N; i++) {
    scanf("%d", &x[i]);
    if(i < N-1){
      scanf(" ");
    }else{
      scanf("\n");
    }
  }
  for (int i = 0; i < M; i++) {
    scanf("%d", &y[i]);
    if(i < M-1){
      scanf(" ");
    }else{
      scanf("\n");
    }
  }

  x[N] = X;
  y[M] = Y;

  std::sort(x, x+N+1);
  std::sort(y, y+M+1);

  if(x[N] < y[0]){
    printf("No War\n");
  } else {
    printf("War\n");
  }
  return 0;
}


Measured memory_bytes: 128
# https://atcoder.jp/contests/agc011/tasks/agc011_b

import sys
input = sys.stdin.buffer.readline

n = int(input())
A = sorted([int(i) for i in input().strip().split()])
_max = A[-1]
cul_sum = [0] * (n + 1)

for i in range(1, n + 1):
    cul_sum[i] = cul_sum[i - 1] + A[i - 1]

ptr = 0
for i in range(1, n + 1):
    if cul_sum[i] * 2 < A[i]:
        ptr = i
    elif cul_sum[i] * 2 >= _max:
        print(n - ptr)
        sys.exit()


Measured memory_bytes: 86852
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    if (a + b == 15)
    {
        printf("+\n");
    }
    else if (a * b == 15)
    {
        printf("*\n");
    }
    else
    {
        printf("x\n");
    }
    return 0;
}

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

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int A,B,C;
  cin>>A>>B>>C;
  int x=max(A,max(B,C));
  if ((3*x-(A+B+C))%2==0) {
    cout<<(3*x-(A+B+C))/2<<endl;
  } else {
    cout<<(3*(x+1)-(A+B+C))/2<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
'''
https://atcoder.jp/contests/abc149/tasks/abc149_b
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    A,B,K = map(int, input().split())
    if A>=K:
        print('{} {}'.format(A-K, B))
    elif A+B>K:
        print('{} {}'.format(0, B-(K-A)))
    else:
        print('0 0')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0;i<n;++i){
			int yi=sc.nextInt();
			int mi=sc.nextInt();
			int di=sc.nextInt();
			int count=0,flag=0;
			for(int y=1;y<1000;++y){
				if(yi==y) flag++;
				for(int m=1;m<=10;++m){
					if(flag==1 && mi==m) flag++;
					for(int d=1;d<=20;++d){
						if(flag==2 && di==d) flag++;
						if((y%3!=0 && m%2==0) && d==19) d=21;
						if(flag==3) count++;
					}
				}
			}
			System.out.println(count);
		}
	}
}


Measured memory_bytes: 27344
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int n,x,y;
  cin >> n >> x >> y;
  
  vector<vector<int>> to(n+1,vector<int>(0));
  
  rep1(i,n-1){
    to[i].push_back(i+1);
    to[i+1].push_back(i);
  }
  to[x].push_back(y);
  to[y].push_back(x);
  
  vector<int> ans(n,0);
  
  rep1(i,n){
      
    //こっからBFS
    int INF = 1000000000;
    vector<int> d(n+1,INF);
    vector<bool> seen(n+1,false);
    queue<int> q;
    q.push(i);
    d[i] = 0;
    while(!q.empty()){
      int now = q.front();
      q.pop();
      if(seen[now]) continue;
      seen[now] = true;
      for(int next : to[now]){
        d[next] = min(d[now]+1,d[next]);
        q.push(next);
      }
    }//while
    
    for(int j=i+1;j<=n;j++) ans[d[j]] ++;
  }//i
  
  rep1(i,n-1) cout << ans[i] << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1100000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)};
const int max_n = 1 << 20;

signed main() {
	int n;string s;cin>>n>>s;
  int ans = 0;
  rep(i,n-1){
    if(s[i] != s[i+1])ans++;
  }
  cout << ans+1 << endl;
}



Measured memory_bytes: 512
#include <stdio.h>
int main(void){
  int n,m,i,j,k,ans;
  char hit[100][9],num[1000][9];
  int lot[100];
  while(1){
    scanf("%d %d",&n,&m);
    if(!n)
      break;
    ans=0;
    for(i=0;i<n;i++)
      scanf("%s %d",hit[i],&lot[i]);
    for(i=0;i<m;i++)
      scanf("%s",num[i]);
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
	for(k=7;k>=0&&hit[i][k]!='*';k--){
	  if(hit[i][k]!=num[j][k])
	    break;
	}
	if(k<0||hit[i][k]=='*')
	  ans+=lot[i];
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String sl[];
    
    sl = r.readLine().split(" ");
    int a = Integer.parseInt(sl[0]);
    int b = Integer.parseInt(sl[1]);
    

    System.out.println(a >= 13 ? b : (a >= 6 ? b / 2 : 0));
    
  }


}


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

int main(){
int x, y;
cin >> x >> y;
vector<int> group_index  = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
if (group_index.at(x - 1) == group_index.at(y - 1)){
    cout << "Yes" << endl;
}
else {
    cout << "No" << endl;
}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll>a(n);
    vector<ll>b(m);
    REP(i,n)cin >> a[i];REP(i,m)cin >> b[i];
    vector<ll>asum(n+1);
    vector<ll>bsum(m+1);
    asum[0]=0;
    bsum[0]=0;
    REP(i,n)asum[i+1]=asum[i]+a[i];
    REP(i,m)bsum[i+1]=bsum[i]+b[i];
    ll answer = 0;
    
    REP(i,n+1){
        if(asum[i] > k)break;
        ll b_read = lower_bound(ALL(bsum),k-asum[i]+1)-bsum.begin()-1;
        answer = max(answer,(ll)i+b_read);
        //cout << "answer = " << answer << " i=" << i << " b_read=" << b_read << endl;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 9596
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

func gcd(a, b, c int) int {
	return gcda(gcda(a, b), c)
}

func gcda(a, b int) int {
	if b == 0 {
		return a
	}
	return gcda(b, a%b)
}

func main() {
	scanner := makeScanner(8192)
	k := eGetInt(scanner)
	var sum int64
	for i := 1; i <= k; i++ {
		for j := 1; j <= k; j++ {
			for m := 1; m <= k; m++ {
				sum += int64(gcd(i, j, m))
			}
		}
	}
	fmt.Println(sum)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
const (
	TooLarge = math.MaxInt64
	TooSmall = math.MinInt64
)

func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeCharScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanRunes)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func pow(a, n int) int {
	if n == 0 {
		return 1
	}
	if n == 1 {
		return a
	}
	if n%2 == 1 {
		return pow((a*a), n/2) * a
	}
	return pow((a * a), n/2)
}
func powMod(a, n, mod int) int {
	if n == 0 {
		return 1 % mod
	}
	if n == 1 {
		return a % mod
	}
	if n%2 == 1 {
		return powMod((a*a)%mod, n/2, mod) * a % mod
	}
	return powMod((a*a)%mod, n/2, mod)
}

func factoricalMod(n, count, mod int) int {
	if count == 1 {
		return n % mod
	}
	return (n % mod) * (factoricalMod(n-1, count-1, mod)) % mod
}

func combinationMod(n, a, mod int) int {
	x := factoricalMod(n, a, mod)
	y := factoricalMod(a, a, mod)
	y = powMod(y, mod-2, mod)
	return ((x % mod) * (y % mod)) % mod
}
func countBitOfOn(i, numbits int) int {
	count := 0
	var bit uint64
	for bit = 0; bit < uint64(numbits); bit++ {
		t := 1 << bit
		if i&t > 0 {
			count++
		}
	}
	return count
}

type ints []int

func ToString(slice []int) string {
	format := fmt.Sprint(slice)
	return fmt.Sprint(format[1 : len(format)-1])
}


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

using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
	int n,x,a=0,b;
	cin >> n;
	for (int i = 1; i < 50005; i++) {
		x = i * 1.08;
		if (x == n) {
			a = 1;
			b = i;
			break;
		}
	}

	if (a) cout << b << endl;
	else cout << ":(" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
priority_queue<int> pq;

void inin(int a, int b) {
	if (a < b) return;
	vector<int> num(a);
	rep(i,a) cin >> num[i];
	sort(num.begin(), num.end(), greater<int>());
	rep(i,b) pq.push(num[i]);
}
int p;
int main() {
	int x,y,a,b,c;
	cin >> x >> y >> a >> b >> c;
	inin(a,x);
	inin(b,y);
	rep(i,c) {
		cin >> p;
		pq.push(p);
	}

	ll ans = 0;
	rep(i,x+y) {
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  ll N; cin >> N;
  vector<int> A;
  const char c[26] = {
    'a','b','c','d','e','f','g','h','i','j','k','l',
    'm','n','o','p','q','r','s','t','u','v','w','x','y','z'
  };
  int i = 0;
  while(N > 1) {
    ll tmp = N % 26;
    if(tmp == 0) A.push_back(26);
    else A.push_back(tmp);
    
    if(tmp == 0) N = N / 26 - 1;
    else N = N / 26;
  }
  if(N == 1) A.push_back(1);
  for(int i = A.size() - 1; i >= 0; --i) {
    cout << c[A[i] - 1];
  }
  cout << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void){
	char rom[101];
	int i , num[101] , sum;
	while(scanf("%s" , rom)!=EOF){
		for(i=0;;i++){
			if(rom[i] == 'I') num[i] = 1;
			else if(rom[i] == 'V') num[i] = 5;
			else if(rom[i] == 'X') num[i] = 10;
			else if(rom[i] == 'L') num[i] = 50;
			else if(rom[i] == 'C') num[i] = 100;
			else if(rom[i] == 'D') num[i] = 500;
			else if(rom[i] == 'M') num[i] = 1000;
			if(rom[i] == '\0'){
				num[i] = 0;
				break;
			}
		}
		sum = 0;
		i = 0;
		while(1){
			if(num[i] == 0 || num[i+1] == 0){
				sum += num[i];
				break;
			}
			if(num[i] >= num[i+1]){
				sum += num[i];
				i++;
			}else{
				sum += num[i+1] - num[i];
				i += 2;
			}
		}
		printf("%d\n" , sum);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<math.h>
using namespace std;

int main() {

	long long int i,j=999,num;
	cin >> i;
	num = i;
	for (int n = 0; n <  (int)log10(num) - 1; n++) {
		if (abs(i % 1000 - 753) < j) {
			j = abs(i % 1000 - 753);/* :(j = j);*/
			//cout << abs(i % 1000 - 753) << ' ' << j << endl;
		}
		//else cout << abs(i % 1000 - 753) << ' ' << j<<endl;
		i /= 10;
	}
	cout << j;
	return 0;
}

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

using namespace std;

int main() {
  long long X, K, D, ans = 9223372036854775807;
  
  cin >> X >> K >> D;
  
  X = abs(X);
  
  long long c = (X / D > K ? K : X / D);
  K -= c;
  X -= c * D;
  
  if (K % 2 == 1) {
    X = abs(X - D);
  }
  
  cout << abs(X) << endl;
  
  return 0;
}

Measured memory_bytes: 3636
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
k, n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.append(k + a[0])
S = sum(abs(a[i] - a[i - 1]) for i in range(1, len(a)))
print(min(S - abs(a[i] - a[i - 1]) for i in range(1, len(a))))

Measured memory_bytes: 74356
/*
 * itikara.cpp
 *
 *  Created on: 2018/05/30
 *      Author: J01003
 */
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int man[4][3][10]={};
	int n,f,s,t,y;
	cin>>n;
	f=0;
	s=0;
	t=0;
	for(int i=0;i<n;i++){
		cin>>f>>s>>t>>y;
		man[f-1][s-1][t-1]+=y;
	}
	for(f=0;f<4;f=f+1){
	for(s=0;s<3;s=s+1){
	for(t=0;t<10;t=t+1){
		cout<<" "<<man[f][s][t];
	}
	cout<<endl;
	}
	if(f!=3){

	cout<<"####################"<<endl;}
	}
	return 0;
}






Measured memory_bytes: 3096
use std::io;
use std::str;
use std::usize;
use std::cmp;


fn main() {
    let (n, m) = {
        let v = read_values::<usize>();
        (v[0], v[1])
    };
    let a = (0..n).map(|_| {
        let mut v = read_values::<usize>();
        for i in 0..v.len() {
            v[i] -= 1;
        }
        v
    }).collect::<Vec<_>>();

    let mut dead = vec![false; m];
    let mut ans = n;
    let mut heads = vec![0; n];
    for _ in 0..(m - 1) {
        let mut count = vec![0; m];
        for i in 0..n {
            while dead[a[i][heads[i]]] {
                heads[i] += 1;
            }
            count[a[i][heads[i]]] += 1;
        }

        let mut largest = a[0][heads[0]];
        for j in 0..m {
            if count[largest] < count[j] {
                largest = j;
            }
        }
        ans = cmp::min(ans, count[largest]);

        for i in 0..n {
            if a[i][heads[i]] == largest {
                heads[i] += 1;
            }
        }
        dead[largest] = true;
    }

    println!("{}", ans);
}

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

fn read_values<T>() -> Vec<T>
    where T: std::str::FromStr,
          T::Err: std::fmt::Debug
{
    read_line()
        .split(' ')
        .map(|a| a.trim().parse().unwrap())
        .collect()
}

Measured memory_bytes: 4352
n, m = map(int, input().split())
A = []
B = []
for i in range(n):
    A.append(input())
for i in range(m):
    B.append(input())

ok = 0
for i in range(n - m + 1):
    for j in range(n - m + 1):
        from_n = [l[j:j+m] for l in A[i:i+m]]
        ok += from_n == B
print('Yes' if ok > 0 else 'No')

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

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

int main()
{
    ll N;
    cin >> N;
    vec T(N);
    REP(i,0,N) cin >> T[i];

    ll L = T[0];
    REP(i,1,N) L = lcm(L,T[i]);
    PR(L);

    return 0;
}

/*



*/

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n, m;
    while (cin >> n, n)
    {
        cin >> m;
        vector<int> ans;
        for (int i = 0; i <= n; i++)
            ans.push_back(i);
        int cnt = 0;
        int i = 1;

        while (cnt != n - 1)
        {
            if (i > ans.size() - 1)
                i = 1;
            int sum = 1;
            while (sum != m)
            {
                sum++;
                i++;
                if (i > ans.size() - 1)
                    i = 1;
            }
            ans.erase(ans.begin() + i);
            cnt++;
        }
        OP(ans[1]);
    }
    return 0;
}


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

N = int(input())

dp = {b: 1 for b in "ACGT"}
for _ in range(N - 1):
    dp_new = {}
    for k in dp:
        for b in "ACGT":
            n = k[-3:] + b
            if n[-3:] in ("AGC", "ACG", "GAC") or n in ("ACGC", "AGGC", "ATGC", "AGCC", "AGGC", "AGTC"):
                continue
            else:
                if n in dp_new:
                    dp_new[n] += dp[k]
                else:
                    dp_new[n] = dp[k]
    dp = dp_new

print(sum(dp.values()) % (10 ** 9 + 7))


Measured memory_bytes: 3064
def main():
    n = int(input())
    aa = list(map(int, input().split()))
    res = 1 << 30
    for a in aa:
        quot = 0
        while a % 2 == 0:
            a //= 2
            quot += 1
        res = min(res, quot)
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
    n, k, *a = map(int, read().split())

    cur = 1
    path = [0] * (n + 1)
    while k:
        if path[cur]:
            break
        else:
            path[cur] = k
            cur = a[cur - 1]
            k -= 1
            if k == 0:
                print(cur)
                sys.exit()
    cycle = path[cur] - k
    k = k % cycle
    while k:
        cur = a[cur - 1]
        k -= 1
    print(cur)

if __name__ == '__main__':
    main()

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

int main(){
  int H, W;
  cin >> H >> W;

  string s1, s2, s3;
  string fake = "";
  for(int i=0;i<W+2;i++)
    fake += '.';

  cin >> s3;
  s3 = '.'+s3+'.';

  for(int i=0;i<H;i++){
    if(i==0)
      s1 = fake;
    else
      s1=s2;

    s2=s3;

    if(i==H-1)
	  s3 = fake;
  	else{
      cin >> s3;
      s3 = '.'+s3+'.';
    }

    for(int j=0;j<W;j++){

      if(s2.at(j+1)=='#'){
        cout << '#';
      }
      else{
        int c=0;
        for(int k=0;k<3;k++){
          if(s1.at(j+k)=='#')
            c++;
          if(s2.at(j+k)=='#')
            c++; // here s2.at(j+1) itself is not '#'
          if(s3.at(j+k)=='#')
            c++;
        }
        cout << c;
      }

    }
    cout << endl;

  }
}


Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();

        int x = in.nextInt();
        int y = in.nextInt();
        int z = in.nextInt();
        boolean good = true;
        long people = 0;
        x = x-z;

			
        while (good == true)
        {
            if (x-z>=0)
            {
                x = x -z;
                if (x-y>=0)
                {
                    x = x-y;
                    people ++;

                } else {
                	good = false;
                }
            }
            else
                {
                    good = false;
                }

        }

        System.out.println(people);
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

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

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

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Measured memory_bytes: 21332
#include <stdio.h>

int n, a[20];
int solve( int, int);

int main()
{

  int q, m;
  int i;
  
  scanf("%d",&n);
  for( i = 0; i < n; i++)
    {
      scanf("%d",&a[i]);
    }
  scanf("%d", &q);
  for( i = 0; i < q; i++)
    {
      scanf("%d",&m);
      if(solve(0,m))printf("yes\n");
      else printf("no\n");
    }
  
  return 0;
  
}

int solve(int i, int m)
{
  int res;
  
  if(m == 0)return 1;
  if(i >= n)return 0;

  res = solve(i+1,m) || solve(i+1, m-a[i]);
  return res;
}



Measured memory_bytes: 2108
// ABC063_C
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18（const int inf   = 1<<29;）

int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N, sum = 0;
    cin >> N;
    vector<ll> num(N);
    REP(i, N) {
        cin >> num[i];
        sum += num[i];
    }
    
    // calculation
    if (sum%10 == 0) {
        sort(num.begin(), num.end());
        bool flag = false;
        REP(i, N) {
            if (num[i]%10 != 0) {
                sum -= num[i];
                flag = true;
                break;
            }
        }
        
        if (flag) {
            cout << sum << "\n";
        } else {
            cout << 0 << "\n";
        }
        
    } else {
        cout << sum << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#
#   Bad python template TM
#
#       Zeyu, 2019
#

from sys import stdin, stdout, setrecursionlimit

input = stdin.readline
flush = stdout.flush

# setrecursionlimit(1000000)

############################################################

OUT = []


def write(item, sep=" "):
    if type(item) is int:
        OUT.append(str(item))
    elif type(item) is float:
        OUT.append("%.9f" % item)
    elif type(item) is list or type(item) is tuple:
        if type(item[0]) is int:
            OUT.append(sep.join(map(str, item)))
        else:
            OUT.append(sep.join(item))
    else:
        OUT.append(item)


def PRINT(sep="\n"):
    print(sep.join(OUT))


GI = lambda: int(input())
GS = lambda: input().rstrip()

gi = lambda: list(map(int, input().split()))
gs = lambda: input().split()

digits = lambda i: list(map(int, str(i)))

############################################################


h, w, n = gi()

MOD = pow(10, 9) + 7

fact = [1, 1]
inv = [1, 1]
f = 1
for i in xrange(2, 300005):
    f = f * i % MOD
    fact.append(f)
    inv.append(pow(f, MOD - 2, MOD))

def mnomial(a, b):
    a = abs(a)
    b = abs(b)
    return fact[a + b] * inv[a] % MOD * inv[b] % MOD

p = [(h - 1, w - 1, 1)]

for i in xrange(n):
    a, b = gi()
    p.append((a - 1, b - 1, 0))

p.sort(key = lambda i: map(abs, i))

def solve(id):
    N = len(p)
    dp = [0] * N
    ans = 0
    for i, (h, w, ID) in enumerate(p):
        tot_1 = mnomial(h, w)
        for j in xrange(i):
            if abs(h - p[j][0]) > abs(h) or abs(w - p[j][1]) > abs(w):
                continue
            if abs(p[j][0]) > abs(h) or abs(p[j][1]) > abs(w) or p[j][2] == ID == id:
                continue
            tot_1 = (tot_1 - dp[j] * mnomial(h - p[j][0], w - p[j][1]) % MOD) % MOD
        dp[i] = tot_1
        if ID == id:
            ans = (ans + tot_1) % MOD
    return ans

ans = 1
for i in xrange(1, 2):
    ans = ans * solve(i) % MOD
print ans

Measured memory_bytes: 73756
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();

			if (n % 10 == n / 100) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 22868
//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#define MAX_INT 2100000000
using namespace std;
typedef long long int ll;
//#include "Header.h"
int main()
{
	ll n, a, b, c, d, e, i, j,f,ans;
	cin >> n >> a >> b >> c >> d >> e;
	f = min(min(min(a, b), min(c, d)), e);
	if (n % f) ans = n / f + 5;
	else ans = n / f + 4;
	cout << ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}



use std::cmp;
use std::iter::Iterator;

fn main() {
    input! {
        n:usize,
        w:[i64;n],
    }

    let mut minsum = 0;

    for i in 0..n-1{
       let left :i64 = w[0..i+1].iter().sum();
       let right :i64 = w[i+1..n].iter().sum();

       let s_abs = ((left - right) as i64).abs();
       if minsum == 0 {
            minsum = s_abs;
       }
        minsum = cmp::min(minsum, s_abs);
    }

    println!("{}", minsum);

}



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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  vector<vector<int>> v(n,vector<int>(3)); cin >> v;
  vector<vector<int>> dp(n+1,vector<int>(3,0));
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < 3; ++j){
      for(int k = 0; k < 3; ++k){
	if(j != k)ChangeMax(dp[i+1][k], dp[i][j] + v[i][k]);
      }
    }
  }
  cout << max({dp[n][0],dp[n][1],dp[n][2]}) << endl;
  return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
inline void write(int x)
{
    if(x<0)
	{
    	putchar('-');
		x=-x;
	}
    if(x>9)
		write(x/10);
    putchar(x%10+'0');
}
int main()
{
	ios::sync_with_stdio(false);
	int a,s=1;
	a=read();
	while(a--)
		s=1ll*s*(a+1)%1000000007;
	write(s);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

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

template <int M> class ModInt {
    int x;

  public:
    constexpr ModInt() : x(0) {}
    constexpr ModInt(int64_t y) : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}
    constexpr ModInt &operator+=(const ModInt p) {
        if((x += p.x) >= M) x -= M;
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt p) {
        if((x += M - p.x) >= M) x -= M;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt p) {
        x = (int)(1LL * x * p.x % M);
        return *this;
    }
    constexpr ModInt &operator/=(const ModInt p) {
        *this *= p.inverse();
        return *this;
    }
    constexpr ModInt operator-() const { return ModInt(-x); }
    constexpr ModInt operator+(const ModInt p) const {
        return ModInt(*this) += p;
    }
    constexpr ModInt operator-(const ModInt p) const {
        return ModInt(*this) -= p;
    }
    constexpr ModInt operator*(const ModInt p) const {
        return ModInt(*this) *= p;
    }
    constexpr ModInt operator/(const ModInt p) const {
        return ModInt(*this) /= p;
    }
    constexpr bool operator==(const ModInt p) const { return x == p.x; }
    constexpr bool operator!=(const ModInt p) const { return x != p.x; }
    constexpr ModInt inverse() const {
        int a = x, b = M, u = 1, v = 0, t = 0;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    constexpr ModInt pow(int64_t k) const {
        ModInt ret(1), mul(x);
        while(k > 0) {
            if(k) ret *= mul;
            mul *= mul;
            k >>= 1;
        }
        return ret;
    }
    constexpr friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }
    constexpr friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t = 0;
        is >> t;
        a = ModInt(t);
        return (is);
    }
};
using modint = ModInt<mod>;

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

    string s;
    cin >> s;
    modint dp[100009][13];
    dp[0][0] = 1;

    int n = s.size();
    rep(i, n) rep(j, 13) {
        if(s[i] == '?') {
            rep(k, 10) dp[i + 1][(j * 10 + k) % 13] += dp[i][j];
        } else {
            dp[i + 1][(j * 10 + s[i] - '0') % 13] += dp[i][j];
        }
    }
    cout << dp[n][5] << endl;

    return 0;
}

Measured memory_bytes: 5584
n,k,c = map(int,input().split())
s = input()
forth = set()
reverse = set()
cur = 0
tired = 0
for i in range(n):
    if s[i] == "o":
        if tired == 0:
            cur += 1
            tired = c
            forth.add(i+1)
        else:
            if tired > 0:
                tired -= 1
    else:
        if tired > 0:
            tired -= 1
if cur > k:
    exit()
s = s[::-1]
cur = 0
tired = 0
for i in range(n):
    if s[i] == "o":
        if tired == 0:
            cur += 1
            tired = c
            reverse.add(n-i)
        else:
            if tired > 0:
                tired -= 1
    else:
        if tired > 0:
            tired -= 1
ans = forth & reverse
ans = list(ans)
ans.sort()
for i in ans:
    print(i)

Measured memory_bytes: 47256
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 26 20:56:50 2020

@author: Kanaru Sato
"""

a,b,c,d = list(map(int, input().split()))

takahashiturns = -1*((-1*c)//b)
aokiturns = -1*((-1*a)//d)

if takahashiturns <= aokiturns:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9168
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    a = list(map(int, input().split()))

    x = 0
    for i in range(2, n):
        x ^= a[i]
    d = a[0]+a[1]-x
    if d%2 == 1 or d < 0:
        print(-1)
        return
    d >>= 1
    if d&x != 0 or d > a[0]:
        print(-1)
        return
    k = x.bit_length()
    tmp = d
    # d^tmp はd&x=0からd|tmpと一緒
    for i in range(k, -1, -1):
        if (x >> i) & 1:
            if tmp|1<<i <= a[0]:
                tmp |= 1<<i
    if 0 < tmp <= a[0]:
        print(a[0]-tmp)
    else:
        print(-1)



if __name__ == '__main__':
    main()

Measured memory_bytes: 9144
#include<stdio.h>
#include<string.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long

int main(){
	int n,tmp;
	ll ans[1001],sum = 1;
	scanf("%d",&n);

	memset(ans,0,sizeof(ans));

	FOR(i,2,n+1){					//2~nについて
		tmp = i;
		FOR(j,2,tmp+1){				//素因数分解
			while(tmp%j == 0){		//割り切れるなら
				tmp /= j;			//tmpを割って、
				ans[j]++;			//ans[今の因数]を1増やす。
			}
		}
	}

	FOR(i,2,1001){
		sum = (sum * (ans[i]+1)) % 1000000007;
	}

	printf("%lld\n",sum);
}

Measured memory_bytes: 128
require 'prime'
def nd(n)
  Prime.prime_division(n).map {|p, e| e + 1 }.inject(:*)
end
def _divisors(primes, k)
  Enumerator.new do |y|
    if primes.size == k
      y << 1
    else
      p, e = primes[k]
      _divisors(primes, k + 1).each {|d|
        (e + 1).times {|e1|
          y << p ** e1 * d
        }
      }
    end
  end
end
def d(n)
  _divisors(Prime.prime_division(n), 0).to_a.sort
end

n=gets.to_i
c=0
if n==2
  puts 1
else
  c=nd(n-1)
  d(n).each do |k|
    next if k==1||k==n
    m=n
    while m%k==0
      m/=k
    end
    c+=1 if m%k==1
  end
  puts c
end



Measured memory_bytes: 2424
#include <stdio.h>

int main(void){
	int a, b;
	int d, r;
	double f;

	scanf("%d %d\n", &a, &b);

	d = a / b;
	r = a % b;
	f = (double)a / b;
	
	printf("%d %d %f\n", d, r, f);

	return 0;
}

Measured memory_bytes: 1836