akhauriyash/Code-Regression huggingface dataset:
/*▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄█████████████  █▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐*/
#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
// #define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vector<ll> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<ll> > vvi;
typedef vector<char> vc;
 
const ll INF = 1e9 + 228;
const ll INFLL = 1e18;
const ll MOD = 1e9 + 7;
// const ll MAXN = 3e5;
const ld eps = 1;
const ld eps2 = 1e-9;
const ll MOD2 = 998244353;
const ll dosz = 5e5;
const ll SZ = (1<<18);
const ld PI = atan2l(0, -1);

void fast_io(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	#ifdef DEBUG
//		freopen("a.in", "r", stdin);
	#endif
}

const int maxn = 2e5 + 228;

int binpow(int n, int k){
	if(!k)
		return 1;
	if(k&1)
		return binpow(n, k-1)*n%MOD2;
	int b = binpow(n, k/2);
	return b*b%MOD2;
}

int fac[maxn];
int rfac[maxn];

int C(int n, int k){
	return fac[n] * rfac[n-k] % MOD2 * rfac[k] % MOD2;
}

void solve(){
	int n, m, k;
	cin >> n >> m >> k;
	int ans = 0;
	fac[0] = rfac[0] = 1;
	for(int i=1; i<maxn; i++){
		fac[i] = fac[i-1] * i % MOD2;
		rfac[i] = rfac[i-1] * binpow(i, MOD2-2) % MOD2;
	}
//	cout << C(3, 1) << endl;
	for(int i=0; i<=k; i++){
		ans += C(n-1, i) * m % MOD2 * binpow(m-1, n-i-1);
		ans %= MOD2;

	}
	cout << ans << endl;
}

signed main(){
	fast_io();
	int q = 1;
//	cin >> q;
	while(q--){
		solve();
	}

}


Measured memory_bytes: 6772
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
signed main(){
    string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int N; cin >> N;
    string s; cin >> s;
    for(auto c : s){
        int t = c - 'A';
        t += N;
        t = (t + 26) % 26;
        cout << alpha[t];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int lli;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define ff first
#define ss second
#define pi pair<lli,lli>
#define pii pair<pi,lli>
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e5 + 5;


int main() {
	IOS
	int T = 1;
	// cin >> T;

	while(T--)
	{
		int n;
		cin >> n;
		vector<lli> v(n+1, 1ll);
		lli ans = 1ll;
		for(lli i = 2; i <= n; i++)
		{
			for(int j = i; j <= n; j+= i)
			{
				v[j]++;
			}
			ans = ans + i*v[i];
		}
		cout << ans << endl;
		

	}
	
	return 0;
}

Measured memory_bytes: 81340
using System;
using System.Collections.Generic;
using System.Linq;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            for (int i = 0; i <= N/7; i++)
            {
                for (int j = 0; j <= N/4; j++)
                {
                    if (N == (7 * i) + (4 * j))
                    {
                        Console.WriteLine("Yes");
                        return;
                    }
                }
            }
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 13140
#![allow(unused_mut, unused_macros, unused_variables, unused_assignments, non_snake_case, unused_imports)]

use std::cmp::*;
use std::collections::*;

// [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 から拝借
macro_rules! input {
    ($($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)*}
    };
}
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)*}
    };
}
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<_>>()
    };
    // ABC128-C-Switches用に拡張
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, $t);
        (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,
        A : usize,
        B : usize,
        C : usize,
        D : usize,
        E : usize
    }
    let pipes = vec!(A, B, C, D, E);
    let min_pipe = pipes.iter().min_by(|a, b| a.partial_cmp(b).unwrap()).unwrap();
    println!("{}", 4 + N / min_pipe + if 0 == N % min_pipe {0} else {1});
}


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

int main(void){
  int N; cin >> N;
  vector<int> A(N);
  for(int i=0; i < N; i++) cin >> A[i];
  int ans = 0;

  for(int i = 0; i < N; i++){
    int minj = i;
    for(int j = i; j < N; j++){
      if(A[j] < A[minj]){
        minj = j;
      }
    }
    swap(A[i], A[minj]);
    if(i != minj) ans++;
  }

  for(int i=0; i < N; i++){
    if(i != N-1){
      cout << A[i] << " ";
    }else{
      cout << A[i] << endl;
    }
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
  const ll m = 1e9 + 7;
  ll a, b;
  cin >> a >> b;
  if (abs(a - b) == 1 || a - b == 0) {
    ll k = max(a, b);
    ll fact[k + 1];
    fact[0] = 1;
    for (ll i = 1; i <= k; i++) {
      fact[i] = fact[i - 1] * i % m;
    }
    if (abs(a - b) == 1)
      cout << fact[a] * fact[b] % m << endl;
    else
      cout << fact[a] * fact[b] * 2ll % m << endl;
  } else
    cout << "0" << endl;
}

Measured memory_bytes: 1024
N = int(input())

if N <= 111:
    print(111)
elif 111 < N <= 222:
    print(222)
elif 222 < N <= 333:
    print(333)
elif 333 < N <= 444:
    print(444)
elif 444 < N <= 555:
    print(555)
elif 555 < N <= 666:
    print(666)
elif 666 < N <= 777:
    print(777)
elif 777 < N <= 888:
    print(888)
elif 888 < N <= 999:
    print(999)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

const int MAX_N = 200100;
int a[MAX_N];
int N;

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

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    
    ll A, B;
    cin >> A >> B;
    if(A <= 5)cout << 0 << endl;
    else if(A <= 12)cout << B / 2 << endl;
    else cout << B << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) begin(x),end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << " " <<
using namespace std;

const int MXN=105;
const int MXK=100005;
const int MOD=1e9+7;
int add(int x,int y){return(x+=y)<MOD?x:x-MOD;}
int sub(int x,int y){return(x-=y)>= 0?x:x+MOD;}

int n,k,a[MXN];
int dp[MXN][MXK];

int main(){
  scanf("%d%d",&n,&k);
  for(int i=1;i<=n;++i)scanf("%d",a+i);
  fill_n(dp[0],k+1,1);
  for(int i=1;i<=n;++i){
    dp[i][0]=1;
    for(int j=1;j<=k;++j){
      dp[i][j]=add(dp[i][j],dp[i][j-1]);
      dp[i][j]=add(dp[i][j],dp[i-1][j]);
      if(j-a[i]>0)dp[i][j]=sub(dp[i][j],dp[i-1][j-a[i]-1]);
    }
  }
  printf("%d\n",sub(dp[n][k],k?dp[n][k-1]:0));
}


Measured memory_bytes: 41216
#include<bits/stdc++.h>
using namespace std;
const string st[8]={"","SAT","FRI","THU","WED","TUE","MON","SUN"};
int main(){
string st1;
cin>>st1;
for (int i=1;i<=7;i++) if (st1==st[i]) {
	cout<<i<<endl;
	return 0;
}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INT long long
#define oo 987654231
using namespace std;
INT n, a[100010], p, ans;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = 1 ; i <= n ; i++ ) cin>>a[i], ans+=abs(p-a[i]), p = a[i];
    ans += abs(p);
    for(int i = 1 ; i <= n ; i++ )
    {
        INT o = abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]);
        INT p = abs(a[i-1]-a[i+1]);
        cout<<ans-abs(o-p)<<endl;
    }
    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}}; ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}

template<typename T>
using vector3d = vector<vector2d<T>>;

using P = pair<int, int>;

int dir[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};

int main() {
    const int INF = 1e9;
    const int INVALID = -1;
    int H, W, K;
    cin >> H >> W >> K;
    int sy, sx, gy, gx;
    cin >> sy >> sx >> gy >> gx;
    sy--, sx--, gx--, gy--;
    vector2d<int> dist(H, vector<int>(W));
    vector2d<bool> visited(H, vector<bool>(W, false));
    for(int i = 0; i < H; i++) {
        string s;
        cin >> s;
        for(int j = 0; j < W; j++) {
            dist[i][j] = s[j] == '@' ? INVALID : INF;
        }
    }
    queue<P> q;
    q.push({sy, sx});
    dist[sy][sx] = 0;
    for(int l = 0; !q.empty(); l++) {
        for(int n = q.size(); n > 0; n--) {
            int y, x;
            tie(y, x) = q.front(); q.pop();
            if(dist[y][x] < l || visited[y][x]) continue;
            visited[y][x] = true;
            for(int d = 0; d < 4; d++) {
                for(int k = 1; k <= K; k++) {
                    int ny = y + k * dir[d][0], nx = x + k * dir[d][1];
                    if(ny < 0 || H <= ny || nx < 0 || W <= nx) break;
                    if(dist[ny][nx] <= l) break;
                    dist[ny][nx] = l + 1;
                    q.push({ny, nx});
                }
            }
        }
    }
    int ans = dist[gy][gx];
    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 11172
//
//  main.cpp
//  Train Ticket
//
//  Created by wenhan on 2017/11/18.
//  Copyright © 2017年 wenhan. All rights reserved.
//

#include <iostream>
using namespace std;
int main() {
    int t;
    cin>>t;
    int a=t/1000,b=t%1000/100,c=t%100/10,d=t%10;
    char v1,v2,v3;
    //cin>>a>>b>>c>>d;
    for(int i=0;i<=7;i++)
    {
        int s=a,j=i;
        if(j%2==0)
        {
            s-=b;
            v1='-';
        }
        else{
            s+=b;
            v1='+';
        }
        j=j/2;
        if(j%2==0)
        {
            s-=c;
            v2='-';
        }
        else{
            s+=c;
            v2='+';
        }
        j=j/2;
        if(j%2==0)
        {
            s-=d;
            v3='-';
        }
        else{
            s+=d;
            v3='+';
        }
        if(s==7){
            cout<<a<<v1<<b<<v2<<c<<v3<<d<<"=7"<<endl;
            break;
        }
    }
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007

ll a,b,i; 

int main()
{
    
    Fast;
 
    cin>>a>>b;
    if(a<b)
    {
        for(i=0;i<b;i++)
            cout<<a;
    }
    else
    {
        for(i=0;i<a;i++)
            cout<<b;
    }
}

Measured memory_bytes: 256
def solve():
  N = int(input())
  B = [int(i) for i in input().split()]
  ans = [ 0 ] * N

  for i in range(N - 1, -1, -1):
    v = -1
    for j in range(i + 1):
      if B[j] == j + 1: v = max(v, j + 1)
    if v == -1: return '-1'
    ans[i] = v
    B.pop(v - 1)
  return '\n'.join(map(str, ans))

print(solve())


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

#define ll long long int
#define ld long double
#define PRECISION 15
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    double ans = 0;
    for(int i=1; i<=n; i++){
        double tmp = 1.0 / n;
        double cmp = i;
        while(cmp < k){
            cmp *= 2;
            tmp /= 2;
        }
        ans += tmp;
    }
    cout << fixed << setprecision(PRECISION) << ans << endl;
    return 0;
}


Measured memory_bytes: 3764
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=20+10;

int n;
int a[maxn],b[maxn],c[maxn];
int kq;

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


Measured memory_bytes: 256
def main():
    n = int(input())
    ki = {}
    for i in range(1,n+1):
        ki[i] = []
    for i in range(n-1):
        u,v,w = map(int,input().split())
        ki[u] += [[v,w%2]]
        ki[v] += [[u,w%2]]
    cl = [-1 for i in range(n)]
    cl[0] = 0
    que = [0]
    while len(que)>0:
        q = que.pop(0)
        for v in ki[q+1]:
            if cl[v[0]-1] != -1:
                continue
            if v[1]==1:
                cl[v[0]-1] = (cl[q]+1)%2
                que.append(v[0]-1)
            else:
                cl[v[0]-1] = cl[q]
                que.append(v[0]-1)
    for i in range(n):
        print(cl[i])

if __name__ == "__main__":
    main()


Measured memory_bytes: 50024
// https://atcoder.jp/contests/abc159/tasks/abc159_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    cout << (N * (N - 1)) / 2 + (M * (M - 1)) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 1e3 + 17;
ll cnt, ans, lnt, sum, n, l1, x, y, a[N], mx = N, b[N][N], m = 753;
pair<ll,ll>pr[N];
vector<ll>v,v2,v3;
map<ll,ll>mp;
bool used[N], t1, t2;
vector<string>sv;

int main()
{
    string s;
    cin >> s;
    for(ll i = 0; i < s.size() - 2; i ++)
    {
        x = ((s[i] - '0') * 100) + ((s[i+1] - '0') * 10) + s[i+2] - '0';
            mx = min(mx, abs(x - 753));
    }
    cout << mx;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef struct {
  int ch[11];
  int num;
  int time;
  int tnum;
} lg;
int M,T,R,P;
vector<lg> team;
 
bool asc(lg t1,lg t2);
 
int main(){
  int i,j,m,t,p;
 
  for(i=0;i<51;i++){
    lg x;
    team.push_back(x);
  }
  while(1){
    cin >> M >> T >> P >> R;
    if(M==0&&T==0&&P==0&&R==0)break;
    for(i=0;i<=T;i++){
      team[i].num=0;
      team[i].time=0;
      team[i].tnum=i+1;
      for(j=0;j<=P;j++)team[i].ch[j]=0;
    }
    for(i=0;i<R;i++){
      cin >> m >> t >> p >> j;
      if(j!=0)team[t-1].ch[p]++;
      else{
    team[t-1].time+=20*team[t-1].ch[p];
    team[t-1].num++;
    team[t-1].time+=m;
      }
    }
 
    sort(team.begin(),team.begin()+T,asc);
 
    for(i=0;i<T;i++){
      if(i==0)cout << team[i].tnum;
      else if(team[i-1].num==team[i].num&&team[i-1].time==team[i].time)cout << "="<<team[i].tnum;
      else cout << ","<<team[i].tnum;
    }
    cout << endl;
  }
  return 0;
}
 
bool asc(lg t1,lg t2){
  if(t1.num>t2.num)return 1;
  else if(t1.num==t2.num&&t1.time<t2.time)return 1;
  else if(t1.num==t2.num&&t1.time==t2.time&&t1.tnum>t2.tnum)return 1;
  else return 0;
}



Measured memory_bytes: 3084
S = input()
n = len(S)
dp = [0 for _ in range(n+1)]
count = [0 for _ in range(2019)]
count[0] = 1
p=1
for i in range(1,n+1):
    dp[i] = (dp[i-1]+int(S[n-i])*p) % 2019
    p = p*10%2019
    count[dp[i]] += 1

for i in range(2019):
    count[i] = count[i]*(count[i]-1)/2

print(int(sum(count)))

Measured memory_bytes: 80880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  priority_queue<P> pq;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;

    pq.push(P(a, i + 1));
  }

  vector<vector<int>> ans(h, vector<int>(w));

  P cur = pq.top();
  pq.pop();

  int id = cur.second;
  int cnt = cur.first;

  for (int i = 0; i < h; i++) {
    if (i % 2 == 0) {
      for (int j = 0; j < w; j++) {
        ans[i][j] = id;
        cnt--;

        if (cnt == 0) {
          cur = pq.top();
          pq.pop();
          id = cur.second;
          cnt = cur.first;
        }
      }
    } else {
      for (int j = w - 1; j >= 0; j--) {
        ans[i][j] = id;
        cnt--;

        if (cnt == 0) {
          cur = pq.top();
          pq.pop();
          id = cur.second;
          cnt = cur.first;
        }
      }
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << ans[i][j];
      if (j != w - 1) {
        cout << " ";
      }
    }
    cout << endl;
  }

  return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    vii g(4);
    rep(i,3) {
        i32 a,b;
        cin >> a >> b;
        g[--a].push_back(--b);
        g[b].push_back(a);
    }

    for(auto node : g) {
        if(node.size() > 2 || node.size() == 0) {
            cout << "NO" << '\n';
            return 0;
        }
    }

    cout << "YES" << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 3632
def floor_sum(n: int, m: int, a: int, b: int) -> int:
    ans = 0
    while True:
        ans += (n - 1) * n // 2 * (a // m)
        a %= m
        ans += n * (b // m)
        b %= m
        y_max = (a * n + b) // m
        if y_max == 0:
            return ans
        x_max = y_max * m - b
        ans += (n - (x_max + a - 1) // a) * y_max
        n, m, a, b = y_max, a, m, (-x_max) % a

import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
    print(floor_sum(*map(int, input().split())))

Measured memory_bytes: 70704
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

N, P = LI()
S = input()

if P == 2 or P == 5:
    ans = 0
    for i in range(N):
        if int(S[N-1 - i]) % P == 0:
            ans += N-i
    print(ans)
else:
    A = [0] * (N+1)
    for i in range(N):
        A[i+1] = (A[i] + int(S[N-1 - i]) * pow(10, i, P)) % P

    c = collections.Counter(A)
    ans = 0
    for v in c.values():
        ans += v * (v-1) // 2
    
    print(ans)


Measured memory_bytes: 44524
//
//  main.cpp
//  hello
//
//  Created by 王　暁彬 on 2018/03/13.
//  Copyright © 2018年 Home. All rights reserved.
//
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
    while(1){
        int a,b;
        cin >> a >> b;
        if(a==0 && b==0)break;
        for(int i=0; i<a; i++) {
            for(int j=0; j<b; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3092
from collections import deque

n, m = map(int, input().split())
path = list(list(map(int, input().split())) for _ in range(m))

d = deque()

dic = dict()
for i in range(m):
    p = path[i]
    if p[0] not in dic:
        dic[p[0]] = [p[1]]
    else:
        dic[p[0]].append(p[1])
    if p[1] not in dic:
        dic[p[1]] = [p[0]]
    else:
        dic[p[1]].append(p[0])
        
sign = [0]*n
done = [0]*n
done[0] = 1

for i in dic[1]:
    d.appendleft(i)
    sign[i-1] = 1
    done[i-1] = 1

while len(d) > 0:
    x = d.pop()
    for i in dic[x]:
        if done[i-1] == 0:
            d.appendleft(i)
            sign[i-1] = x
            done[i-1] = 1
        
print("Yes")
for i in range(n-1):
    print(sign[i+1])

Measured memory_bytes: 65096
#include<iostream>
using namespace std;
#include<cstdio>
#include<vector>
#include<utility>
#include<queue>

typedef vector<pair<int, int> > adj;

struct current_cost
{
    int index, cost;
    bool operator < (const current_cost &cur) const
    {
        return cost > cur.cost;
    }
};

current_cost init(int i, int c)
{
    current_cost cur;
    cur.index = i, cur.cost = c;
    return cur;
}

int main()
{
    int i, j, k, n, m, r, next, cost;
    scanf("%d %d %d", &n, &m, &r);
    adj *adlist;
    adlist = new adj [n];

    for(int k = 0; k < m; k++){
        scanf("%d %d %d", &j, &next, &cost);
        adlist[j].push_back(make_pair(next, cost));
    }

    int *d;
    d = new int [n];
    for(i = 0; i < n; i++){ d[i] = 1000000000; }
    d[r] = 0;

    priority_queue<current_cost> C;
    current_cost cur = init(r, 0);
    C.push(cur);

    int size;
    bool *check;
    check = new bool [n];
    for(i = 0; i < n; i++){ check[i] = false; }

    while(!C.empty())
    {
        cur = C.top(); C.pop();
        i = cur.index;
        if(check[i]) continue;
        check[i] = true;
 
        size = adlist[i].size();
        for(int j = 0; j < size; j++){
            int k = adlist[i][j].first;
            if(d[i] + adlist[i][j].second < d[k]){
                d[k] = d[i] + adlist[i][j].second;
                C.push(init(k, d[k]));
            }
        }
    };
    for(i = 0; i < n; i++){
        (check[i] ? printf("%d\n", d[i]) : printf("INF\n"));
    }
    return 0;
}

Measured memory_bytes: 11348
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    string s, t;
    cin >> s >> t;

    t.pop_back();
    if(s == t){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	int a;cin >> a;
	int b;cin >> b;
	int k;cin >> k;
	int cnt = 0;
	int ans = 0;

	for(int i = min(a,b); i > 0; i--){
		if(a%i == 0 && b%i == 0){
			cnt++;
			if(cnt == k){
				ans = i;
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <queue>
using namespace std;
 
int a[1024];
 
int main()
{
    int n,m;
    while(cin >> n >> m, n||m)
    {
        queue<int> q;
        for(int i=0; i<n; i++) q.push(i+1);
 
 
        for(int i=1; q.size()!=1; i++)
        {
            int t=q.front(); q.pop();
 
            if(i%m!=0)
            {
                q.push(t);
            }
        }
        cout << q.front() << endl;;
    }
}

Measured memory_bytes: 1224
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

namespace
{
	bool AnimalCheck(int N, char a0, char a1, const vector<char>& ans)
	{
		vector<char> animal(N+2);
		animal[0] = a0;
		animal[1] = a1;

		for (int i = 1; i <= N; ++i)
		{
			if ((animal[i] == 'S' && ans[i] == 'o') || (animal[i] == 'W' && ans[i] == 'x'))
			{
				animal[i + 1] = animal[i - 1];
			}
			else
			{
				animal[i + 1] = animal[i - 1] == 'W' ? 'S' : 'W';
			}
		}
		bool check = (animal[0] == animal[N]) && (animal[1] == animal[N+1]);
		if (check)
		{
			for (int i = 0; i < N; ++i)
			{
				cout << animal[i];
			}
			cout << endl;
		}
		return check;
	}
}
void ARC069D()
{
	int N;
	cin >> N;
	string s;
	cin >> s;
	vector<char> ans(N+1);
	for (int i = 0; i < N; ++i)
	{
		ans[i] = s[i];
	}
	ans[N] = ans[0];

	if (AnimalCheck(N, 'S', 'S', ans))
	{
		return;
	}
	if (AnimalCheck(N, 'S', 'W', ans))
	{
		return;
	}
	if (AnimalCheck(N, 'W', 'S', ans))
	{
		return;
	}	if (AnimalCheck(N, 'W', 'W', ans))
	{
		return;
	}
	cout << -1 << endl;
}

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

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

int f(int x){
  int sum=0;
  while (x) {
    sum += x % 10;
    x/=10;
  }
  return sum;
}

int main() {
  int n, a, b, sum=0;
  cin>>n>>a>>b;
  for (int i = a; i <= n; ++i) {
    int sd = f(i);
    if(a<=sd&&sd<=b) sum+=i;
  }
  cout<<sum<<endl;
}


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

using namespace std;

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> heights(N);
  rep(i, N){
    cin >> heights.at(i);
  }
  vector<vector<int>> paths(N);
  rep(i, M){
    int A, B;
    cin >> A >> B;
    paths.at(A-1).push_back(B-1);
    paths.at(B-1).push_back(A-1);
  }
  
  int counter = 0;
  rep(i, N){
    bool heighest = true;
    for(int j : paths.at(i)){
      if(heights.at(i) <= heights.at(j)){
        heighest = false;
        break;
      }
    }
    if(heighest){
      counter++;
    }
  }
  
  cout << counter << endl;
  
}

Measured memory_bytes: 8804
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	if(n*a<b)cout<<n*a<<endl;
	else cout<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;


int A, B, K;

signed main()
{
	cin >> A >> B >> K;

	int cnt = 0;
	for (int i = 100; i >= 1; i--)
	{
		if (A % i == 0 && B % i == 0)
		{
			cnt++;
		}
		if (cnt >= K)
		{
			cout << i << endl;
			return 0;
		}
	}
}









Measured memory_bytes: 256
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <utility>

using std::pair;
using std::vector;
typedef pair<int,int> pii;
const int N = 610;
int _w;

int n, d1, d2, c1[N][N], c2[N][N];
vector<pii> ans[4], dir;

bool inside( int x, int y ) {
	return x >= 0 && x < n+n && y >= 0 && y < n+n;
}

void dfs( int i, int j, int c[N][N] ) {
	for( int d = 0; d < (int)dir.size(); ++d ) {
		int x = i + dir[d].first;
		int y = j + dir[d].second;
		if( inside(x, y) && !c[x][y] ) {
			c[x][y] = 3 - c[i][j];
			dfs(x, y, c);
		}
	}
}

void solve( int d, int c[N][N] ) {
	dir.clear();
	for( int i = 0; i*i <= d; ++i )
		for( int j = 0; j*j+i*i <= d; ++j )
			if( i*i+j*j == d ) {
				dir.push_back( pii(i, j) );
				dir.push_back( pii(-i, j) );
				dir.push_back( pii(i, -j) );
				dir.push_back( pii(-i, -j) );
			}
	for( int i = 0; i < n+n; ++i )
		for( int j = 0; j < n+n; ++j )
			if( !c[i][j] ) {
				c[i][j] = 1;
				dfs(i, j, c);
			}
}

int getid( int x, int y ) {
	int t1 = c1[x][y];
	int t2 = c2[x][y];
	if( t1 == 1 ) {
		return t2 == 1 ? 0 : 1;
	} else {
		return t2 == 1 ? 2 : 3;
	}
}

int main() {
	_w = scanf( "%d%d%d", &n, &d1, &d2 );
	solve(d1, c1);
	solve(d2, c2);
	for( int i = 0; i < n+n; ++i )
		for( int j = 0; j < n+n; ++j ) {
			int id = getid(i, j);
			ans[id].push_back( pii(i, j) );
		}
	for( int i = 0; i < 4; ++i ) {
		int m = (int)ans[i].size();
		if( m >= n*n ) {
			for( int j = 0; j < n*n; ++j )
				printf( "%d %d\n", ans[i][j].first, ans[i][j].second );
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 29272
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

        var ans = b[0] + b[n - 2];
        for (int i = 1; i < n - 1; i++)
        {
            ans += Math.Min(b[i], b[i - 1]);
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(int i=0;i<N;++i)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

bool comp(const PII& l, const PII& r){
  return (double)l.second/l.first > (double)r.second/r.first;
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(15);

  ll N;cin >> N;
  int N_MAX = 2.5e7;
  vector<PLL> x(3);
  cin >> x[0].first >> x[1].first >> x[2].first;
  cin >> x[0].second >> x[1].second >> x[2].second;
  int M = x.size();
  //dp[i+1][j]:i番目まで見て,j個ある時の変換後の最大数
  ll dp[N_MAX+1];
  REP(j,N+1){
    dp[j] = j;
    REP(i,M){
      if(j < x[i].first)continue;
      dp[j] = max(dp[j], dp[j-x[i].first] + x[i].second);
    }
  }
  N = dp[N];

  REP(j,N+1){
    dp[j] = j;
    REP(i,M){
      if(j < x[i].second)continue;
      dp[j] = max(dp[j], dp[j-x[i].second] + x[i].first);
    }
  }
  N = dp[N];

  cout << N << endl;
  return 0;
}


Measured memory_bytes: 195584
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
left = 0
score = 0
for i in reversed(range(N+1)):
    if i == 0:
        score += min(left, A[i])
        continue
    monster = A[i]
    if left >= A[i]:
        score += A[i]
        left = B[i-1]
    else:
        score += left
        monster = A[i]-left
        if B[i-1] >= monster:
            score += monster
            left = B[i-1]-monster
        else:
            score += B[i-1]
            left = 0
print(score)


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

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

  ll N; cin >> N;
  ll A; cin >> A;
  ll B; cin >> B;

  ll q = N / (A + B);
  ll r = N % (A + B);
  ll ans = q * A + min(r, A);
  cout << ans << '\n';
  return 0;
}

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

int main(){
    int x,a,b;
    cin >> x >> a >> b;
    if (b<=a){
        cout << "delicious" <<endl;
    }
    else if(a+x>=b){
        cout << "safe" << endl;
    }
    else{
        cout << "dangerous" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define PF first
#define PS second
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl;
#define OUTD(x) cout << fixed << x << endl;
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 1000000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  IN(ll,N);
  vector<P> num(N);
  for(ll i=0;i < N; i++){
    cin >> num[i].first;
    num[i].second = i;
  }
  SORT(num);
  REP(i,N){
    if(i == num[N-1].second){
      OUT(num[N-2].first);
    }else{
      OUT(num[N-1].first);
    }
  }
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int main(){
  // taking input into an array
  int n;
  cin >> n;
  int arr[n];
  for(int i = 0; i < n; i++){
       cin >> arr[i];
  }
  // finding the first and second maximum numbers
  int maxi1=0, maxi2=0;
  for (int i = 0; i < n; i++){
  	if(arr[i] >= maxi1){
    	maxi2 = maxi1;
      	maxi1 = arr[i];
      
    }
    else if (arr[i] > maxi2) 
      maxi2 = arr[i];
  }
  // 
  for (int i = 0; i < n; i++){
  	if(arr[i] == maxi1) cout << maxi2 <<'\n';
    else cout << maxi1 <<'\n';
  }
  
  return 0;
}

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

int main(){
  int n,b,f,r,v;
  int i,j,k;
  int count[4][3][10] = {0};

  cin >> n;

  for(i = 0; i < n; i++){
    cin >> b >> f >> r >> v;
    count[b - 1][f - 1][r - 1] += v;
  }

  for(i = 0; i < 4; i++){
    for(j = 0; j < 3; j++){
      for(k = 0; k < 10; k++){
        cout << " " << count[i][j][k];
      }
      cout << endl;
    }
    if (i < 3) cout << "####################" << endl;
  }
 return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S,T;
    cin>>S>>T;
    if(T.substr(0,T.length()-1)==S){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;

    return 0;
    
    
  
    
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;

template<typename T1,typename T2> using P = pair< T1, T2 >;
using Pii = P<int,int>;

template<typename T1,typename T2> using M = map< T1, T2>;
using Mii = M<int, int>;
using Mll = M<LL, LL>;

const int MOD = 1000000007;

//Bipartite method : x^n
LL BMPow(int x,int n,int m=0){
    LL ans=1;LL p=x;
    if(m==0){ while(n>0){if(n&1==1){ans*=p;} p*=p; n>>=1;}}
    else{ while(n>0){if(n&1==1){ans=(ans*p)%m;} p=(p*p)%m ;n>>=1;}}
    return ans;
}

//x^-1=x^(m-2) mod m
LL modInv(LL x,int m){return BMPow(x,m-2,m);}

P<Vll,Vll> primeFactor(LL n){
    Vll p,e; LL m=n; int c;
    for(LL i=2;i*i<=n;i++){
        if(m%i!=0){continue;}
        c=0;
        while(m%i==0){c++;m/=i;}
        p.pb(i); e.pb(c);
    }
    if(m>1){ p.pb(m); e.pb(1);}
    return mp(p,e);
}

int main(){
    int n;
    cin>>n;
    Vi a(n),a_inv(n);
    REP(i,n) cin>>a[i];
    REP(i,n) a_inv[i] = modInv(a[i],MOD);

    Mll primes;

    REP(i,n){
        auto p = primeFactor(a[i]);
        REP(j,p.fi.size()){
            auto it = primes.find(p.fi[j]);
            if(it != primes.end()){
                primes[p.fi[j]] = max(primes[p.fi[j]],p.se[j]);
            }else{
                primes[p.fi[j]] = p.se[j];
            }
        }
    }

    LL L = 1;
    for(auto prime : primes){
        L = (L * BMPow(prime.fi,prime.se,MOD))%MOD;
    }

    LL ans = 0;
    REP(i,n){
        ans = (ans + (L*a_inv[i])%MOD)%MOD;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<cstdio>
#define MN 200000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
char st[MN+5];
int n,K;
void AplusB(int a,int l,int r,int rev,int len,int K);
void BplusA(int b,int l,int r,int rev,int len,int K);
void Solve(int l,int r,int rev,int len,int K);
 
void Solve(int l,int r,int rev,int len,int K)
{
	if(!K)
	{
		for(int i=l;i<=r;++i) printf("%c",((st[i]-'A')^rev)+'A');
		for(int i=1;i<=len;++i) printf("%c",(i&1)==(len&1)?'A':'B');
		return;
	}
	if(l>r)
	{
		if(n&1)
		{
			if(K&1) cout<<"B";
			else cout<<"A";	
		}
		for(int i=1+(n&1);i<=n;++i) printf("%c",(i&1)==(len&1)?'A':'B');
		return;		
	}
	int posa=l;
	for(;posa<=r&&((st[posa]-'A')^rev);++posa);
	if(posa>r) BplusA(r-l+2-(len&1),2,1,0,len-2+(len&1),K);
	else BplusA(posa-l,posa+1,r,rev,len,K);
}
 
void AplusB(int a,int l,int r,int rev,int len,int K)
{
	if(!K)
	{
		for(int j=1;j<=a;++j) putchar('A');putchar('B');
		for(int i=l;i<=r;++i) printf("%c",((st[i]-'A')^rev)+'A');
		for(int i=1;i<=len;++i) printf("%c",(i&1)==(len&1)?'A':'B');
		return;	
	}
	if(!a) 
	{
		if(l>r) Solve(2,1,0,n,K-(n&1)); 
		else st[l-1]='A'+(rev^1),Solve(l-1,r,rev,len,K);
	}
	else if(a==1)
	{
		if(l>r)
		{
			if(n&1) Solve(2,1,0,n,K);
			else if(K>=3) Solve(2,1,0,n,K-3);
			else 
			{
				if(K==1) cout<<"BB";
				if(K==2) cout<<"AA";
				for(int i=3;i<=n;++i) putchar((i&1)==(n&1)?'A':'B');	
			}
		} 
		else 
		{
			st[l-1]='A'+(rev^1);
			AplusB(0,l-1,r,rev,len,K-1);
		}
	}
	else 
	{
		if(K==1)
		{
			putchar('B');
			for(int j=2;j<=a;++j) putchar('A');putchar('B');
			for(int i=l;i<=r;++i) printf("%c",((st[i]-'A')^rev)+'A');
			for(int i=1;i<=len;++i) printf("%c",(i&1)==(len&1)?'A':'B');
		}
		else BplusA(a-1,l,r,rev^1,len+1,K-2);
	}
}
 
void BplusA(int b,int l,int r,int rev,int len,int K)
{
	if(!K)
	{
		for(int j=1;j<=b;++j) putchar('B');putchar('A');
		for(int i=l;i<=r;++i) printf("%c",((st[i]-'A')^rev)+'A');
		for(int i=1;i<=len;++i) printf("%c",(i&1)==(len&1)?'A':'B');
		return;
	}
	if(!b) 
	{
		if(l>r) Solve(2,1,0,n,K-1+(n&1));
		else AplusB(0,l,r,rev,len,K-1);
	}
	else AplusB(b-1,l,r,rev^1,len+1,K-1);
}
 
int main()
{
	n=read();K=read();scanf("%s",st+1);
	int posa=1;
	for(;st[posa]=='B';++posa);
	if(posa>n)
	{
		--K;
		for(int j=1;j<=n;++j) st[posa]='A';
		posa=1; 	
	}
	BplusA(posa-1,posa+1,n,0,0,K);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int a=0,b=0;
    string s;
    cin>>s;
    for(int i =0;i<3;i++)
    {
        if(s.at(i)=='A')
            a++;
        else
            b++;
    }
    if(a>0&&b>0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
        
    return 0;
}


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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

int main() {
    ll N, x; cin >> N >> x;
    vector<ll> a(N); REP(i, N) cin >> a[i];
    
    ll ans = INF;
    vector<ll> b(N, INF);
    REP(i, N) {
        ll sum = i * x;
        REP(j, N) {
            b[j] = min(b[j], a[(j-i+N)%N]);
            sum += b[j];
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
# N, M = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars
# T = gets.chomp.chars

A = gets.chomp.to_i
B = gets.chomp.to_i
C = gets.chomp.to_i
D = gets.chomp.to_i
E = gets.chomp.to_i

# 10で割った余りが 1 以上で一番小さいものを最後に注文
arr = [A, B, C, D, E]
largest = 0
last_i = 0
0.upto(4).each do |i|
  remain = 10 - (arr[i] % 10)
  if remain == 10 # 0 should be skipped
    next
  end
  # p "remain of #{i}: #{remain}"
  if remain > largest
    largest = remain
    last_i = i
  end
end
# p "last_i: #{last_i}"

ans = 0
0.upto(4).each do |i|
  if i == last_i
    # For Debug
    # p "#{i}: #{arr[i]}"
    ans += arr[i]
  else
    # For Debug
    # p "#{i}: #{(arr[i] + 9) / 10 * 10}"
    ans += (arr[i] + 9) / 10 * 10
  end
end

p ans

Measured memory_bytes: 1788