akhauriyash/Code-Regression huggingface dataset:
import sys

N,M = [ int(x) for x in input().split(" ")]
s = [None]*M
c = [None]*M
for i in range(M):
    s[i],c[i] = [ int(x) for x in input().split(" ")] 

a = [None]*N

for i in range(len(s)):
    if(N<s[i]):
        print(-1)
        exit(0)
    if(1==s[i]):
        if(not N==1):
            if(0==c[i]):
                print(-1)
                exit(0)
    if not None==a[s[i]-1]:
        if not a[s[i]-1]==c[i]:
            print(-1)
            exit(0)
    a[s[i]-1]=c[i]

ans = 0
for i in range(len(a)):
    if None==a[0]:
        if N==1:
            a[0]=0
        else:
            a[0]=1
    if None==a[i]:
        a[i]=0
    ans+=a[i]*10**(len(a)-i-1)
print(ans)

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

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

	int d, ans = 0;
	for (int i = 0; i < 3; i++) {
		d = a % 10;
		if (d == 1) d = 9;
		else d = 1;
		ans += d * pow(10, i);
		a /= 10;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#include<string>
#include<set>
#include<deque>
#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define ld long double
#define int long long

mt19937 rnd(51);

const int MOD = 1e9 + 7;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int s;
    cin >> s;
    if (s < 3){
        cout << 0;
        return 0;
    }
    int dp[s][s];
    for (int i = 0; i < s; i++){
        for (int j = 0; j < s; j++){
            dp[i][j] = 0;
        }
    }
    for (int j = 0; j < s; j++){
        dp[0][j] = 1;
    }
    int ans = 0;
    for (int i = 1; i < s; i++){
        for (int j = 3; j < s; j++){
            dp[i][j] = dp[i - 1][j - 3] + dp[i][j - 1];
            dp[i][j] %= MOD;
            ans %= MOD;
        }
        ans += dp[i - 1][s - 3];
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 34816
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int s[30],n;

int main(){
	for(int i=0;i<28;i++){cin>>n;s[n-1]=1;}
	for(int i=0;i<30;i++)if(s[i]==0)cout<<i+1<<endl;
}

Measured memory_bytes: 0
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <algorithm>
#include <functional>
using namespace std;



int main(){
	

	int i,j;
	int N,K;
	
	
	string S;

	cin >> S;
	if (S == "MON"){
		cout << 6 << endl;
	}

	if (S == "TUE"){
		cout << 5 << endl;
	}

	if (S == "WED"){
		cout << 4 << endl;
	}

	if (S == "THU"){
		cout << 3 << endl;
	}

	if (S == "FRI"){
		cout << 2 << endl;
	}
	if (S == "SAT"){
		cout << 1 << endl;
	}
	if (S == "SUN"){
		cout << 7 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import Data.List

mode :: (Ord a) => [a] -> [a]
mode ns =
    let dist = (map (\ks -> (head ks, length ks)) . group . sort) ns
        maxn = (maximum . map snd) dist
    in map fst $ filter ((== maxn) . snd) dist

main :: IO ()
main = interact $ unlines . map show . mode . map (read :: String -> Int) . lines

Measured memory_bytes: 4108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int count = Integer.parseInt(br.readLine());
		
		for (int i = 0; i < count; i++) {
			String str = br.readLine();
			String[] str1Ary = str.split(" ");
			int[] intAry = {Integer.parseInt(str1Ary[0]), Integer.parseInt(str1Ary[1]), Integer.parseInt(str1Ary[2])};
			Arrays.sort(intAry);
			if(intAry[0]*intAry[0] + intAry[1]*intAry[1] == intAry[2]*intAry[2]){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
}

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

vector<pair<long long, long long>> divisor_pair(long long n) {
	vector<pair<long long, long long>> v;
	for (long long i = 1; i * i <= n; ++i) {
		if (n % i == 0) v.emplace_back(i, n/i);
	}
	return v;
}

vector<long long> divisor(long long n) {
	vector<pair<long long, long long>> div_pair = divisor_pair(n);
	vector<long long> v(div_pair.size()*2);
	if (div_pair.back().first == div_pair.back().second) v.pop_back();
	for (int i = 0, j = v.size()-1; i < div_pair.size(); i++, j--) {
		v[i] = div_pair[i].first;
		v[j] = div_pair[i].second;
	}
	return v;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> A(n);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		sum += A[i];
	}
	auto v = divisor(sum);
	int ans = 1;
	for (int d : v) {
		vector<int> plus(A);
		for (int &e : plus) {
			e = e % d;
		}
		sort(plus.begin(), plus.end());
		vector<int> minus(plus);
		for (int &e : minus) {
			if (e != 0) e -= d;
		}
		for (int i = 1; i < n; i++) {
			plus[i] += plus[i-1];
		}
		for (int i = n-1; i > 0; i--) {
			minus[i-1] += minus[i];
		}
		int x = k+1;
		for (int i = 0; i < n-1; i++) {
			if (plus[i] == -minus[i+1]) {
				x = plus[i];
				break;
			}
		}
		if (x <= k) ans = d;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  long long int A, B;
  cin >> A >> B;
  for(int i = 1; i <= B; i++){
    if((A * i) % B == 0){
      cout << A * i << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() 
{

    ll n;
    cin>>n;
    vector<vector<ll>> a(n,vector<ll>(3));
    for(int i=0;i<n;i++)
    {
        cin>>a[i][0];
        cin>>a[i][1];
        cin>>a[i][2];
    }
    vector<vector<ll>> dp(n,vector<ll>(3));
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a[i][2];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
void solve(long long X, long long Y, long long Z){
  cout << Z << " " << X << " " << Y << endl;
}

int main(){
    long long X;
	scanf("%lld",&X);
	long long Y;
	scanf("%lld",&Y);
	long long Z;
	scanf("%lld",&Z);
    solve(X, Y, Z);
}


Measured memory_bytes: 256
#include<stdio.h>

int main (){
  int a,b[100000],c=0,d,i;
  scanf("%d",&a);
  for(i=0;i<a;i++)scanf("%d",&b[i]);
  for(i=0;i<a-1;i++){
    if(b[a-1]>=b[i]){d=b[i];b[i]=b[c];b[c]=d;c++;}
  }
  d=b[a-1];b[a-1]=b[c];b[c]=d;
  for(i=0;i<a;i++){
    if(i==c)printf("[%d]",b[i]);
    else printf("%d",b[i]);
    if(i==a-1)printf("\n");
    else printf(" ");
  }
}



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

int main(void){
    ll N,D,A;
    cin >> N >> D >> A;
    vector<pair<ll,ll>> XH(N);
    for(ll i = 0; i < N; i++){
        cin >> XH.at(i).first >> XH.at(i).second;
        XH.at(i).second = 1 + (XH.at(i).second -1) / A;
    }
    sort(XH.begin(), XH.end());
    
    ll zero = 0;
    vector<ll> range(N); //iを左端にしたとき、range[i]までダメージを受ける。
    for(ll i = 0; i < N; i++){
        range.at(i) = lower_bound(XH.begin(), XH.end(), make_pair(XH.at(i).first + 2*D + 1, zero)) - XH.begin();
        range.at(i)--;
    }
    vector<ll> leftrange(N); //iを右端にしたとき、leftrange[i]+1までダメージを受ける。
    for(ll i = 0; i < N; i++){
        leftrange.at(i) = lower_bound(XH.begin(), XH.end(), make_pair(XH.at(i).first - 2*D, zero)) - XH.begin();
        leftrange.at(i) = leftrange.at(i) - 1;
    }

    ll tmp = 0;
    vector<ll> bomb(N+1,0); //i+1を左端にして爆発させる爆弾の数の累積和
    for(ll i = 1; i < N+1; i++){
        bomb.at(i) = bomb.at(i-1);
        if(XH.at(i-1).second <= bomb.at(i) - bomb.at(leftrange.at(i-1) + 1)){
            continue;
        }
        else{
            tmp = XH.at(i-1).second - bomb.at(i) + bomb.at(leftrange.at(i-1) + 1);
            bomb.at(i) += tmp;
        }
    }

    
    printf("%lld\n", bomb.at(N));
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
string s,t;
int ans;
int main()
{
	cin>>s;
	cin>>t;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]!=t[i])
		{
			ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000


int main(){
	
	long long N;
	cin>>N;
	
	cout<<N*(N-1)/2<<endl;
		
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int num;
  int a[100];
  int i, j, swap, read;
  int count = 0;
  int min_i, min;

  scanf("%d", &num);
  for(i = 0; i < num; i++) {
    scanf("%d", &read);
    a[i] = read;
  }
  if(num == 1) printf("%d", a[0]);
  else{
  for(i = 0; i < num-1; i++){
    min_i = i; min = a[i];
    for(j = i+1; j < num; j++) if(min > a[j]){min_i = j; min = a[j];}
    if(i != min_i){
      swap = a[i];
      a[i] = a[min_i];
      a[min_i] = swap;
      count++;
    }
    printf("%d ", a[i]);
    if(i == num-2) printf("%d", a[num-1]);
  }
  }
  printf("\n%d\n", count);

  return 0;
}

Measured memory_bytes: 1772
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

#define pr_arr(name, a, b) \
  for (int i = (a); i < (b); i++) { \
    for (int j = (a); j < (b); j++) {\
      if (j > (a)) printf(" "); \
      printf("%lld", name[i][j]); \
    }\
    printf("\n");\
  }\

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

int ans;
int A, B;

int main(void) {
    scanf("%d %d", &A, &B);

    if (A+B==4) puts("2");
    else if (A+B==3) puts("3");
    else puts("1");   

  
  

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007
#define MOD2 1000000014000000049LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, int M>
struct ModFact {
    int inv[N+1];
    int fact[N+1];
    int ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        ll f = 1;
        fact[0] = f;
        for (int i = 0; i < N; i++) {
            f = f*(i+1)%M;
            fact[i+1] = f;
        }
        f = power(f, M-2);
        ifact[N] = f;
        for (int i = N-1; i >= 0; i--) {
            f = f*(i+1)%M;
            ifact[i] = f;
        }
        inv[0] = 0;
        for (int i = 0; i < N; i++) {
            f = ll(fact[i])*ll(ifact[i+1])%M;
            inv[i+1] = f;
        }
    }
    constexpr ll power(ll a, ll b) {
        ll r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
	int operator[](int n) {
		return inv[n];
	}
};

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}

inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

ModFact<100000, MOD> fact;

int main() {
    ll ans = 0, d;
    int a, N, prev, now;
    N = getint();
    prev = getint();
    REP(i, N-1) {
        now = getint();
        d = now - prev;
        prev = now;
        a = (a + fact[i+1]) % MOD;
        ans += a * d % MOD;
        // a += fact.inv[i+1];
        // if(a > MOD) a -= MOD;
        // ans += a * d;
        // if(ans > MOD2) ans -= MOD2;
    }
    printf("%lld\n", ((ans%MOD)*fact.fact[N-1])%MOD);
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int n, q;
vector<int> v, parent, depth;

int find(int a){
  if(parent[a] == a) return a;
  else return parent[a] = find(parent[a]);
}

void unite(int a, int b){
  int pa = find(a), pb = find(b);
  if(pa == pb) return ;

  if(depth[pa] > depth[pb]) swap(pa, pb);
  if(depth[pa] == depth[pb]) ++depth[pa];
  parent[pb] = pa;
}

bool same(int a, int b){
  return find(a) == find(b);
}

int main() {
  cin >>n >>q;
  v = vector<int>(n);
  parent = vector<int>(n);
  depth = vector<int>(n, 1);
  REP(i, n)
    v[i] = parent[i] = i;
  REP(i, q){
    int query, x, y;
    cin >>query >>x >>y;
    if(query)
      cout <<(same(x, y) ? 1 : 0) <<endl;
    else
      unite(y, x);
  }
  return 0;
}

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

fn main() {
    input! {
        n: usize, d: usize,
        x: [[i64; d]; n]
    }

    let mut cnt = 0;
    for i in 0..n {
        for j in i+1..n {
            let mut c = 0;
            for k in 0..d {
                c += (x[i][k] - x[j][k]).abs().pow(2);
            }
            let f = (c as f64).sqrt();
            if f == f.ceil() {
                cnt += 1;
            }
        }
    }
    println!("{}", cnt);
}

Measured memory_bytes: 4352
/*
 * atcoder/abc091/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
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; }

struct Point {
  int x, y;
};
ostream & operator << (ostream & out, Point const & v) {
  out << "Point(" << v.x << ", " << v.y << ')';
  return out;
}

bool xAsc(const Point& lh, const Point& rh) {
     return lh.x < rh.x;
}

bool yDesc(const Point& lh, const Point& rh) {
     return lh.y > rh.y;
}


int N;
vector<Point> red, blue;
bool done[300] = {0};

void solve() {
  cin >> N;
  int x, y;
  loop(n,0,N) {
    cin >> x >> y; red.push_back({ x, y });
  }
  loop(n,0,N) {
    cin >> x >> y; blue.push_back({ x, y });
  }
  sort(red.begin(), red.end(), yDesc);
  sort(blue.begin(), blue.end(), xAsc);

  int count = 0;
  loop(b,0,N) {
    loop(r,0,N) {
      if (done[r]) continue;
      if (red[r].x < blue[b].x and red[r].y < blue[b].y) {
        count++;
        done[r] = true;
        break;
      }
    }
  }
  cout << count << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 256
//              _      _                 
//             (_)    | |                
//    _ __ ___  _  ___| |__   __ _  ___  
//   | '_ ` _ \| |/ __| '_ \ / _` |/ _ \ 
//   | | | | | | | (__| | | | (_| | (_) |
//   |_| |_| |_|_|\___|_| |_|\__,_|\___/ 
//                                       
// 
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int inf=1e18+9;
const int MAX=1e5+5;
const int mod=1e9+7;
int dp[MAX][2];
int ile[MAX][2];
vector<pii> P[MAX];
int n,m,s,t,now=0;
int norm(int x)
{
	while (x>=mod)x-=mod;
	return x;
}
void dijkstra(int u)
{
	for (int i=1;i<=n;i++)dp[i][now]=inf;
	dp[u][now]=0;
	ile[u][now]=1;
	priority_queue<pii>Q;
	Q.push(mp(0,u));
	while (!Q.empty())
	{
		pii akt=Q.top();
		Q.pop();
		akt.st=-akt.st;
		if (akt.st!=dp[akt.nd][now])continue;
		for (auto it:P[akt.nd])
		{
			int v=it.st;
			int cost=it.nd;
			if (dp[akt.nd][now]+cost<=dp[v][now])
			{
				if (dp[akt.nd][now]+cost<dp[v][now])ile[v][now]=ile[akt.nd][now],dp[v][now]=dp[akt.nd][now]+cost,Q.push(mp(-dp[v][now],v));
				else ile[v][now]=norm(ile[v][now]+ile[akt.nd][now]);
			}
		}
	}
	now++;
}
vector<pair<pii,int>>edges;
int32_t main()
{
  BOOST;
  cin>>n>>m>>s>>t;
  for (int i=1;i<=m;i++)
  {
  	int a,b,c;
  	cin>>a>>b>>c;
  	P[a].pb(mp(b,c));
  	P[b].pb(mp(a,c));
  	edges.pb(mp(mp(a,b),c));
  	edges.pb(mp(mp(b,a),c));
  }
  dijkstra(s),dijkstra(t);
  int ans=(ile[t][0]*ile[t][0])%mod;
  int stala=dp[t][0];
  for (int i=1;i<=n;i++)
  {
  	if (dp[i][0]*2==stala && dp[i][1]*2==stala)
  	{
  		int x=(ile[i][0]*ile[i][1])%mod;
  		x=(x*x)%mod;
  	  ans=(ans-x+mod)%mod;
  	}
  }
  
  for (auto it:edges)
  {
  	int a=it.st.st;
  	int b=it.st.nd;
  	int c=it.nd;
  	if (dp[a][0]*2<stala && dp[b][1]*2<stala && c+dp[a][0]+dp[b][1]==stala)
  	{
  		int x=(ile[a][0]*ile[b][1])%mod;
  		x=(x*x)%mod;
  	  ans=(ans-x+mod)%mod;
  	}
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 28968
def f2(cnt, n, ci):
    if ci >= 10 or n > 45:
        return 0
    elif n < ci:
        return 0
    elif n == ci and cnt > 1:
        return 0
    elif n == ci and cnt == 1:
        return 1
    else:
        v = f2(cnt - 1, n - ci, ci + 1)
        v += f2(cnt, n, ci + 1)
        return v


while 1:
    n, s = map(int, input().split())
    if n == 0 and s == 0:
        break
    print(f2(n, s, 0))

Measured memory_bytes: 7648
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>

using ll = long long;

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	ll t = max(a, b);
	ll m = min(a, b);
	ll ans = lcm(t, m);
	cout << ans;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static char[][] c;
    public static void main(String[] args) throws InterruptedException {
        Scanner scan = new Scanner(System.in);
        int[][] c = new int[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                c[i][j] = scan.nextInt();
            }
        }
        for (int i = 0; i < 3; i++) {
            if (c[i][0] - c[i][1] != c[0][0] - c[0][1] ||  c[i][1] - c[i][2] != c[0][1] - c[0][2]) {
                System.out.println("No");
                return;
            }
        }
        for (int i = 0; i < 3; i++) {
            if (c[0][i] - c[1][i] != c[0][0] - c[1][0]||  c[1][i] - c[2][i] != c[1][0] - c[2][0]) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 22996
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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();
		
		List<Integer> list = new ArrayList<Integer>();
		List<Integer> compareList = new ArrayList<Integer>();
		compareList.add(1);
		compareList.add(9);
		compareList.add(7);
		compareList.add(4);
		
		list.add(a);
		list.add(b);
		list.add(c);
		list.add(d);
		
		if(list.containsAll(compareList)) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21972
import Queue
memo = {}
def swap(state, a, b):
    state2 = state[:]
    state2[a], state2[b] = state2[b], state2[a]
    return state2
gkey = lambda state: "".join(map(str, state))

que = Queue.Queue()

init = range(8)
que.put((init, 0, 0))
memo[gkey(init)] = 0
while not que.empty():
    state, pos, c = que.get()
    def next_state(nxt):
        state2 = swap(state, nxt, pos)
        key = gkey(state2)
        if not memo.has_key(key):
            memo[key] = c+1
            que.put((state2, nxt, c+1))
    if pos!=0 and pos!=4:
        next_state(pos-1)
    if pos!=3 and pos!=7:
        next_state(pos+1)
    if pos<4:
        next_state(pos+4)
    else:
        next_state(pos-4)
while True:
    try:
        print memo[raw_input().replace(" ", "")]
    except EOFError:
        break

Measured memory_bytes: 7136
#define s(a,b) (t=a,a=b,b=t)
f(int*a){*a=(*a&7)<<4|*a>>4;}char p[9];m,a,b,c,t,r;main(n){while(scanf("%d",&n),n){r=1,a=97,b=82,c=67;while(n--){scanf("%s",p);m=*p-76;t=m%6==0?(s(b,c),m>0?f(&c):f(&b)):1<m&&m<8?(s(a,b),m^7?f(&b):f(&a)):(s(a,c),m>0?f(&c):f(&a));r+=a&7;}printf("%d\n",r);}}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}

int main(void) {
    string S;
    cin >> S;

    map<int,int> mp;
    reverse(S.begin(), S.end());
    int t = 0;
    for(int i=0; i<S.size(); i++) {
        t += (S[i]-'0') * mod_pow(10, i, 2019);
        t %= 2019;
        mp[t]++;
    }

    int ans = 0;
    for(auto [key, val]: mp) {
        ans += val*(val-1)/2;
    }

    cout << ans + mp[0] << endl;
    return 0;
}


Measured memory_bytes: 3736
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node{
	int key;
	Node *next,*prev;
};

Node *nil;

Node* listSearch(int key){
	Node *cur = nil->next;
	while(cur != nil && cur->key != key){
		cur=cur->next;
	}
	return cur;
}

void init(){
	nil=(Node *)malloc(sizeof(Node));
	nil->next=nil;
	nil->prev=nil;
}

void printList(){
	Node *cur=nil->next;
	int isf=0;
	while(1){
		if(cur==nil) break;
		if(isf > 0) printf(" ");
		printf("%d",cur->key);
		isf = 1;
		cur=cur->next;
	} 
	printf("\n");
}

void deleteNode(Node *t){
	if(t==nil) return;
	t->prev->next=t->next;
	t->next->prev=t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
} 

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	deleteNode(listSearch(key));
}

void insert(int key){
	Node *x=(Node *)malloc(sizeof(Node));
	x->key=key;
	x->next=nil->next;
	nil->next->prev=x;
	nil->next=x;
	x->prev=nil;
} 


int main() {
	
	int key,n,i;
	int size=0;
	char com[20];
	int np=0,nd=0;
	scanf("%d",&n);
	init();
	for(int i=0;i<n;i++){
		scanf("%s%d",com,&key);
		if(com[0]=='i'){
			insert(key);np++;size++;
		}else if(com[0]=='d'){
			if(strlen(com)>6){
				if(com[6]=='F') deleteFirst();
				else if(com[6]=='L') deleteLast();
			}else{
				deleteKey(key);nd++;
			}
			size++;
		}
	}
	
	printList();
	
	return 0;
}

Measured memory_bytes: 33832
package main

import (
	"fmt"
)

func main() {
	var n int
	var y int
	fmt.Scan(&n)
	fmt.Scan(&y)

	max5000 := min(n, y/5000)
	max10000 := min(n, y/10000)

	var i, j int
	for i = 0; i <= max10000; i++ {
		for j = 0; j <= max5000-i; j++ {
			if y-10000*i-5000*j == 1000*(n-i-j) {
				fmt.Println(i, j, n-i-j)
				return
			}
		}
	}

	fmt.Println(-1, -1, -1)
	return
}

func min(i, j int) int {
	if i <= j {
		return i
	}
	return j
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  rep(i,n){
    int p;
    cin >> p;
    a[i]=b[i]=p;
  }
  sort(all(b));
  reverse(all(b));

  rep(i,n){
    if(a[i]!=b[0]) cout << b[0] << endl;
    else cout << b[1] << endl;
  }

  return 0;
}


Measured memory_bytes: 3200
s = input()
n = len(s)
MOD = 10 ** 9 + 7

# 先頭i文字としてあり得る数のうち、13で割ったあまりがjである個数
dp = [[0] * 13 for _ in range(n+1)]

dp[0][0] = 1

for i in range(n):
    if s[i] == '?':
        c = -1
    else:
        c = int(s[i])
    for d in range(10):
        if c != -1 and c != d:
            continue
        for j in range(13):
            dp[i+1][(10*j+d)%13] += dp[i][j]
    
    for j in range(13):
        dp[i+1][j] %= MOD
    
print(dp[n][5])


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

int main() {
 int n; cin >> n;
 vector<int> a(n),ans(n);
 rep(i,n){
   cin >>a[i];ans[a[i]-1]=i+1;
 }
 rep(i,n)cout << ans[i] << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#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, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

//vector< vector<int> > v (size1, vector<int>(size2) );


ll N,K;
ll a;
ll ans;
vector< vector<ll> > G(100005);
vector<bool> B(100005,1);
stack<ll> s;

void dfs(){
    if(s.empty()==false){
        a=s.top();
        if(G[a].size()==0) s.pop();
        else{
            if(B[G[a].back()]){
                s.push(G[a].back());
                B[G[a].back()]=false;
                ans*=K-G[a].size();
                ans%=MOD;
                G[a].pop_back();
            //以下の分岐はeditorialのk-2_P_c (cはG[a].size())を実現するためのもの
            }else if(G[a].size()>1){
                swap(G[a].back(),G[a].front());
            }else{
                G[a].pop_back();
            }
        }
        dfs();
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N>>K;
    for(int i=0;i<N-1;++i){
        int a,b;cin>>a>>b;a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    bool impossible=false;
    FOR(i,0,N){
        if(G[i].size()>=K){
            impossible=true;
            break;
        }
    }

    if(impossible) cout<<0<<endl;
    else{
        s.push(0);
        B[0]=false;
        ans=K;
        dfs();
        cout<<ans%MOD<<endl;
    }
}
//72 参考　https://atcoder.jp/contests/abc133/submissions/6291149

Measured memory_bytes: 6516
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	long long int a[100001], b[100001];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		cin >> b[i];
	}
	long long int needa = 0, needb = 0;
	for(int i = 0; i < n; i++){
		if(a[i] > b[i]){
			needb += a[i] - b[i];
		} else if(a[i] < b[i]){
			needa += (b[i] - a[i]) / 2;
			if(a[i] % 2 != b[i] % 2){
				needa++;
				needb++;
			}
		}
	}
	if(needa >= needb) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main()
{
    int x;
    string a,b;
    cin>>x>>a>>b;
    rep(i,x) cout<<a[i]<<b[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 450;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clzll(x) - 1;	}

ll n, a[MAXN], pre[MAXN], dp[MAXN][MAXN];

ll sum(int i, int j) {
	return pre[j] - pre[i - 1];
}

ll solve(int l, int r) {
	if(l == r) return 0;
	if(dp[l][r]) return dp[l][r];
	ll ans = LLINF;

	for(int i = l; i < r ; ++i) {
		ans = min(ans, solve(l , i) + solve(i + 1, r) + sum(l, r));
	}

	return dp[l][r] = ans;
}

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

	cin >> n;

	for(int i = 1 ; i <= n ; ++i) {
		cin >> a[i];
		pre[i] = a[i];
		pre[i] += pre[i - 1];
	}

	cout << solve(1, n) << endl;

	return 0;
}	

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

#define ll long long

using namespace std;

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

	ll a, b;
	a = 1900 * M + 100 * (N - M);
	b = 1;
	for (int i = 0; i < M; i++) b *= 2;

	cout << a * b << endl;

	system("pause");
	return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    vector<int> T(999);
    T.at(0)=1;
    for (int i=1; i<999; i++) T.at(i)=T.at(i-1)+i+1;
    for (int i=1; i<999; i++) {
        if(T.at(i-1)-a == T.at(i)-b) {
            cout << T.at(i-1)-a << "\n";
        }
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

using namespace std;
typedef long long ll;

int main() {

    ll N;
    cin >> N;
    ll B[N-1];
    rep(i,N-1) cin >> B[i];
    ll out = 0;
    rep(i,N){
        if(i==0) out += B[0];
        else if(i==N-1) out += B[N-2];
        else out += min(B[i],B[i-1]);
    }
    cout << out << endl;
    return 0;
}


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

using namespace std;

int main(){
    string N,ans="No";
    cin >> N;
    int a = 0,b=N.size();
    for(int i = 0;i < b;i++){
        int n = N[i]-'0';
        a += n;
    }
    if(a%9==0)ans = "Yes";
    cout << ans << endl;
}

Measured memory_bytes: 3756
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 1000000

int main() {
	int n, m ,i, cnt = 0, arr[10000], total = 0;
	cin>>n>>m;

	for(i = 0; i < n; i++) {
		cin>>arr[i];
		total += arr[i];
	}

	int thres = total % (4*m) == 0 ? total/(4*m) : total/(4*m) + 1;

	for(i = 0; i < n; i++) {
		if(arr[i] >= thres) cnt++;
	}

	if(cnt >=m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 3656
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int r,D;
    int[] x = new int[20];
    r = s.nextInt();
    D = s.nextInt();
    x[0] = s.nextInt();
    for(int i = 0; i < 10 ;i++){
      x[i + 1] = r * x[i] - D;
      System.out.println(x[i + 1]);
    }
  }
}


Measured memory_bytes: 23124
import numpy as np
#入力
N, D = map(int, input().split())
data = []
for i in range(N):
  data.append(list(map(int, input().split())))
data = np.array(data)


#処理
count = 0
for i in range(N):
  for j in range(N-i-1):
    pool = data[i,:] - data[i+j+1,:]
    pool = np.sqrt(np.sum(np.power(pool, 2)))
    if pool.is_integer():
      count += 1
print(count)      

Measured memory_bytes: 12424
use std::io::Write;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let s = s.trim().to_owned().chars().collect::<Vec<char>>();
    let n = s.len();
    let mut next = vec![0; n];
    for i in 0..n {
        if s[i] == 'L' {
            next[i] = i - 1;
        } else {
            next[i] = i + 1;
        }
    }
    let mut dp = next.clone();
    for _ in 0..17 {
        for i in 0..n {
            next[i] = dp[dp[i]];
        }
        std::mem::swap(&mut next, &mut dp);
    }
    let mut ans = vec![0; n];
    for d in dp {
        ans[d] += 1;
    }
    for (i, v) in ans.iter().enumerate() {
        if i > 0 {
            write!(out, " ").unwrap();
        }
        write!(out, "{}", *v).unwrap();
    }
    write!(out, "\n").unwrap();
}

fn main() {
    run();
}


Measured memory_bytes: 6524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair < ll, ll > PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main() {
    int n, m;
    cin >> n >> m;
    if ( n >= m ) {
        cout << 0 << endl;
        return 0;
    }
    vector<ll> x(m);
    rep(i, m) cin >> x[i];
    sort(x.begin(), x.end());
    vector<ll> difx(m);
    difx[0] = 0;
    for ( int i = 1; i < m; i++ ) {
        difx[i] = x[i] - x[i-1];
    }

    ll ans = 0;
    sort(difx.begin(), difx.end());
    for (int i = 1; i < m-n+1; i++ ) {
        ans += difx[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a[201];
int main()
{
  int i,j,k,l,o,p,n,m;
  cin>>n>>m;
  a[2]=1;
  for(i=3;i<=13;i++)
    a[i]=a[i-1]+1;
  a[1]=a[13]+1;
  if(a[n]==a[m]) 
  {
    cout<<"Draw"<<endl;
	return 0;	
  } 
  if(a[n]>a[m])
  {
  	cout<<"Alice"<<endl;
  	return 0;
  }
  if(a[n]<a[m])
  {
  	cout<<"Bob"<<endl;
  	return 0;
  }
  return 0;
}

Measured memory_bytes: 256
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
#include <pthread.h>
#include <omp.h>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
using namespace std;
using namespace std::chrono;

unordered_map<int, int> factor(int n){
  int cnt = 0;
  unordered_map<int, int> m;
  int nn = n;
  while (!(nn & 1))
    cnt++, nn /= 2;
  if(cnt)
    m[2] = cnt;
  for (int i = 3; i <= sqrt(n); i++){
    cnt = 0;
    while(nn % i == 0)
      nn /= i, cnt++;
    if (cnt)
      m[i] = cnt;
  }
  if (nn > 2)
    m[nn] = 1;
  
  return m;
}

signed main(){
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);
  int n;
  cin >> n;
  int j = n;
  string ans;
  while(j)
    if (j % 26 == 0)
      ans += "z", j -= 26, j /= 26;
    else
      ans += (char)((int)'a' + j % 26 - 1), j /= 26;
  for (int i = ans.size() - 1; i >= 0; i--)
    cout << ans[i];
  cout << endl;
}


Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.function.Function;
import java.util.stream.Collectors;


public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String a = scanner.next();
        scanner.close();

        List<String> list = new ArrayList<>();
        for(int i = 0; i < a.length() ; i++){
            list.add(a.substring(i,i+1));
        }
        Map<String,Integer> map = list.stream().collect(
                Collectors.groupingBy(
                        Function.identity(),
                        Collectors.summingInt(s->1))
        );
        int zero = map.containsKey("0")? map.get("0") : 0;
        int one = map.containsKey("1")? map.get("1") : 0;
        int count = zero > one ? one : zero;
        System.out.println(count * 2);
    }
}


Measured memory_bytes: 35572
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cstdio>
using namespace std;

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


Measured memory_bytes: 640
from collections import deque

N, M = [int(x) for x in input().split()]

conn = [[] for _ in range(N + 1)]
for i in range(M):
    A, B = [int(x) for x in input().split()]
    conn[A].append(B)
    conn[B].append(A)

ans = 0
q = deque([])
check = [False] * (N + 1)
for u in range(1, N + 1):
    if check[u] == False:
        check[u] = True
        q.append(u)
        size = 1
        while q:
            v = q.popleft()
            for w in conn[v]:
                if check[w] == False:
                    check[w] = True
                    q.append(w)
                    size += 1
    ans = max(ans, size)

print(ans)

Measured memory_bytes: 45148
#include <bits/stdc++.h>
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
typedef long long ll;
using namespace std;

int dr[] = {0, 0, -1, +1, -1, -1, +1, +1};
int dc[] = {-1, +1, 0, 0, -1, +1, -1, +1};

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    vector<ll> ans{b*d, a*c, a*d, b*c};
    cout << *max_element(all(ans)) << endl;
}


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

using namespace std;

int main()
{

   int n,test;
   long long x,y,sum;
    vector <int> v;

    scanf("%d",&n);

    for(test=0;test<n;test++)
    {
        scanf("%lld %lld",&x,&y);

         sum= x+y;

        v.push_back(sum);
    }

    sort(v.begin(),v.end());


    printf("%d\n",v[0]);

    v.clear();
    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
#include<stdio.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

bool isOK(int a[],int index,int key){
    if(a[index] >= key){
        return true;
    }else{
        return false;
    }
}

int binary_search(int a[],int n,int key){
    int left = -1;
    int right = n;

    while(right-left>1){
        int mid = left + (right - left)/2;
        if(isOK(a,mid,key)){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}



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

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

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

using namespace std;

int main() {
    int n, k;
    scanf("%d", &n);
    scanf("%d", &k);
    int a[n];
    for (int i = 0; i < n; i++) {
        a[i] = 0;
    }
    for (int i = 0; i < k; i++) {
        int d;
        scanf("%d", &d);
        for (int j = 0; j < d; j++) {
            int b;
            scanf("%d", &b);
            a[b - 1]++;
        }
    }
    int c = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            c++;
        }
    }
    printf("%d\n", c);

    return 0;
}

Measured memory_bytes: 3732
using System;

class Program
{
    static void Main()
    {
        // Input
        string[] str = Console.ReadLine().Split(' ');

        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        int c = int.Parse(str[2]);
        int ans = 0;

        for (int i = a; i <= b; i++)
        {
            if (c % i == 0)
            {
                ans++;
            }
        }

        // Output
        Console.WriteLine("{0}", ans);
    }
}

Measured memory_bytes: 9216
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

int main() {
    int N, K;
    cin >> N >> K;
    vector<pair<ll,ll>> A(N);
    vector<ll> B(0), C(0);
    rep(i,0,N) {
        int n;
        cin >> n;
        A[i].second = n;
        if (n >= 0) {
            A[i].first = n;
            B.push_back(n);
        } else {
            A[i].first = -n;
            C.push_back(n);
        }
    }
    rep(i,0,N) A[i].first = A[i].second > 0 ? A[i].second : -A[i].second;
    sort(all(A));
    sort(all(B));
    sort(all(C));

    ll ans = 1;
    int m = C.size();
    int M = 1000000007;

    if ((m == N && K % 2) || (K == N && m % 2)) {
        // 積は負
        rep(i,0,K) {
            ans *= A[i].second;
            ans %= M;
        }
        if (ans < 0) ans += M;
    } else {
        // 正
        reverse(all(B));
//        reverse(all(C));
        int m_cur = min(K, m);
        if (m_cur % 2) m_cur--;
        int p_cur = K - m_cur;
        while (m_cur > 1 && p_cur + 2 <= N-m) {
            if (B[p_cur]*B[p_cur+1] < C[m_cur-1]*C[m_cur-2]) break;
            m_cur -= 2;
            p_cur += 2;
        }

        rep(i,0,p_cur) {
            ans *= B[i];
            ans %= M;
        }
        rep(i,0,m_cur) {
            ans *= C[i];
            ans %= M;
        }
        if (ans < 0) ans += M;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8320