akhauriyash/Code-Regression huggingface dataset:
#A問題
S = list(str(input()))
Slen = len(S)
now = ""
count = 0

dp = [0 for i in range(Slen)]

if Slen >= 1:
    dp[0] = 1
if Slen >= 2:
    if S[0] == S[1]:
        dp[1] = 1
    else:
        dp[1] = 2
if Slen >= 3:
    if S[0] == S[1] or S[1] == S[2]:
        dp[2] = 2
    else:
        dp[2] = 3

for i in range(Slen-3):
    I = i+3
    if now == S[I]:
            dp[I] = dp[I-3]+2
            
    else:
        dp[I] = dp[I-1]+1
            
    now = S[I]
            
print(dp[Slen-1])

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

int main() {
	int64_t A,B,C,K;
	cin >> A >> B >> C >> K;

	int64_t max_sum=0;
	if (A>=K) max_sum=K;
	else if (B>=(K-A)) max_sum=A;
	else max_sum=A-(K-A-B);
	cout << max_sum << endl;
	return 0;
}


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

int INF = 1'000'000'000;

int main(){
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<vector<int>> med(401, vector<int>(401, INF));
    queue<tuple<int, int, int>> que; 
    int a, b, c;
    for (int i = 0; i < n; i++){
        cin >> a >> b >> c;
        que.push(tie(a, b, c));
        for (int x = 0; x < 401; x++){
            for (int y = 0; y < 401; y++){
                int p = x + a;
                int q = y + b;
                int r = med[x][y] + c;
                if (med[x][y] != INF) que.push(tie(p, q, r));
            }
        }
        while (que.size() > 0){
            a = get<0>(que.front());
            b = get<1>(que.front());
            c = get<2>(que.front());
            que.pop();
            med[a][b] = min(med[a][b], c);
        }
    }
    int ans = INF;
    int x = 0;
    int y = 0;
    while (1){
        x += ma;
        y += mb;
        if (x > 400 || y > 400) break;
        ans = min(ans, med[x][y]);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 1152
#include <iostream>

using namespace std;

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

    if (a > b)
    {
        swap(a, b);
    }
    if (b > c)
    {
        swap(b, c);
    }
    a = a*b/2;
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

//#include<bits/stdc++.h>

// #include "beginner_138/beginner_138.h"
// Still dunno how to put linker 

using namespace std; 

void a_ques(){
    int n;
    cin >> n;

    cout << 3 * (n * n);
}

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

    a_ques();
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll mod=1e9+7;

int main()
{
    ll a,b;
    cin >> a >> b;
    if(100*a>=80*b+80 || 80*b>=100*a+100){
        cout << -1 << endl;
        return 0;
    }
    ll p=max(100*a,80*b);
    ll q=min(100*a+100,80*b+80);
    for(ll i=p;i<q;i++){
        if(i%8==0){
            cout << i/8 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
} 

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

bool ok[1010];
ll f[1010];
signed main(void)
{
	ll x, n;
	set<ll> st;
	cin >> n;
	x = n;
	for(ll i = 2; i * i <= n; i++)
	{
		ll cnt = 0;
		while (x % i == 0)
		{
			cnt++;
			x /= i;
		}
		for(int j = 1; j <= cnt; j++)
		{
			st.insert(pow(i, j));
			cnt -= j;
		}
	}
	if (x != 1) st.insert(x); 
	ll ans = st.size();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4000
#include"iostream"

using namespace std;

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

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

int main() {
  string s;
  cin >> s;

  int ans = 0;
  ans += atoi(s.substr(0, 1).c_str());
  ans += atoi(s.substr(1, 1).c_str());
  ans += atoi(s.substr(2, 1).c_str());
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Arrays;

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

        int counter = 0;
        int x , y;
        while(true){
            x = sc.nextInt();
            y = sc.nextInt();
            if(x==0 && y==0)break;
            if(x<y)System.out.println(x+" "+y);
            else System.out.println(y+" "+x);
        }

    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                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) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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



Measured memory_bytes: 27016
def main():
    H, W = map(int, input().split())
    board = list()

    for i in range(H):
        board.append(list(input()))

    stat = [[False for i in range(W)] for j in range(H)]

    go = True
    i = j = 0
    stat[i][j] = True
    while go:

        if (i < H) and (j + 1 < W) and board[i][j + 1] == "#":
            j = j + 1
            stat[i][j] = True
        elif (i + 1 < H) and (j < W) and board[i + 1][j] == "#":
            i = i + 1
            stat[i][j] = True
        else:
            break

    ans = True
    for i in range(H):
        for j in range(W):
            if board[i][j] == "#" and stat[i][j] == False:
                ans = False

    if ans:
        print("Possible")
    else:
        print("Impossible")
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 9176
n = int(input())
f_matrix = [[0]*10]*n
p_matrix = [[0]*11]*n
f_matrix = [[int(i) for i in input().split()] for _ in range(n)]
p_matrix = [[int(i) for i in input().split()] for _ in range(n)]

ans = -10**20
for i in range(1, 2**10):
  tmp = 0
  for j in range(n):
    c = 0
    for k in range(10):
      if i>>k&1 and f_matrix[j][k] is 1:
        c += 1
    tmp += p_matrix[j][c]
  ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 3064
K = int(input())
used = set()
pos = 1
v = 0

while 1:
    v += 7*pow(10, pos-1, K)
    v %= K
    if v==0:
        print(pos)
        break
    if v in used:
        print(-1)
        break
    used.add(v)
    pos += 1

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
    cin.sync_with_stdio(false);
    ll n, l, a, b, s, t;
    cin >> n >> l;

    bool ok = false;
    cin >> a;
    rep(i, n - 1) {
        cin >> b;
        if (a + b >= l) {
            ok = true;
            s = i;
            t = i + 1;
        }
        a = b;
    }

    if (ok) {
        cout << "Possible" << endl;
        rep(i, s) cout << i + 1 << endl;
        for(int i = n - 2; i > s; i--) cout << i + 1 << endl;
        cout << s + 1 << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}

Measured memory_bytes: 896
#include <stdio.h>
int main(void)
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if ((0 <= a) && (0 <= b) && (0 <= c) && (a <= 100) && (b <= 100) && (c <= 100) && (a < b) && (b < c))
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 30;
const ll MOD = 1000000007;

ll dp[101010];

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int n; cin >> n;
    vector<ll> a(3 * n);
    for(int i = 0; i < 3 * n; ++i){
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());

    ll ans = 0;
    for(int i = 0; i < n; ++i){
        ans += a[2 * i + 1];
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    bool flag = true;
    int cnt = 0;
    while (flag) {
        for (int i = 0; i < n; i++) {
            if (a[i]%2 == 0) {
                a[i] /= 2;
            }
            else flag = false;
        }
        cnt++;
    }

    cout << cnt - 1 << endl;

    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    ll yi;
    ll y;
    vector<ll> lis;
    cin >> N;
    repi2(i, 1, N) {
        yi = i;
        y = (i + 1) * i / 2;
        if(y >= N) break;
    }
    repi2(i, 1, yi) if(i != y - N) cout << i << endl;
    return 0;
}


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

const ll INF = pow(10, 9) + 7;

int main() {
  int N;
  cin >> N;
  map<string,int> m;
  rep(i,N){
    string s;
    cin >> s;
    m[s]++;
  }
  int mm = 0;
  for(auto p:m) mm = max(mm,p.second);
  for(auto p:m){
    if(p.second != mm) continue;
    cout << p.first << endl;
  }
}


Measured memory_bytes: 25216
from collections import deque
import copy
N,K = map(int, input().split())
p = list([(i+1)* i/2/i for i in map(int, input().split())])
que = deque([0]* K)
sumM = 0
sumq = 0
E = 0.0

for i in range(N):
    sumq -= que.popleft()
    sumq += p[i]
    que.append(p[i])
    if E < sumq:
        E = sumq
print(E)

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int cnt = 0;
  rep(i, 0, n){
    if(s[i]=='p')cnt++;
  }
  cout << n/2-cnt << endl;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int max = 1e5 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

 int getSum(ll n) 
    {  
    int sum = 0; 
    while (n != 0) 
    { 
     sum = sum + n % 10; 
     n = n/10; 
    }  
 return sum; 
 } 

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	//ifstream cin (".in");
	//ofstream cout (".out");
    string s;
    cin >> s;
    int ans = 0;
    for(int i=0; i<s.size(); i++){
    	ans+=s[i]-'0';
    }
    if(ans%9 == 0){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
}




Measured memory_bytes: 3748
import java.util.Scanner;

public class Main{
	public  static void main(String[] args) {
    	try (Scanner sc = new Scanner(System.in)) {
    		//dp[重さ]=価値
    		int N=sc.nextInt();
    		int W=sc.nextInt();
    		int[] v=new int[N+1];
    		int[] w=new int[N+1];
    		for(int i=1; i<=N; i++) {
    			v[i]=sc.nextInt();
    			w[i]=sc.nextInt();
    		}
    		int[][] dp=new int[N+2][W+1];
    		for(int i=1; i<=N; i++) {
    			for(int j=1; j<=W; j++) {
    				if(w[i]<=j) {
    					dp[i+1][j]=Math.max(dp[i][j-w[i]]+v[i], dp[i][j]);
    				}
    				else
    					dp[i+1][j]=dp[i][j];
    			}
    		}
    		System.out.println(dp[N+1][W]);
    	}
    }
}


Measured memory_bytes: 31364
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N+1];

        int num = 0;
        int pre = -2;

        for(int i = 1; i<=N; i++) {
            a[i] = sc.nextInt();
            if(a[i] == i) {
                if(pre == i-1) pre = 0;
                else {
                    num++;
                    pre = i;
                }
            }
        }
        System.out.println(num);




    }
}

Measured memory_bytes: 50656
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        a: [u64; n]
    }

    let mut cnt_4 = 0usize;
    let mut cnt_2 = 0usize;
    for i in 0..n {
        if a[i] % 4 == 0 {
            cnt_4 += 1;
        } else if a[i] % 2 == 0 {
            cnt_2 += 1;
        }
    }
    let is_ok = cnt_4 >= n/2 || cnt_4 >= (n - cnt_2 + 1) / 2;
    println!("{}", if is_ok {"Yes"} else {"No"});
}

Measured memory_bytes: 4352
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp3
{

    class Program
    {
        static void Main(string[] args)
        {
            float n = float.Parse(Console.ReadLine());
            float a = 0;

            if (n % 2 == 0)
            {
                a = n / 2;
            }
            else if(n ==1)
            { a = 1; }

            else if (n % 2 == 1)
            { a = (n+1) / 2 ; }


            Console.WriteLine(a/n);
        }
    }
}

Measured memory_bytes: 11092
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin >> n;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        if (!(i & 1) && a & 1) ++ans;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3656
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

char s[110];
ll ans=INF;
int main(){
	scanf("%s",s);
	ll n=strlen(s);
	rep(c,'a','z'+1){
		ll temp=0;
		ll pre=-1;
		s[n]=c;
		for(ll i=0;i<n+1;i++)if(s[i]==c){
			temp=max(temp,i-pre-1);
			pre=i;
		}
		ans=min(ans,temp);
	}
	printf("%lld\n",ans);
}

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

const int mxN=1000, M=1e9+7;
int h, w, dp[mxN][mxN];
string g[mxN];

bool ie(int i, int j) {
	return i>=0&&j>=0&&g[i][j]=='.';
}

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

	cin >> h >> w;
	for(int i=0; i<h; ++i)
		cin >> g[i];
	dp[0][0]=1;
	for(int i=0; i<h; ++i) {
		for(int j=0; j<w; ++j) {
			if(ie(i-1, j))
				dp[i][j]+=dp[i-1][j];
			if(ie(i, j-1))
				dp[i][j]+=dp[i][j-1];
			dp[i][j]%=M;
		}
	}
	cout << dp[h-1][w-1];
}

Measured memory_bytes: 5248
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,Classes;
var
  h,w,i,j,count,x,y,sw,m,n,c:Integer;
  a:array[0..12] of Integer = (0,1,3,1,2,1,2,1,1,2,1,2,1);
  s123,s1,s2,s3:string;
  tf:Boolean;
  nyu:TStringList;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Read(x);
    Readln(y);

    if a[x]=a[y] then
      Writeln('Yes')
    else
      Writeln('No');
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] prefix_postfix_digits = new int[100];
        for (int i = 1; i <= N; i++) {
            String s = Integer.toString(i);
            char[] d = s.toCharArray();
            int len = d.length;
            char first = d[0];
            char last = d[len - 1];
            int index = ((int)first-'0')*10 + ((int)last-'0');
            prefix_postfix_digits[index] += 1;
        }
        long ans = 0;
        for (int i = 11; i < 100; i++) {
            if (i % 10 == 0) {
                continue;
            }
            if (prefix_postfix_digits[i]==0) {
                continue;
            }
            int r = (i % 10) * 10 + i / 10;
            if (prefix_postfix_digits[r]==0) {
                continue;
            }
            ans += ((long) prefix_postfix_digits[i]) * ((long) prefix_postfix_digits[r]);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 38868
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    ans = 1000-N%1000
    if ans == 1000:
        print(0)
    else:
        print(ans)

if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> q[i];
    }

    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        v[i] = i+1;
    }
    int cnt = 0;
    int a, b;
    bool flag;
    do{
        cnt++;
        flag = true;
        for (int i = 0; i < n; ++i) {
            if (v[i] != p[i]) flag = false;
        }
        if (flag) a = cnt;

        flag = true;
        for (int i = 0; i < n; ++i) {
            if (v[i] != q[i]) flag = false;
        }
        if (flag) b = cnt;
    } while(next_permutation(all(v)));

    cout << abs(a-b) << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int N,K;cin>>N>>K;
    int V[N];
    REP(i,N)cin>>V[i];
    int ans=0;
    priority_queue<int> que;
    for(int A=0;A<=min(N,K);A++){
        for(int B=0;B<=min(N,K)-A;B++){
            int preans=0;
            while(!que.empty())que.pop();
            REP(i,A)que.push(-V[i]);
            REP(i,B)que.push(-V[N-1-i]);
            REP(i,K-A-B){
                if(que.empty()) break;
              	int d=que.top();
                if(d>0)que.pop();
            }
            while(!que.empty()){
                preans-=que.top();
                que.pop();
            }
            ans=max(ans,preans);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
const { count } = require("console");

function main(lines) {
  const [N, M] = na();

  const ans = count(N) + count(M);

  function count(n) {
    let cnt = 0;
    n--;
    while (n > 0) {
      cnt += n;
      n--;
    }
    return cnt;
  }
  
  return ans;
}



const lines = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");

let lineCount = 0;
const s = () => lines[lineCount++];
const n = () => Number(s());
const b = () => BigInt(s());
const sa = () => s().split(' ');
const na = () => sa().map(Number);
const ba = () => sa().map(BigInt);

const ans = main(lines);
console.log( ans );

Measured memory_bytes: 29580
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  int t=1;
  
  cin >>N>>K;
  
  for(int i=0;i<N;i++){
    if(t*2<t+K) t=t*2;
    else t=t+K;
    
  }
  
  cout << t <<endl;
  
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
using namespace std;

int main() {

  long long int n, k;
  cin >> n >> k;

  vector< long long int > v0, v1;

  for ( long long int i = 0; i < n; i++ ) {

    long long int in;
    cin >> in;

    if ( in < 0 ) {
      v0.push_back( -in );
    } else {
      v1.push_back( in );
    }

  }

  sort( v0.begin(), v0.end() );
  sort( v1.begin(), v1.end() );

  long long int ans = 1145141919114514LL;

  for ( long long int i = 0; i <= v0.size(); i++ ) {

    long long int j = k - i;
    if ( j > v1.size() ) continue;

    long long int x = 0, y = 0;
    if ( i > 0 ) x = v0[ i - 1 ];
    if ( j > 0 ) y = v1[ j - 1 ];

    ans = min( ans, min( x, y ) * 2 + max( x, y ) );

  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 1656
#include<iostream>

using namespace std;

const int MAX_N = 100 ;
int A[MAX_N];
int flag[1000];
int N ;


int main(void){
  int sum = 0 ;
  cin >> N ;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }

  for(int i = 0; i < N; i++){
    flag[A[i]] = 1 ;
  }
  for(int i = 0; i < 1000; i++){
    sum += flag[i];
  }


  cout << sum << endl;

  return 0;




}



Measured memory_bytes: 256
from collections import deque
import copy
INF = 20 * 20 + 1

def main():
    H, W = map(int, input().split())
    maze = [list(input()) for _ in range(H)]

    ans = 0
    goal_base = [[-1 for _ in range(W+2)] for _ in range(H)]
    goal_base = [[-1 for _ in range(W+2)]] + goal_base + [[-1 for _ in range(W+2)]]
    for h in range(H):
        for w in range(W):
            if maze[h][w] == '#':
                goal_base[h+1][w+1] = -1
            else:
                goal_base[h+1][w+1] = INF

    for hs in range(H):
        for ws in range(W):
            if maze[hs][ws] == '#':
                continue

            goal_dists = copy.deepcopy(goal_base)
            goal_dists[hs+1][ws+1] = 0
            d = deque([[hs+1, ws+1]])
            while len(d) > 0:
                ht, wt = d.popleft()
                dist = goal_dists[ht][wt]
                for dh, dw in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
                    if goal_dists[ht+dh][wt+dw] == INF:
                        goal_dists[ht+dh][wt+dw] = dist + 1
                        d.append([ht+dh, wt+dw])
            
            max_dist = [goal_dists[h][w] for w in range(1, W+2) for h in range(1, H+2) if goal_dists[h][w] != INF]
            ans = max(ans, max(max_dist))

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3436
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

string s; int n;
int K;
int dp[300][300][301];
int iter[2][300][26];

int dfs(int l, int r, int x) {
	int len = r - l + 1;
	if (len == 1) return 1;
	if (len <= 0) return 0;
	if (dp[l][r][x] != -1) return dp[l][r][x];
	
	int ret = 0;
	if (x > 0 && len >= 2) ret = 2 + dfs(l + 1, r - 1, x - (s[l] != s[r]));
	
	for (int i = 0; i < 26; i++) {
		int nl = iter[0][l][i];
		int nr = iter[1][r][i];
		if (nl == -1 || nr == -1 || nl > nr) continue;
		int res = 2 - (nl == nr) + dfs(nl + 1, nr - 1, x);
		ret = max(ret, res);
	}
	return dp[l][r][x] = ret;
}

int main() {
	int i, j, k;
	
	cin >> s >> K;
	n = s.length();
	rep(i, n) rep(j, n) rep(k, n + 1) dp[i][j][k] = -1;
	rep(i, 2) rep(j, n) rep(k, 26) iter[i][j][k] = -1;
	
	rep(i, n) {
		for (j = i; j < n; j++) {
			if (iter[0][i][s[j] - 'a'] == -1) {
				iter[0][i][s[j] - 'a'] = j;
			}
		}
		for (j = i; j >= 0; j--) {
			if (iter[1][i][s[j] - 'a'] == -1) {
				iter[1][i][s[j] - 'a'] = j;
			}
		}
	}
	int res = dfs(0, n - 1, K);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 106112
def resolve():
    MOD = 998244353
    N = int(input())
    D = list(map(int, input().split()))

    if D[0] != 0:
        print(0)
        return

    CNT = [0] * N
    for i in D:
        CNT[i] += 1

    if CNT[0] > 1:
        print(0)
        return

    ans = 1
    for i in range(1, N):
        ans *= pow(CNT[i - 1], CNT[i], MOD)
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 20572
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s;
 cin >> s;
 int jk = 0;
 if(s.at(0) == 'o'){
	jk++;}
 if(s.at(1) =='o'){
	jk++;}
 if(s.at(2) == 'o'){
 	jk++;}
 cout << 700 + 100*jk << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#define MAX 1000005

using namespace std;
int ans[MAX];

int main(){
    int n;
    int cur;
    scanf("%d",&n);
    for(int i =0;i<n-1;i++){
        scanf("%d",&cur);
        ans[cur]++;
    }
    for(int i =1;i<=n;i++)printf("%d\n",ans[i]);
    
}

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

int main(){
  long long N, M;
  cin >> N >> M;
  vector<pair<long long,long long>> A(N);
  for(long long i=0; i<N; i++) cin >> A[i].first >> A[i].second;
  sort(A.begin(), A.end());
  long long ans=0;
    for(long long i=0; i<N; i++){
      if(A[i].second<M){
        ans+=A[i].first*A[i].second;
        M-=A[i].second;
      }
      else{
        ans+=A[i].first*M;
        break;
      }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    double a,b,h,w;cin>>a>>b>>h>>w;
    double x=2*pi*abs(h/12+w/60/12-w/60);
    decimal;
    out(sqrt(a*a+b*b-2*a*b*cos(x)));
}

Measured memory_bytes: 4228
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
#define dbg(...)    cerr << "> "; ZZ(#__VA_ARGS__,__VA_ARGS__);
template <typename Arg1> void ZZ(const char* val1, Arg1&& arg1) { cerr << val1 << ": " << arg1 << endl; }
template <typename Arg1, typename... Args> void ZZ(const char* vals, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(vals + 1, ',');
    std::cerr.write(vals, comma - vals) << ": " << arg1<<" , ";
    ZZ(comma+1, args...);
}

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    
    int n;
    cin >> n;
    map<int, int> m;
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        m[i] = a;
    }
    int c = 0;
    for (int i = 1; i <= n; i++) {
        if (m[m[i]] == i) c++;
    }
    cout << c / 2 << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    
    ios_base::sync_with_stdio(0);
    int n,m;
    cin>>n>>m;
    int d[m];
    for(int i=0;i<m;i++)    cin>>d[i];

    int coins[n+1];
    for(int i=0;i<=n;i++)   coins[i]=INT_MAX;
    coins[0] = 0, coins[1] = 1;
    
    //for(int i=0;i<=n;i++)    cout<<coins[i]<<" ";
    //cout<<"\n";
    for(int i=2;i<=n;i++){
        for(int j=0;j<m;j++){
            if(i>=d[j]){
                coins[i] = min(coins[i], coins[i-d[j]]+1);
            }
        }
    }
   //for(int i=0;i<=n;i++)    cout<<coins[i]<<" ";
   //cout<<"\n";
    cout<<coins[n]<<endl;
    //for(int i=0)
    return 0;
}




Measured memory_bytes: 3360
import bisect

N, K = map(int, input().split())
V = list(map(int, input().split()))


ans = 0
R = min(N, K)
for r in range(R+1):
  for a in range(r+1):
    left = V[:a]
    b = r - a
    if b == 0:
      right = []
    else:
      right = V[-b:]
    
    v = left + right
    v.sort()
    n_nega = bisect.bisect_left(v, 0)
    k = min(n_nega, K-r)
    ans = max(ans, sum(v[k:]))


print(ans)

Measured memory_bytes: 3064
import java.io.PrintWriter
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
  val paras = listOfInt()
  val r = paras[0]-paras[1]
  val ans =  if(paras[2] >= r) paras[2]-r else 0
  println(ans)
}

// 入力取得
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37824
#include <iostream>

using namespace std;

int pow(int r){
	int result=1;
	for(int i=0;i<r;i++){
		result *= 10;
	}
	return result;
}

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		char inp[20]={0},out[10]={0};
		int a=0,b=0,t;
		bool num=true;
		cin >> inp;
		for(int j=0;j<10;j++){
			if(inp[j]==0){ break; }
			if(inp[j]=='m'||inp[j]=='c'||inp[j]=='x'||inp[j]=='i'){
				if(num==true){
					t=1;
				}
				num=true;
				a+=t*((inp[j]=='m')?1000:((inp[j]=='c')?100:((inp[j]=='x')?10:1)));
			}
			else{
				t=inp[j]-48;
				num=false;
			}
		}
		cin >> inp;
		num=true;
		for(int j=0;j<10;j++){
			if(inp[j]==0){ break; }
			if(inp[j]=='m'||inp[j]=='c'||inp[j]=='x'||inp[j]=='i'){
				if(num==true){
					t=1;
				}
				num=true;
				b+=t*((inp[j]=='m')?1000:((inp[j]=='c')?100:((inp[j]=='x')?10:1)));
			}
			else{
				t=inp[j]-48;
				num=false;
			}
		}
		int k=0,l=3,m;
		t=a+b;
		//cout <<a<<"+"<<b<<"="<<t <<endl;
		while(t>0){
			m=(int)(t/pow(l));
			if(m==1){
				out[k]=((l==3)?'m':((l==2)?'c':((l==1)?'x':'i')));
				k++;
			}
			else if(m!=0){
				out[k]=m+48;
				out[k+1]=((l==3)?'m':((l==2)?'c':((l==1)?'x':'i')));
				k+=2;
			}
			t=t-m*pow(l);
			l--;
		}
		cout << out <<endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

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

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
    fact.resize(n+5);
    inv_fact.resize(n+5);
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = (fact[i-1] * i) % mod;
        inv_fact[i] = exp(fact[i], mod-2, mod);
    }
}
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
    if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll komb(ll a, ll b){
    if(a < b) return 0;
    return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 2e5 + 5;

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	int n, k; cin>>n>>k;
	vector<int> vec(n);
	for(auto &x: vec) cin>>x;
	if(k == 0){
		int mx = 0;
		for(int i = 0; i < n; i++) mx = max(mx, vec[i]);
		cout<<mx;
		return 0;
	}
	int l = 1, r = 1e9;
	while(l < r){
		int mid = (l + r)/2;
		ll cnt = 0;
		for(int i = 0; i < n; i++){
			cnt += (vec[i] - 1) / mid;
		}
		if(cnt <= k) r = mid;
		else l = mid+1;
	}
	cout<<l;
}

Measured memory_bytes: 3976
void main()
{
    string s = rdStr;

    s = s[0..$-2];
    long len = s.length >> 1;
    while (s[0..len] != s[len..$])
    {
        s = s[0..$-2];
        --len;
    }

    s.length.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from math import ceil
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

n,k=map(int,input().split())
A=list(map(int,input().split()))
print(ceil((n-1)/(k-1)))


Measured memory_bytes: 59376
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i).sort
arr = Array.new((10 ** 6)+1,0)
a.each do |i|
    next if arr[i] == 2 
    sa = i
    until i > 10 ** 6 
        arr[i] += 1 
        i += sa
    end
end
count = 0
a.each do |i|
    count += 1 if arr[i] == 1
end
puts count

Measured memory_bytes: 39872
#include<stdio.h>

int main(){

  int W,H,x,y,r;

  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

  if(x*y>=0){
    if(x>=0){
      if ((x-r)>=0 && (y-r)>=0 && (W-x)>=r && (H-y)>=r){
        printf("Yes\n");
      }
      else{
        printf("No\n");
      }
    }
    else{
      printf("No\n");
    }
}

    else {
      printf("No\n");
    }

  return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int a, b, c, d;

int main(void){
    
    scanf("%d %d %d %d", &a, &b, &c, &d);
    printf("%d\n", max(a * b, c * d));
    
    return 0;
}

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


int a[1010];
int convert(int l,int r){
	int ret=0;
	for(int i=l;i<=r;++i) ret=10*ret+a[i];
	return ret;
}

set<int> s;

int main(void){
	int n;
	cin >> n;
	for(int i=0;i<n;++i) cin >> a[i];

	for(int l=0;l<n;++l){
		for(int r=l;r<n;++r){
			if(r-l+1>=10) continue;
			s.insert(convert(l,r));
		}
	}

	int ans=0;
	while(s.find(ans)!=s.end()) ans++;
	cout << ans << endl;
	return 0;
}

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

int main() {
  int x, m = 1, t;
  cin >> x;
  for(int i = 2; i < 33; i++) {
    t = i * i;
    if(t > x)
      continue;
    while(t <= x)
      t *= i;
    m = max(m, t / i);
  }
  cout << m << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int h, w;
    cin >> h >> w;
    map<char, int> mp;
    rep (i, 0, h * w) {
        char a;
        cin >> a;
        mp[a]++;
    }
    int odd = 0, over4 = 0;
    bool ans = 1;
    for (auto p : mp) {
        if (p.second % 2 == 1) odd++;
        if (p.second > 3) {
            over4 += p.second / 4;
        }
    }
    if (h % 2 == 1 && w % 2 == 1) {
        if (odd > 1) {
            ans = 0;
        }
    } else {
        if (odd > 0) {
            ans = 0;
        }
    }
    if ((h / 2) * (w / 2) > over4) {
        ans = 0;
    }
    if (ans) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

Measured memory_bytes: 256
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Measured memory_bytes: 9376
#include<iostream>
using namespace std;
int main()
{
  int i,x;
  int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin>>x;
  cout<<a[x-1];
  return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val m = sc.nextInt()
  val k = sc.nextInt()
  val uf = UnionFind(n)
  val ans = new Array[Int](n)
  for (i <- 0 until m) {
    val a = sc.nextInt() - 1
    val b = sc.nextInt() - 1
    uf.unite(a, b)
    ans(a) = ans(a) - 1
    ans(b) = ans(b) - 1
  }
  for (i <- 0 until n) {
    ans(i) = ans(i) + uf.size(i) - 1
  }
  for (i <- 0 until k) {
    val c = sc.nextInt() - 1
    val d = sc.nextInt() - 1
    if (uf.same(c, d)) {
      ans(c) = ans(c) - 1
      ans(d) = ans(d) - 1
    }
  }
  for (i <- 0 until n) {
    print(ans(i))
    if (i < n - 1) print(" ")
  }
  println()
  case class UnionFind(val n: Int) {
    val par = Array.fill(n)(-1)
    val sz = Array.fill(n)(1)
    def find(x: Int): Int = {
      if (par(x) == -1) par(x) = x
      if (par(x) != x) {
        par(x) = find(par(x))
      }
      par(x)
    }
    def unite(x: Int, y: Int): Unit = {
      val a = find(x)
      val b = find(y)
      if (a == b) return
      if (sz(a) > sz(b)) {
        sz(a) += sz(b)
        par(b) = par(a)
      } else {
        sz(b) += sz(a)
        par(a) = par(b)
      }
    }
    def same(x: Int, y: Int): Boolean = {
      find(x) == find(y)
    }
    def size(x: Int): Int = {
      sz(find(x))
    }
  }
}


Measured memory_bytes: 115088
#include <iostream>
#include <vector>
#define INF (int)1e9
using namespace std;

int main() {
    int n, min = INF;
    vector<int> a;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        a.push_back(x);
        if (x < min) min = x;
    }
    for (int i = 1; i <= min; i++) {
        bool flag = true;
        for (int j = 0; j < n; j++) {
            if (a[j] % i != 0) {
                flag = false;
                break;
            }
        }
        if (flag) cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
n = int(input())
a = [int(x) for x in input().split()]

b_even = [x for n, x in enumerate(a) if (n+1) % 2 == 0]
b_odd = [x for n, x in enumerate(a) if (n+1) % 2 == 1]

if n % 2 == 0:
    b_even.reverse()
    res = b_even + b_odd
else:
    b_odd.reverse()
    res = b_odd + b_even

print(*res)

Measured memory_bytes: 25156