akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000001145
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans=0;
int h,w,n;
string s[333];
int a[333][333];
signed main(){
	
	cin>>h>>w>>n;
	rep(i,h){
		cin>>s[i];
	}
	rep(i,h)rep(j,w)a[i][j]=-1;
	int num=0;
	rep(i,h){
		int flag=0;
		rep(j,w)if(s[i][j]=='#')flag=1;
		if(!flag)continue;
		int strflag=0;num++;
		rep(j,w){
			if(s[i][j]=='#' && !strflag){
				strflag=1;
				a[i][j]=num;
				continue;
			}
			if(strflag){
				if(s[i][j]=='#')num++;
			}
			a[i][j]=num;
		}
	}
	rep(i,h)rep(j,w){
		if(i==0)continue;
		if(a[i][j]==-1){
			a[i][j]=a[i-1][j];
		}
	}
	repb(i,h)rep(j,w){
		if(i==h-1)continue;
		if(a[i][j]==-1){
			a[i][j]=a[i+1][j];
		}
	}
	rep(i,h){
		rep(j,w){
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
}


Measured memory_bytes: 1664
ar = [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]

def sol(k):
    return ar[k-1]

def main():
    k = int(input())
    print(sol(k))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
// this line is here for a reason
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define ft front()
#define bk back()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define SET(a, b) memset((a), (b), sizeof(a))
template <class t>
bool ckmin(t& a, const t& b) {
  return a > b ? a = b, true : false;
}
template <class t>
bool ckmax(t& a, const t& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p);
template <class T>
struct IsC {
  template <class C>
  static char test(typename C::const_iterator*);
  template <class C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <class C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(
    ostream& o, const C& c) {
  o << '{';
  for (auto it = c.begin(); it != c.end();)
    o << *it << (++it != c.end() ? ", " : "}");
  return o;
}
template <class a, class b>
ostream& operator<<(ostream& o, const pair<a, b>& p) {
  return o << '(' << p.fi << ", " << p.se << ')';
}

const ll inf = 1e17;

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

    int n, W;
    cin >> n >> W;

    vector<ll> wgt(n), val(n);
    F0R(i, n) cin >> wgt[i] >> val[i];

    ll maxVal = accumulate(ALL(val), 0);

    vector<vector<ll>> dp;
    dp.eb(n, 0);

    FOR(r, 1, maxVal + 1) {
        dp.eb(n, inf);
        F0R(c, n) {
            if(!c) {
                if(val[0] == r)
                    dp[r][0] = wgt[0];
            } else {
                dp[r][c] = min(dp[r][c - 1], 
                               r - val[c] < 0 ? inf : dp[r - val[c]][c - 1] + wgt[c]);
            }
        }
    }

    int r = SZ(dp) - 1;
    while(dp[r][n - 1] > W)
        r--;
    cout << r << endl;

}



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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int a, b, c;
  cin >> a >> b >> c;
  int ans = min(c, b/a);
  cout << ans << endl;
}

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

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  cout << *max_element(A.begin(), A.end()) - *min_element(A.begin(), A.end()) << endl;

  return 0;
}


Measured memory_bytes: 256
#ifdef _WIN32
	#include <vector>
	#include<set>
	#include<map>
	#include<algorithm>
	#include<stdio.h>
	#include<iostream>
#else
	#include <bits/stdc++.h>
#endif
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	int ans = (N*(N - 1) / 2) + (M*(M - 1) / 2);
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    int N; cin >> N;
    vector<P> A(N);
    rep(i,N) {
        int p; cin >> p;
        A[i] = P(p,i);
    }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());

    ll ans = 0;
    set<int> st = {-1,N};
    rep(i,N) {
        int a = A[i].first,j = A[i].second;
        int left1 = *(--st.lower_bound(j));
        int right1 = *st.lower_bound(j);
        //printf("a: %d, j: %d, left1: %d, right1 %d\n",a,j,left1,right1);
        if (left1 >= 0) {
            int left2 = *(--st.lower_bound(left1));
            ans += (ll)a*(left1 - left2)*(right1 - j);
        }
        if (right1 < N) {
            int right2 = *st.lower_bound(right1 + 1);
            ans += (ll)a*(right2 - right1)*(j - left1);
        }
        //printf("ans: %ld\n",ans);
        st.insert(j);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
using namespace std;
typedef long long ll;
  
  int main(void){
    cin.tie(0); //cin高速化
    ios::sync_with_stdio(false); //cin高速化
	
    int n,x;
    cin >> n >> x;
    int cnt = n;
    vector<int> m(n);
    rep(i,n){
      cin >> m[i];
    }
    int sum = accumulate(m.begin(),m.end(),0);
    x -= sum;
    int min = *min_element(m.begin(),m.end());
    while(x>0){
      x -= min;
      n++;
    }
    if(x==0){
    cout << n << endl;
    }else{
      cout << n-1 << endl;
    }
    return 0;
  }    

Measured memory_bytes: 256
N = int(input())
S = input()

#BGR, BRG, GBR, GRB, RBG, RGB
r, g, b = 0, 0, 0
for i in range(N):
    if S[i] == 'R':
        r += 1
    elif S[i] == 'G':
        g += 1
    else:
        b += 1

ans = r*g*b #条件1を満たす組みの総和

for i in range(N):
    for j in range(i+1, N):
        if 2*j - i < N:
            if S[i] != S[j] and S[i] != S[2*j-i] and S[j] != S[2*j-i]:
                ans -= 1
        else:
          continue
          
print(ans)

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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()


int main() {
    int A,B;
    cin >> A >> B;

    for(int i=1;i<=3;i++){
        if((A*B*i)%2==1){
            PRINT("Yes");
            return 0;
        }
    }

    PRINT("No");
    return 0;
}



Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    ll n;
    cin >> n;
    ll ans = INF;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0) ans = min(ans, n / i + i - 2);
    }

    cout << ans << endl;
}   

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

int main(){
  int N,M;
  cin >> N >> M;
  if(N==1){
    N=14;
  }
  if(M==1){
    M=14;
  }
  if(N<M){
    cout << "Bob" << endl;
  }
  else if(N==M){
    cout << "Draw" << endl;
  }
  else{
    cout << "Alice" << endl;
  }
}


Measured memory_bytes: 3524
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val S = sc.nextLine().toCharArray

    // 各プレイヤーは, パーをグーよりも多く出してはいけない
    // 片方の手が全て先にわかっている状態で特点を最大化する
    // つまり, 入力として入ってくる手はそれを満たしている
    // 制約の中でより多く勝てばいい
    // グーかパーしか出せない
    // グーはいつでも出せる
    // 負けとあいこでは, あいこの方がいい
    // あいこでグーの数を稼がないと, パーは出すことができない
    // 途中どこかで負ける方が高いケースがあるか？ ..不明
    // とりあえず貪欲に行く
    // 勝ちに行った場所を負けた場所に補填したとして, 結局 +- 0なので変わらなそう
    def solve(S: Array[Char]): Int = {
      @scala.annotation.tailrec
      def loop(i: Int, g: Int, p: Int, point: Int): Int =
        if (i < S.length) {
          S(i) match {
            case 'g' =>
              if (p < g) loop(i + 1, g, p + 1, point + 1)
              else loop(i + 1, g + 1, p, point)
            case 'p' =>
              if (p < g) loop(i + 1, g, p + 1, point)
              else loop(i + 1, g + 1, p, point - 1)
          }
        } else point
      loop(0, 0, 0, 0)
    }

    println(solve(S))
  }

}


Measured memory_bytes: 29760
#include <bits/stdc++.h>
using namespace std;
int n[4];
int main(){
  for(int i= 0; i < 3; i++){
    scanf("%d", &n[i]);
  }
  sort(n, n + 3);
  cout << (n[0] * n[1]) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

#define int long long
#define endl '\n'
const int N = 100001;

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	if((a - b) < c) cout << c - (a - b);
	else cout << 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  cin >> n ;
  map<intll,int> data;
  int ans = 0;
  
  rep(i,n){
    int a ; 
    cin >> a ;
    data[a]++;
    if(data[a] % 2 == 1) ans ++ ;
    else                 ans -- ;
    
  }
  

  
  cout << ans ;


}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using tiii = tuple<int, int, int>;

int main()
{
    int n;
    cin >> n;
    vector<int> t(n + 1), x(n + 1), y(n + 1);
    t[0] = x[0] = y[0] = 0;
    rep(i, 1, n + 1)
        cin >> t[i] >> x[i] >> y[i];

    bool ans = true;
    rep(i, 1, n + 1)
    {
        int dis = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
        int time = t[i] - t[i - 1];

        if (dis > time) ans = false;
        else if ((time - dis) % 2 != 0) ans = false;


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

Measured memory_bytes: 1408
use std::io;
use std::collections::HashMap;


fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

fn main() {
    let _ = read::<u32>()[0];
    let arr = read::<u32>();

    let mut hm = HashMap::new();

    for num in arr {
        *hm.entry(num).or_insert(0) += 1;
    }

        let cnt = hm.into_iter()
            .map(|(idx, num)| if num >= idx { num - idx } else { num })
            .sum::<u32>();

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

Measured memory_bytes: 8444
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	vector<int> vi;
	for(int i=0;i<s.size();i++)
	{
		vi.push_back(s[i]-'0');
	}
	int sum1=0,sum0=0;
	int x0 = 0,x1 = 1;
	for(int i=0;i<vi.size();i++)
	{
		if(vi[i]!=x0)
			sum0++;
		x0^=1;
	}
	for(int i=0;i<vi.size();i++)
	{
		if(vi[i]!=x1)
			sum1++;
		x1^=1;
	}
	cout<<min(sum0,sum1)<<endl;
	return 0;
}

Measured memory_bytes: 1020
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		double x1 = scan.nextDouble();
		double y1 = scan.nextDouble();
		double x2 = scan.nextDouble();
		double y2 = scan.nextDouble();
		
		System.out.println(Math.sqrt(Math.pow(x2 - x1,2) + Math.pow(y2 - y1,2)));
	}
}

Measured memory_bytes: 18424
#include <iostream>
using namespace std;
int main(){
    int x;
    int y;
    int t;
    while(1){
        cin >> x >> y;
         if ( x == 0 && y == 0 ) {
          break;  
         }
         
         if(x>y){
              t=x;
              x=y;
              y=t;
         }
         
         cout<<x<<" "<<y<<endl;
    }
    
    return 0;
}


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

int64_t MOD = 1000000007;
double PI = 3.141592653589793;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> list(N);
    for (int i = 0; i < M; i++)
    {
        int p, q;
        cin >> p >> q;
        p--, q--;
        list[p].push_back(q), list[q].push_back(p);
    }
    vector<bool> arrived(N, false); //訪問済みかどうか

    queue<int> que; //訪問予定
    map<int, int> nokori;
    for (int i = 0; i < N; i++)
        nokori[i] = 1;
    int search, now, ans = -1;

    que.push(0);
    arrived[0] = true;
    while (!nokori.empty())
    {
        while (!que.empty())
        {
            int now = que.front();
            que.pop();
            nokori.erase(now);
            for (int i = 0; i < list[now].size(); i++)
            {
                int search = list[now][i];
                if (!arrived[search]) //未訪問
                {
                    arrived[search] = true;
                    que.push(search);
                }
            }
        }
        auto tmp = nokori.begin();
        que.push(tmp->first);
        ans++;
    }
    cout << ans;
}

Measured memory_bytes: 13296
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int e;
    while (cin >> e, e) {
        int ret = 1e6;
        for (int z=0; z*z*z<=e; ++z) {
            int y = (int)pow(e - z*z*z, 1.0/2.0);
            int x = e - z*z*z - y*y;
            ret = min(ret, x+y+z);
        }
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

H = inp()
W = inp()
N = inp()

x = max(H,W)
print((N-1)//x+1)


Measured memory_bytes: 4328
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


import math

def mirror_prime(n):
    answer = True
    # Test 0 and 1
    if n==0 or n==1:
        answer = False
    # End if

    # Test even numbers
    if n != 2 and n%2==0:
        answer= False
    # End if

    # Test if there is a proper odd divisor
        for d in range (3, int(math.sqrt(n))+1, 2):
            if n%d==0:
                answer=False
            # End if
        # End for



    #Reverse n
    mirror_n = int(str(n)[::-1])
    mirror_answer = True

    # Test 0 and 1
    if mirror_n==0 or mirror_n==1:
        mirror_answer = False

def primes(n):
    """ Returns  a list of primes < n """
    sieve = [True] * n
    for i in range(3,int(n**0.5)+1,2):
        if sieve[i]:
            sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,n,2) if sieve[i]]

# BIT = Bit(10**5+1)

isprime = None
 
def sieve(n):
    global isprime
 
    if n < 2:
        isprime = [False] * (n + 1)
        return
 
    isprime = [True if i % 2 != 0 else False for i in range(n + 1)]
    isprime[0] = isprime[1] = False
    isprime[2] = True
 
    from math import sqrt, ceil
 
    for i in range(3, int(sqrt(n)) + 1):
        if isprime[i] == True:
            for j in range(i + i, n + 1, i):
                isprime[j] = False

# plist = primes(10**5+1)
sieve(10**5+1)


accm = [0] * (10**5+1)
for i in range(3, 10**5+1):
    accm[i] += accm[i-1]
    # if mirror_prime(i) and mirror_prime((i+1)//2):
    if isprime[i] and isprime[(i+1)//2]:
        accm[i] += 1

Q = int(input())
for i in range(Q):
    l,r = map(int,input().split())
    # if mirror_prime(l) and mirror_prime((l+1)//2):
    if isprime[l] and isprime[(l+1)//2]:
        l-=1
    # if mirror_prime(r) and mirror_prime((r+1)//2):
    if isprime[r] and isprime[(r+1)//2]:
        r+=1
    print( accm[r] - accm[l] ) 


Measured memory_bytes: 7344
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;

typedef long long int64;
static int64 MOD = 1e9 + 7;

class ECommonSubsequence {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n, m;
        in >> n >> m;
        vector<int> u(n), v(m);
        forn(i, n)in >> u[i];
        forn(i, m)in >> v[i];

        vector<vector<int> > dp(n + 1, vector<int>(m + 1, 0));

        forn(i, n + 1)dp[i][0] = 1;
        forn(i, m + 1)dp[0][i] = 1;

        fore(i, 1, n)
            fore(j, 1, m) {
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
                if (u[i - 1] != v[j - 1])
                    dp[i][j] = (dp[i][j] - dp[i - 1][j - 1] + MOD) % MOD;
            }

        out << dp[n][m] << endl;
    }
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ECommonSubsequence solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 16000
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>


using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N - 1);

    for (int i = 0; i < N; i++)
    {
        /* code */
        cin >> A[i];
    }
    for (int i = 0; i < N; i++)
    {
        /* code */
        cin >> B[i];
    }
    for (int i = 0; i < N - 1; i++)
    {
        /* code */
        cin >> C[i];
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        /* code */
        ans += B[A[i] - 1];
    }

    for (int i = 1; i < N; i++)
    {
        /* code */
        if(A[i] == A[i - 1] + 1 ){
            ans += C[A[i] - 2];
        }
    }

    cout << ans << endl;

}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

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

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

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

	if(a+b+c>=22)cout<<"bust"<<endl;
	else cout<<"win"<<endl;

	return 0;
}

Measured memory_bytes: 256
N, M = [int(x) for x in input().split(" ")]
next_to_1 = []
next_to_last = []

for i in range(M):
  tmp = input().split(" ")
  if int(tmp[0]) == 1:
    next_to_1.append(int(tmp[1]))
  if int(tmp[1]) == N:
    next_to_last.append(int(tmp[0]))

if len(list(set(next_to_1) & set(next_to_last))) > 0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")
    

Measured memory_bytes: 27596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    sort(a.begin(),a.end());

    ll ans=0;
    rep(i,n){
        ans+=a[i];
        ans--;
    }

    cout<<ans<<endl;
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	map<int, unsigned> m;
	int ans = 0;
	rep(i, n){
		int a;
		cin >> a;
		m[a] += 1;
	}
	for(auto it = m.begin(); it != m.end(); ++it) {
        if(it->second%2 == 1) ans++;
    }
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8232
#include <stdio.h>

typedef struct pair* ppair;

typedef struct pair {
  int first, second;
} pair;


int size;
pair v[1000000];
int psize;
int preorder[1000000];

void swap(ppair a, ppair b) {
  pair t = *a;
  *a = *b;
  *b = t;
}

int getp(int begin, int end) {
  int i;
  int p = begin;
  for(i = begin+1; i < end; ++i) {
    if(v[i].first < v[p].first) {
      p = i;
    }
  }
  swap(&v[end-1], &v[p]);
  return end-1;
}

void qsort(int begin, int end) {
  int i, j;
  if(begin >= end) return;
  getp(begin,end);
  preorder[psize++] = v[end-1].second;
  if(begin+1 == end) return;
  for(i = begin, j = begin; i < end; ++i) {
    if(v[i].second < v[end-1].second) {
      swap(&v[i], &v[j++]);
    }
  }
  swap(&v[j],&v[end-1]);
  qsort(begin, j);
  qsort(j+1, end);
}

int main() {
  int i, j;
  int n, k;
  char s[100];
  size = 0;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    scanf("%s", s);
    if(s[0] == 'i') {
      scanf("%d", &k);
      v[size++] = (pair){i,k};
    } else {
      psize = 0;
      qsort(0, size);
      for(j = 0; j < size; ++j) {
        printf(" %d", v[j].second);
      }
      printf("\n");
      for(j = 0; j < size; ++j) {
        printf(" %d", preorder[j]);
      }
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 7564
# C 
li = list(input())
li = [int(num) for num in li]

def dfs(index, total, ans):
    if (index==3):
        if total + li[index] == 7:
            return ans + '+' + str(li[index])
        elif total - li[index] == 7:
            return ans + '-' + str(li[index])
        else:
            return None
   
    if index == 0:
        return dfs(index + 1, total+li[index], ans+str(li[index]))
    else:
        val1 = dfs(index + 1, total + li[index], ans + '+' + str(li[index]))
        val2 = dfs(index + 1, total - li[index], ans + '-' + str(li[index]))
        if val1:
             return val1
        if val2:
             return val2
print(dfs(0, 0, '') + '=7')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define pld pair <ld, ld>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >
#define cld complex <double>

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 1e6 + 100;
const ll inf = 1e9;

ll n, m, k, t;

vector <ll> V[maxn];

ll H[maxn];

void dfs(ll v, ll p) {
    if (v != p) {
        H[v] = H[p] + 1;
    }
    for (auto v1 : V[v]) {
        if (v1 == p) {
            continue;
        }
        dfs(v1, v);
    } 
}

int main() {
    pyshnapyshnakaa
    ll q, w, e, a, b, c;
    cin >> n;
    for (q = 0; q < n - 1; q++) {
        cin >> a >> b;
        a--; b--;
        V[a].pb(b);
        V[b].pb(a);
    }
    dfs(0, 0);
    ll mx = 0, mxi = 0;
    for (q = 0; q < n; q++) {
        if (H[q] > mx) {
            mx = H[q];
            mxi = q;
        }
    }
    for (q = 0; q < n; q++) {
        H[q] = 0;
    }
    dfs(mxi, mxi);
    mx = 0;
    for (q = 0; q < n; q++) {
        mx = max(mx, H[q]);
    }
    mx++;
    // cout << mx << " MX" << endl;
    if (mx % 3 != 2) {
        cout << "First";
        return 0;
    }
    cout << "Second";
    return 0;
}

Measured memory_bytes: 44140
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//1 2 3 4 100 1
/*
配列を持っているa
四こに分ける
どれぞれの総和をおんなじくらいへ
配列の総和を半分にカットする関数

1回めのカット
右に
*/


int main(void){
    int a, b,c,x;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&x);

    int i,j,k,val,counter = 0;
    for(i=0;i<=a;i++){
        for(j=0;j<=b;j++){
            for(k=0;k<=c;k++){
                if(x == i*500 + j*100 + k*50){
                    counter ++;
                }
            }
        }
    }
    printf("%d\n",counter);
    return 0;
}

Measured memory_bytes: 128
#coding:utf-8

n, x = map(int, input().split())
m = []
cnt = 0

for i in range(n):
    m.append(int(input()))

for i in range(len(m)):
    x -= m[i]
    cnt+=1

while(x>0):
    x -= min(m)
    if x<0:
        break
    cnt+=1

print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;

bool f(string s){//回文判定
    string s_=s;
    reverse(ALL(s_));
    if(s==s_) return true;
    else return false; 
};
int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    string s1,s2;
    s1  = s.substr(0,(n-1)/2);
    s2 = s.substr((n+1)/2);
    if(f(s) and f(s1) and f(s2)) cout << "Yes" << endl;
    else cout <<"No" << endl;
    
}

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

int N, K, S;

int dfs(int i, int k, int sum) {
    if(i > N && k < K) {
        return 0;
    }
    if(k == K) {
        return S == sum;
    }
    return dfs(i+1, k, sum) + dfs(i+1, k+1, sum+i);
}

int main() {
    while(cin >> N >> K >> S, N) {
        cout << dfs(1, 0, 0) << endl;
    }
}


Measured memory_bytes: 2984
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;

const int maxn=3111;
int mod;
int qpow(int x,int y,const int&mod=::mod)
{
	int ret=1;
	while(y)
	{
		if(y&1)ret=(LL)ret*x%mod;
		x=(LL)x*x%mod;
		y>>=1;
	}
	return ret;
}
inline void add(int&x,int y){x+=y;if(x>=mod)x-=mod;}

int s[maxn][maxn],n,fac[maxn],invf[maxn],inv[maxn];
int main()
{
	scanf("%d%d",&n,&mod);
	
	fac[0]=1;for(int i=1;i<maxn;i++)fac[i]=(LL)i*fac[i-1]%mod;
	invf[maxn-1]=qpow(fac[maxn-1],mod-2);for(int i=maxn-1;i>=1;i--)invf[i-1]=(LL)i*invf[i]%mod;
	for(int i=1;i<maxn;i++)inv[i]=(LL)invf[i]*fac[i-1]%mod;
	s[0][0]=1;
	for(int i=1;i<=n+1;i++)for(int j=1;j<=i;j++)s[i][j]=(s[i-1][j-1]+(LL)j*s[i-1][j])%mod;
	
	int ans=0;
	for(int i=0;i<=n;i++)
	{
		int sum=0,val=qpow(2,n-i),p=1;
		for(int k=0;k<=i;k++)
		{
			sum=(sum+(LL)s[i+1][k+1]*p)%mod;
			p=(LL)p*val%mod;
		}
		sum=(LL)sum*fac[n]%mod*invf[i]%mod*invf[n-i]%mod*qpow(2,qpow(2,n-i,mod-1))%mod;
		if(i&1)add(ans,mod-sum);
		else add(ans,sum);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 35968
#include<algorithm>
#include<cstdio>
int a[5001],b[5001];
int c,d,i,j,s=0;
main(){
scanf("%d%d",&c,&d);
for(i=0;i<c;i++){
scanf("%d",&a[i]);
}
for(j=0;j<d;j++){
scanf("%d",&b[j]);
}
for(int now=0;now<d;now++){
int r=now;
for(i=0;i<c;i++){
if(a[i]==b[r]){
r++;
if(r==d){
break;
}
}
}
s=std::max(r-now,s);
}
printf("%d\n",s);return 0;
}

Measured memory_bytes: 1060
n,k=map(int,input().split())
arr=[int(i) for i in input().split()]
dp=[0 for i in range(k+1)]
for i in range(1,k+1):
    for j in range(n):
        if arr[j]<=i and dp[i-arr[j]]==0:
            dp[i]=1
if dp[k]==1:
    print("First")
else:
    print("Second")


Measured memory_bytes: 45040
#include"bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = b - 1; i >= a; i--)
#define RREP(i, n) RFOR(i, 0, n)
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define rrep(i, a, b) for (auto i = a; i > b; i--)
#define range(i, a, b) (a <= i && i < b)
#define fi first
#define fs first
#define se second
#define sc second
#define int long long
using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
typedef pair<int, int> P;

int dx[] = { 0, 1, 0, -1 };
int dy[] = { 1, 0, -1, 0 };

int n, m, c, s, g;
int x, y, d, co;
int INF = 1LL << 60;
vec p(20);
mat q(20, vec(55,0)), r(20, vec(55,0)),cost(20,vec(55,0));

struct edge {
	int x, y, d;
	edge(int a, int b, int c):x(a),y(b),d(c){};
};

vector<edge> e[20];

void solve() {
	cin >> n >> m >> c >> s >> g;
	if (!n) exit(0);
	REP(i, 20) e[i].clear();
	REP(_, m) {
		cin >> x >> y >> d >> co;
		x--; y--; co--;
		e[co].push_back(edge(x, y, d));
	}
	REP(i, c) cin >> p[i];
	REP(i, c) {
		REP(j, p[i] - 1) cin >> q[i][j+1];
		REP(j, p[i]) {
			cin >> r[i][j + 1];
			if(j != p[i]-1) cost[i][j + 1] = cost[i][j] + (q[i][j + 1]-q[i][j]) * r[i][j+1];
		}
	}

	mat dist(n, vec(n, INF));
	REP(i, n) dist[i][i] = 0;
	REP(z, c) {
		mat tmp(n, vec(n, INF));
		REP(j, n) tmp[j][j] = 0;
		for (auto t : e[z]) {
			//cout << t.x << " " << t.y << " " <<  t.d << endl;
			tmp[t.x][t.y] = min(tmp[t.x][t.y], t.d);
			tmp[t.y][t.x] = min(tmp[t.y][t.x], t.d);
		}

		REP(k,n){
			REP(i, n) {
				REP(j, n) {
					tmp[i][j] = min(tmp[i][j], tmp[i][k] + tmp[k][j]);
				}
		    }
		}

		//REP(i, n) {
		//	REP(j, n) {
		//		cout << tmp[i][j] << " ";
		//	}
		//	cout << endl;
		//}

		REP(i, n) {
			REP(j, n) {
				if (tmp[i][j] == INF || tmp[i][j] == 0)  continue;
				int val = -1;
				FOR(id, 1, p[z]) {
					if (q[z][id] < tmp[i][j]) continue;
					val = cost[z][id - 1] + (tmp[i][j] - q[z][id - 1])*r[z][id];
					break;
				}
				if (val == -1) val = cost[z][p[z] - 1] + (tmp[i][j] - q[z][p[z] - 1])*r[z][p[z]];
				tmp[i][j] = val;
			}
		}
		REP(i, n) {
			REP(j, n) {
				dist[i][j] = min(tmp[i][j], dist[i][j]);
			}
		}
		REP(k, n) {
			REP(i, n) {
				REP(j, n) {
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}

		//REP(i, n) {
		//	REP(j, n) {
		//		cout << dist[i][j] << " ";
		//	}
		//	cout << endl;
		//}
	}
	if (dist[s - 1][g - 1] == INF) cout << -1 << endl;
	else cout << dist[s - 1][g - 1] << endl;
}

signed main() {
	while (1) solve();
}


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

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

  if(A == B){
    if(C != A)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }else if(A == C){
    if(B != A)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }else if(B == C){
    if(A != B)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }else
      cout << "No" << endl;
}

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

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) {
        cin >> A.at(i);
    }
    ll sum = 0;
    rep(i,N){
        sum += A.at(i);
    }
    ll now = 0;
    ll half = 0;
    bool judge = false;
    rep(i,N){
        now += A.at(i);
        if(now*2 == sum) {
            judge = true;
            //cout <<i <<endl;
        }
        else {
            if(now* 2 > sum){
                half = i;
                break;
            }
        }
    }
    ll sum1 = 0;
    rep(i,half){
        sum1 += A.at(i);
    }
    ll sum2 = 0;
    rep(i,half+1){
        sum2 += A.at(i);
    }
    ll d1 = sum - 2*sum1;
    ll d2 = 2*sum2 - sum;
    //cout << d1 <<d2 <<endl;
    if(judge) cout << 0 << endl;
    else {
       cout << min(d1,d2) <<endl;
    }
    
    
}

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

# 階乗を使う
import math

N, M = map(int, input().split())

ans = 0
if abs(N -M) >= 2:
    print(0)
    exit()
elif abs(N - M) == 1:
    ans = math.factorial(N) * math.factorial(M)
elif abs(N - M) == 0:
    ans = math.factorial(N) * math.factorial(M) * 2

print(ans % (10 ** 9 + 7))

Measured memory_bytes: 5180
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())

    K = 0
    for i in range(1,10**3):
        if i * (i-1) // 2 == N:
            K = i
            break

    if K == 0:
        print("No")
        exit()
    
    S = [[0] * (K-1) for _ in range(K-1)]

    a = 1
    for i in range(K-1):
        for j in range(i+1):
            S[i][j] = a
            S[j][i] = a
            a += 1

    ans = []
    for s in S:
        ans.append("{} {}".format(K-1, " ".join(map(str, s))))


    tri = [S[i][i] for i in range(K-1)]
    ans.append("{} {}".format(K-1, " ".join(map(str, tri))))

    print("Yes")
    print(K)

    print("\n".join(ans))

    
if __name__ == "__main__":
    main()


Measured memory_bytes: 12404
#include <iostream>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <tuple>
using namespace std;

template <class T> void chmax(T &x, T y) {if(x<y) x=y;}
template <class T> void chmin(T &x, T y) {if(x>y) x=y;}

#include <string>
#include <cassert>

bool comp(char x,char y)
{
    if(x=='?' or y=='?') return true;
    return x==y;
}

using p32=pair<int,int>;

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

    string s[3]; cin>>s[0]>>s[1]>>s[2];
    const int offs=4040;
    bool dif[3][3][offs*3]={};
    for(int i=0; i<3; ++i)
    {
        for(int j=0; j<3; ++j)
        {
            auto &now=dif[i][j];
            for(int x=0; x<(int)s[i].size(); ++x)
            {
                for(int y=0; y<(int)s[j].size(); ++y)
                {
                    now[x-y+offs]|=!comp(s[i][x],s[j][y]);
                }
            }
        }
    }


    int ans=6000;
    for(int i=-offs; i<offs; ++i)
    {
        if(dif[0][1][i+offs]) continue;
        for(int j=-offs; j<offs; ++j)
        {
            if(!dif[0][2][j+offs] and (j-i+offs<0 or !dif[1][2][j-i+offs]))
            {
                int l=min({0,i,j});
                int r=max({(int)s[0].size(),i+(int)s[1].size(),j+(int)s[2].size()});
                chmin(ans, r-l);
            }
        }
    }
    cout << ans << "\n";
}



Measured memory_bytes: 384
nums = gets
nums = gets.split(' ').map(&:to_i).group_by{ |n| n%2 }[0]
check = 'APPROVED'
unless nums.nil?
  nums.each do |num|
    if num % 3 != 0 && num % 5 != 0
      check = 'DENIED'
    end
  end
end
puts check

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define ll long long
using namespace std;
bool prime[10000001];
ll d[10000001], p[10000001];
void sieve()
{
    for(int i=1; i<=10000000; i++)d[i]= 1ll, p[i]= i;
    for(int i=2; i<=10000; i++)
    if(!prime[i])
    {
        for(int j=2*i; j<=10000000; j+=i)
        {
            prime[j]= 1;
            int c= 0;
            while(!(p[j]%i))p[j]/= i, c++;
            d[j]*= (c+1);
        }
    }
    for(int i=2; i<=10000000; i++)
    if(p[i]!=1)d[i]*= 2ll;
    return;
}
int main()
{
    sieve();
    int n;
    ll res= 0;
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
    res+= (d[i]*i);
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 169832
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE


void solve (void)
{
  int K;cin>>K;
  int N = 50;
  int Q = K/N;
  int R = K%N;
  vector<int> vec (N,Q);
  for (int i = R; i < N; i++)
  {

    vec[i] += (i-R);
  }
  
  for (int i = R-1; i >= 0; i--) 
  {

    vec[i] += N -i;
  }
  cout<<N<<endl;
  for (int i = 0; i < N; i++)
  {
    if(i != 0)cout<<char(32);
    cout<<vec[i];
  }
  cout<<endl;
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

 main() {
string s,t;
cin >>s >>t;
sort(s.begin(),s.end());
sort(t.begin(),t.end());
reverse(t.begin(),t.end());
if(s<t){
    cout <<"Yes"<<endl;
}
else{
    cout <<"No"<<endl;
}
 }




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

int main(){

	int cnt[4][4] = {0};
	double l, r, sight[5];

	sight[0] = 2.1;
	sight[1] = 1.1;
	sight[2] = 0.6;
	sight[3] = 0.2;
	sight[4] = 0.0;

	while(cin >> l >> r){
		for(int i=0; i<4; i++){
			if(sight[i+1] <= l && l < sight[i]){
				cnt[0][i]++;
			}
			if(sight[i+1] <= r && r < sight[i]){
				cnt[1][i]++;
			}
		}
	}

	for(int i=0; i<4; i++){
		cout << cnt[0][i] << " " << cnt[1][i] << endl;
	}

	return 0;

}

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

using namespace std;

const int mod = 998244353;

int add() {
  return 0;
}
template<typename... Args>
int add(int a, Args... args) {
  int s = a + add(args...);
  return s - mod * (s >= mod);
}

int mul() {
	return 1;
}
template<typename... Args>
int mul(int a, Args... args) {
  return int(1ll * a * mul(args...) % mod);
}

int power(int a, int x) {
	if (x == 0) {
		return 1;
	}
	return mul(power(mul(a, a), x / 2), (x % 2 ? a : 1));
}

int sub(int a, int b) {
	return a - b + mod * (a < b);
}

int divide(int a, int b) {
	return mul(a, power(b, mod - 2));
}

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

  const int N = 1e6 + 1;
  int n;
  cin >> n;
  vector<int> cnt(N);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    ans = sub(ans, x);
    ++cnt[x];
  }
  vector<int> cf(N);
  for (int i = 1; i < N; ++i) {
    cf[i] = divide(1, i);
  }
  for (int i = 1; i < N; ++i) {
    for (int j = i + i; j < N; j += i) {
      cf[j] = sub(cf[j], cf[i]);
    }
  }
  for (int g = 1; g < N; ++g) {
    int sum = 0;
    for (int i = g; i < N; i += g) {
      sum = add(sum, mul(cnt[i], i));
    }
    ans = add(ans, mul(sum, sum, cf[g]));
  }
  cout << divide(ans, 2);

  return 0;
}

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

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

    int n;
    while(cin >> n){
        vector<bool> F(n + 1, true);
        for(int i = 2; i <= (int)sqrt(n); i++){
            if(F[i]){
                for(int j = i + i; j <= n; j += i){
                    F[j] = false;
                }
            }
        }

        int cnt = 0;
        for(int i = 2; i <= n / 2; i++){
            if(F[i] and F[n - i + 1]){
                cnt += 2;
                //cout << i << ' '<< n - i + 1 << endl;
            }
        }

        if(n > 1 and n % 2 and F[n / 2 + 1]) cnt++;

        cout << cnt << endl;

    }

    return 0;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i,n){
        cin >> v.at(i);
    }

    vector<int> fr(n+1),fl(n+1);
    fl.at(0) = 0;
    fr.at(0) = 0;
    rep(i,n){
        fl.at(i+1) = fl.at(i) + v.at(i);
        fr.at(i+1) = fr.at(i) + v.at(n-1-i);
    }
    // rep(i,n+1) cout << fl.at(i) << " ";
    // cout << endl;
    // rep(i,n+1) cout << fr.at(i) << " ";
    // cout << endl;

    vector<pair<int,int>> vp;
    rep(i,n){
        if(v.at(i) < 0) vp.push_back({v.at(i), i});
    }
    sort(vp.begin(), vp.end());

    int res = 0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n && i+j<=k && i+j<=n;j++){
            int kmx = k-i-j;
            int kcr=0;
            int tot=0;
            tot += fl.at(i);
            tot += fr.at(j);
            for(auto p:vp){
                if(kcr>=kmx) break;
                if(p.second < i || p.second > n-1-j){
                    kcr++;
                    tot -= p.first;
                }
            }
            // if(res <= tot){
            //     cout << i << " " << j << " " << tot << endl;
            // }
            res = max(res,tot);
        }
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

int n, a, b, c, mi=9999999;
vector<int> v;

void calc(int m, vector<int> l, int cost){
	if(m==n){
		if(l[0]==0 || l[1]==0 || l[2]==0) return;
		cost+=abs(a-l[0]);
		cost+=abs(b-l[1]);
		cost+=abs(c-l[2]);
		//cout<< cost << endl;
		mi=min(mi, cost);
		return;
	}

	for(int i=0;i<4;i++){
		l[i]+=v[m];
		if(l[i]==v[m] || i==3) calc(m+1, l, cost);
		else calc(m+1, l, cost+10);
		l[i]-=v[m];
	}
}

int main(){

	vector<int> l={0, 0, 0, 0};
	cin>> n >> a >> b >> c;

	v.resize(n);

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

	calc(0, l, 0);
	
	cout<< mi << endl;

}

Measured memory_bytes: 256
N, M = map(int, input().split())

A    = set([int(input()) for _ in range(M)])


dp   = [0]*(N+1)
dp[0] = 1

for i in range(0, N, 1):

    if i+1 == 1 and not (i+1) in A:
        dp[i+1] = dp[i]
    elif not (i+1 in A) and not(i in A) and not(i-1 in A):
        dp[i+1] = dp[i] + dp[i-1] 
    elif not(i+1 in A) and not (i in A) and (i-1 in A):
        dp[i+1] = dp[i]
    elif not(i+1 in A) and (i in A) and not(i-1 in A):
        dp[i+1] = dp[i-1] 

print(dp[N]%1000000007)


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

const int mod = 1e9+7;
const int N = 10000003;
int prime[N];
unordered_map <ll, ll> max_map;

ll power(ll x, ll y){
	x %= mod;
	if(y == 0) return 1;
	if(y == 1) return x;
	ll num = power(x,y/2) % mod;
	if(y%2 ==  0) return (num*num)%mod;
	else return (((num*num)%mod)*x)%mod;
}

void solve(){
 	
 	ll a,b;
 	cin >> a >> b;
 	cout << (a*b)/__gcd(a,b);

	return;
}


int main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		solve();
		// cout << "\n";
	}

	// cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

int alpha,beta;

char function(char c){

	//文字を数字に変える。
	int num = c-'a';

	int tmp = (alpha*num+beta)%26;

	char ans = (char)tmp + 'a';

	return ans;


}

int main(){
	alpha = 3;
	beta = 2;

	int n;
	cin>>n;
	cin.ignore();

	for(int i=0;i<n;i++){
		string str;
		
		getline(cin,str);

		char tmp[260];
		int breakFlag=0;
		for(alpha = 0;alpha<1000;alpha++){
			for(beta = 0;beta<26;beta++){
				for(int j=0;j<str.size();j++){
					if(str[j]==' '){
						tmp[j] = ' ';
					}
					else{
						tmp[j] = function(str[j]);
					}
				}
				/*
				for(int j=0;j<str.size();j++){
					cout<<tmp[j];
				}
				cout<<endl;
				*/
				for(int j=0;j<str.size()-3;j++){
					if(tmp[j]=='t'&&tmp[j+1]=='h'&&tmp[j+2]=='i'&&tmp[j+3]=='s'){
						breakFlag=1;
						break;
					}
					if(tmp[j]=='t'&&tmp[j+1]=='h'&&tmp[j+2]=='a'&&tmp[j+3]=='t'){
						breakFlag=1;
						break;
					}
				}
				if(breakFlag==1){
					break;
				}
			}
			if(breakFlag == 1){
				break;
			}
		}
		for(int j=0;j<str.size();j++){
			cout<<tmp[j];
		}
		cout<<endl;
	}

	return 0;


}

/*
Sample Input
1
y eazqyp pnop pngtg ye obmpngt xmybp mr lygw
Output for the Sample Input
i submit that there is another point of view
*/

Measured memory_bytes: 1204