akhauriyash/Code-Regression huggingface dataset:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
N = ri()
if N % 2 == 1:
    print(0)
    exit()
print(sum([N // (2 * (5 ** i)) for i in [j for j in range(1, 100)]]))


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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H.at(i);
	}

	vector<int> cnt(N, 1);
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		int h_A = H.at(A - 1), h_B = H.at(B - 1);
		if (h_A > h_B) {
			cnt.at(B - 1) = 0;
		} else if (h_A < h_B) {
			cnt.at(A - 1) = 0;
		} else {
			cnt.at(A - 1) = 0;
			cnt.at(B - 1) = 0;
		}
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		ans += cnt.at(i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

ll gcd(ll x, ll y){
    if (y==0) return x;
    else return gcd(y, x%y);
}
int main(){
    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    ll ans = A[0];
    rep(i,N){
        if (i == 0) continue;
        ans = gcd(ans,A[i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define MAXN 600
using namespace std;

int arr[MAXN], outro[MAXN], n, k;

bool solve(int g) {
	int soma = 0;
	for (int i=0; i<n; i++) {
		outro[i] = arr[i] % g;
		soma += g - outro[i];
	}
	if (soma == 0) return true;
	sort(outro, outro+n);
	int suma = 0;
	for (int i=0; i<n; i++) {
		suma += outro[i];		
		soma -= g - outro[i];
		if (suma == soma) return suma <= k;
	}
	return false;
}

int main() {
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif
	scanf("%d %d", &n, &k);
	int soma = 0;
	for (int i=0; i<n; i++) {
		scanf("%d", &arr[i]);
		soma += arr[i];
	}

	int res = 1;
	for (int i=1; i<=sqrt(soma)+2; i++) {
		if (soma % i == 0) {
			if (solve(i)) res = max(res, i);
			if (solve(soma/i)) res = max(res, soma/i);
		}
	}

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



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll      long long
#define pii     pair<int, int>
#define f       first
#define s       second
#define read	freopen("input.txt", "r", stdin)
#define write	freopen("output.txt", "w", stdout)
#define mx      5e12

using namespace std;
ll dp[3010][3010];
int main()
{
    string s, t, ans;
    cin>>s;
    cin>>t;

    int n = s.size(), m = t.size();
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }

//    cout<<dp[n][m];

    for(int i=n, j=m; i>0 & j>0;){
        if(dp[i][j]!=dp[i-1][j] && dp[i][j]!=dp[i][j-1]){
            ans = s[i-1] + ans;
            i--;
            j--;
        }
        else if(dp[i][j] == dp[i][j-1]){
            j--;
        }
        else
            i--;
    }

    cout<<ans;
}




Measured memory_bytes: 70912
package main

import (
    "fmt"
    "os"
)

func main() {

    var N, Y int64
    fmt.Fscanf(os.Stdin, "%d %d", &N, &Y)

    for a := int64(0); a <= N; a++ {
        for b := int64(0); b <= N; b++ {
            if a+b > N {
                break
            }
            remain := Y - a*10000 - b*5000
            if remain < 0 {
                break
            }
            c := remain / 1000
            if a+b+c != N {
                continue
            }
            fmt.Printf("%d %d %d\n", a, b, c)
            return
        }
    }
    fmt.Printf("-1 -1 -1\n")
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n; cin >> n;
  vector<ll> a(n), b(n), c(n+1, 0);
  rep(i, n) cin >> a[i] >> b[i];

  for(int i = n-1; i >= 0; --i) {
    a[i] += c[i+1];
    c[i] = (b[i] - a[i]%b[i]) % b[i];
    c[i] += c[i+1];
  }
  cout << c[0] << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int64_t N;
    cin >> N;
    int64_t r = N * 800;
    int64_t s = (N / 15) * 200;
    cout << r - s << endl;
    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int H = int.Parse(str[0]);
        int W = int.Parse(str[1]);
        int N = int.Parse(Console.ReadLine());
        str = Console.ReadLine().Split(' ');
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = int.Parse(str[i]);
        }
        int[,] C = new int[H,W];
        int p = 0;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(A[p] == 0){
                    p++;
                }
                if(i%2 == 0){
                    C[i,W-1-j] = p+1;
                }
                else{
                    C[i,j] = p+1;
                }
                A[p]--;
            }
        }
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                sb.Append(C[i,j]);
                if(j == W-1){
                    sb.Append("\n");
                }
                else{
                    sb.Append(" ");
                }
            }
        }
    }
}

Measured memory_bytes: 11360
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

    void solve() throws IOException {
        int n = ni();
        int[] a = nia(n);
        Arrays.sort(a);

        int ans = 0;
        long sum = 0;
        for (int i = 0; i < n; i++) {
            if (sum * 2 < a[i]) {
                ans = 0;
            }

            sum += a[i];
            ans++;
        }

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 42324
# coding: utf-8
# Your code here!

num = int(input())
cardlist = [[0 for i in range(13)]for j in range(4)]
for i in range(num):
    card = input().split()
    if(card[0]=="S"):
        cardlist[0][int(card[1])-1] = 1
    elif(card[0]=="H"):
        cardlist[1][int(card[1])-1] = 1
    elif(card[0]=="C"):
        cardlist[2][int(card[1])-1] = 1
    elif(card[0]=="D"):
        cardlist[3][int(card[1])-1] = 1
strsuit = "S"
for suit in range(len(cardlist)):
    for cmax in range(13):
        if(cardlist[suit][cmax] == 0):
            print("{0} {1}".format(strsuit,cmax+1))
    if(suit == 0):
        strsuit = "H"
    elif(suit == 1):
        strsuit = "C"
    elif(suit == 2):
        strsuit = "D"



Measured memory_bytes: 5620
#include<stdio.h>
main()
{
int x,y,z,sum=0;
scanf("%d",&x);
z=x;
while(z>0)
{
y=z%10;
sum=sum+y;
z=z/10;
}
if(x%sum==0)
printf("Yes\n");
else
printf("No\n");
return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
	string str1, str2,str3,str4,str5;
	int i,n,j,k,a,b;
	cin >> str1;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> str2;
		if (str2 == "replace") {
			cin >> a >> b >> str3;
			str1.replace(a, (b - a+1), str3);
		}
		else if (str2 == "reverse") {
			cin >> a >> b;
			for (k = a; k <= b; k++) {
				str4 += str1[k];
			}
			reverse(str4.begin(), str4.end());
			str1.replace(a, (b - a+1), str4);
			str4 = "";
		}
		else {
			cin >> a >> b;
			for (j = a; j <= b; j++) {
				cout<< str1[j];
			}
			cout << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3224
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

ll euclid(ll a, ll b)
{
    int nr = 0;
    while (b != 0)
    {
        int c = b;
        b = a % b;
        a = c;
        nr++;
    }
    return nr;
}


int main()
{
    string s;
    int nr0 = 0;
    int nr1 = 0;
    cin >> s;
    int lung = s.length();
    for (int i = 0; i < lung; i++)
    {
        if (s[i] == '0')
        {
            nr0++;
        }
        if (s[i] == '1')
        {
            nr1++;
        }
    }
    cout << min(nr0, nr1) * 2;
    return 0;
}


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

using namespace std;

typedef long long ll;


int main(int, char**)
{
	string s;
	ll x = 0, y = 0, ans = 0;
	cin >> s;

	for (int i = 0; i < s.length(); i++) {
		if ((i % 2) == 0) {
			if(s[i] == '1') {
				++x;
			} else {
				++y;
			}
		} else {
			if(s[i] == '1') {
				++y;
			} else {
				++x;
			}
		}
	}

	ans = min(x, y);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    rr = []
    g = []
    if n % 2 == 1:
        g.append([n])
        n -= 1
    for i in range(1,n//2+1):
        g.append([i,n-i+1])

    l = len(g)
    for i in range(l):
        for j in range(i+1,l):
            for c in g[i]:
                for d in g[j]:
                    rr.append('{} {}'.format(c, d))

    return '{}\n{}'.format(len(rr), '\n'.join(rr))


print(main())




Measured memory_bytes: 6860
#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <assert.h>
#include <sstream>
#include <type_traits>
#define SET(x,y) x |= (1 << y)
#define CLEAR(x,y) x &= ~(1<< y)
#define READ(x,y) ((0u == (x & (1<<y)))?0u:1u)
#define TOGGLE(x,y) (x ^= (1<<y))
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define si(n) scanf("%d",&n)
#define sf(n) scanf("%f",&n)
#define sl(n) scanf("%lld",&n)
#define slu(n) scanf("%llu",&n)
#define sd(n) scanf("%lf",&n)
#define ss(n) scanf("%s",n)
#define pnl printf("\n")
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pF first
#define pS second
#define CL(a,b) memset(a,b,sizeof(a))
#define sqr(x) ((x)*(x))
#define intLIMIT numeric_limits<int>
#define longLIMIT numeric_limits<long long>
#define GCD(a,b) __gcd((a),(b))
#define dbl(x) (double)(x)
#define vi vector <int>
#define vii vector < pair <int, int> >
#define vll vector <long long>
#define allof(x) (x).begin(), (x).end()
#define fastCin cin.sync_with_stdio(0);cin.tie(0)
#define scanUnsigned(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#define printArr(a,l) cout<<#a<<": ";for(int i=0;i<(l);i++){cout<<a[i]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(int i=0;i<(r);i++){for(int j=0;j<(c);j++){cout<<a[i][j]<<" ";}cout<<endl;}
char _;
using namespace std;
void PRINT (int x, int y) { for (int i = y-1; i >= 0; i--) { cout << READ(x,i); } cout << endl; }

vector<string>vec_splitter(string s){s+=',';vector<string>res;while(!s.empty()){res.push_back(s.substr(0,s.find(',')));s=s.substr(s.find(',')+1);}
return res;}
void debug_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,__attribute__((unused))int LINE_NUM){cerr<<endl;}
template<typename Head,typename...Tail>void debug_out(vector<string>args,int idx,int LINE_NUM,Head H,Tail...T){if(idx>0)cerr<<", ";else cerr<<"Line("<<LINE_NUM<<") ";stringstream ss;ss<<H;cerr<<args[idx]<<" = "<<ss.str();debug_out(args,idx+1,LINE_NUM,T...);}
#ifdef LOCAL_DBG
#define dbg(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define dbg(...) 42
#endif

int main () {
	fastCin;
	int n, x, t;
	cin >> n >> x >> t;
	cout << (int)ceil ((double)n/(double)x) * t << "\n";
	return 0;
}

Measured memory_bytes: 3248
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(size_t i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(size_t i=(b)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))

bool check(vector<int> v) {
	int tmp = 0;
	Foreach(item, v) {
		if (tmp == item) return false;
		tmp = item;
	}
	return true;
}


int main(){
	int N;
	cin >> N;
	map<int, int> m;
	REP(i, N) {
		int ai;
		cin >> ai;
		m[ai]++;
	}
	ll ans = m.size();
	out(ans % 2 != 0 ? ans : ans - 1);
}



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

int N, a[10009], sum, minx = 100000000, minid = 0;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) { cin >> a[i]; sum += a[i]; }
	for (int i = 0; i < N; i++) {
		int J = abs(a[i] * N - sum);
		if (minx > J) {
			minx = J; minid = i;
		}
	}
	cout << minid << endl;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
//#define fisier 1
using namespace std;
typedef long long ll;
const double dancila = 3.14159265359;
bool compara(int a, int b){
	if (a < b) return false;
	return true;
}
int main(){
	#ifdef fisier
        ifstream cin("input.in");
        ofstream cout("output.out");
    #endif	
		
	ios_base::sync_with_stdio();
	cin.tie(0);
	
	int n, m;
 	double s = 0;
	cin >> n >> m;
	vector < int > v(n);
	for (int i = 0; i < n; ++i){
		cin >> v[i];
		s+=v[i];
	}
	s /= (4 * m);
	sort (v.begin(), v.end(), compara);
	for (int i = 0; i < m; ++i){
		if (v[i] < s){
			cout << "No";
			return 0;
		}
	}	
	cout << "Yes";
}


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

int main() {
	// your code goes here
	string s;
	cin>>s;
	long long res = 0;
	for(int c=0;c<s.size();c++) {
		res += (s[c]-'0');
		res %= 9;
	}
	if(res==0) {
		cout<<"Yes";
	} else {
		cout<<"No";
	}
}

Measured memory_bytes: 3744
package main

import "fmt"

var n, m, q int
var as, bs, cs, ds []int
var max int

func main() {
	fmt.Scan(&n, &m, &q)

	as = make([]int, q)
	bs = make([]int, q)
	cs = make([]int, q)
	ds = make([]int, q)
	for i := 0; i < q; i++ {
		fmt.Scan(&as[i], &bs[i], &cs[i], &ds[i])
		as[i]--
		bs[i]--
	}

	for i := 1; i <= m; i++ {
		dfs([]int{i})
	}
	fmt.Println(max)
}

func dfs(vs []int) {
	if len(vs) == n {
		// score
		calc(vs)
		return
	}
	last := vs[len(vs)-1]
	for i := last; i <= m; i++ {
		dfs(append(vs, i))
	}
}

func calc(vs []int) {
	sum := 0
	for i := 0; i < q; i++ {
		if vs[bs[i]]-vs[as[i]] == cs[i] {
			sum += ds[i]
		}
	}
	if sum > max {
		max = sum
	}
}


Measured memory_bytes: 5976
#include<cstdio>
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
string s[5*5001+1];
char a[5010];
int k,cnt=0,size=0;
bool Cmp(string t1,string t2)
{
	int i;
	for (i=0;i<t1.size()&&i<t2.size();i++)
	{
		if (t1[i]<t2[i]) return true;
		if (t1[i]>t2[i]) return false;
	}
	if (t1.size()<t2.size()) return true;
	else return false;
}
bool cmp(const string& t1,const string& t2)
{
	return Cmp(t1,t2);
}
int main()
{
	scanf("%s%d",a,&k);
	for (;a[size]>='a'&&a[size]<='z';size++) ;
	for (int i=0;i<size;i++)
	{
		for (int p=0;p<=min(size-i-1,4);p++)
		{
			cnt++;
			for (int o=i;o<=i+p;o++) s[cnt].push_back(a[o]);
		}
	}
	sort(s+1,s+cnt+1,cmp);
	unique(s+1,s+cnt+1);
	cout<<s[k];
	return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int max_n = 200011, inf = 1000111222, mod = 1000000007;

int n, a[max_n], c[max_n];
int p[max_n], s[max_n];

void get_p(int a[], int p[]) {
    memset(c, 0, sizeof(c));
    p[0] = 1;
    c[a[0]] = 1;
    for (int i = 1; i < n; ++i) {
        if (i) {
            p[i] = p[i - 1];
        }
        if (i && a[i] != a[i - 1]) {
            p[i] = (p[i] + c[a[i]]) % mod;
            c[a[i]] = p[i];
        }
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    get_p(a, p);
    reverse(a, a + n);
    get_p(a, s);
    reverse(a, a + n);
    reverse(s, s + n);
    cout << p[n - 1] << endl;
    /*for (int i = 0; i < n; ++i) {
        cout << p[i] << " ";
    } cout << endl;
    for (int i = 0; i < n; ++i) {
        cout << s[i] << " ";
    } cout << endl;*/
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)

int main(){
  ll n;cin>>n;
  vector<ll> t(0);//見たならtrue
  rep(i,n)
  {
    ll a;cin>>a;
    if(!i){t.pb(a);continue;}

    int itr=lower_bound(all(t),a)-t.begin();

    if(!itr)t.insert(t.begin(),a);
    else t[itr-1]=a;

  }
  cout<<siz(t)<<endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
    ll A, B, C, X, Y;
     cin >> A >> B >> C >> X >> Y;

     ll sum = 0;
     ll a=0, b=0, c=0;
     ll hikaku = A+B;
     ll shoki;
     if(X >= Y){
          shoki = Y;
     }
     else{
          shoki = X;
     }
     if(C*2 <= hikaku){
         sum += shoki*C*2;
         a += shoki;
         b += shoki;
     }
     else{
         sum += (A+B)*shoki;
         a += shoki;
         b += shoki;
     }

     if(X>=Y){
         if(C*2 <= A){
             sum += C*2*(X-a);
         }
         else{
             sum += A*(X-a);
         }
     }
     else{
         if(C*2<=B){
             sum += C*2*(Y-b);
         }
         else{
             sum += B*(Y-b);
         }
     }

     cout << sum << endl;

}


Measured memory_bytes: 888
from itertools import combinations_with_replacement

N, M, Q, *ABCD = map(int, open(0).read().split())

L = list(zip(*[iter(ABCD)] * 4))

print(max(sum(d for a, b, c, d in L if A[b - 1] - A[a - 1] == c) for A in combinations_with_replacement(range(1, M + 1), N)))

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()
#define INF 2000000000

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> dp(n+k, INF);
    vector<int> high(n+k);
    rep(i,n) scanf("%d", &high.at(i));
    for (int i=n; i<n+k; i++) high.at(i) = INF;
    dp.at(0) = 0;
    rep(i,n) {
        rep(j,k) {
            dp.at(i+j+1) = min(dp.at(i+j+1), dp.at(i)+abs(high.at(i)-high.at(i+j+1)));
        }
    }
    printf("%d\n", dp.at(n-1));
}

Measured memory_bytes: 1024
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define eps 1e-6
#define pi 3.141592653589793
using namespace std;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;
ll fastpower(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y&1)
        res*=x;

        y>>=1;
        x=x*x;
    }
    return res;
}

void swap(ll &a,ll &b)
{
    a ^= b; 
    b ^= a; 
    a ^= b;
}
int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x,ans=1;
    cin>>n;
    set<int> s;
    cin>>x;
    s.insert(x);
    for(int i=1;i<n;++i)
    {
        cin>>x;
        auto it=s.lower_bound(x);
        if (it != s.begin()) {
            it--;
            
            //cout << *it << endl;
            } 
            else ans++;
        s.insert(x);
    }
    
    cout<<ans;

    return 0;
}

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

int main(void) {
	int i, c, way, n, m, mt[200];

	scanf("%d%d", &n, &m);
	for (i = 0; n * 2 > i; i++)
		mt[i] = i + 1;
	for (i = 0; m > i; i++){
		int mta[199], mtb[199];
		scanf("%d", &way);
		if (!way){

			memcpy(mta, mt, sizeof(int) * n);
			memcpy(mtb, &mt[n], sizeof(int) * n);
			for (c = 0; n > c; c++){
				mt[(c * 2)] = mta[c];
				mt[(c * 2) + 1] = mtb[c];
			}
		}
		else {
			memcpy(mta, mt, sizeof(int) * way);
			memcpy(mtb, &mt[way], sizeof(int) * (n * 2 - way));
			memcpy(mt, mtb, sizeof(int) * (n*2 - way));
			memcpy(&mt[n*2-way], mta, sizeof(int) * way);
			
		/*	for (c = 0; n * 2 - way > c; c++){
				mt[c] = mtb[c];
			}
			for (c = 0; way > c; c++){
				mt[c + (n * 2 - way)] = mta[c];
			}*/
		}
	}
	for (i = 0; n * 2 > i; i++){
		printf("%d\n", mt[i]);
	}

	return 0;
}

Measured memory_bytes: 1048
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define uniq(x) (x).erase(unique(all(x)),(x).end())

typedef long long ll;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e16;
const int MOD = 1000000007;
const ll N = 50LL;

void solve(void){
    ll K;
    cin >> K;
    printf("%lld\n", N);
    rep(N, n) {
        if (n < K%N) printf("%lld ", 2*N-(K%N)+K/N);
        else printf("%lld ", N-1-(K%N)+K/N);
    }
    putchar('\n');
}

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


Measured memory_bytes: 256
from collections import defaultdict

INF = 10 ** 9 + 7
N = int(input())

d = defaultdict(int)
for i in range(1, N + 1):
    for j in range(2, int(i ** 0.5) + 1):
        while i % j == 0:
            d[j] += 1
            i //= j
    if i > 1:
        d[i] += 1
ans = 1
for i in d.values():
    ans *= (i + 1)
    ans %= INF

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main() {
  long long N;
  cin >> N;
  vector<string> X(N);
  for(int i=0; i<N; ++i){
    cin >> X[i];
    sort(X[i].begin(), X[i].end());
  }
  long long cnt=1;
  long long ans=0;
  sort(X.begin(), X.end());
  for(int i=1; i<N; ++i){
    if(X[i] == X[i-1]){
      ans +=cnt;
      ++cnt;
    }
    else cnt=1;
  }
//  for(int i=0; i<N; ++i) cout << X[i] << endl;
  cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 

typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 

typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 1000001;

ll X, Y, A, B, C;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> X >> Y >> A >> B >> C;
    vl a(A), b(B), c(C);
    F0R(i, A) cin >> a[i];
    F0R(i, B) cin >> b[i];
    F0R(i, C) cin >> c[i];
    sort(all(a), greater<ll>()); sort(all(b),greater<ll>()); sort(all(c), greater<ll>());
    
    int ai = 0, bi = 0;
    ll ans = 0;
    vl reds, greens;
    F0R(i, X) reds.pb(a[i]);
    F0R(i, Y) greens.pb(b[i]);
    sort(all(reds)); sort(all(greens));
    F0R(i, C) {
        if (ai < X && bi < Y) {
            if (reds[ai] < greens[bi] && reds[ai] < c[i]) {
                reds[ai++] = c[i];
            } else if (greens[bi] <= reds[ai] && greens[bi] < c[i]) {
                greens[bi++] = c[i];
            }
        } else if (ai < X) {
            if (reds[ai] < c[i]) reds[ai++] = c[i];
        } else if (bi < Y) {
            if (greens[bi] < c[i]) greens[bi++] = c[i];
        }
    }
    
    trav(i, reds) ans += i;
    trav(i, greens) ans += i;
    cout << ans;
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 4852
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

int main(){
  double a, b, h, m;
  cin >> a >> b >> h >> m;

  double hh = 0.5*m + 0.5*60*h;
  double mm = 6*m;

  double RAD = (PI*abs(hh-mm))/180;

  double ans = (a*a + b*b) - (2 * a*b * cos(RAD));
  
  cout << fixed << setprecision(10)  << (double)sqrt(ans)<< endl;
  return 0;
}

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

using namespace std;

long long keta(long long n){
    long long cnt = 0;
    
    while (n > 0){
        n /= 10;
        cnt++;
    }
    return cnt;
}

int main(void){
   long long n;
   cin >> n;
   
   long long ans = 100;
   
   for (long long i = 1; i * i <= n; i++){
       if (n % i != 0) continue;
       
       long long temp = n / i;
       
       long long a = keta(i);
       long long b = keta(temp);
       
       ans = min(ans, max(a,b));
   }
    
    cout <<  ans << endl;;
}


Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    // plus 2 num
    int max_num = max(max(a, b), c);
    int ans = 0;
    int even_num = 0;
    if((max_num - a) % 2 == 0) even_num++;
    if((max_num - b) % 2 == 0) even_num++;
    if((max_num - c) % 2 == 0) even_num++;
    ans += (max_num - a) / 2;
    ans += (max_num - b) / 2;
    ans += (max_num - c) / 2;
    if(even_num == 3){
        cout << ans << endl;
        return 0;
    }
    if(even_num == 1){
        cout << ans + 1 << endl;
        return 0;
    }
    if(even_num == 2){
        cout << ans + 2 << endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    
    long long n, a=2, sq;
    cin >> n;
    
    cout << n << ":";
    sq=sqrt(n);
    while(n!=1){
        if(n%a ==0){
            n/=a;
            cout << " " << a;
            a=2;
        }else{
            a++;
        }
        if(a>sq){
            cout << " " << n;
            break;
        }
    }
    cout <<endl;
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define ld long double
#define mkp make_pair
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define watch(x) cout << (#x) << " is " << (x) << endl; cout.flush()
#define endl '\n'
#define _ << ' '
#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min(min(a, d), min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max(max(a, d), max(b, c))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = (ll)1e9+7;
const ll INF = (ll)1e9+1;

int n, q, a, b, x, p;
vector<int> adj[200001];
int d[200001], ans[200001];

void dfs(int cur, int p)
{
    ans[cur] += d[cur];
    for(auto nxt : adj[cur])
    {
        if(nxt==p) continue;
        ans[nxt] = ans[cur];
        dfs(nxt, cur);
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("A.txt", "r", stdin);
    #endif
    cin >> n >> q;
    for(int i=0; i<n-1; i++)
    {
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    while(q--)
    {
        cin >> p >> x;
        d[p] += x;
    }
    dfs(1, -1);
    for(int i=1; i<=n; i++) cout << ans[i] _;
}



Measured memory_bytes: 24064
#include<bits/stdc++.h>
#define lowbit(x) (x&-x)
#define gcd(a,b) __gcd(a,b)
#define mset(a,x) memset(a,x,sizeof(a))
#define FIN     freopen("input","r",stdin)
#define FOUT    freopen("output","w",stdout)
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll inv2(ll b){return b==1?1:(mod-mod/b)*inv2(mod%b)%mod;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
int dir[4][2]={0,1,1,0,0,-1,-1,0};
int main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	if(x==y)
		printf("0\n");
	else if(abs(x)==abs(y))
		printf("1\n");
	else
	{
		if(abs(x)<abs(y))
			printf("%d\n",abs(y)-abs(x)+(x<0)+(y<0));
		else
			printf("%d\n",abs(x)-abs(y)+(x>0)+(y>0)); 
	} 
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < n; i++) {
    cout << s[i] << t[i];
  }
  cout << '\n';
  return 0;
}

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

int main(void){
	int k;
	cin>>k;
	int ik=0,nk=0;
	string ans="Hikiwake";
	vector<string> is(k);
	vector<string> ns(k);
	for(int i=0;i<k;++i){
		string tis;
		cin>>tis;
		is[i]=tis;
	}
	for(int i=0;i<k;++i){
		string tns;
		cin>>tns;
		ns[i]=tns;
	}
	for(int i=0;i<k;++i){
		if(is[i]=="kougekida"){
			if(ik==0&&ns[i]!="kougekida"){ans="Nakajima";break;}
			else if(ik==0&&ns[i]=="kougekida"){
				if(nk==0)continue;
				else {ans="Nakajima";break;}
			}
			else if(ns[i]=="kougekida"){
				if(ik==nk){ik=0;nk=0;continue;}
				else if(ik>nk){ans="Isono";break;}
				else {ans="Nakajima";break;}
			}
			else if(ns[i]=="mamoru"){
				if(ik==5){ans="Isono";break;}
				else {ik=0;continue;}
			}
			else {ans="Isono";break;}
		}
		else if(is[i]=="tameru")if(ik<5)++ik;
		
		if(ns[i]=="kougekida"){
			if(nk==0&&is[i]!="kougekida"){ans="Isono";break;}
			else if(is[i]=="kougekida"&&ik>0){ans="Isono";break;}
			if(is[i]=="tameru"){ans="Nakajima";break;}
			else if(is[i]=="mamoru"){
				if(nk==5){ans="Nakajima";break;}
				else nk=0;continue;
			}
		}
		else if(ns[i]=="tameru")if(nk<5)++nk;
	}
	cout<<ans<<"-kun"<<endl;
return 0;
}



Measured memory_bytes: 3236
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"("<<(x).FI<<", "<<(x).SE<<")"<<endl;
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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

ll dp[220000][5];
vector<ll> A;

ll cost(int i, int s)
{
  if (s == 0 || s == 4){
    return A[i];
  } else if (s == 1 || s == 3) {
    if (A[i] == 0) return 2;
    else return A[i] % 2;
  } else {
    return (A[i] + 1) % 2;
  }
}

int main()
{
  int L; cin >> L;
  A = vector<ll>(L); REP(i, L) cin >> A[i];

  REP(i, 220000) REP(j, 5) dp[i][j] = LLINF;
  dp[0][0] = 0;
  REP(i, L) {
    REP(j, 5) {
      for (int k = j; k < 5; k++) {
        dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + cost(i, k));
      }
    }
  }

  ll res = LLINF;
  REP(i, 5) res = min(res, dp[L][i]);
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 10368
#import numpy as np
#import collections
#import math

from scipy.special import comb

#f = open('./input_D.txt')

#f.readline()
#S=int(f.readline())
#map(int, f.readline().split())
#list(map(int, f.readline().split()))

#input()
S=int(input())
#map(int, input().split())
#list(map(int, input().split()))

Nmax=S//3
ans=0
b = 10**9 +7
for n in range(1,Nmax+1):
    Q = S - 3*n
    ans += int(comb(Q+n-1,Q,exact=True))
    ans %= b


print(ans)

Measured memory_bytes: 42224
import Control.Applicative

import Data.List
    (intersperse)
    
import Text.Printf
    (printf)
    
type Data = [Double]

type Set = (Int, Data)

type Problem = [Set]

type Result = [Double]

calcDeviation :: Set -> Double

calcDeviation (n, list)
    = sqrt a where
        m = sum list / fromIntegral n
        s = sum $ map (\x -> (x - m) ** 2) list
        a = s / fromIntegral n

solve :: Problem -> Result

solve problem
    = map calcDeviation problem

output :: Result -> String

output result
    = concat $ intersperse "\n" $ map (printf "%.6f") result
    
input :: IO Problem

input
    = inputProblem []
    
inputProblem :: Problem -> IO Problem

inputProblem problem
    = do
        n <- read <$> getLine
        if n == 0
            then return problem
            else do
                list <- map read.words <$> getLine
                inputProblem $ problem ++ [(n, list)]

main :: IO ()

main
    = putStr.output =<< solve <$> input

Measured memory_bytes: 5164
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;cin>>n;
    vector<int>p(n);
    for(int i=0;i<n;i++)cin>>p[i];
    int ans=0;
    if(p[0]==1){
        swap(p[0],p[1]);
        ans++;
    }
    for(int i=1;i<n-1;i++){
        if(p[i]==i+1){
            if(p[i-1]==i){
                swap(p[i-1],p[i]);
            }
            else{
                swap(p[i],p[i+1]);
            }
            ans++;
        }
    }
    
    if(p[n-1]==n){
        swap(p[n-2],p[n-1]);
        ans++;
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------




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

using namespace std;
typedef long long ll;

struct range {
    ll mi;
    ll ma;

    bool operator<(const range &another) const {
        if (mi != another.mi) return mi < another.mi;
        return ma < another.ma;
    };
};

ll solve1(vector<range> &v, int n) {
    vector<range> dp1(n + 1, {-1, 1145141919810});
    for (int i = 1; i <= n; i++) {
        dp1[i].mi = max(dp1[i - 1].mi, v[i - 1].mi);
        dp1[i].ma = min(dp1[i - 1].ma, v[i - 1].ma);
    }
    vector<range> dp2(n + 1, {-1, 1145141919810});
    for (int i = n - 1; i >= 0; i--) {
        dp2[i].mi = max(dp2[i + 1].mi, v[i].mi);
        dp2[i].ma = min(dp2[i + 1].ma, v[i].ma);
    }

    ll ret = 0;
    for (int i = 0; i <= n; i++) {
        ll now = 0;
        if (i != 0)now += max((ll) 0, (dp1[i].ma - dp1[i].mi + 1));
        if (i != n)now += max((ll) 0, (dp2[i].ma - dp2[i].mi + 1));
        ret = max(ret, now);
    }
    return ret;
}

ll solve2(vector<range> &v, int n) {
    ll maxrange = 0;
    int maxindex = 0;
    for (int i = 0; i < n; i++) {
        if (maxrange < v[i].ma - v[i].mi) {
            maxrange = v[i].ma - v[i].mi + 1;
            maxindex = i;
        }
    }

    range common{-1, 1145141919810};
    for (int i = 0; i < n; i++) {
        if (i == maxindex)continue;
        common.mi = max(common.mi, v[i].mi);
        common.ma = min(common.ma, v[i].ma);
    }
    return maxrange + max((ll) 0, common.ma - common.mi + 1);
};

int main() {
    int n;
    cin >> n;

    vector<range> v(n);
    for (int i = 0; i < n; i++) cin >> v[i].mi >> v[i].ma;
    sort(v.begin(), v.end());

    cout << max(solve1(v, n), solve2(v, n)) << endl;
    return 0;
}

Measured memory_bytes: 4992
S=list(input())
f=1
e=0
for i in range(len(S)):
    if f:
        f=0
        if S[i]=='L':
            print('No')
            e=1
            break
    elif not f:
        f=1
        if S[i] =='R':
            print('No')
            e=1
            break
if not e:
    print('Yes')    

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




int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, d, x;
    int a[101];
    cin >> n >> d >> x;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        for (int j = 1, k =0; j <= d; j=k*a[i]+1) {
            k++;
            ans++;
        }
    }
    cout << ans + x << endl;
    
    return 0;
}



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

S = input()
l = len(S)
count = 0
if len(S)%2 == 1:
    #print("here")
    for i in range(int(len(S)/2)):
        #print(S[i], S[l-i-2])
        if S[i] != S[l-i-2]:
            count += 1
else:
    for i in range(int((len(S)-1)/2)):
        #print(S[i], S[l-i-2])
        if S[i] != S[l-i-2]:
            count += 1

print(count)


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

int adj[101][101] = {};

int main()
{
    int n, u, k, v;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        while (k > 0)
        {
            cin >> v;
            adj[u][v] = 1;
            k--;
        }
    }

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            if (j > 1)
                cout << " ";
            cout << adj[i][j];
        }
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 3124
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

w = input()

dic = defaultdict(int)

for x in w:
	dic[x] += 1

for y in dic:
	if dic[y]%2 == 1:
		print("No")
		break
else:
	print("Yes")



Measured memory_bytes: 5200
import sys
#input = sys.stdin.buffer.readline
import copy

def main():
    N = str(input())
    K = int(input())
    
    l = len(N)
    dpa = [[0 for _ in range(K+1)] for _ in range(l)]
    dpb = copy.deepcopy(dpa)
    
    dpa[0][0],dpa[0][1],dpb[0][1] = 1,int(N[0])-1,1
    for i in range(1,l):
        dpa[i][0] = 1
        num = int(N[i])
        if num == 0:
            for j in range(K):
                j += 1
                dpa[i][j] = dpa[i-1][j-1]*9 + dpa[i-1][j]
                dpb[i][j] = dpb[i-1][j]
        else:
            for j in range(K):
                j += 1
                dpa[i][j] = dpa[i-1][j-1]*9 + dpa[i-1][j] + dpb[i-1][j-1]*(num-1) + dpb[i-1][j]
                dpb[i][j] = dpb[i-1][j-1]

    print(dpa[l-1][K]+dpb[l-1][K])

if __name__ == "__main__":
    main()


Measured memory_bytes: 3444