akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int get_random(int l, int r) {
  int k = r - l + 1;
  return l + rng() % k;
}

const int N = 365 + 7;
const int K = 26 + 7;
int n;
int c[K], s[N][K], t[N], last[K], sol[N], best = -(int) 2e9;

int get() {
  for (int j = 1; j <= 26; j++) {
    last[j] = 0;
  }
  int sol = 0, grow = 0;
  for (int i = 1; i <= n; i++) {
    sol += s[i][t[i]];
    grow += c[t[i]] * (i - last[t[i]]);
    last[t[i]] = i;
    sol += grow;
  }
  return sol;
}

void upd() {
  int cur = get();
  if (cur > best) {
    best = cur;
    for (int i = 1; i <= n; i++) {
      sol[i] = t[i];
    }
  }
}

void make_better(double seconds) {
  time_t bg = clock();
  int c = 0;
  int cur = get();
  while (1) {
    c++;
    if (c % 10 == 0) {
      time_t nd = clock();
      if ((double) (nd - bg) / CLOCKS_PER_SEC > seconds) {
        break;
      }
    }
    int i = get_random(1, n), x = get_random(1, 26);
    while (x == t[i]) {
      x = get_random(1, 26);
    }
    int init = t[i];
    t[i] = x;
    int after = get();
    if (after > cur) {
      cur = after;
    } else {
      t[i] = init;
    }
  }
  upd();
}

void generate_max() {
  for (int i = 1; i <= n; i++) {
    t[i] = 1;
    for (int j = 1; j <= 26; j++) {
      if (s[i][j] > s[i][t[i]]) {
        t[i] = j;
      }
    }
  }
  int modif = get_random(1, 20);
  while (modif--) {
    int i = get_random(1, n), x = get_random(1, 26);
    while (t[i] == x) {
      x = get_random(1, 26);
    }
    t[i] = x;
  }
}

void generate_random() {
  generate_max();
  for (int i = 1; i <= n; i++) {
    t[i] = get_random(1, 26);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= 26; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 26; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 1; i <= 150; i++) {
    generate_random();
    make_better(0.01);
    upd();
  }
  generate_max();
  make_better(0.2);
  upd();
  for (int i = 1; i <= n; i++) {
    cout << sol[i] << "\n";
  }
  return 0;
}


Measured memory_bytes: 3736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            const int M = 1000000007;

            string[] input = Console.ReadLine().Split(' ');
            int m = int.Parse(input[0]);
            int n = int.Parse(input[1]);

            Console.WriteLine(CalcPow(m, n, M));
        }

        static long CalcPow(int m, int n, int M)
        {
            long ret = 1;

            if (n > 0)
            {
                ret = CalcPow(m, n / 2, M);

                ret = (ret * ret) % M;

                if (n % 2 == 1) ret = (ret * m) % M;
            }
            return ret;
        }
    }
}

Measured memory_bytes: 9184
from sys import stdin
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
n, k = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに
r,s,p = map(int, stdin.readline().rstrip().split())
ts = str(stdin.readline().rstrip())

points  = 0

win = []

def padd(t, points,win):
    if t == "r":
        win.append("r")
        return points+p, win
    elif t=="s":
        win.append("s")
        return points+r, win
    else:
        win.append("p")
        return points+s, win

for i in range(n):
    if i < k:
        points,win = padd(ts[i], points,win)
    else:
        if ts[i] == win[i-k]:
            win.append("n")
        else:
            points, win = padd(ts[i],points,win)

print(points)


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

using namespace std;

#define INF 100010001000
#define MOD 1000000007
#define int long long int
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

typedef pair<int, int> P;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

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

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

int mpow(int N, int P, int M)  //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) {           //bit計算
    if (x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) {   //素数判定
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

signed main() {
    int H, W;
    int ans = 0;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) cin >> S[i];
    rep(si, H)
        rep(sj, W) {
            if (S[si][sj] == '#')continue;
            vector<vector<int>> dist(H, vector<int>(W, INF));
            queue<P> q;
            auto update = [&](int i, int j, int x) {
                if (dist[i][j] != INF) return;
                dist[i][j] = x;
                q.push(P(i, j));
            };
            update(si, sj, 0);
            while (!q.empty()) {
                int i = q.front().first;
                int j = q.front().second;
                q.pop();
                rep(dis, 4) {
                    int ni = i + dx[dis];
                    int nj = j + dy[dis];
                    if (ni<0||ni>=H||nj<0||nj>=W) continue;
                    if (S[ni][nj] == '#') continue;
                    update(ni, nj, dist[i][j] + 1);
                }
            }
            rep(i, H)rep(j, W) {
                    if (dist[i][j] == INF)continue;
                    ans = max(ans, dist[i][j]);
                }
        }
    cout << ans << endl;
}


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

for lf in ['SS','SW','WS','WW']:
    tmp = lf
    for c in S:
        if (tmp[-1]=='W') ^ (c=='x'):
            t = 'S' if tmp[-2]=='W' else 'W'
        else:
            t = 'S' if tmp[-2]=='S' else 'W'
        tmp += t
    if tmp[:2] == tmp[-2:]:
        print(tmp[1:-1])
        exit()
print(-1)

Measured memory_bytes: 3444
using namespace std;
#include<bits/stdc++.h>
#define ll long long int
#define bigint int64_t
#define vll vector<ll>
#define vpll vector<pll>
#define pb push_back
#define MOD 1000000007
#define sz(x) (ll)(x).size()
#define op2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define op3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define op4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define op5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define en cout<<"\n"
#define LCM(a,b) (a*(b/__gcd(a,b)))
#define all(v) v.begin(),v.end()
#define maxqueue    priority_queue<int>
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define minqueue    priority_queue<int,vector<int>,greater<int> >
#define lb(v,val)  (lower_bound(v.begin(),v.end(),val)-v.begin())
#define ub(v,val)  (upper_bound(v.begin(),v.end(),val)-v.begin())
#define INF (ll)(1e18)
#define ini(a,b) memset(a,b,sizeof(a))
#define vvll vector<vector<ll>>
#define ar array
#define pll ar<ll,2>
#define prec(n) fixed<<setprecision(n)
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define forn(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define op1(x)                cerr<<#x<<": "<<x<<endl
#define op6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define GET5(a, b, c, d, e, ...) e
#define D_EBC(...) GET5(__VA_ARGS__, op4, op3, op2, op1)
#define op(...) D_EBC(__VA_ARGS__)(__VA_ARGS__)
#define each(x, a) for (auto& x: a)
#define ff first
#define ss second


template <typename T>
void read(T &x) {
    cin >> x;
}
template <typename T , typename T0>
void read(T &x, T0 &y) {
    cin >> x >> y;
}

template <typename T , typename T0 , typename T1>
void read(T &x, T0 &y, T1 &z) {
    cin >> x >> y >> z;
}

template <typename T , typename T0 , typename T1 , typename T2>
void read(T &x, T0 &y, T1 &z, T2 &w) {
    cin >> x >> y >> z >> w;
}

template <typename T>
void read(vector< T > &oneD, ll n) {
    for (ll i = 0; i < n; i++) {
        read(oneD[i]);
    }

}

template <typename T>
void read(T oneD[] , ll n) {
    for (ll i = 0; i < n; i++) {
        read(oneD[i]);
    }
}
void answer(){
        ll k,a,b;
    read(k,a,b);
    b/=k;
    if(b*k>=a) cout<<"OK";
    else cout<<"NG";
        en;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    // read(t);
    while(t--){
        answer();
    }
}


Measured memory_bytes: 3640
using System;
class aoj
{
    static void Main()
    {
        while (true)
        {
            int a = int.Parse(Console.ReadLine());
            if (a == 0) break;
            int[,] b = new int[a+2,a+2];
            b[(a - 1) / 2 + 1+1, (a - 1) / 2+1] = 1;
            int[] c = {(a-1)/2+1+1, (a - 1) / 2 +1};
            int k = 2;
            for(int i = 1; i < a * a; i++)
            {
                c[0]++;
                c[1]++;
                while (true)
                {
                    int z = 0;
                    if (c[0]  == a+1)
                    {
                        z++;
                        c[0] = 1;
                    }
                    else if (c[0] == 0)
                    {
                        c[1] = a;
                        z++;
                    }
                    else if (c[1]  == a+1)
                    {
                        z++;
                        c[1] = 1;
                    }
                    else if (c[1] == 0)
                    {
                        z++;
                        c[1] = a;
                    }
                    else if (b[c[0] , c[1]] != 0)
                    {
                        c[0]++;
                        c[1]--;
                        z++;
                    }
                    if (z == 0) { break; }
                }
                b[c[0], c[1]] = k;
                k++;
            }
            for (int i = 1; i <= a; i++)
            {
                for(int j = 1; j <= a; j++)
                {
                    Console.Write("{0,4}", b[i, j]);
                }
                Console.WriteLine();
            }
        }
    }
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int n, m;

    while(cin >> n, n){
        long long v[4010];
        vi id;
        rep(j, 4010) v[j] = 0;
        rep(p, n){
            long long  a, b, c;
            cin >> a >> b >> c;
            if(v[a] == 0) id.pb(a);
            v[a] += b*c;
        }
        bool isP = false;
        rep(i, id.size()) if(1000000 <= v[id[i]]){isP = true; cout << id[i] << endl;}
        if(!isP) cout << "NA" << endl;
}
}

Measured memory_bytes: 1268
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

array<array<int, 10>, 10> v;

int check(string s){
    int d = 0;
    for (int i = 0; i < s.size(); ++i) {
        d = v[d][s[i]-'0'];
    }
    return d;
}

int main() {
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> v[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < 10000; ++i) {
        string s = to_string(i);
        while(s.size() < 4) s = '0'+s;
        int ok = 0;

        s += check(s)+'0';
        for (int j = 0; j < 4; ++j) {
            if(s[j] == s[j+1]) continue;
            swap(s[j], s[j+1]);
            if(check(s) == 0){
                ok = 1;
            }
            swap(s[j], s[j+1]);
        }
        for (int k = 0; k < 5; ++k) {
            for (int j = 0; j < 10; ++j) {
                if(s[k] != j+'0'){
                    char tmp = s[k];
                    s[k] = j+'0';
                    if(check(s) == 0){
                        ok = 1;
                    }
                    s[k] = tmp;
                }
            }
        }
        ans += ok;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll  long long
#define PR  pair<int, int>

const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int n;
    cin >> n;
    int x = n / 1000;
    if (n % 1000) {
        x++;
    }
    int z = x * 1000;
    cout << z - n << '\n';
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <map>
#include <cassert>
using namespace std;

char field[8][8];
int dx[8] = { 0, 0,-1,-1,-1, 1, 1, 1};
int dy[8] = { 1,-1, 0, 1,-1,0, 1, -1};
char cookies[2] = {'o','x'};
char rev(char m){
  if(m == 'o')return 'x';
  else if(m == 'x')return 'o';
  return '.';
}
void print_field(){
  for(int i = 0;i < 8;i++){
	  for(int j = 0;j < 8;j++){
		cout << field[i][j];
	}
	cout << endl;
  }
}

bool replace(int k,char m,int x,int y){
  if(x < 0 || x >= 8 || y < 0 || y >= 8 || field[y][x] == '.')return false;
  if(m == field[y][x])return true;
  else if(field[y][x] == rev(m) && replace(k,m,x+dx[k],y+dy[k])){
	field[y][x] = m;
	return true;
  }
  return false;
}

int check(int k,char m,int x,int y,int cnt){
  if(x < 0 || x >= 8 || y < 0 || y >= 8 || field[y][x] == '.')return 0;
  assert(field[y][x] != '.');
  if(field[y][x] == rev(m)){
	return check(k,m,x+dx[k],y+dy[k],cnt+1);
  } 
  assert(field[y][x] == m);
  return cnt;
}

int main(){

  for(int i = 0;i < 8;i++){
	for(int j = 0;j < 8;j++){
	  cin >> field[i][j];
	}
  }
  int turn = 0;
  int f = 0;
  while(1){
	turn %= 2;
	
	int m_cnt = 0;
	int m_x = -10;
	int m_y = -10;
	
	for(int i = 0;i < 8;i++){
	  for(int j = 0;j < 8;j++){
		int k_x,k_y;
		int tmp = 0;
		k_x = j;
		k_y = i;
		if(turn == 1){
		  k_x = 7-j;
		  k_y = 7-i;
		}
		if(field[k_y][k_x] != '.')continue;
		for(int k = 0;k < 8;k++){
		  tmp += check(k,cookies[turn],k_x+dx[k],k_y+dy[k],0);
		}

		if(m_cnt < tmp){
		  m_cnt = tmp;
		  m_x = k_x;
		  m_y = k_y;
		}
	  }
	}
	if(m_cnt != 0){
	  field[m_y][m_x] = cookies[turn];
	  for(int k = 0;k < 8;k++){
		replace(k,cookies[turn],m_x+dx[k],m_y+dy[k]);
	  }
	  f = 0;
	}else{
	  f++;
	  if(f == 2)break;
	}
	
	turn++;
  }


  print_field();	
  return 0;
}

Measured memory_bytes: 1136
#include <bits/stdc++.h>
#define db double 
#define maxn 300005 
#define mod 998244353
#define vi vector<double>
#define pb push_back
#define ll long long
using namespace std;
ll ksm(ll a, ll b) {
	if (!b) return 1;
	ll ns = ksm(a, b >> 1);
	ns = ns * ns % mod;
	if (b & 1) ns = ns * a % mod;
	return ns;
}
inline int add(int a, int b) {
	a += b;
	return (a < mod) ? a : (a - mod);
}
inline int sub(int a, int b) {
	a -= b;
	return (a < 0) ? a + mod : a;
}
inline int mul(int a, int b) {
	return (ll)a * b % mod;
}
// head

int n;
char inp[maxn]; 
int cnt[8];
int main() {
	int n;
	cin >> n;
	scanf("%s", inp);
	ll ans = 1;
	for (int i = 1; i <= n; i++)	
		ans = ans * i % mod;
	for (int i = 0; i < 3 * n; i++) {
		int tp = 0;
		if (inp[i] == 'R') tp = 1;
		else if (inp[i] == 'G') tp = 2;
		int fl = 0;
		for (int i = 7; i >= 0; i--) {
			if (i & (1 << tp)) continue;
			if (cnt[i]) {
				fl = 1;
				ans = ans * cnt[i] % mod;
				cnt[i]--, cnt[i ^ (1 << tp)]++;
				break;
			}
		}
		if (!fl)
			cnt[1 << tp]++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(){
    int sec;
    int h, m, s;

    scanf("%d", &sec);

    h = sec/3600;
    m = (sec%3600)/60;
    s = sec - h*3600 - m*60;

    printf("%d:%d:%d\n", h, m, s);

    return 0;
}


Measured memory_bytes: 2044
package main

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

func main() {
	sc := NewScanner()
	K := sc.NextInt()
	A, B := sc.NextInt(), sc.NextInt()

	for i := A; i <= B; i++ {
		if i%K == 0 {
			fmt.Println("OK")
			return
		}
	}
	fmt.Println("NG")
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 1760
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1e9
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
ll N,M;
ll x[100010];
vector<ll> v;
int main(){
    cin >> N >> M;
    if(N >= M){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 0; i < M; i++) cin >> x[i];
    sort(x,x+M);
    ll ans = 0;
    for(int i = 1; i < M; i++){
        v.push_back(x[i] - x[i-1]);
    }
    for(int i = 0; i < v.size(); i++) ans += v[i];
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    if(N == 1){
        cout << ans << endl;
        return 0;
    }
    for(int i = 0; i < N-1; i++){
        ans -= v[i];
    }
    if(ans <= 0){
        cout << 0 << endl;
        return 0;
    }
    cout << ans << endl;
}



Measured memory_bytes: 2168
import sys

fact = [-1] * 2001
fact[0] = 1
for i in range(1, 2001):
    fact[i] = fact[i-1]*i

def combinations(n, k):
    return fact[n] // (fact[n-k] * fact[k])

def solve(N, i):
    # 赤いボール K の i 箇所(両端含んでよい)を選ぶ
    r = combinations(N-K+1, i) % 1000000007

    # 青いボール (N-K) に i-1 個の仕切りを入れる
    b = combinations(K-1, i-1) % 1000000007
    #return (N, i), r * b, "C(%d,%d)=%d"%(K+1, i, r), b
    return (r * b) % 1000000007


N, K = map(int, input().split())
# K <= N <= 2000
for i in range(1, K+1):
    print(solve(N, i))


Measured memory_bytes: 5748
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  while(cin>>a>>b>>c){
    c+=10;
    b+=10;
    int p=a*10000+b*100+c;
    if(p<18681918)cout<<"pre-meiji"<<endl;
    else if(p<19121740)cout<<"meiji"<<' '<<a-1867<<' '<<b-10<<' '<<c-10<<endl;
    else if(p<19262235)cout<<"taisho"<<' '<<a-1911<<' '<<b-10<<' '<<c-10<<endl;
    else if(p<19891118)cout<<"showa"<<' '<<a-1925<<' '<<b-10<<' '<<c-10<<endl;
    else cout<<"heisei"<<' '<<a-1988<<' '<<b-10<<' '<<c-10<<endl;
  }
}

Measured memory_bytes: 3008
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N=1e5+10;
vector<int>G[N];
int n,m;
int dis[N],fa[N];
const int inf=0x3f3f3f3f;
struct node
{
    int u,w;
    bool operator<(const node &o)const
    {
        return w>o.w;
    }
};
void bfs()
{
    priority_queue<node>que;
    que.push({1,0});
    mem(dis,inf);
    dis[1]=1;
    while(que.size())
    {
        node now=que.top();que.pop();
        for(int v:G[now.u]){
            if(dis[v]>dis[now.u]+1){
                fa[v]=now.u;
                dis[v]=dis[now.u]+1;
                que.push({v,dis[v]});
            }
            else if(dis[v]==dis[now.u]+1){
                if(fa[v]>now.u) fa[v]=now.u;
            }
        }
    }
}
void solve()
{
    scanf("%d%d",&n,&m);
    rep(i,1,m)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    bfs();
    int flag=1;
    rep(i,1,n){
        if(dis[i]==inf) flag=0;
    }
    if(!flag){
        puts("No");
        return ;
    }
    puts("Yes");
    rep(i,2,n) printf("%d\n",fa[i]);

}
int main()
{
	//ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//int _;cin>>_;while(_--)
	solve();
}


Measured memory_bytes: 11100
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,k = map(int,ipt().split())
    a = list(map(int,ipt().split()))
#    n = 2*10**5
#    k = 2*10**5
#    a = [i+1 for i in range(n)]
    nxt = [-1]*(n)
    pa = [-1]*(2*10**5+1)
    for i,ai in enumerate(a*2):
        pai = pa[ai]
        if pai == -2:
            continue
        if pai == -1:
            pa[ai] = i
        else:
            nxt[pai] = i-pai+1
            if i <= n-1:
                pa[ai] = i
            else:
                pa[ai] = -2
    dbl = [nxt]
    ni = 1
    while ni <= n*k:
        nnxt = [0]*n
        pnxt = dbl[-1]
        for i in range(n):
            nnxt[i] = pnxt[i]+pnxt[(i+pnxt[i])%n]
        dbl.append(nnxt)
        if min(nnxt) > n*k:
            break
        ni *= 2
    np = 0
    ld = len(dbl)
    ni = len(dbl)-1
#    print(dbl)
    for db in dbl[::-1]:
        while True:
            if db[np%n] < n*k-1-np:
                np += db[np%n]
            else:
                break
#        print(np)
    ans = []
    np %= n
    while np < n:
        if nxt[np]+np > n:
            ans.append(a[np])
            np += 1
        elif nxt[np]+np == n:
            np = n
        else:
            np = nxt[np]+np
    print(" ".join(map(str,ans)))



    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 309696
#include <bits/stdc++.h>
 
 
using namespace std;
 
#define ll long long
#define ul unsigned long long
#define snd second
#define fst first
 

ll a,b,c,d,e,f,n,m,h;
ll INF =  999999999999;
int main(){
    std::ios::sync_with_stdio(false);
    cin >> h >> n;
    ll cost[10001 + h];
    ll dp[h + 10001];
    for(int i=0;i<10001 + h;i++) cost[i] = -1;
    for(int i=0;i< (10001 + h);i++) dp[i] = -1;

    for(int i=0;i<n;i++){
        ll m, x;
        cin >> m >> x;
        if(cost[m] == -1) cost[m] = x;
        else cost[m] = min(x,cost[m]);
    }
    dp[0] = 0;
    for(int i=1;i<= h + 10000; i++){
        for(int j=1;j<=i;j++){
            if(cost[j] != -1 && dp[i - j] != -1){
                if(dp[i] == -1) dp[i] = dp[i-j] + cost[j];
                else dp[i] = min(dp[i-j] + cost[j],dp[i]);
            }
        }
    }
    ll minBef = INF;
    for(int j=h;j<= h + 10000; j++){
        if(dp[j] > -1) minBef = min(minBef,dp[j]);
    }
    //for(int i=0;i<=10000;i++) cout << cost[i] <<" index-> " << i << endl;
    cout << minBef;

    return 0;
}

Measured memory_bytes: 640
//#include <cstdio>
#include <iostream>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>
#include <tuple>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

VI F;
void build_factorial_table(int N, int P) {
   F = VI(N+1);
   F[0] = 1;
   for (int i = 1; i <= N; ++i)
      F[i] = (F[i-1] * 1LL * i) % P;
}

VI invF;
void build_inverse_factorial_table(int N, int P) {
   VI inv(N+1);
   invF = VI(N+1);
   inv[0]  = inv[1] = 1;
   invF[0] = invF[1] = 1;
   for (int i = 2; i <= N; ++i) {
   // inv[i] = (-(P/i) * inv[P % i] ) % P + P;
      inv[i] = (P - (P / i) * 1LL * inv[P % i] % P) % P;
      invF[i] = (inv[i] * 1LL * invF[i-1]) % P;
   }
}

int nCk(int n, int k, int P) {
   if (n < 0 || k < 0 || k > n)  // invalid n or k
      return 0;
   long long res = F[n];
   res = (res * invF[k]) % P;
   res = (res * invF[n-k]) % P;
   return res;
}


struct Pos {
   int row, col;
};

const int MOD = 1e9 + 7;

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int R, C, N;
   cin >> R >> C >> N;

   build_factorial_table(R+C+4, MOD);
   build_inverse_factorial_table(R+C+4, MOD);

   vector<Pos> blocked;
   REP(i, N) {
      int r, c;
      cin >> r >> c;
      blocked.push_back({r, c});
   }

   sort(blocked.begin(), blocked.end(),
      [&] (Pos a, Pos b) -> bool {
         return a.row + a.col < b.row + b.col;   // sort by diagonal
      }
   );

   VI DP(N);  // DP[i] = number of "valid" paths that end at blocked cell i and
              //         no other blocked cells before

   REP(i, N) {
      int r = blocked[i].row, c = blocked[i].col;
      DP[i] = nCk(r + c - 2, r - 1, MOD);
      REP(j, i) {
         int r0 = blocked[j].row, c0 = blocked[j].col;
         DP[i] = (DP[i] - DP[j] * 1LL * nCk(r-r0 + c-c0, r-r0, MOD)) % MOD;
         if (DP[i] < 0)
            DP[i] += MOD;
      }
   }

   int res = nCk(R + C - 2, R - 1, MOD);
   REP(j, N) {
      int r0 = blocked[j].row, c0 = blocked[j].col;
      res = (res - DP[j] * 1LL * nCk(R-r0 + C-c0, R-r0, MOD)) % MOD;
      if (res < 0)
         res += MOD;
   }

   cout << res << '\n';

   return 0;
}


Measured memory_bytes: 2560
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
#endif

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

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
typedef long long Long;
typedef long double Double;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}

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

template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}

template <class T>
void ms_erase_one(multiset<T>& ms, const T value) {
  ms.erase(ms.find(value));
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int res = 0;
  for (int i = 1; i <= 5; ++i) {
    int x;
    cin >> x;
    res ^= x ^ i;
  }
  cout << res << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll N; cin >> N;
  ll MAX_DIGIT = 29;
  vector<ll> a(N), b(N);
  REP(i,N) cin >> a[i];
  REP(i,N) cin >> b[i];
  ll ans = 0;
  //k-bit目を特定する k:0-indexed
  IREP(k,MAX_DIGIT){
    // a[i]+b[j]のうち，k-bit目が1となる個数の偶奇
    ll parity = 0;
    // 2**(k+1)でmodとってOK
    REP(i,N) {
      a[i] %= 1<<(k+1);
      b[i] %= 1<<(k+1);
    }
    sort(ALL(b));
    ll T = 1<<k;
    // [T-a_i,2T-a_i), [3T-a_i,4T-a_i)の範囲にあるb_jをカウント
    REP(i,N){
      parity += lower_bound(ALL(b),2*T-a[i]) - upper_bound(ALL(b),T-a[i]-1);
      parity += lower_bound(ALL(b),4*T-a[i]) - upper_bound(ALL(b),3*T-a[i]-1);
    }
    parity %= 2;
    ans += parity * (1<<k);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
# coding: utf-8

def main():
    N = int(input())
    num_to_order = [0 for _ in range(N)]

    for student_no, come_order in enumerate(input().split()):
        num_to_order[int(come_order)-1] = str(student_no + 1)
    
    print(' '.join(num_to_order))

main()

Measured memory_bytes: 16280
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N;
vector<pair<int,int> >G[1<<17];
pair<int,int>dp1[1<<17];
pair<int,int>dfs1(int u,int p)
{
	pair<int,int>ret;
	ret.first=ret.second=0;
	for(pair<int,int>q:G[u])
	{
		if(q.first==p)continue;
		pair<int,int>now=dfs1(q.first,u);
		ret.first=max(ret.first,now.first+q.second);
		ret.second=max(ret.second,max(now.second,q.second));
	}
	dp1[u]=ret;
	return ret;
}
int ans;
void dfs2(int u,int p,pair<int,int>P)
{
	vector<pair<pair<int,int>,int> >A;
	A.push_back(make_pair(P,-1));
	for(int i=0;i<G[u].size();i++)
	{
		int v=G[u][i].first;
		if(v==p)continue;
		A.push_back(make_pair(make_pair(dp1[v].first+G[u][i].second,max(dp1[v].second,G[u][i].second)),i));
	}
	sort(A.rbegin(),A.rend());
	pair<int,int>dmax1,dmax2,emax1,emax2;
	dmax1=dmax2=emax1=emax2=make_pair(0,-1);
	while(A.size()<3)A.push_back(make_pair(make_pair(0,0),-(int)A.size()-1));
	for(int i=0;i<A.size();i++)
	{
		ans=max(ans,A[i].first.second+A[i==0?2:0].first.first+A[i==1?2:1].first.first);
		if(dmax1.first<=A[i].first.first)
		{
			dmax2=dmax1;
			dmax1=make_pair(A[i].first.first,A[i].second);
		}
		else if(dmax2.first<=A[i].first.first)
		{
			dmax2=make_pair(A[i].first.first,A[i].second);
		}
		if(emax1.first<=A[i].first.second)
		{
			emax2=emax1;
			emax1=make_pair(A[i].first.second,A[i].second);
		}
		else if(emax2.first<=A[i].first.second)
		{
			emax2=make_pair(A[i].first.second,A[i].second);
		}
	}
	for(int i=0;i<G[u].size();i++)
	{
		if(G[u][i].first==p)continue;
		dfs2(G[u][i].first,u,make_pair(G[u][i].second+(dmax1.second==i?dmax2.first:dmax1.first),max(G[u][i].second,emax1.second==i?emax2.first:emax1.first)));
	}
}
main()
{
	cin>>N;
	for(int i=1;i<N;i++)
	{
		int p,w;cin>>p>>w;
		G[p].push_back(make_pair(i,w));
		G[i].push_back(make_pair(p,w));
	}
	dfs1(0,-1);
	dfs2(0,-1,make_pair(0,0));
	cout<<ans<<endl;
}


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

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define LOCAL
#define MP make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define PF push_front 
#define PB push_back
#define PP push
#define lb lower_bound 
#define ub upper_bound
#define lowbit(x) x&(-x)
#define testbit(x,i) x&(1<<i)

inline void checkmin(int &x,int y){x=min(x,y);}
inline void checkmax(int &x,int y){x=max(x,y);}

int n, k;
bool vis[110];

int main() 
{
	#ifndef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>n>>k;
    for(int i = 0; i < k; i++) {
    	int x;
    	cin>>x;
    	for(int j = 0; j < x; j++) {
    		int a;
    		cin>>a;
    		vis[a] = true;
		}
	}
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(!vis[i]) {
			cnt++;
		}
	} 
	cout<<cnt<<endl;
    /* end code */
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
const ll inf = 1e9 + 10;
const ll maxn = 1e5 + 163;
const ll alf = 26;
const ll dlm = 1e9+7;
const ll del = 10979 ;
const int eps = 1e-7 ;
const int maxq = 3e3+132 ;


int main()
{
    ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
    vector <int> dp(3) ;
    int n ;
    cin>>n ;
    for(int i=1;i<=n;i++){
        int c[3] ;
        for(int j=0;j<3;j++)cin>>c[j] ;
        vector <int> new_dp(3) ;
        for(int j=0;j<3;j++){
            for(int z=0;z<3;z++){
                if(j==z)continue ;
                new_dp[j] = max(new_dp[j] , dp[z] + c[j] ) ;
            }
        }
        dp = new_dp;
    }
    cout<<max({dp[0] , dp[1] , dp[2]}) ;
    return 0;
}



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

using namespace std;

void solve()
{
	int n;
	while(cin >> n)
	{
		vector<int> a;
		if(n == -1)
		{
			break;
		}
		else if(n == 0)
		{
			cout << 0 << endl;
			goto NEXT;
		}
		while(n)
		{
			a.push_back(n % 4);
			n /= 4;
		}
		reverse(a.begin(), a.end());
		for(int i = 0; i < a.size(); ++i)
		{
			cout << a[i];
		}
		cout << endl;
NEXT:
		;
	}
}

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

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

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


Measured memory_bytes: 3956
N=int(input())
A=list(map(int, input().split()))
D={}
for i in range(N):
  D[A[i]]=i
if N==1:
  print(1)
else:
  for i in range(N-1):
    print(D[i+1]+1,end=" ")
  print(D[N]+1)

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

int main(void) {
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  
  if(A1+A2+A3 >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

template<typename T> void Show(vector<vector<T>> v) {
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i].size(); j++) {
			cout << v[i][j];
			if (j != v[i].size() - 1) {
				cout << " ";
			} else {
				cout << endl;
			}
		}
	}
}
template<typename T> void Show(vector<T> v) {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i];
		if (i != v.size() - 1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}
template<typename T> vector<T> getUniform(T value, int n) {
	vector<T> ts;
	ts.resize(n);
	for (int i = 0; i < n; i++) {
		ts[i] = value;
	}
	return ts;
}

int main() {
	int numbers[12]{ 1,3,1,2,1,2,1,1,2,1,2,1 };
	int x = -1, y = -1;
	cin >> x >> y;
	if (numbers[x - 1] == numbers[y - 1]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
n = int(input())

dict = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for i in range(n):
  c = input()
  dict[c] = dict[c] + 1

for k, v in dict.items():
  print(k + ' x ' + str(v))
 

Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int n,i,ans=1000,k;
  cin>>s;
  n=s.length();
  for(i=0;i<=n-3;i++){
    k=100*(s.at(i)-'0')+10*(s.at(i+1)-'0')+(s.at(i+2)-'0');
    if(abs(k-753)<ans) ans=abs(k-753);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,a[3],b;
    for(i=0;i<3;i++)
    {
        cin >> a[i];
    }
    sort(a,a+3);

    b=abs(a[2]-a[1])+abs(a[1]-a[0]);
    cout<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n,a,b;
int sqrid[200111];
#define getid(x,y) ((x)*601+(y))
const int B=400000;
int f[B*2];
int N;
int gf(int x){return f[x]==x?x:f[x]=gf(f[x]);}
vector<pair<int,int> > con;
bool ok[611][611];
void un(int x,int y)
{
	x=gf(x);y=gf(y);
	f[x]=y;
}
void solve(int a)
{	
	for(int i=0;i<B*2;i++)f[i]=i;
	con.clear();
	for(int i=0;i*i<=a;i++)
	{
		if(sqrid[a-i*i]!=-1)
		{
			con.PB(MP(i,sqrid[a-i*i]));
			con.PB(MP(i,-sqrid[a-i*i]));
		}
	}
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)
		{
			for(int t=0;t<con.size();t++)
			{
				int ni=i+con[t].FF,nj=j+con[t].SS;
				if(ni<N&&nj<N&&nj>=0)
				{
			//		cerr<<i<<","<<j<<" "<<ni<<","<<nj<<endl;
					un(getid(i,j),B+getid(ni,nj));
					un(B+getid(i,j),getid(ni,nj));
					assert(gf(getid(i,j))!=gf(getid(i,j)+B));
				}
			}
		}
	}
	int cur=-1;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)
		{
			if(ok[i][j])
			{
				if(cur==-1)
				{
					cur=getid(i,j);
				}
				if(gf(getid(i,j)+B)==gf(cur))ok[i][j]=0;
				else un(getid(i,j),cur);
			}
		}
	}
}
int main()
{
	memset(sqrid,-1,sizeof(sqrid));
	for(int i=0;i*i<=200000;i++)sqrid[i*i]=i;
	cin>>n>>a>>b;
	N=n+n;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)ok[i][j]=1;
	solve(a);
	solve(b);
	int cnt=n*n;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)
	{
		if(ok[i][j]&&cnt)
		{
			for(int t=0;t<con.size();t++)
			{
				int ni=i+con[t].FF,nj=j+con[t].SS;
				if(ni<N&&nj<N&&nj>=0)
				{
					if(ok[ni][nj])cerr<<i<<" "<<j<<" "<<ni<<" "<<nj<<endl;
					assert(!ok[ni][nj]);
				}
			}
			printf("%d %d\n",i,j);
			cnt--;
		}
	}
	assert(cnt==0);
	return 0;
}


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

int main()
{
  long double W, H, x, y;
  cin >> W >> H >> x >> y;
  cout << fixed << setprecision(6) << (H * W) / 2.0 << ' ';
  if ((int64_t)W % 2 == 0 && (int64_t)H % 2 == 0 && W / 2 == x && H / 2 == y)
  {
    cout << 1 << endl;
  }
  else
  {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 3776
# https://atcoder.jp/contests/abc127_c
# Prison

N, M = map(int, input().split())
pairs = [[int(c) for c in input().split()] for _ in range(M)]
left = max(pair[0] for pair in pairs)
right = min(pair[1] for pair in pairs)
print(max(0, right - left + 1))


Measured memory_bytes: 21156
from itertools import product


def main():
    N = int(input())
    testimonies = []
    for _ in range(N):
        a = int(input())
        xy = []
        for _ in range(a):
            xy.append(list(map(int, input().split(" "))))
        testimonies.append(xy)

    assumptions = product([0, 1], repeat=N)
    assumptions = sorted(assumptions, key=lambda x: x.count(0))
    for assumption in assumptions:
        for i in range(N):
            if assumption[i]:
                for testimony in testimonies[i]:
                    if not assumption[testimony[0] - 1] == testimony[1]:
                        break
                else:
                    continue
                break
        else:
            print(assumption.count(1))
            break
        continue


if __name__ == '__main__':
    main()

Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define v(x) vector<x>
#define pb push_back 
#define mp make_pair
const ll maxint=2e18;
const ll minint =-2e18;
/*
(͡ ° ͜ʖ ͡ °): Hi, be careful of overflow.
*/
int main(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	cout << max({a*c,a*d,b*c,d*b})<<'\n';
	return 0;
}

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

const int N = 1500;
const int oo = 0x3f3f3f3f;

int n;
int a[N + 5][N + 5];
int f[N + 5][N + 5];
char st[N + 5][N + 5];
int L[N + 5][N + 5], R[N + 5][N + 5];

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) {
        scanf("%s", st[i] + 1);
        for(int j = 1; j <= n; ++j) {
            a[i][j] = (st[i][j] == '#') ? 0 : st[i][j] - '0';
        }
    }

    long long ans = 0;
    for(int j = n; j >= 1; --j) if(a[n][j] > 0) {
        L[n][j] = j; 

        if(a[n][j + 1] > 0) {
            f[n][j] = f[n][j + 1];
            R[n][j] = R[n][j + 1];
        } else {
            R[n][j] = j;
        }

        ans += a[n][j] * f[n][j];
        f[n][j] += a[n][j];
    }

    for(int i = n - 1; i >= 1; --i) {
        for(int j = n; j >= 1; --j) if(a[i][j] > 0) {
            bool r = (a[i][j + 1] > 0), d = (a[i + 1][j] > 0);

            if(!r && !d) {
                L[i][j] = R[i][j] = j;
                for(int k = i + 1; k <= n; ++k) L[k][j] = oo, R[k][j] = -oo;
            } else if(r && !d) {
                L[i][j] = j;
                R[i][j] = R[i][j + 1];
                f[i][j] = f[i][j + 1];
                for(int k = i + 1; k <= n; ++k) L[k][j] = L[k][j + 1], R[k][j] = R[k][j + 1];
            } else if(!r && d) {
                f[i][j] = f[i + 1][j];
                L[i][j] = R[i][j] = j;
            } else {
                L[i][j] = j; R[i][j] = R[i][j + 1];
                f[i][j] = f[i + 1][j] + f[i][j + 1];

                int lim = 0;
                for(int k = i + 1; k <= n; ++k) {
                    if(R[k][j] >= L[k][j + 1] && L[k][j + 1] > lim) {
                        f[i][j] -= f[k][L[k][j + 1]];
                    }
                    lim = R[k][j];
                    L[k][j] = min(L[k][j], L[k][j + 1]);
                    R[k][j] = max(R[k][j], R[k][j + 1]);
                }
            }
            
            ans += a[i][j] * f[i][j];
            f[i][j] += a[i][j];
        }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 37888
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <vector>
#include <stack>
#include <set>
using namespace std;
typedef  long long ll;
const int maxn=1e6+50;
const int inf=0x3f3f3f3f;
const int MOD=1e9+7;
const int HASH=131;


int main()
{
    int n;
    cin>>n;
    int i=0;
    while(i*1000<n)
    {
        i++;
    }
    printf("%d\n",i*1000-n);
    return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
typedef long long ll;
#define FOR(i,n) for(int i=0;i<n;i++)

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> flag(n);
  for(int i=0;i<n;i++) flag[i] = 0;

  for(int i=0;i<k;i++){
    int a;
    cin >> a;
    vector <int> b(a);
    for(int i=0;i<a;i++){
      cin >> b[i];
    }
    for(int i=0;i<a;i++){
      flag[b[i] - 1] = 1;
    }
  }

  int ans=0;
  for(int i=0;i<n;i++){
    if(flag[i] == 0)ans++;
  }
  cout << ans;
  return 0;
}


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

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            int n = int.Parse(Console.ReadLine());

            var sDic = new Dictionary<string, int>();

            for (int i = 0; i < n; i++) {
                var s = Console.ReadLine();
                if (sDic.ContainsKey(s)) {
                    sDic[s]++;
                } else {
                    sDic.Add(s, 1);
                }
            }

            var max = sDic.Values.Max();

            var array = sDic.Where(x => x.Value == max).ToArray();

            Array.Sort(array, (x, y) => String.Compare(x.Key, y.Key, StringComparison.OrdinalIgnoreCase));

            foreach (var res in array) {
                Console.WriteLine(res.Key);
            }

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 45680
var
 a,b,c,s:longint;
begin
 readln(a,b,c);
 s:=3;
 if a=b then dec(s);
 if a=c then dec(s);
 if b=c then dec(s);
 if (a=b)and(a=c)and(b=c) then s:=1;
 writeln(s);
end.

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> x(n), y(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		y[i] = x[i];
	}
	sort(x.begin(), x.end());
	
	for (int i = 0; i < n; i++) {
		if (y[i] >= x[n / 2]) {
			cout << x[n / 2 - 1] << endl;
		}
		else {
			cout << x[n / 2] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3712