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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const i64 P = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n;
    string x;
    cin >> n >> x;
    vi ds;
    for1(i, n) if (n % i == 0 && i % 2) ds.pb(i);
    vi64 cnt(n + 1);
    for (int d: ds) {
        int p = n / d;
        string y(x.begin(), x.begin() + p);
        while (y.size() < n) y += y[y.size() - p] ^ 1;
        bool ok = y <= x;
        i64 C = 0;
        forn(i, p) C = (2 * C + x[i] - '0') % P;
        if (ok) C = (C + 1) % P;
        cnt[d] = C;
    }
    for (int d = n; d >= 1; --d) for (int dd = 2 * d; dd <= n; dd += d) (cnt[d] += P - cnt[dd]) %= P;
//    for (int d: ds) cerr << d << ' ' << cnt[d] << '\n';
    i64 ans = 0;
    for1(i, n) (ans += cnt[i] * 2 * n / i) %= P;
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 2632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll NN = 1e6+10;

int K,X;
ll up = 2000001;
ll down = -1000000;

vector<int> ve;
int main(){
//	freopen("test.in","r",stdin);
	cin>>K>>X;
	for(int i = X-1;i>X-K && i>down;i--){
		ve.push_back(i);
	}
	for(int i = X;i<X+K && i<up;i++){
		ve.push_back(i);
	}
	sort(ve.begin(),ve.end());
	for(auto v:ve){
		printf("%d ",v);
	}
	return 0;
}

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

using namespace std;
 
int main() {
  int n;
  cin >> n;
  int a=0;
  int sum=0;
  
  vector<int> vct(n);
  
  for(int i=0;i<n;i++){
    cin >>vct.at(i);
  }
  
  for(int i=0;i<n;i++){
    sum++;

    if(vct.at(a)==2){
      cout << sum<<endl;
      return 0;}
       a=vct.at(a)-1;
  }
  cout<<-1<<endl;


  }

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

int A = 0, B = 0, C = 0;
int D = 0;

int main() {
  cin >> A >> B >> C >> D;
  bool indirect = (abs(B-A) <= D && abs(C-B) <= D) ? true : false;
  bool direct = (abs(C-A) <= D) ? true : false;
  if (indirect || direct) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

#define for0(i,n) for(ll i = 0;i < (n);i++)
#define for1(i,n) for(ll i = 1;i<=(n);i++)
#define for2(i,n) for(ll i = 2;i<=(n);i++)
#define fastio cin.tie(0);cout.tie(0);ios::sync_with_stdio(0)
#define rep(i,st,en,cnt) for(ll i = st;i <= en;i+=cnt)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define bit(x,n) (x & (1<<(n)))
#define EPS 1e-8
#define all(x) (x).begin(),(x).end()
#define INF 0x3f3f3f3f3f3f3f
#define NEGINF -INF
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define inp_arr(a,n) for0(i,n) {cin>>a[i];}
#define out_arr(a,n) for0(i,n) {cout<<a[i]<<" ";}cout<<endl;
#define deb1(a) cout<<(a)<<endl;
#define deb2(a,b) cout<<(a)<<" "<<(b)<<endl;
#define deb3(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl;

using namespace std;

typedef pair<int,int> ii;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<vector<ll> > vvl;
typedef vector<pair<long long, long long> > vll;

ii DR8[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
ii DR4[] = {{-1,0},{0,-1},{0,1},{1,0}};

const ll mod = 998244353;

ll nop = 2;
vi primes(nop+1,1);

void sieve(){
    primes[1] = primes[0] = 0;
    for(ll i = 2;i * i <= nop;i++){
        if(primes[i]){
            for(ll j = i*i; j <= nop;j+=i){
                primes[j] = 0;
            }
        }
    }
}

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

void extgcd(ll a,ll b,ll& x,ll& y){  //a smaller b larger
    if(a==0) {
        x = a;y = b;
        return;
    }
    extgcd(b%a,a,x,y);
    ll y1 = y,x1 = x;
    x = y1 - (b/a)*x1;
    y = x1;
}

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

ll bexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans *= num;
        }
        num *= num;
        e>>= 1;
    }
    return ans;
}

ll mexp(ll num,ll e){
    ll ans = 1;
    while(e>0){
        if(e&1){
            ans = (ans *num)%mod;
        }
        num *= num;
        num %= mod;
        e>>=1;
    }
    return ans%mod;
}

ll modinv(ll a){
    a %= mod;
    return mexp(a,mod-2);
}

void solve() {
    int n;
    cin>>n;
    map<string,int> cnt;
    for0(i,n) {
        string tmp;
        cin>>tmp;
        cnt[tmp]++;
    }
    for(string t : {"AC","WA","TLE","RE"}) {
        cout<<t<<" x "<<cnt[t]<<endl;
    }
}

int main() {
    fastio;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t = 1;
    //cin>>t;
    while(t--) {
        solve();
    }
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif */
    return 0;
}


Measured memory_bytes: 3684
#include<stdio.h>
#include<algorithm>
using namespace std;

const int MAX = 100000;
int main() {
	int N, M, P, Y;
	scanf("%d%d", &N, &M);
	static pair<pair<int, int>, int> city[MAX]; // <<P, Y>, i>を記憶しているよ
	static pair<int, int> num[MAX]; // 求めた番号を記録するよ
	for (int i = 0;i < M;++ i) {
		scanf("%d%d", &P, &Y);
		city[i] = make_pair(make_pair(P, Y), i);
	}
	sort(city, city+M);
	for (int i = 0, c = 1;i < M;++ i, c = i < M && city[i - 1].first.first == city[i].first.first ? c + 1 : 1) {
		
		num[city[i].second] = make_pair(city[i].first.first, c);
	}
	for (int i = 0;i < M;++ i) {
		printf("%06d%06d\n", num[i].first, num[i].second);
	}
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まず、P順→Y順にソートすると、それぞれについてxが一意に定まる
これを次にi順にソートすればxが分かっているので無事に求まる
*/

Measured memory_bytes: 3328
import java.io.*;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line;
        int[] a;
        a = new int[3];
        try{
        line = reader.readLine();
        String[] x = line.split(" ");
        a[0] = Integer.parseInt(x[0]);
        a[1] = Integer.parseInt(x[1]);
        a[2] = Integer.parseInt(x[2]);

        Arrays.sort(a);

        System.out.println(a[0]+" "+a[1]+" "+a[2]);

        }catch (NumberFormatException e) {
            System.out.println(e);
        } catch (IOException e) {
            System.out.println(e);
        }

    
    }
}



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

int main(){
    int n,k;
    cin>>n>>k;
    
    if(n==1) cout<<k<<endl;
    else
    {
    int r=k;
    for (int i = 1; i < n; i++){
        r*=(k-1);
    }
    cout<<r<<endl;
    }
}

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

int main()
{
	int64_t k, a, b;
	cin >> k >> a >> b;
	if (a + 2 <= b)
	{
		if (k <= a)
		{
			cout << k + 1 << endl;
		}
		else
		{
			int64_t t = (k - (a - 1)) / 2;
			cout << b + (t - 1) * (b - a) + ((k - (a - 1)) % 2) << endl;
		}
	}
	else
	{
		cout << k + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
        int n,k;
        cin>>n>>k;
        int h[n];
        for(int i=0;i<n;i++)
        {
            cin>>h[i];
        }
        if(k>=n)
        {
            cout<<0;
        }
        else
        {
            sort(h,h+n);
            long long sum=0;
            for(int i=0;i<n-k;i++)
            {
                sum+=h[i];
            }
            cout<<sum;
        }
        return 0;
    }


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,f1,f2,cnt=0;
    cin>>n;
    vector<ll> a(n),b(n),v;
    for(ll i=0;i<n;i++)
    cin>>a[i];
    for(ll i=0;i<n;i++)
    cin>>b[i];
    for(ll i=0;i<n;i++)
    v.push_back(i+1);
    do{
        ll f=0;
        for(ll i=0;i<n;i++)
        if(v[i]!=a[i])
        f=1;
        if(f==0)
        f1=cnt;
        f=0;
        for(ll i=0;i<n;i++)
        if(v[i]!=b[i])
        f=1;
        if(f==0)
        f2=cnt;
        cnt++;
    }while(next_permutation(v.begin(),v.end()));
    cout<<abs(f1-f2);
}


Measured memory_bytes: 256
<?php
    $input = fgets(STDIN);
	$a = explode(" ", $input);
	$A = (int)$a[0];
	$B = (int)$a[1];

	for($i=0;;$i++){
      if($A * $i - ($i -1) >= $B){  
        echo $i;
        break;
      }
    }
    


Measured memory_bytes: 4732
import Data.Array
import qualified Data.IntSet as S

main = do
  li <- getLine
  let n = read li
  co <- getContents
  let as = map read $ lines co
  let ans = compute n as
  print ans

compute :: Int -> [Int] -> Int
compute n as = loop S.empty 1 0
  where
    aa = listArray (1,n) as
    loop s i c
      | S.member i s = -1
      | i == 2 = c
      | True = loop (S.insert i s) (aa ! i) (succ c)


Measured memory_bytes: 32636
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int n, a[100001];
    cin >> n;
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a, a+n);

    if(n==2){
        cout << a[1] - a[0] << endl;
        cout << a[1] << ' ' << a[0] << endl;
        return 0;
    }

    // マイナスの場所
    int minus_max = -1;
    for(int i=0;i<n;i++){
        if(a[i]>=0) break;
        minus_max = i;
    }


    queue<pair<int,int> > q;
    int minus_min = 0;

    if(minus_max==n-1){
        long int tmp = a[minus_max] - a[minus_max-1];
        q.push(make_pair(a[minus_max], a[minus_max-1]));
        for(int i=minus_max-2;i>0;i--){
            q.push(make_pair(tmp, a[i]));
            tmp -= a[i];
        }
        q.push(make_pair(tmp, a[0]));
        cout << tmp - a[0] << endl;
    } else if(minus_max>0){
        int right = n-1;
        int left = 1;
        long int tmp = a[0];

        while(minus_max+1 < right){
            q.push(make_pair(tmp, a[right]));
            tmp -= a[right];
            right--;
        }
        long int tmp_pls = a[right];
        while(left <= minus_max){
            q.push(make_pair(tmp_pls, a[left]));
            tmp_pls -= a[left];
            left++;
        }
        q.push(make_pair(tmp_pls, tmp));
        cout << tmp_pls - tmp << endl;

    } else {
        // long int mid=0;
        // for(int i=1;i<n-1;i++) mid+=a[i];
        // cout << a[n-1] - a[0] + mid << endl;
        long int tmp=a[0]-a[1];
        q.push(make_pair(a[0],a[1]));
        for(int i=2;i<n-1;i++){
            q.push(make_pair(tmp, a[i]));
            tmp -= a[i];
        }
        q.push(make_pair(a[n-1], tmp));
        cout << a[n-1]- tmp << endl;
    }

    while(!q.empty()){
        cout << q.front().first << ' ' << q.front().second << endl;
        q.pop();
    }
    return 0;
}




Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
    int n,m;
	cin >> n>>m;
    fori(m){
        int hoge;
        cin>>hoge;
        n-=hoge;
        if(n<0){
            cout<<-1;
            return 0;
        }
    }
    cout<<n;
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int f[44];
int fib(int n){
    if( n==0 || n==1) return f[n] = 1;
    if(f[n]!=0) return f[n];
    return f[n] = fib(n-1)+fib(n-2);
}
int main(){
    int n;
    scanf("%d",&n);
    n = fib(n);
    printf("%d\n",n);
    return 0; 
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000000
using namespace std;
int main(){
    int N,sum;
    while(1){
        sum = 0;
        cin >> N;
        if(N==0) return 0;
        int A[N];
        for(int i=0;i<N;i++){
            cin >> A[i];
            sum += A[i];
        }
        double ave = (double)sum/N;
        int ans = 0;
        for(int i=0;i<N;i++){
            if(A[i]<=ave) ans++;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3120
fun main(args: Array<String>) {
    var (a,b,c,x) = (1..4).map{
                readLine()!!.toInt()
                }
    var cnt = 0
    (0..a).map{i->
        (0..b).map{j->
            (0..c).map{k->
                if(x == 500*i+100*j+50*k) cnt++
            }
        }    
    }
    println(cnt)
}

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

int main() {
  int A,B,N,K;
  cin >>N>>K;
  vector<long long>a(N),b(N+K);
 for(int i=0;i<N;i++){
   cin>>a[i];
 }
   for(int i=0;i<N+K;i++){
   b[i]=1000000000;
 }
  b[0]=0;
  for(int i=0;i<N;i++){
    for(int j=1;j<K+1;j++){
      if(i+j==N){
        break;
      }
    b[i+j]=min(b[i+j],b[i]+abs(a[i]-a[i+j]));
  }
  }
  cout <<b[N-1]<< endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define mod 1000000007
using namespace std;

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);cout.tie(NULL);
	string s,t;
	cin>>s>>t;

	int a=s.length(),b=t.length();
	vector<vector<int> > dp(a+1,vector<int>(b+1,0));

	for(int i=1;i<=a;++i){
		for(int j=1;j<=b;++j){
			if(s[i-1]==t[j-1]){
				dp[i][j] = dp[i-1][j-1]+1;
			}
			else
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	}
	// for(int i=0;i<a+1;++i)
	// {
	// 	for(int j=0;j<=b;++j)
	// 		cout<<dp[i][j]<<" ";
	// 	cout<<'\n';
	// }
	int j = b;
	int i = a;
	string ans="";

	while(j>0 && i>0){
		if(s[i-1]==t[j-1]){
			ans+=s[i-1];
			i--;
			j--;
		}
		else if(dp[i][j-1]>dp[i-1][j])
			j--;
		else
			i--;
	}
	reverse(all(ans));
	cout<<ans;
	// cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
	return 0;
}

Measured memory_bytes: 35584
import java.util.*;
import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		System.out.println("ABC" + String.valueOf(N));
		
		
	}
}

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

using namespace std;

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

    string one, two;
    getline(cin, one);
    getline(cin, two);

    constexpr int kMod = 1e9 + 7;
    int res = 1;

    int occupied = 0;
    size_t i = 0;

    while (i < one.size()) {
        if (one[i] == two[i]) {
            res = (1LL * res * (3 - occupied)) % kMod;
            occupied = 1;
            i += 1;
        } else {
            res = (1LL * res * (occupied == 2 ? 3 : occupied == 1 ? 2 : 6)) % kMod;
            occupied = 2;
            i += 2;
        }
    }

    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int n, m, k;
bool f;

int main(){
	scanf("%d %d %d", &n, &m, &k);
	for(int i=0; i<=n; ++i)
		for(int j=0; j<=m; ++j)
			if(i * m + j * n - 2 * i * j == k) f = true;
	if(f) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,i;
	string s,str;
	cin>>k;
	cin>>s;
	if(s.length()<=k)
	{
		cout<<s;
	}
	else
	{
		for(int j=0;j<k;j++)
		{
		str+=s[j];	
		}
		str.append("...");
		cout<<str;
	}
	return 0;
}

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

S, C = [], []
for _ in range(N):
    a, b = map(int, input().split())
    S.append((a, b))

for _ in range(M):
    c, d = map(int, input().split())
    C.append((c, d))

for a, b in S:
    ans = None
    min_dist = 1 << 32
    for i, (c, d) in enumerate(C):
        dist = abs(c - a) + abs(d - b)
        if dist < min_dist:
            min_dist = dist
            ans = i
    print(ans + 1)

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;
const int maxn = 2e5 + 10, P = 998244353;

int Inc(int x, int y) {
  return x + y < P ? x + y : x + y - P;
}

int Dec(int x, int y) {
  return x < y ? x - y + P : x - y;
}

void Add(int &x, int y) {
  x += y;
  if (x >= P) x -= P;
}

void Sub(int &x, int y) {
  x -= y;
  if (x < 0) x += P;
}

int qp(int a, int k) {
  int res = 1;
  for (; k; k >>= 1, a = 1ll * a * a % P) {
    if (k & 1) res = 1ll * res * a % P;
  }
  return res;
}

int inv[maxn], fac[maxn], ifac[maxn];

int binom(int n, int m) {
  return n < m ? 0 : 1ll * fac[n] * ifac[m] % P * ifac[n - m] % P;
}

void init() {
  fac[0] = ifac[0] = 1;
  inv[1] = fac[1] = ifac[1] = 1;
  rep(i, 2, maxn - 1) {
    inv[i] = 1ll * (P - P / i) * inv[P % i] % P;
    fac[i] = 1ll * i * fac[i - 1] % P;
    ifac[i] = 1ll * inv[i] * ifac[i - 1] % P;
  }
}

int n, m, k;

void solve() {
  init();
  cin >> n >> m >> k;
  int res = 0;
  rep(i, 0, k) {
    res = (res + 1ll * qp(m - 1, n - i - 1) * binom(n - 1, i)) % P;
  }
  cout << 1ll * m * res % P << endl;
}

int main() {
//  int T = read();
//  while (T--) solve();
  solve();
  return 0;
}

Measured memory_bytes: 6032
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

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

int main() {
	int n; cin >> n;
	VI b(n), f(n), r(n), v(n);
	rep(i, n)cin >> b[i] >> f[i] >> r[i] >> v[i];

	//cnt[棟][階][部屋]
	vector<vector<VI>> cnt(9, vector<VI>(9, VI(19)));
	rep(i, n) {
		cnt[b[i] - 1][f[i] - 1][r[i] - 1] += v[i];
	}

	//print
	rep(i, 4) {
		rep(j, 3) {
			rep(k, 10) {
				cout << " " << cnt[i][j][k];
			}
			puts("");
		}
		if (i != 3) {
			rep(l, 20)cout << "#";
			puts("");
		}
	}
}


Measured memory_bytes: 3164
#include "stdio.h"

int W, H;
int map[90][90] = {};
int place[8500] = {};
int use[8500] = {};
int m[4] = {};
int ans = 0;

void Check(int x[],int p, int num) {
	use[p] = 0;
	for (int i = 0; i < 4; i++) {
		if (use[p+m[i]]==true){
		//	printf("%d??????%d????§??????????\n", p, p + m[i]);
			if (ans < num+1)ans = num+1;
			Check(x,p + m[i], num+1);
		}
	}
	//printf("\n");
	use[p] = 1;
	return;
}

int main() {
	scanf("%d", &W);
	scanf("%d", &H);
	while (!(W == 0)) {
		ans = 0;
		for (int i = 0; i < W*H + 400; i++) {
			place[i] = 0;
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				map[i][j] = false;
				scanf("%d", &map[i][j]);
			//	place[(i + 1)*(W + 2) + j + 1] = 0;
				place[(i+1) * (W+2) + j+1] = map[i][j];
			}
		}
		m[0] = 1;
		m[1] = W+2;
		m[2] = -1;
		m[3] = -W-2;
		for (int i = 0; i < W*H+400; i++) {
			for (int j = 0; j < W*H+400; j++) {
				use[j] = place[j];
			}
			if (place[i]==1)Check(m,i, 1);
		}
		printf("%d\n", ans);
		scanf("%d", &W);
		scanf("%d", &H);
	}
	return 0;
}

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

const string key = "0123456789";
string convert(int num, int base) 
{
	string result = "";
	while (num > 0) 
	{
		int remainder = num % base;
		result += key[remainder];
		num -= remainder;
		num /= base;
	}
	string reverse(result.rbegin(), result.rend());
	return reverse;
}

int main()
{
    int n, k;
    cin >> n >> k;
    string s = convert(n, k);
    cout << s.length() << endl;
}

Measured memory_bytes: 3612
#include <iostream>

int happy(int money, int coin, int happiness){
    int x = money / coin;

    return x * happiness;
}

int main(){
    int X;
    std::cin >> X;

    int ans = happy(X, 500, 1000);
    ans += happy(X % 500, 5, 5);

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define per(i,m,n) for(lli i=m-1;i>=n;i--)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  bool ok;
  char a,b;
  cin>>a>>b;
  if(a=='H')ok=true;
  else ok=false;
  if(ok){
    if(b=='H')cout<<'H'<<endl;
    else cout<<'D'<<endl;
  }
  else if(!ok){
    if(b=='H')cout<<'D'<<endl;
    else cout<<'H'<<endl;
  } 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;
#define mod 1000000007;

int main (void){
	int n,m,x,a[101],i,cost=0;
	cin >> n >> m >> x;
	for(i=1;i<=m;i++) {
		cin >> a[i];
		if(a[i]>x) cost++;
	}
	cost=min(cost,m-cost);
	cout << cost << endl;
	return 0;
}

Measured memory_bytes: 256
mod=10**9+7
n=int(input())
arr=[int(input()) for _ in range(n)]
tmp=[arr[0]]
for i in range(1,n):
  if arr[i]!=tmp[-1]:
    tmp.append(arr[i])
n=len(tmp)
arr=tmp
dp=[0]*n
dp[0]=1
g=[[] for _ in range(max(arr)+1)]
for i in range(n):
  g[arr[i]].append(i)
cnt=[0]*(max(arr)+1)
lim=[0]*(max(arr)+1)
for i in range(max(arr)+1):
  lim[i]=len(g[i])
for i in range(n-1):
  dp[i+1]+=dp[i]
  dp[i+1]%=mod
  if cnt[arr[i]]+1<lim[arr[i]]:
    dp[g[arr[i]][cnt[arr[i]]+1]]+=dp[i]
    dp[g[arr[i]][cnt[arr[i]]+1]]%=mod
    cnt[arr[i]]+=1
print(dp[-1]%mod)

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

int main(){

    int x,y,z,a;
    cin>>x>>y>>z;

    a=z;
    z=y;
    y=x;
    x=a;

    cout<<x<<" "<<y<<" "<<z<<endl;

    





    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long double w , h , x , y;
bool isEqual(long double a , long double b){
	if(abs(a-b) <=1e-5)
		return true;
	return false;
}
int main() {
	cin>>w>>h>>x>>y;
	long double bigarea = w*h/2;
	cout<<fixed<<setprecision(6);
	if(x==w/2&&y==h/2)
		cout<<bigarea<<" 1";
	else cout<<bigarea<<" 0";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int inputNum = Integer.parseInt(sc.nextLine());
		for (int i = 0; i < inputNum; i++) {
			String[] inputData = sc.nextLine().split(" ");
			double[] d = new double[6];
			for (int j = 0; j < 6; j++) {
				d[j] = Double.parseDouble(inputData[j]);
			}
			double distance = Math.sqrt((d[0] - d[3]) * (d[0] - d[3])
					+ (d[1] - d[4]) * (d[1] - d[4]));
			double a = d[2] + d[5];
			int printNum = 0;
			if (distance > a) {
				printNum = 0;
			} else {

				if (d[2] > d[5] + distance) {
					printNum = 2;
				} else if (d[5] > d[2] + distance) {
					printNum = -2;
				} else {
					printNum = 1;
				}

			}
			System.out.println(printNum);
		}
	}

}

Measured memory_bytes: 26452
/**
 *    author: r1933
**/
#include "bits/stdc++.h"

using namespace std;

long long lcm(long long a, long long b) { return a / __gcd(a, b) * b; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  long long L = 1;
  for (int i = 0; i < n; ++i) {
    long long t;
    cin >> t;
    L = lcm(L, t);
  }
  cout << L << "\n";
  return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int d, t, s;
    cin >> d >> t >> s;
    if(t * s >= d) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3616
N = int(input())
H = list(map(int, input().split()))

start = 0
left = 0
right = 1
ans = 0

while right < N:
    if H[left] >= H[right]:
        left += 1
        right += 1
    else:
        ans = max(ans, right - start - 1)
        left = right
        right += 1
        start = left
        
ans = max(ans, right - start - 1)
print(ans)

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

string enc(int x)
{
	string s;
	if(x/1000>1) s.push_back(char(x/1000 + '0'));
	if(x/1000) s.push_back('m');
	x %= 1000;
	if(x/100>1) s.push_back(char(x/100 + '0'));
	if(x/100) s.push_back('c');
	x %= 100;
	if(x/10>1) s.push_back(char(x/10 + '0'));
	if(x/10) s.push_back('x');
	x %= 10;
	if(x>1) s.push_back(char(x + '0'));
	if(x) s.push_back('i');
	return s;
}

int dec(string s)
{
	int sum = 0;
	string::iterator itr = s.begin();
	while(itr != s.end())
	{
		int factor = 1;
		if(*itr >= '2' && *itr <= '9') factor = *itr++ - '0';
		switch(*itr++)
		{
			case 'm': factor *= 10;
			case 'c': factor *= 10;
			case 'x': factor *= 10;
		}
		sum += factor;
	}
	return sum;
}

int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		string s1, s2;
		cin >> s1 >> s2;
		cout << enc(dec(s1) + dec(s2)) << endl;
	}
	return 0;
}

Measured memory_bytes: 3148
#include"bits/stdc++.h"
using namespace std;


int main() {
	int N; cin >> N;
	vector<char> S(N+1);
	for (int i = 1; i <= N; i++) cin >> S[i];

	int m = 1000000;
	vector<int> R(N+1), L(N+1);
	R[0] = 0; L[0] = 0;

	for (int i = 1; i <= N; i++) {
		if (S[i] == 'E') {
			R[i] += R[i - 1] + 1;
			L[i] = L[i - 1];
		}
		else {
			L[i] += L[i - 1] + 1;
			R[i] = R[i - 1];
		}
		//cout << R[i] << " " << L[i] << endl;
	}

	int sum = 0;
	for (int i = 1; i <= N; i++) {
		if (i == 1) {
			sum = R[N] - R[1];
		}
		else if (i == N) {
			sum = L[N];
		}
		else {
			sum = L[i - 1] + R[N] - R[i];
		}
		//cout << sum << endl;
		if (sum < m) m = sum;
	}
	cout << m << endl;
}

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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  rep(i, N){
    rep(j, D){
      cin >> X.at(i).at(j);
    }
  }

  int ans = 0;

  rep(i, N){
    for(int j = i + 1; j < N; j++){
      ll A_2 = 0;
      rep(k, D){
        A_2 += (X.at(i).at(k) - X.at(j).at(k)) * (X.at(i).at(k) - X.at(j).at(k));
      }
      double A = sqrt(A_2);
      //cout << A << endl;
      if(ceil(A) == floor(A)) ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b,t;
    cin>>a >> b>>t;
    cout << t/a*b;

    return 0;
}

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

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

using namespace std;

const int L_MAX=1030;
int rad[2*L_MAX];
void Manacher(const char *s){
	int m=2*strlen(s);
	for(int i=0,j=0;i<m;){
		while(0<=i-j && i+j+1<m && s[(i-j)/2]==s[(i+j+1)/2]) j++;
		rad[i]=j;

		int k;
		for(k=1;i-k>=0 && rad[i-k]<rad[i]-k;k++) rad[i+k]=rad[i-k];

		i+=k;
		j=(j>k?j-k:0);
	}
}

bool is_subpalindrome(const string &s,const string &t){
	int m=s.length(),n=t.length();
	return m<=n && m%2==n%2 && s==t.substr(n/2-m/2,m);
}

int main(){
	for(string s;getline(cin,s);){
		string t;
		rep(i,s.length()) if(isalpha(s[i])) t+=toupper(s[i]);

		Manacher(t.c_str());

		vector<string> ans;
		rep(i,2*t.length()) if(rad[i]>=3) ans.push_back(t.substr((i+1)/2-rad[i]/2,rad[i]));

		sort(ans.begin(),ans.end());
		ans.erase(unique(ans.begin(),ans.end()),ans.end());

		bool b=false;
		rep(i,ans.size()){
			bool ok=true;
			rep(j,ans.size()) if(i!=j) if(is_subpalindrome(ans[i],ans[j])) { ok=false; break; }
			if(ok) cout<<(b?" ":"")<<ans[i], b=true;
		}
		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#[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(std::io::BufReader::new(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, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd(a:u64, b:u64) -> u64 {
    if b==0 {
        a
    } else {
        gcd(b, a%b)
    }
}

fn lcm(a:u64, b:u64) -> u64 {
    a / gcd(a, b) * b
}

fn main() {
    input!{
        n:usize,
        t:[u64;n],
    }
    let mut ans = 1;
    for tt in t {
        ans = lcm(ans, tt);
    }
    println!("{}", ans);
}

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

int main()
{
    string s;
    cin>>s;
    int i,j,n;
    n=s.length();
    for(i=0;i<n;i+=2)
    {
        j=i+1;
        if(s[i]=='L' || s[j]=='R')
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

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

            while(true)
            {
                n = n - p2;
                if (n < p2)
                {
                    break;
                }
            }

            Console.WriteLine(n);
        }
        }
}


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

int main() {
  int N, A, B, P1, P2, X;
  cin >> N >> A >> B;
  P1 = A * N;
  P2 = B;

  if (P1 <= P2) {
    X = P1;
  }
  else {
    X = P2;
  }
  cout << X << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int dp[405][405]; //the min. cost of getting [a][b]

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, ma, mb;
	cin >> n >> ma >> mb;
	rep(i, 405) rep(j, 405) dp[i][j] = 1e9;
	dp[0][0] = 0;
	vi a(n), b(n), c(n);
	int sumA = 0, sumB = 0;
	rep(i, n) cin >> a[i] >> b[i] >> c[i], sumA += a[i], sumB += b[i];
	rep(i, n){
		for(int j = sumA - a[i]; j >= 0; j--){
			for(int k = sumB - b[i]; k >= 0; k--){
				dp[j + a[i]][k + b[i]] = min(dp[j + a[i]][k + b[i]], dp[j][k] + c[i]);
			}
		}
	}
	int ans = 1e9;
	repn(i, 1, sumA + 1) repn(j, 1, sumB + 1){
		int i1 = i, j1 = j;
		int g = gcd(i, j);
		i1 /= g, j1 /= g;
		if(i1 == ma && j1 == mb) ans = min(ans, dp[i][j]);
	}
	if(ans == 1e9) ans = -1;
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cassert>
#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jiglypuff
#define ld long double
#define itn int
#define pir pair<int, int> 
#define all(x) (x).begin(), (x).end()
using namespace std;

lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x1, ld y1, ld x2, ld y2)
{
	return ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
	return (a * (a + 1LL)) / 2;
}
char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };


const int N = 1e6 + 30;
const lli mod = 1e9 + 7;
const ld pi = acos(-1);
const int T = 238;
const ld e = 74e-9;

lli bp(lli a, lli b = -2LL)
{
	lli ret = 1;
	while (b)
	{
		if (b & 1) ret *= a, ret %= mod;
		a *= a;
		a %= mod;
		b >>= 1;
	}
	return ret;
}


int n;
string s, t;
int fact[N];
int V2(int a)
{
	int ret = 0;
	while (a % 2 == 0)ret++, a /= 2;
	return ret;
}
int main()
{
	fastio;
	cin >> n >> s;
	for (int i = 0; i < s.length() - 1; i++)
	{
		t += abs(s[i] - s[i + 1]) + '0';
	}
	if (n == 2)
	{
		cout << t << endl;
		return 0;
	}
	int a = 0, b = 0;
	bool bl = false;
	for (int i = 1; i <= n; i++)
	{
		fact[i] = fact[i - 1] + V2(i);
	}
	for (int i = 0; i < t.length(); i++)
	{
		if (t[i] == '1') bl = true;
		if (fact[i] + fact[n - 2 - i] == fact[n - 2]) a ^= (t[i] % 2), b ^= (t[i] == '2');
	}
	if (a == 1)
	{
		cout << a << endl;
		return 0;
		vector<int> fp;
		cout << fp[0];
	}
	else if (bl) cout << 0 << endl;
	else cout << b * 2 << endl;
	return 0;
}


/*
  __
*(><)*
  \/ /
  ||/
--||
  ||
  /\
 /  \
/    \
*/


Measured memory_bytes: 7196
let () =
  let n,m = Scanf.scanf "%d %d " (fun a b -> a,b) in

  Printf.printf "%d\n" @@
  if n+m = 2 then 1 else
  if n=1 || m=1 then (n*m) - 2 else
  if n=2 || m=2 then 0 else
    (n-2)*(m-2)





Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	   int b[3005];
	   int n;
	   scanf("%d",&n);
	   for(int i=0;i<n;i++)
	   scanf("%d",&b[i]);
	   int sum=0;
	   for(int i=0;i<n;i++)
	   sum+=b[i];
	   printf("%d",sum-n);
	   return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
const int N=1e5+7;
typedef long long i64;
int n,m,a[N],s1[N];
i64 s[N],ans=1ll<<60;
void mins(i64&a,i64 b){if(a>b)a=b;}
void add(int l,int r,int a){
	s[l]+=a,s[r+1]-=a;
}
void add(int l,int r){
	++s1[l],--s1[r+1];
}
void chk(int l,int r){
	if(l<r){
		add(1,l,r-l);
		add(r+1,m,r-l);
		add(l+1,r,r+1);
		add(l+1,r);
	}else{
		add(r+1,l,m+r-l);
		add(1,r,r+1);
		add(l+1,m,m+r+1);
		add(1,r);
		add(l+1,m);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d",a+i);
	for(int i=2;i<=n;++i)chk(a[i-1],a[i]);
	for(int i=1;i<=m;++i){
		s1[i]+=s1[i-1];
		s[i]+=s[i-1];
		mins(ans,s[i]-i64(i)*s1[i]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
int a[100010][3];
int te[100010];
// dp[i][j]:i番目にjの手を出した時の点数の最大値
int dp[100010][3];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, K; cin >> n >> K;
	int r, s, p; cin >> r >> s >> p;
	string t; cin >> t;
	rep(i, n) {
		if (t[i] == 's') {
			a[i][0] = r;
		}
		else if (t[i] == 'p') {
			a[i][1] = s;
		}
		else {
			a[i][2] = p;
		}
	}
	rep(i, 100010)te[i] = -1;
	rep(i, n) {
		rep(j, 3) {
			rep(k, 3) {
				if (i-K >= 0 &&k == te[i-K])continue;
				if (a[i][k] != 0) {
					te[i] = k;
				}
				if (dp[i + 1][k] < dp[i][j] + a[i][k]) {
					dp[i + 1][k] = dp[i][j] + a[i][k];
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 3; i++) {
		chmax(ans, dp[n][i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5968
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = ["".join(sorted(list(str(input().rstrip('\n'))))) for _ in range(n)]
    s = collections.Counter(s).most_common()
    t = 0
    for i, v in s:
        for j in range(v-1, 0, -1):
            t += j
    print(t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 72540
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	char s[10];
	cin>>s+1;
	bool flag=false;
	for(int i=1;i<=3;i++){
		if(s[i]=='7') flag=true;
	}
	cout<<(flag?"Yes":"No")<<'\n';
	return 0;
}

Measured memory_bytes: 3652
from collections import deque
H,W = map(int,input().split())
INF = 1000000
Ch,Cw = map(int,input().split())
Dh,Dw = map(int,input().split())
maze = []
maze.append(['#']*(W+2))
for i in range(H):
    maze.append(['#']+list(input())+['#'])
maze.append(['#']*(W+2))
dis = [[INF]*(W+2) for _ in range(H+2)]
d = deque()
nextd = []
dis[Ch][Cw] = 0
d.append((Ch,Cw))
dy = [0,1,0,-1]
dx = [1,0,-1,0]
cur = 0
while d:
    while d:
        y,x = d.popleft()
        if dis[y][x] == cur:
            for i in range(4):
                newy = y+dy[i]
                newx = x+dx[i]
                if maze[newy][newx] == '.':
                    if dis[newy][newx] > cur:
                        dis[newy][newx] = cur
                        d.append((newy,newx))
            for DY in range(-2,3):
                for DX in range(-2,3):
                    if abs(DX)+abs(DY) >= 2:
                        newy = y+DY
                        newx = x+DX
                        if newy <= H and newy >= 1 and newx <= W and newx >= 1: 
                            if maze[newy][newx] == '.':
                                if dis[newy][newx] > cur+1:
                                    dis[newy][newx] = cur+1
                                    nextd.append((newy,newx))
    cur += 1
    d = deque(nextd)
    nextd = []
if dis[Dh][Dw] == INF:
    print(-1)
else:
    print(dis[Dh][Dw])


Measured memory_bytes: 125372
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int,int> PII;
int a,b;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define MAX(a,b) a>b? a:b
#define MIN(a,b) a>b? b:a

int MAXX(vector<int> v,int k){
int max=0;
REP(i,k){if(v[i]>=max){max=v[i];}}
return max;
}

int main(){
int n,a,b,sum=0;
bool boo=true;
  cin>>n;
  vector<pair<int,int>> v(n);
  REP(i,n){
  cin>>a>>b;
  swap(a,b);
  v[i]=make_pair(a,b);
  }
  sort(v.begin(),v.end());
  REP(i,n){
  sum+=v[i].second;
  if(sum>v[i].first)boo=false;
  }
  if(boo)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
return 0;
}

Measured memory_bytes: 1792
s = list(map(int,input().split()))
s.sort()
a = s[0]
b = s[1]
c = s[2]

ans = 0
if (b-a)%2 == 0:
    while b < c:
        a += 1
        b += 1
        ans += 1
    ans += (c-a)/2
else:
    while b <= c:
        a += 1
        b += 1
        ans += 1
    a += 1
    ans += 1
    ans += (b-a)/2

print(int(ans))



Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    string s;
    cin >> s;
    bool f = (s[0] == s[1]) | (s[1] == s[2]) | (s[2] == s[3]);
    cout << (f? "Bad":"Good") << endl;
    return 0;
}


Measured memory_bytes: 764
/**
*  author: chaitanya
*  created: 05:09:01 PM, 13 September 2020
**/
#include <bits/stdc++.h>
using namespace std;

#define intll 1
#define interactive 0

#ifdef chaitanya
#include "/home/chaitanya/.templates/header.h"
#else
#define debug(x...)
#endif

#if !interactive
#define IOS                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);                      \
  cin.exceptions(cin.failbit);
#define endl "\n"
#else
#define IOS
#endif

#if intll
#define int long long int
#endif

#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define F first
#define S second

const int N = 300009;
const int mod = 1000000007;

void pre() {}

int32_t main() {
  int x;
  cin >> x;
  cout << 1-x << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
ld ans,sum=0,tmp;
int n;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>tmp;
		sum+=(1.0/tmp);
	}
	ans=1.0/sum;
	cout<<fixed<<ans;
	return 0;
}


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

int main()
{
  ll a,b;
  cin >> a >> b;
  cout << max(max(a+b,a-b),a*b);
  return 0;
}

Measured memory_bytes: 256
from itertools import accumulate as ac
n,k=map(int,input().split())
*l,=map(int,input().split())
*m,=map(lambda x:max(x,0),l)
*acc,=ac([0]+l)
*acm,=ac([0]+m)
v=0
for i in range(n-k+1):
  v=max(v,max(0,acc[i+k]-acc[i])+acm[n]-acm[i+k]+acm[i])
print(v)

Measured memory_bytes: 18496
#include<iostream>
#include<vector>
#include<string>
#define SIZE 1299710
using namespace std;

int main() {
	bool *hantei;
	hantei = new bool[SIZE] {};
	hantei[0] = hantei[1] = true;
	for (int a = 2; a < SIZE; a++) {
		if (!hantei[a]) {
			for (int b = a * 2; b < SIZE; b += a)hantei[b] = true;
		}
	}
	int c;
	while (cin >> c, c) {
		if (c == 1 || !hantei[c]) { cout << 0 << endl; continue; }
		int d = 1;
		for (int e = c + 1;; e++) {
			if (!hantei[e])break;
			d++;
		}
		for (int f = c - 1;; f--) {
			if (!hantei[f])break;
			d++;
		}
		cout << d+1<< endl;
	}
}

Measured memory_bytes: 4288
import heapq
def func(n):
    return -n

def main():
    N, M = map(int, input().split())
    A = list(map(func, map(int, input().split())))

    heapq.heapify(A)

    for _ in range(M):
        tmp = -heapq.heappop(A) // 2
        heapq.heappush(A,-tmp)

    print(-sum(A))

main()

Measured memory_bytes: 72216