akhauriyash/Code-Regression huggingface dataset:
use std::cmp::{max, min};

const N: usize = 33;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let time: u64 = sc.read();

    let mut ab = vec![];
    let mut a_zero = vec![];
    for _ in 0..n {
        let a = sc.read::<u64>();
        let b = sc.read::<u64>();
        if a == 0 {
            a_zero.push(b);
        } else {
            ab.push((a, b));
        }
    }
    ab.sort_by(|&(a0, b0), &(a1, b1)| {
        let c0 = a1 * (b0 + 1);
        let c1 = a0 * (b1 + 1);
        c0.cmp(&c1)
    });

    let mut dp = vec![time + 1; N + 1];
    dp[0] = 0;
    for (a, b) in ab.into_iter() {
        for i in (0..N).rev() {
            dp[i + 1] = min(dp[i + 1], (a + 1) * (dp[i] + 1) + b);
        }
    }

    a_zero.sort();
    let mut b_sum = vec![0];
    for (i, b) in a_zero.into_iter().enumerate() {
        let prev = b_sum[i];
        b_sum.push(prev + b + 1);
    }

    let mut ans = 0;
    for (tail, tail_sum) in b_sum.into_iter().enumerate() {
        for head in 0..N {
            if tail_sum + dp[head] > time {
                continue;
            }
            ans = max(ans, tail + head);
        }
    }

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

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 6320
var
  a,b,c:longint;
begin
  readln(a,b,c);
  writeln(a,' ',b,' ',3*c-a-b);
  writeln(4*c-2*a-b,' ',c,' ',2*a+b-2*c);
  writeln(a+b-c,' ',2*c-b,' ',2*c-a);
end.

Measured memory_bytes: 128
#include <stdio.h>

#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;
const double eps = 1e-6;
int main() {
    int k;
    scanf("%d", &k);
    if (k % 2==0 || k % 10 == 5) {
        puts("-1");
        return 0;
    }
    int cnt = 7;
    int val = 7;
    int ans = 1;
    while (val < k) {
        cnt *= 10;
        val += cnt;
        ++ans;
    }
    val %= k;
    while (val % k) {
        cnt = cnt * 10 % k;
        val = (val + cnt) % k;
        ++ans;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
#define sz(a) (int)a.size()
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;
using vi = vector<int>;
const ll MOD = (ll)1e9 + 7;
vector<ll> dist;

void dfs(int u, int par, const vector<vector<pair<int, int>>>& adj) {
    for(auto& node: adj[u]) {
        int v = node.first;
        int cost = node.second;
        if(v == par) continue;
        dist[v] = dist[u] + cost;
        dfs(v, u, adj);
    }
}

int main() {
    int n;
    cin >> n;
    dist.assign(n + 10, 0);
    vector<vector<pair<int, int>>> adj(n + 2);
    rep(i, 0, n - 1) {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].emplace_back(b, c);
        adj[b].emplace_back(a, c);
    }
    int q, k;
    cin >> q >> k;
    dfs(k, k, adj);
    while(q--) {
        int a, b;
        cin >> a >> b;
        cout << dist[a] + dist[b] << "\n";
    }
    return 0;
}

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

const string uma = "41412121";
const int INF = 1e9;

int main() {
  vector<int> p(8);
  auto input = [&]() {
    for (int i = 0; i < 8; ++i) {
      if (cin >> p[i]) continue;
      return false;
    }
    return true;
  };
  while (input()) {
    int m = INF;
    string ans = uma;
    for (int i = 0; i < 8; ++i) {
      int s = 0;
      string c;
      for (int j = 0; j < 8; ++j) {
        c += uma[(i + j) % 8];
        s += max(0, p[j] - (uma[(i + j) % 8] - '0'));
      }
      if (s < m) {
        ans = c;
        m = s;
      } else if (s == m) {
        ans = (stoi(ans) < stoi (c)) ? ans : c;
      }
    }
    for (int i = 0; i < 8; ++i) cout << ( (i) ? " " : "" ) << ans[i];
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


const int MOD=1000000007;
int INF=100100100100100;
ivec pos,neg;
int zero=0;
signed main(){
  int n,k;cin>>n>>k;
  rep(i,n){
    int x;cin>>x;
    if(x>0)pos.pb(x);
    else if(x<0)neg.pb(-x);
    else zero++;
  }
  if(zero+k>n){
    cout<<0<<endl;
    return 0;
  }
  pos.pb(0);
  neg.pb(0);
  sort(all(pos),greater<int>());
  sort(all(neg),greater<int>());
  int po=pos.size()-1,ne=neg.size()-1;
  int s=0,t=0;
  rep(i,k){
    if(pos[s]>=neg[t])s++;
    else t++;
  }
  //cout<<s<<t<<endl;
  if(t%2){
    if(s!=po || t!=ne){
      if(s==po){
        if(s>0)s--,t++;
      }
      else if(t==ne){
        if(t>0)s++,t--;
      }
      else if(s==0)s++,t--;
      else if(t==0)s--,t++;
      else{
        if(pos[s]*pos[s-1]>=neg[t]*neg[t-1])s++,t--;
        else s--,t++;
      }
    }
  }
  int ans=1;
  if(t%2){
    if(zero)cout<<0<<endl;
    else{
      ivec v;
      for(int i=0;i<pos.size();i++)v.pb(pos[i]);
      for(int i=0;i<neg.size();i++)v.pb(neg[i]);
      
      sort(all(v));
      int ima=0;
      int cnt=0;
      while(cnt<k){
        if(v[ima]!=0)(ans*=v[ima])%=MOD,cnt++;
        ima++;
      }
      ans=(MOD-ans)%MOD;
      cout<<ans<<endl;
    }
    
    return 0;
  }
  
  rep(i,s)(ans*=pos[i])%=MOD;
  rep(i,t)((ans*=neg[i]))%=MOD;
  
  cout<<ans<<endl;         
  return 0;
}

Measured memory_bytes: 6944
from collections import defaultdict
n,k = map(int,input().split())
nums = input().split()
count_per_nums = defaultdict(int)
for n in nums:
  count_per_nums[n] += 1
count_per_nums = sorted(count_per_nums.items(), key=lambda x:x[1])
ans = 0
for i in range(len(count_per_nums)-k):
  ans += count_per_nums[i][1]
print(ans)


Measured memory_bytes: 44048
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int K = int.Parse(Console.ReadLine());

            List<string> substring = new List<string>();

            input = input.Replace(" ", "");

            for(int i = 1; i <= input.Length;i++)
            {
                if (i > 5) break;
                for (int j = 0; j <= input.Length - i; j++)
                {
                    string s = input.Substring(j, i);
                    if (!substring.Contains(s)) substring.Add(s);
                }
            }
            substring.Sort();
            Console.WriteLine(substring[K-1]);
        }
    }
}


Measured memory_bytes: 13664
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define repr(i, n) for (ll i = n - 1; i >= 0; --i)
const int MOD = 1000000007;
const ll INF = 10000000000;
using namespace std;

void solve(void)
{
    int n;
    cin >> n;
    vector<ll> a(3 * n), f(3 * n);
    rep(i, 3 * n) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    for (int i = 2; i <= 2 * n; i += 2)
        ans += a[3 * n - 1 + 1 - i];
    cout << ans << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 8020
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char c=0;
	scanf("%c",&c);
	if(c>='a'&&c<='z')
		printf("a");
	else if(c>='A'&&c<='Z')
		printf("A");
	else
		;
	return 0;
} 

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){ 
  int N, M;
  cin >> N >> M;
  
  if (M == 0) {
    if (N == 1) {
      cout << 0 << endl;
      return 0;
    }
    if (N == 2) {
      cout << 10 << endl;
      return 0;
    }
    if (N == 3) {
      cout << 100 << endl;
      return 0;
    }
  }
  else {
  	vector<int> s(M);
  	vector<int> c(M);
  	rep(i,M) cin >> s[i] >> c[i];

    rep(j,M-1) {
        for (int k = j+1; k<M; k++) {
            if ((s[j] == s[k]) && (c[j] != c[k])) {
                cout << -1 << endl;
                return 0;
            }
        }
    }

  
  	vector<int> ans(N, 10);
    
    rep(i,N) {
      bool seen = false;
      rep(j,M) {
        if (s[j] == i+1) {
          if (!seen) {
            ans[i] = c[j];
            seen = true;
          }
        }
      }
      if (!seen) {
          if (i == 0) ans[i] = 1;
          else ans[i] = 0;
      }
    }
    
    int x;

    if (N == 1) x = ans[0];
    if (N == 2) x = ans[0] * 10 + ans[1];
    if (N == 3) x = ans[0] * 100 + ans[1] * 10 + ans[2];

    if (N > 1 && ans[0] == 0) {
        cout << -1 << endl;
        return 0;
    }
    
    cout << x << endl;
  }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
#define endl '\n'
#define rep(i,a) for(i = 0 ; i < a ; i++)

int main()
{
	string s1,s2,s3,s4;
	cin >> s1 >> s2;
	s3 = s4 = "";
	ll i;
	rep(i,3)
	{
		s3 += s1[3-i-1];
		s4 += s2[3-i-1];
	}
	if(s1[0] == s2[2] and s1[1] == s2[1] and s1[2] == s2[0])
	cout << "YES" << endl;
	else
		cout << "NO" ;
	return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll A,B,C;
    string S;
    cin >> A>>B>>C;
    vector<ll> vec(3);
    vec.at(0) = A;
    vec.at(1) = B;
    vec.at(2) = C;
    sort(vec.begin(), vec.end());

    ll tmp1 = vec.at(2) - vec.at(1);
    ll tmp2 = vec.at(2) - vec.at(0);
    
    //cout << tmp1 << tmp2 <<endl;

    if(tmp1%2==0&&tmp2%2==0){
        cout << (tmp1 + tmp2) / 2 << endl;
    }
    else if (tmp1 % 2 == 1 && tmp2 % 2 == 1)
    {
        cout << (tmp1 + tmp2) / 2 << endl;
    }
    else{
        ll tmp = vec.at(2) + 1;
        //cout << tmp << endl;
        cout << (tmp - vec.at(1) + tmp - vec.at(0) + 1) / 2 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int cnt, h, Max = 0, ans = 0;
    cin >> cnt;
    for(int i=0; i<cnt; i++){
        cin >> h;
        if(h>=Max){
            ans++;
            Max = h;
        }
    }
    cout << ans;
    return 0;
}


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

class UF {
  int n;
  vector<int> v;
public:
  UF(int n) 
    : n(n), v(n) {
    for (int i = 0; i < n; ++i) v[i] = i;
  }
  int root(int i) {
    if (v[i] == i) return i;
    return v[i] = root(v[i]);
  }
  void unite(int i, int j) {
    int ri = root(i);
    int rj = root(j);
    if (ri == rj) return;
    v[ri] = rj;
  }
  map<int, vector<int>> get() {
    map<int, vector<int>> mp;
    for (int i = 0; i < n; ++i) {
      mp[root(i)].push_back(i);
    }
    return mp;
  }
};

const int m = 100000;
int n;
int x[m], y[m];
int mx[m], my[m];
int main() {
  cin >> n;
  UF uf(n);
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    x[i] = a;
    y[i] = b;
  }
  
  for (int i = 0; i < m; ++i) mx[i] = my[i] = -1;
  for (int i = 0; i < n; ++i) {
    int a = x[i];
    int b = y[i];
    if (mx[a] != -1) uf.unite(mx[a], i);
    if (my[b] != -1) uf.unite(my[b], i);
    mx[a] = i;
    my[b] = i;
  }
  
  long sum = 0;
  for (auto&& p : uf.get()) {
    set<int> xs;
    set<int> ys;
    for (int i : p.second) {
      xs.insert(x[i]);
      ys.insert(y[i]);
    }
    sum += (long)xs.size() * ys.size();
  }
  cout << sum - n << endl;
}

Measured memory_bytes: 7288
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        Integer[] arr = new Integer[]{a, b, c, d, e};
        Arrays.sort(arr, (d1,d2) -> {
            int rem1 = d1 % 10;
            int rem2 = d2 % 10;
            if (rem1 == 0) rem1 += 10;
            if (rem2 == 0) rem2 += 10;
            return Integer.compare(rem2, rem1);
        });

        int sum = 0;

        for (int i = 0; i < arr.length; i++) {
            sum = (int) Math.ceil(sum / 10.0) * 10;
            sum += arr[i];
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 29140
#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))

const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAXN = 200005;

int r, c, k;

const ll minf = -1e16;
ll dp[3005][3005][4];
ll mat[3005][3005];

ll solve(int i, int j, int l) {
	if (l == 4 || i == r || j == c) {
		return minf;
	}
	if (i == r-1 && j == c-1) {
		return l < 3 ? mat[i][j] : 0;
	}
	ll &ret = dp[i][j][l];
	if (ret != -1) {
		return ret;
	}
	ret = 0;
	//ignore
	ret = max(ret,solve(i+1,j,0));
	ret = max(ret,solve(i,j+1,l));
	//not ignore
	if (l < 3) {
		ret = max(ret,mat[i][j]+solve(i+1,j,0));
		ret = max(ret,mat[i][j]+solve(i,j+1,l+1));
	}
	return ret;
}

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

	memset(dp,-1,sizeof dp);
	cin >> r >> c >> k;
	
	FOR(i,0,k){
		int x, y;
		cin >> x >> y;
		cin >> mat[x-1][y-1];
	}
	
	cout << solve(0,0,0) << "\n";
	
}


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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  int total = 0;
  REP(i, N){
    cin >> a[i];
    total ^= a[i];
  }
  REP(i, N){
    cout << (a[i]^total) << " ";
  }
  cout << endl;


  return 0;
}


Measured memory_bytes: 3972
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
int compare_int_small(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
// 公約数
long long int gcd(long long int a, long long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long long int lcm(long long int a, long long int b){
  return a * b / gcd(a, b);
}

// min
int main(void){

  int H, W;
  int h, w;

  scanf("%d%d%d%d", &H, &W, &h, &w);
  
  printf("%d\n", H*W - (h*W + w*H - h*w));

  return 0;
}


Measured memory_bytes: 128
(defun split (str delim)
  (let ((res (make-array 1 :element-type 'string
                           :fill-pointer 0
                           :adjustable t)))
    (loop for i from 0 below (length str)
          with start = 0
          when (eq (char str i) delim)
          do (vector-push-extend (subseq str start i) res)
             (setf start (1+ i))
          finally (let ((tail (subseq str start)))
                    (when tail
                      (vector-push-extend tail res))))
    res))

(let* ((l (map 'vector 'parse-integer (split (read-line) #\ )))
       (a (aref l 0))
       (b (aref l 1)))
  (when (= a 1) (setf a 14))
  (when (= b 1) (setf b 14))
  (if (= a b)
      (format t "Draw~%")
      (if (> a b)
          (format t "Alice~%")
          (format t "Bob~%"))))

Measured memory_bytes: 16484
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
  
N = int(input())
print(num2alpha(N).lower())

Measured memory_bytes: 9196
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

int main() {
  int table[31];
  table[0] = 1;
  table[1] = 1;
  table[2] = 2;
  for (int i=3; i<=30; ++i) {
    table[i] = table[i-1] + table[i-2] + table[i-3];
  }
  int n;
  while(cin >> n,n) {
    cout << (table[n]-1)/10/365+1 << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


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

  set<string> S;
  for(int i = 0;i < N;i++) {
    string s;
    cin >> s;
    S.insert(s);
  }

  cout << S.size() << endl;

}


Measured memory_bytes: 19228
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	int n,m,a;
	int h,p,q;
	VI list,list2;
	while(1){
		cin >> n >> m >> a;
		if(n==0&&m==0&&a==0){
			break;
		}
		for(int i=0;i<m;i++){
				cin >> h >> p >> q;
			list.PB(h);	
			list2.PB(p*q);
		}
	
		for(int i=0;i<m;i++){
			for(int j=i+1;j<m;j++){
				if(list[i]<list[j]){
					int tmp;
					tmp=list[i];
					list[i]=list[j];
					list[j]=tmp;
					tmp=list2[i];
					list2[i]=list2[j];
					list2[j]=tmp;
				}
			}
		}	
		for(int i=0;i<m;i++){
			if(list2[i]==a*(a+1)){
				a=list2[i]/a;
			}
			else if(list2[i]==a*(a-1)){
				a=list2[i]/a;
			}
		}
		cout << a << endl;
		list.clear();
		list2.clear();
	}
	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < D; j++)
    {
      cin >> X.at(i).at(j);
    }
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = i + 1; j < N; j++)
    {
      int dd = 0;
      for (int k = 0; k < D; k++)
      {
        dd += pow(abs(X.at(i).at(k) - X.at(j).at(k)), 2);
      }
      if ((int)sqrt(dd) * (int)sqrt(dd) == dd)
      {
        ans++;
      }
    }
  }

  cout << ans << endl;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;

    if(s == u){
        a--;
    }else{
        b--;
    }
    cout << a << " " << b << endl;
    return 0;
}


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loop2(num) for (lli j = 0 ; j < num ; j ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }
#define looppu(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . push_back (x) ;}
#define loopin(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . insert (x) ;}

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back ()
#define pof pop_front ()

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

signed main ()
{
    fastio
    ll a ; cin >> a ;
    st s [a] ; bool t = true ;
    loopcin(a , s) ;
    loop(a) {
        loop2(a) {
            if (i == j )
                continue ;
            else if (s[i] == s[j] )
                t = false ;
        }
    }
    if (t){
        for (ll i = 0 , j = 1 ; i < a - 1 ; j ++ , i ++){
            if (s[i] . back() != s[j] . front())
                t = false ;
        }
        (t ? Yes : No) ;
    }
    else
        No ;
    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int n, l, total = 0, total_mai = 0, min = 10000;
    scanf("%d%d", &n, &l);
    int taste[n], taste_minor[n];
    for(int i = 0; i < n; i++) {
        taste[i] = l + (i+1) - 1;
    }
    if(l >= 0) {
        
        for (int i = 1; i < n; i++) {
            total += taste[i];
        }
        printf("%d\n",total);
        
    } else {
        
        
         for(int m = 0; m < n; m++) {
                if(taste[m] < 0) {
                    taste_minor[m] = -taste[m];
                } else {
                    taste_minor[m] = taste[m];
                }
            }
        
        int j, q = -1;
        for(j = 0; j < n; j++) {
            if(taste_minor[j] < min) {
                min = taste_minor[j];
                q++;
            }
        }
        if(taste[q] < 0) {
            min = -min;
        }
        
        for(int k = 0; k < n; k++) {
            total_mai += taste[k];
        }
        total_mai -= min;
        printf("%d\n",total_mai);
    }
    return 0;
}


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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)

using VI = vector<int>;
using PII = pair<int, int>;
using ll = long long;

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

    
    vector<pair<string,int>> v1;
    vector<pair<string,int>> v2;
    REP(i,n){
        string s;int p;cin >> s >> p;
        pair<string,int> psi = make_pair(s,-p);
        v1.push_back(psi);//入力順
        v2.push_back(psi);//紹介準
    }

    sort(v2.begin(),v2.end());
    
    REP(i,n){
        REP(j,n){
            if(v2[i]==v1[j]) cout << j+1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int W = sc.nextInt();
		sc.close();
		if (S > W) {
			System.out.println("safe");
		} else {
			System.out.println("unsafe");
		}
	}
}


Measured memory_bytes: 35820
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
  int k,n;
  cin>>k>>n;
  vi a(n);
  ll int sum_dis=0;
  int pre;
  rep(i,n)cin>>a[i];
  int max_dis=0;
  int ans_idx=0;
  rep(i,n){
    if(i==0){
      continue;
    }
    if(max_dis<a[i]-a[i-1]){
      max_dis = a[i]-a[i-1];
      ans_idx=i;
    }
  }
  max_dis = max(max_dis,abs(a[0]+(k-a[n-1])));

  cout<<k-max_dis<<endl;


}




Measured memory_bytes: 1024
A,B,Q=map(int,input().split())

# 左右の神社両方に行ってから最短の寺に行くパターンと、
# 左右の寺両方に行ってから最短の神社に行くパターン
# 両方を試して最小値を取る

S=[None] * A
T=[None] * B

for i in range(A):
  S[i] = int(input())
for i in range(B):
  T[i] = int(input())

import bisect

INF = 10**11
def getshortest(x,A,B):
  # xの両端のAをまず求める
  ind = bisect.bisect_right(A,x)
  dist_left = 0
  # 左に進む場合
  if ind == 0:
    dist_left = INF
  else:
    x2 = A[ind-1]
    dist_left = abs(x - A[ind-1])
    
    ind2 = bisect.bisect_right(B,x2)
    if ind2 == 0:
      dist_left += abs(B[0] - x2)
    elif ind2 == len(B):
      dist_left += abs(x2 - B[-1])
    else:
      dist_left += min(abs(x2 - B[ind2-1]),abs(B[ind2] - x2))
  
  dist_right = 0
  # 右に進む場合
  if ind == len(A):
    dist_right = INF
  else:
    x2 = A[ind]
    dist_right = abs(x - A[ind])
    
    ind2 = bisect.bisect_right(B,x2)
    if ind2 == 0:
      dist_right += abs(B[0] - x2)
    elif ind2 == len(B):
      dist_right += abs(x2 - B[-1])
    else:
      dist_right += min(abs(x2 - B[ind2-1]),abs(B[ind2] - x2))
  return (dist_left,dist_right)[dist_left > dist_right]
  
for i in range(Q):
  x = int(input())
  s = getshortest(x,S,T)
  t = getshortest(x,T,S)
  print((s,t)[t<s])
  

Measured memory_bytes: 12020
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
using namespace std;

int main() {
	long long n;
	cin >> n;
	vector<long long>a(n, 0);
	vector<long long>b(n, 0);
	long long max = 0;
	long long p = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		if (a[i] > max) {
			max = a[i];
			p = b[i];
		}
	}
	cout << max + p;

	return 0;
}





Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define l1 long long
int main(){ int x,y,f=0; cin>>x>>y; 
 for(int i=0;i<=x;i++){
 	for(int j=0;j<=x;j++){
 		if((2*i+4*j)==y && (i+j==x)){f=1;cout<<"Yes";break;
		 }
	 } if(f==1)break;
 } if(f==0)cout<<"No";
}


Measured memory_bytes: 3588
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner stdIn=new Scanner(System.in);
    int A=stdIn.nextInt();
    int B=stdIn.nextInt();
    int C=stdIn.nextInt();
    if(A==B){
      System.out.println(C);
    }else if(B==C){
      System.out.println(A);
    }else{
      System.out.println(B);
    }
  }
}


Measured memory_bytes: 23252
#include <cstdio>
#include <vector>
#include <queue>

int main(void)
{

    int N;
    scanf("%d", &N);

    std::vector<int> A, B;
    std::queue<int> skipped, answer1, answer2;
    int x;
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &x);
        A.push_back(x);
    }
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &x);
        B.push_back(x);
    }

    for (int i = 0, j = N - 1; i < N; i++)
    {
        while (j >= 0 && B[j] == A[i])
        {
            skipped.push(B[j]);
            j--;
        }
        if (j < 0)
        {
            if (skipped.front() != A[i])
            {
                answer1.push(skipped.front());
                skipped.pop();
                continue;
            }
            else
            {
                break;
            }
        }
        answer1.push(B[j]);
        j--;
    }
    while(!skipped.empty()){
        skipped.pop();
    }
    for (int i = 0, j = 0; i < N; i++)
    {
        while (j < N && B[j] == A[i])
        {
            skipped.push(B[j]);
            j++;
        }
        if (j == N)
        {
            if (skipped.front() != A[i])
            {
                answer2.push(skipped.front());
                skipped.pop();
                continue;
            }
            else
            {
                break;
            }
        }
        answer2.push(B[j]);
        j++;
    }

    if (answer1.size() != N && answer2.size() != N)
    {
        printf("No\n");
    }
    else if (answer1.size() == N)
    {
        printf("Yes\n");
        while (!answer1.empty())
        {
            printf("%d ", answer1.front());
            answer1.pop();
        }
    }
    else
    {
        printf("Yes\n");
        while (!answer2.empty())
        {
            printf("%d ", answer2.front());
            answer2.pop();
        }
    }

    return 0;
}

Measured memory_bytes: 5872
N, Z, W = map(int, input().split())
A = list(map(int, input().split()))
if N == 1:
    print(abs(A[0]-W))
elif A[-1]==A[-2]:
    print(abs(A[-1]-W))
else:
    print(max(abs(A[-1]-A[-2]),abs(A[-1]-W)))

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

#include <math.h>
#include <stdlib.h>


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

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; }

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int x; cin >> x;
    int pr[6] = {100, 101, 102, 103, 104, 105};

    set<int> st;
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int a = q.front();
        q.pop();
        for(int i = 0; i < 6; i++){
            int b = a + pr[i];
            if(b == x) {
                cout << 1 << endl;
                return 0;
            }
            if(b < x && st.count(b) == 0){
                q.push(b);
                st.insert(b);
            }
        }
    }

    cout << 0 << endl;


    return 0;
}


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

int bubblesort(int A[], int N);
int main(){
    int N, n;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    n = bubblesort(A, N);
    for(int i = 0; i < N; i++){
        if(i>0) cout << ' ';
        cout << A[i];
    }
    cout << endl << n << endl;
}

int bubblesort(int A[], int N){
    bool flag = 1;
    int n = 0;
    int k = 0;
    while(flag){
        flag = 0;
        for(int j = N - 1; j > k; j--){
            if(A[j] < A[j-1]){
                swap(A[j], A[j-1]);
                flag = 1;
                n++;
            }
        }
        k++;
    }
    return n;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
const int inf=1e9;
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	int n=read(),k=read(),s=read();
	if(s<inf){
		For(i,1,k)wri(s);
		For(i,k+1,n)wri(inf);	
	}else{
		For(i,1,k)wri(s);
		For(i,k+1,n)wri(1);
	}
}
/*
0 1 2 3 4 7 7

*/

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

using namespace std;

int main(void) {
	int n, d; cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int norm = 0;
			for (int k = 0; k < d; k++) {
				int diff = abs(x[i][k] - x[j][k]);
				norm += diff * diff;
			}
			bool flag = false;
			for (int k = 0; k <= norm; k++) {
				if (k * k == norm) {
					flag = true;
					break;
				}
			}
			if (flag) ans++;
		}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define R cin>>
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

int main() {
  int n,m;
  while(cin >> n >> m && n) {
    P a[n];
    rep(i,n) {
      char c;
      cin >> c >> a[i].F;
      if(c=='R') a[i].S=1;
      else a[i].S=-1;
    }
    int ans=0,x;
    rep(t,m) {
      int y=-1,c=0;
      rep(i,n) a[i].F+=a[i].S;
      rep(i,n) {
	REP(j,i+1,n) {
	  if(a[i].F==a[j].F && a[i].S!=a[j].S) swap(a[i].S,a[j].S);
	}
	if(a[i].F>=0 && a[i].F<=m) c++;
	if(a[i].F==0) y=i;
	if(a[i].F==m && y==-1) y=i;
      }
      if(!c) break;
      ans++;
      if(y!=-1) x=y+1;
    }
    PR(ans,x);
  }		 
  return 0;
}


Measured memory_bytes: 1160
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    C = [0]*10**5
    for i in range(N):
        C[A[i]] += 1
    ma = 0
    for i in range(1, len(C)-1):
        count = C[i-1] + C[i] + C[i+1]
        if count > ma:
            ma = count    
    print(ma)
if __name__ == "__main__":
    main()

Measured memory_bytes: 13964
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	set := make(map[int]int)
	nums := []int{}
	for i := 0; i < N; i++ {
		a := sc.nextInt()
		set[a]++
		if set[a] == 2 {
			nums = append(nums, a)
			set[a] = 0
		}
	}

	sort.Ints(nums)
	if len(nums) < 2 {
		fmt.Fprintln(wtr, 0)
	} else {
		fmt.Fprintln(wtr, nums[len(nums)-1]*nums[len(nums)-2])
	}
	wtr.Flush()
}


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

int main()
{
    double n=0,a=0,b=0,c=0,d=0,i=0,j=0;
    cin >> a >> b >> c >> d;
    i=(sqrt(((c-a)*(c-a))+((d-b)*(d-b))));
   // printf("%.5f\n",i);
    cout <<setprecision(14)<<  i <<endl;

}

Measured memory_bytes: 1280
def getlist():
	return list(map(int, input().split()))

#受け取り
K = int(input())
N = 50
a = K // 50
b = K % 50

ans = []
for i in range(b):
	ans.append(N + N + a - b)
for i in range(N - b):
	ans.append(N - 1 + a - b)
print(N)
ans = list(map(str, ans))
print(" ".join(ans))

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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 4000000000; //4*10^9;
constexpr auto MOD = 1000000007; //10^9+7;


vi a(1000), b(1000);
int dp[1010][10010];

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

    rep(i, n)cin >> a[i] >> b[i];

    rep(i, 110) dp[i][0] = 0;

    rep(i, n) {
        for (int j = 1;j <= h;j++) {
            if (i == 0) dp[i][j] = ((j + a[0] - 1) / a[0]) * b[0];
            else dp[i][j] = min(dp[i - 1][j], dp[i][max(j - a[i], 0)] + b[i]);
        }
        
    }
    cout << dp[n - 1][h] << endl;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int,string> Pis;

int main(){
  ll a,b,k;
  cin>>a>>b>>k;
  if(a<k){
    k-=a;
    a=0;
  }else{
    a-=k;
    k=0;
  }
  if(b<k){
    b=0;
  }else{
    b-=k;
  }
  cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
const int MaxN = 2000;
using namespace std;
int a[MaxN + 5][MaxN + 5], b[MaxN + 5][MaxN + 5];
int l[MaxN + 5], r[MaxN + 5], h[MaxN + 5];
int n, m;
char s[MaxN + 5][MaxN + 5];
bool check(int x, int y){
	int res = 0;
	res += b[x][y];
	res += b[x][y + 1];
	res += b[x + 1][y];
	res += b[x + 1][y + 1];
	return res & 1;
}
void Init(){
	memset(b, 0, sizeof(b));
	memset(a, 0, sizeof(a));
	for(int i = 1;i <= n;i++) scanf("%s", s[i] + 1);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			if(s[i][j] == '#') b[i][j] = 1;
		}
	}
	for(int i = 1;i <= n - 1;i++){
		for(int j = 1;j <= m - 1;j++){
			if(check(i, j)) a[i][j] = 0;
			else a[i][j] = 1;
		}
	}
}
void Solve(){
	int ans = max(n, m);
	n--, m--;
	memset(l, 0, sizeof(l));
	memset(h, 0, sizeof(h));
	memset(r, 0, sizeof(r));
	int lmax = 0, rmax = 0;
	for(int i = 1;i <= m;i++) l[i] = 1, r[i] = m;
	for(int i = 1;i <= n;i++){
		lmax = 1;
		for(int j = 1;j <= m;j++){
			if(a[i][j]) {
				h[j]++;
				if(lmax > l[j]) l[j] = lmax;
			}
			else lmax = j + 1, h[j] = 0, l[j] = 1, r[j] = m;
		}
		rmax = m;
		for(int j = m;j >= 1;j--){
			if(a[i][j]){
				if(rmax < r[j]) r[j] = rmax;
				ans = max(ans, (r[j] - l[j] + 2) * (h[j] + 1));
			}
			else rmax = j - 1;
		}
	}
	printf("%d\n" , ans);
}
int main()
{
	while(~scanf("%d%d", &n, &m)){
		Init();
		Solve();
	}
}

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

int main(){
    ll n,x,m;
    cin>>n>>x>>m;
    if(x==0){cout<<0;return 0;}
    if(x==1){cout<<n;return 0;}
    ll summ = 0;ll count = 0;
    set<ll> s;
    //unordered_map<ll,ll> m;
    vector<ll> v;
    while(x){
        v.push_back(x);
        s.insert(x);
        summ+=x;
        count++;
        if(count==n)break;
        x = (x*x)%m;
        if(s.find(x)!=s.end()){
            break;
        }
    }
    if(x==0){cout<<summ<<endl;return 0;}
    if(count==n){cout<<summ<<endl;return 0;}
    int i;
    for( i=0;i<v.size();++i){
        if(v[i]==x)break;
    }
    ll repeats = v.size()-i;
    ll extra_summ = 0;
    for(int j=i;j<v.size();++j){
        extra_summ += v[j];
    }
    ll leftt = n - count;
    ll soul = leftt/repeats;    //extraacase
    summ = summ + soul*extra_summ;
    if(leftt%repeats!=0){
        ll special = leftt%repeats;
        for(int j=0;j<special;++j){
            summ = summ + v[j+i];
        }
    }
    cout<<summ<<endl;
    return 0;


    

}



Measured memory_bytes: 5840
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; scanf("%lld", &x); return x;}
ld fin(){double x; scanf("%lf", &x); return x;}
char yuyushiki[1000010]; string stin(){scanf( "%s", yuyushiki ); return yuyushiki;}

// head

int w, h;
int n;

int convert(int x, int y){
  if(y == 0){
    return x;
  } else if(x == w){
    return w + y;
  } else if(y == h){
    return w + h + (w - x);
  } else if(x == 0){
    return 2 * w + h + (h - y);
  }
  return -1;
}

int main(){

  w = in();
  h = in();
  n = in();

  using pi = pair<int, int>;
  vector<pi> v(0);
  REP(i, n){
    int a, b;
    {
      int x = in();
      int y = in();
      a = convert(x, y);
    }
    {
      int x = in();
      int y = in();
      b = convert(x, y);
    }
    if(a != -1 && b != -1){
      v.pb(a, i);
      v.pb(b, i);
    }
  }

  sort(v.begin(), v.end());
  stack<int> st;
  int m = v.size();
  REP(i, m * 2){
    if(st.empty() || st.top() != v[i%m].se){
      st.push(v[i%m].se);
    } else {
      st.pop();
    }
  }

  if(st.empty()){
    puts("YES");
  } else {
    puts("NO");
  }
  
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  long ans = 1;
  long const o = 1000000007;
  
  for (int i = 1; i <= n; i++){
    ans = (ans * i) % o;
  }
  cout << ans << endl;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){
  int N, K;
  cin >> N >> K;
  vector<ll> a(N);
  REP(i, N){
    cin >> a[i];
  }
  vector<ll> bubun;
  REP(i, N){
    ll sum = 0;
    FOR(j, i, N){
      sum += a[j];
      bubun.push_back(sum);
    }
  }
  ll x = 0;
  REPR(i, 43){
    int cnt = 0;
    ll bit = (1LL << (i-1));
    REP(j, bubun.size()){
      if(((x+bit)&bubun[j]) == (x+bit)){
        cnt++;
      }
    }
    // cout << "i:" << i << " cnt:" << cnt << endl;
    if(cnt >= K){
      x += bit;
    }
  }
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 6132
#include <iostream>
#include <vector>

using namespace std;

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

    return false;
}

class Graph {
   public:
    vector<vector<int>> G;
    vector<int> Trans;
    vector<int> inDeg;
    int numV;

    Graph(int numV) {
        this->numV = numV;
        inDeg.assign(numV, 0);
        Trans.assign(numV, 0);
        G.assign(numV, vector<int>());
    }

    int topologicalSort(int v, vector<int> &dp) {
        if (dp[v] != -1) {
            return dp[v];
        }

        int res = 0;

        for (auto to : G[v]) {
            chmax(res, topologicalSort(to, dp) + 1);
        }

        return dp[v] = res;
    }
};

int main(void) {
    int N, M;
    cin >> N >> M;

    Graph g(N);
    vector<vector<int>> GSorted;
    GSorted.assign(N, vector<int>());

    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g.G[x].push_back(y);
        g.inDeg[y]++;
    }

    vector<int> dp(100000, -1);

    int res = 0;
    for (int i = 0; i < N; i++) {
        chmax(res, g.topologicalSort(i, dp));
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 10624