akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
void revs(string s)
{
    for(int i=s.length() -1;i>=0;i--)
    {
        cout<<s[i];
    }
}
int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    string s;
    cin>>s;
    int q;
    cin>>q;
    int rev=0;
    string a,b; 
    while(q--)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            rev++;
        }
        else
        {
            int f;
            char c;
            cin>>f>>c;
            if((f+rev)%2==1)
            {
                a+=c;
            }
            else
            {
                b+=c;
            }
        }
    }
    if(rev%2==0)
    {
        revs(a);
        cout<<s<<b;
    }
    else
    {
        revs(b);
        revs(s);
        cout<<a;
    }
    return 0;
}

Measured memory_bytes: 1104
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    int k;
    cin>>k;
    int ans=k/2;
    if(k%2==0){
        ans*=k/2;
    }else{
        ans*=k/2+1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Harshad
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class TaskC {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n, m;
        in >> n >> m;
        vector<int> freq(26);
        for (int i = 0; i < n; ++i) {
            string s;
            in >> s;
            for (int j = 0; j < m; ++j) {
                freq[s[j] - 'a']++;
            }
        }
        int g1, g2, g4;

        if (n % 2 == 1 && m % 2 == 1) {
            g1 = 1;
            g2 = (n / 2) + (m / 2);
            g4 = (n / 2) * (m / 2);
        } else if (n % 2 == 1 && m % 2 == 0) {
            g1 = 0;
            g2 = m / 2;
            g4 = (n / 2) * (m / 2);
        } else if (n % 2 == 0 && m % 2 == 1) {
            g1 = 0;
            g2 = n / 2;
            g4 = (n / 2) * (m / 2);
        } else {
            g1 = 0;
            g2 = 0;
            g4 = (n / 2) * (m / 2);
        }

        for (int i = 0; i < 26; ++i) {
            if (freq[i] % 2 == 1) {
                g1--;
                freq[i]--;
            }
            while (g4 > 0 && freq[i] >= 4) {
                g4--;
                freq[i] -= 4;
            }
            while (g2 > 0 && freq[i] >= 2) {
                g2--;
                freq[i] -= 2;
            }
        }
        if (!g1 && !g2 && !g4) {
            out << "Yes";
        } else
            out << "No";
    }
};


int main() {
    TaskC solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 1001001001;

void solve(int n, int x){
  int ans = 0;
  for(int i = 1; i <= n; i++){
    for(int j = i+1; j<=n; j++){
      for(int k = j+1; k <= n; k++){
        if(i+j+k == x) ans++;
      }
    }
  }
  cout << ans << endl;
}


int main(){

  while(1){
    int n,x;
    cin >> n >> x;
    if(n == 0) break;
    solve(n,x);
  }
}



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

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

    vector<int> v(n+1);
    for (int i = 0; i < n; i++) {
        v[a[i]] += 1;
    }
    sort(v.begin(), v.end());

    int sum = 0;
    for (int i = 0; i < v.size() - k; i++) {
        sum += v[i];
    }

    cout << sum << endl;
}


Measured memory_bytes: 1792
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class BBingo {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      vector<vector<int>> a(3, vector<int>(3));
      rep(i, 3) {
        rep(j, 3) {
          cin >> a[i][j];
        }
      }
      vector<vector<bool>> b(3, vector<bool>(3));
      int n; cin >> n;
      rep(i, n) {
        int c; cin >> c;
        rep(j, 3) {
          rep(k, 3) {
            if (c == a[j][k]) b[j][k] = true;
          }
        }
      }
      bool ans = false;
      rep(i, 3) {
        if (b[i][0]&&b[i][1]&&b[i][2]) ans = true;
      }
      rep(j, 3) {
        if (b[0][j]&&b[1][j]&&b[2][j]) ans = true;
      }

      if (b[0][0]&&b[1][1]&&b[2][2]) ans = true;
      if (b[2][0]&&b[1][1]&&b[0][2]) ans = true;


      if (ans) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }



    }
};

signed main() {
  BBingo solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, raw_input().split())
paths = {}
for m in range(M):
	path = map(int, raw_input().split())
	a_p = paths.get(path[0],[])
	b_p = paths.get(path[1],[])
	a_p.append(path[1])
	b_p.append(path[0])
	paths[path[0]] = a_p
	paths[path[1]] = b_p

visited = [False] * (N+1)

visited[0] = True
to_visit = [1]
signposts = [None] * (N+1)
i = 0
while len(to_visit) > i:
	curr = to_visit[i]
	if visited[curr]:
		i += 1
	else:
		path = paths[curr]
		for p in path:
			if signposts[p] == None:
				signposts[p] = curr
				to_visit.append(p)
		visited[curr] = True
		i += 1
all_visited = all(visited)

if all_visited:
	print 'Yes'
	for s in range(2,len(signposts)):
		print signposts[s]
else:
	print 'No'




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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// ordered_set X;
// *X.find_by_order(i) = ith largest element (counting from zero)
// X.order_of_key(k) = number of items in X < k (strict lt)

ll MOD = 1000000007;

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

    int N;
    ll K;

    cin >> N >> K;
    vll A(N);
    for (int i=0;i<N;i++) cin >> A[i];

    ll num_invs = 0;
    for (int i=0;i<N;i++) {
        for (int j=i+1;j<N;j++) {
            if (A[i] > A[j]) num_invs++;
        }
    }

    ll num_gt = 0;
    for (int i=0;i<N;i++) {
        for (int j=0;j<N;j++) {
            if (A[i] > A[j]) num_gt++;
        }
    }

    ll ksum = (K*(K-1))/2;
    ksum %= MOD;

    ll ans = 0;
    ans += (ksum * num_gt);
    ans %= MOD;

    ans += K * (num_invs);
    ans %= MOD;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

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

int main() {
	string s;
	cin >> s;

	if (s == "AAA" or s == "BBB") {
		cout << "No\n";
	}
	else {
		cout << "Yes\n";
	}


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;

int main() {
  int n,ans=INT_MAX;
  cin >> n;
  int a[n];
  int l=1000,m=0;
  REP(i,n) { cin>>a[i]; l=min(l,a[i]); m=max(m,a[i]); }
  if (l == m) { cout << 0 << endl; return 0; }
  for(int x = l; x <= m; x++) {
    int sum = 0;
    REP(i,n) sum += pow(a[i]-x, 2);
    ans = min(ans, sum);
  }
  cout << ans << endl;
}

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

#ifdef LOCAL
#define show(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define show(x) true
#endif

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "P(" << p.first << ", " << p.second << ")";
}

template <class T> ostream& operator<<(ostream& os, const V<T>& v) {
    os << "[";
    for (auto d : v) os << d << ", ";
    return os << "]";
}

V<ll> primes(ll x) {
    V<ll> res;
    for (ll i = 2; i * i <= x; i++) {
        if (x % i) continue;
        res.push_back(i);
        while (x % i == 0) x /= i;
    }
    if (x > 1) res.push_back(x);
    return res;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n;
    cin >> n;
    V<ll> a(n + 1);
    ll g = 0;
    for (int i = n; i >= 0; i--) {
        cin >> a[i];
        g = gcd(g, a[i]);
    }
    V<ll> cands = primes(g);
    for (int x = 2; x < 10010; x++) {
        bool is_pr = true;
        for (int y = 2; y * y <= x; y++) {
            if (x % y == 0) {
                is_pr = false;
                break;
            }
        }
        if (is_pr) cands.push_back(x);
    }
    sort(cands.begin(), cands.end());
    cands.erase(unique(cands.begin(), cands.end()), cands.end());
    for (ll p: cands) {
        if (a[0] % p) continue;


        V<ll> buf(min<ll>(n + 1, p - 1));
        for (int i = 0; i <= n; i++) {
            buf[i % (p - 1)] += a[i];
            buf[i % (p - 1)] %= p;
        }
        bool ok = true;
        for (auto d: buf) {
            if (d) {
                ok = false;
                break;
            }
        }
        if (!ok) continue;
        cout << p << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;
int main()
{
	int x,ANS=0;
	cin >> x;
	if (x <= 3) {
		disp("1");
	}
	else {
		for (int i = 2; i <= 32; i++) {
			for (int j = 2; pow(i, j) <= x; j++) {
				if (ANS <= pow(i, j))ANS = pow(i, j);
			}
		}
		disp(ANS);
	}
}

Measured memory_bytes: 384
N, K = list(map(int, input().split()))
haves = [False for _ in range(N)]
 
def judge_Flag(flags, num):
    As = list(map(int, input().split()))
    for i in range(num):
        flags[As[i] - 1] = True
        
for _ in range(K):
    people_num = int(input())
    judge_Flag(haves, people_num)
print(haves.count(False))

Measured memory_bytes: 9192
n = int(input())
d,x = map(int,input().split())
A = [int(input()) for _ in range(n)]
ans = 0
for i in range(n):
  cnt = 0
  for j in range(d):
    if A[i] * j + 1 <= d:
      ans += 1
    else:
      break
print(ans + x)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
  
#define SIZE 250
  
int main(){
  int i,m;
  int b[SIZE];
  
  scanf("%d",&m);
  
  for(i = 1; i <= m; i++){
    scanf("%d",&b[i]);
  }
  
  for(i = 1; i <= m; i++){
    printf("node %d: key = %d,",i ,b[i]);
    if(i != 1){
      printf(" parent key = %d,",b[i/2]);
    }
    
    
 if(2*i <= m){
      printf(" left key = %d,",b[2*i]);
    }
 if(2*i+1 <= m){
      printf(" right key = %d,",b[2*i+1]);
    }
    printf(" \n");
  }
  return 0;
}

Measured memory_bytes: 608
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<stdio.h>

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


using namespace std;

LL lcm(LL n, LL m)
{
	LL u;
	LL ansl = 0;
	for(u=m; u>=m; u++){
		if(u%n == 0){
			if(u%m == 0){
				ansl = u;
				break;
			}
		}
	}
	return ansl;
}


int main(void){

    LL n;
    cin >>n;
    vector<int>d(n);
    rep(i,n){
        cin >>d[i];
    }
    sort(d.begin(),d.end());
    cout << d[n/2]-d[n/2-1]<<endl;


    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

ll nim_from0(ll to){
    ll calc=0, product=4;
    calc=((to%4+1)/2)%2;
    for(; product<=2*to; product*=2) calc+=(max(((to+1)%product)-(product/2), (ll)0)%2)*(product/2);//, cout<< to << " "  << product <<" " <<calc <<endl;
    return calc;
}

int main(void){
    ll A, B;
    ll A_calc, B_calc;
    cin>>A>>B;
    A_calc=nim_from0(A-1);
    B_calc=nim_from0(B);
    //cout <<A_calc <<" " <<B_calc<<endl;
    cout << (A_calc^B_calc) << endl;
    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
b=[i for i in range(k+1,n+1)]
ans=0
if k==0:
    for i in range(len(b)):
        t=b[i]
        j=t-k
        ii=n//t
        ans+=ii*j
        ans+=max(n-ii*t-k,0)
    print(ans)
    exit()
for i in range(len(b)):
    t=b[i]
    j=t-k
    ii=n//t
    ans+=ii*j
    ans+=max(n-ii*t-k+1,0)
print(ans)

Measured memory_bytes: 71764
#include <stdio.h>          // putchar(), scanf()
#include <stdbool.h>

int
main(int argc, char **argv)
{
	const char abacus[10][8] = {"* = ****",  "* =* ***",  "* =** **",  "* =*** *",  "* =**** ",  " *= ****",  " *=* ***",  " *=** **",  " *=*** *",  " *=**** "};
	int x;
	int a[5];

	bool f = false;
	while (scanf("%d", &x) != EOF)
	{
		for (int i = 4; i >= 0; --i)
		{
			a[i] = x % 10;
			x /= 10;
		}

		if (f)
			putchar('\n');

		for (int i = 0; i < 8; ++i)
		{
			for (int j = 0; j < 5; ++j)
				putchar(abacus[a[j]][i]);

			putchar('\n');
		}

		f = true;
	}

	return 0;
}

Measured memory_bytes: 1816
from collections import OrderedDict
from collections import defaultdict
N = int(input())
ans = dict()
for _ in range(N):
    k = str(input())
    if k in ans:
        ans[k] += 1
    else:
        ans.update({k: 1})
groupedByValue = defaultdict(list)
for key, value in sorted(ans.items()):
    groupedByValue[value].append(key)
l = groupedByValue[max(groupedByValue)]
for i in l:
    print(i)

Measured memory_bytes: 45268
import Control.Applicative
import Data.List

main = do
  contents <- fmap readZ . lines <$> getContents
  mapM_ (print . (maxSum [])) (dataCut contents)

dataCut :: [Int] -> [[Int]]
dataCut (0:_) = []
dataCut (x:xs) = (take x xs) : (dataCut (drop x xs))

readZ :: String -> Int
readZ all@(x:xs)
  | x == '-' = negate $ (read :: String -> Int) xs
  | otherwise = (read :: String -> Int) all

maxSum :: [Int] -> [Int] -> Int
maxSum [] (x:xs) = maxSum [x] xs
maxSum ls [] = maximum ls
maxSum ls (x:xs)
  | w > x = maxSum (w:ls) xs
  | otherwise = maxSum (x:ls) xs
    where
      w = head ls + x

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

class Node():
    def __init__(self):
        self.parent = None
        self.left_child = None
        self.right_sibling = None
        self.type = None

tree = []
for _ in range(n):
    tree.append(Node())

for _ in range(n):
    tmp = list(map(int, input().split()))
    id = tmp[0]
    degree = tmp[1]
    children = tmp[2:]
    if degree > 0:
        tree[id].left_child = children[0]
        for (cnt, child) in enumerate(children):
            tree[child].parent = id
            if cnt < degree - 1:
                tree[child].right_sibling = children[cnt + 1]
    
    
def get_depth(id):
    out = 0
    node = tree[id]
    while node.parent is not None:
        out += 1
        node = tree[node.parent]
    return out

def get_children(id):
    left_child_id = tree[id].left_child
    if left_child_id is None:
        return []
    node = tree[left_child_id]
    out = [left_child_id]
    while node.right_sibling is not None:
        out.append(node.right_sibling)
        node = tree[node.right_sibling]
    return out

def get_type(id):
    node = tree[id]
    if node.parent is None:
        return 'root'
    elif node.left_child is not None:
        return 'internal node'
    else:
        return 'leaf'
    
for id in range(n):
    print(f"node {id}: parent = {-1 if tree[id].parent is None else tree[id].parent}, depth = {get_depth(id)}, {get_type(id)}, {get_children(id)}")



Measured memory_bytes: 33660
#include <iostream>
#include <algorithm>
#include <vector>
#define endl '\n'
#define ll long long
using namespace std;

int a[3];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	for (int i = 0; i < 3; i++) cin >> a[i];
	
	swap(a[0], a[1]);
	swap(a[0], a[2]);

	for (auto i : a) cout << i << " ";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int i = 0;
	int x ,y;
	while(1){
		scanf("%d %d", &x ,&y);
		if ( x == 0 && y == 0 )break;
		if( x <= y ){
			printf("%d %d\n",x,y);
		}else{
			printf("%d %d\n",y,x);
		}
	}

	return 0;
} 


Measured memory_bytes: 2036
N=int(input())
S=list(input())
a=[0]*4

for i in range(N):
  if S[i]=='R':a[0]+=1
  if S[i]=='G':a[1]+=1
  if S[i]=='B':a[2]+=1
    
for i in range(N):
  for j in range(i+1,N):
    k=j+(j-i)
    if k>=N:
      break
    else:
      if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i] and j-i==k-j:
        a[3]+=1

print(a[0]*a[1]*a[2]-a[3])

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define _ << ' ' <<
using ll = long long;
using vi = vector<int>;
void view(const vector<int>& v){for(const auto& e : v)cout << e << " ";cout << endl;}

int main(){
	int i;
	int n, k;
	string s;
	cin >> n >> k >> s;
	s += 'x';
	vector<int> organ;
	char past = s[0];
	int count = 0;
	for(i=0; i<s.length(); ++i){
		if(past != s[i]) organ.push_back(count), count = 0;
		count ++;
		past = s[i];
	}
	for (int i=1; i<organ.size(); ++i)
		organ[i] += organ[i - 1];
	int humanState = (s[0] == '1');
	int maxHuman = 0;
	for(i=0; i<organ.size(); ++i){
		int r = min((int)organ.size()-1, i+2*k-1+(humanState+i)%2);
		int s = organ[r] - (i? organ[i-1] : 0);
		maxHuman = max(maxHuman, s);
	}
	cout << maxHuman << endl;
	return 0;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    string s;
    cin >> s;

    int64_t m = s.size();

    vector a(1, 0L);
    int64_t t = 0;
    for (auto c : s) {
        if (c == '0') {
            a.push_back(t);
        } else {
            ++t;
        }
    }
    a.push_back(t);

    int64_t k;
    cin >> k;
    k = min(k, a.back());

    int64_t n = a.size();

    constexpr auto M = 998244353L;

    vector dp(vector(k + 1, vector(a.back() + 1, 0L)));
    int64_t mk = 0;
    dp[0][0] = 1;
    for (auto i : irange(0L, n - 1)) {
        for (auto j : irange(mk, -1L, -1L)) {
            for (auto c : irange(0L, a.back() - a[i + 1] + 1)) {
                for (auto b : irange(c + 1, min(c - j + k + 1, c + a[i + 1] - a[i] + 1))) {
                    auto w = j + b - c;
                    mk = max(mk, w);
                    dp[w][c] += dp[j][b];
                    if (dp[w][c] >= M) {
                        dp[w][c] -= M;
                    }
                }
            }

            for (auto c : irange(1L, a.back() - a[i + 1] + 1)) {
                dp[j][c] += dp[j][c - 1];
                if (dp[j][c] >= M) {
                    dp[j][c] -= M;
                }
            }
        }
    }

    int64_t ans = 0;
    for (auto i : irange(0L, mk + 1)) {
        ans += dp[i][0];
        if (ans >= M) {
            ans -= M;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3852
import numpy as np
from numba import jit
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=np.int64)

# 高速化
@jit
def imo(a, n):
    imos = np.zeros(n+1, dtype=np.int64)
    for i in range(n):
        imos[max(0, i-a[i])] += 1
        imos[min(n, i+a[i])+1] -= 1

    # 累計和はnumpyの方が高速
    immo = np.zeros(n+1, dtype=np.int64)
    immo = np.cumsum(imos)

    return immo[:n]


for _ in range(min(K, 41)):
    A = imo(A, N)

print(*A)

Measured memory_bytes: 124948
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <bitset>
#include <utility>
#include <sstream>
#include <fstream>
#include <stack>
#include <cstdlib>
#include <complex>
#include <set>
#include <iomanip>

using namespace std;

#define INF 1070000000LL
#define pb push_back
#define irep(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) irep(i,0,n)

typedef long long lint;
typedef pair<int, int> pint;
struct Edge{
    int to,weight;
};
typedef vector<vector<Edge> > Graph;

void make_prime(vector<int> &prime){
    prime.push_back(2);
    irep(i,3,101000){
	int a = sqrt(i);
	bool flg = false;
	for(auto b :  prime){
	    if(b <= a){
		if(i % b != 0){
		    continue;
		}
		else{
		    flg = true;
		    break;
		}
	    }
	    else{
		break;
	    }
	}
	if(flg == false)prime.push_back(i);	
    }
}


int main(){
    int a;
    cin >> a;
    vector<int> prime;
    make_prime(prime);
    int temp = 0;
    for(auto item : prime){
	if(temp < a && a <= item){
	    cout << item << endl;
	    return 0;
	}
	temp = item;
    }
}


Measured memory_bytes: 384
def bfs(field,H,W,start_x,start_y,tmp_N):
    direction = [[-1,0],[1,0],[0,-1],[0,1]]
    que = []
    que.append([start_x,start_y])
    INF = 1000000
    min_path = [[INF] * W for i in range(H)]
    min_path[start_y][start_x] = 0
    while len(que) != 0:
        current = que.pop(0)
        for d in direction:
            nx = current[0] + d[0]
            ny = current[1] + d[1]
            if 0 <= nx < W and 0 <= ny < H and field[ny][nx] != "X" and min_path[ny][nx] == INF:
                min_path[ny][nx] = min_path[current[1]][current[0]] + 1
                if field[ny][nx] == tmp_N:
                    return nx,ny,min_path[ny][nx]
                else:
                    que.append([nx,ny])

def getField():
    matrix = []
    first = input().strip()
    H,W,N = map(int,first.split())
    for i in range(H):
        row = list(input().strip())
        for j in range(W):
            if row[j].isdigit():
                row[j] = int(row[j])
        matrix.append(row)
    return matrix,H,W,N

def getStart(field):
    for y in range(len(field)):
        for x in range(len(field[0])):
            if field[y][x] == "S":
                return x,y

def main():
    matrix,H,W,N = getField()
    sx,sy = getStart(matrix)
    distance = 0
    tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,sx,sy,1)
    distance += tmp_dist
    tmps = [tmp_x,tmp_y]
    for k in range(N-1):
        tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,tmps[0],tmps[1],k+2)
        distance += tmp_dist
        tmps = [tmp_x,tmp_y]
    print(distance)

if __name__=='__main__':
    main()

Measured memory_bytes: 36904
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int N;
  int d[100];
  int count = 0;
  cin >> N;
  for(int i=0;i<N;++i){
    cin >> d[i];
  }
  sort(d, d+N);
  int mochi = 0;
  for(int i=0;i<N;++i){
    if (mochi != d[i]) {
      ++count;
      mochi = d[i];
    }
  }
  cout << count;
  
  return 0;
}

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

using namespace std;
using ll = long long;
const ll MAX = 1e9+1, MOD = 998244353;
struct SegmentTree
{
    vector<ll> _data;
    ll N;
    bool minimum;
    SegmentTree(bool minimum):minimum(minimum){}
    void init_0(ll _N){
        N=1;
        while (N < _N)N*=2;
        _data = vector<ll>(N*2-1, 0);
    }

    void init_MAX(ll _N){
        N=1;
        while (N < _N)N*=2;
        if(minimum)
            _data = vector<ll>(N*2-1, INT64_MAX);
        else
            _data = vector<ll>(N*2-1, INT64_MIN);
    }
    void update(ll i, ll value){
        i += N-1;
        _data[i] = value;
        while (i)
        {
            i = (i-1)/2;
            if (minimum) _data[i] = min(_data[i*2+1], _data[i*2+2]);
            else _data[i] = max(_data[i*2+1], _data[i*2+2]);
        }
    }

    void initVector(vector<ll> v){
        for (ll i = 0; i < v.size(); i++)
            update(i, v[i]);
    }

    ll getMax(ll left, ll right, ll l = 0, ll r = -1, ll k = 0){
        if(r == -1)r=N;
        if(r<=left||right<=l)return INT64_MIN;
        if(left<=l&&right>=r)return _data[k];
        ll v1=getMax(left,right,l,(l+r)/2,k*2+1);
        ll v2=getMax(left,right,(l+r)/2,r,k*2+2);
        return max(v1,v2);
    }

};

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<pair<ll, ll> > XD;
    for (ll i = 0; i < N; i++){
        ll x, d; cin >> x >> d;
        XD.push_back(make_pair(x, d));
    }
    sort(XD.begin(), XD.end());
    vector<ll> be_moved_robots;
    for (vector<pair<ll, ll>>::iterator itr = XD.begin(); itr < XD.end(); itr++){
        vector<pair<ll, ll>>::iterator itr_last = lower_bound(itr, XD.end(), make_pair((*itr).first+(*itr).second, -MAX));
        be_moved_robots.push_back(itr_last - XD.begin());
    }
    SegmentTree seg = SegmentTree(false);
    seg.init_MAX(N);
    seg.initVector(be_moved_robots);
    for (int i = N-2; i >= 0; i--)
    {
        be_moved_robots[i] = seg.getMax(i, be_moved_robots[i]);
        seg.update(i, be_moved_robots[i]);
    }
    
    vector<ll> combination(N+1, 0);
    combination[0] = 1;
    for (ll i = 1; i <= N; i++){
        combination[i] += combination[i-1] + combination[N - be_moved_robots[N-i]];
        combination[i] %= MOD;
    }
    cout << combination[N] << endl;
}

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

int main (void)
{
  int n, m;
  int i, j;
  char a[100], b[100];
  char c;

  while(1){

    cin >> n ;
    if (n == 0){ break; }
    for(i = 0; i < n; i++){
      cin >> a[i] >> b[i];
    }
    a[i] = '\0';
    b[i] = '\0';

    cin >> m;
    
    for(i = 0; i < m; i++){
      
      cin >> c;
      for(j = 0; a[j] != '\0'; j++){
	if(c == a[j]){
	  c = b[j];
	  break ;
	}
	
      }
      cout << c;
    }

	cout << endl;
    
  }
  
  return 0;
}
  

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}



const ll MOD = 1e9 + 7;
struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint& operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}
  mint& operator-=(const mint a) {if ((x += MOD-a.x) >= MOD) x -= MOD;return *this;}
  mint& operator*=(const mint a) {(x *= a.x) %= MOD;return *this;}
  mint operator+(const mint a) const {mint res(*this);return res+=a;}
  mint operator-(const mint a) const {mint res(*this);return res-=a;}
  mint operator*(const mint a) const {mint res(*this);return res*=a;}
  mint pow(ll b) const {
    mint res(1), a(*this);
    while (b) {
      if (b & 1) res *= a;
      a *= a;
      b >>= 1;
    }
    return res;
  }
  // for prime MOD
  mint inv() const {return pow(MOD-2);}
  mint& operator/=(const mint a) {return (*this) *= a.inv();}
  mint operator/(const mint a) const {mint res(*this);return res/=a;}
};
ostream& operator<<(ostream& os, const mint& a) {os << a.x; return os;}


mint dp[305][305][305];

int main2() {
  int N = nextLong();
  int M = nextLong();

  vector<vector<pair<int,int>>> cond(N+1);
  REP(i, M) {
    int L = nextLong();
    int R = nextLong();
    int x = nextLong();
    cond[R].push_back({L, x});
  }

  REP(r, N+1) REP(g, N+1) REP(b, N+1) dp[r][g][b] = 0;
  dp[0][0][0] = 1;

  REP(r, N+1) REP(g, N+1) REP(b, N+1) {
    mint cur = dp[r][g][b];
    if (cur.x == 0) continue;

    int m = max({r, g, b});
    bool ok = true;
    for (auto c : cond[m]) {
      int k = 0;
      if (c.first <= r || m == r) k++;
      if (c.first <= g || m == g) k++;
      if (c.first <= b || m == b) k++;
      // cout << r << g << b << "   " << c << "   k=" << k << endl;
      if (k != c.second) ok = false;
    }
    if (!ok) {
      dp[r][g][b] = 0;
      continue;
    }

    dp[m+1][g][b] += cur;
    dp[r][m+1][b] += cur;
    dp[r][g][m+1] += cur;
  }

  mint ans = 0;

   REP(r, N+1) REP(g, N+1) REP(b, N+1)
   {
     if (r == N || g == N || b == N) ans += dp[r][g][b];
   }
  cout << ans << endl;


  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 225372
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n), c(m), d(m);

    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    for (int j = 0; j < m; ++j) {
        cin >> c[j] >> d[j];
    }

    for (int i = 0; i < n; ++i) {
        vector<int> mh(m);
        for (int j = 0; j < m; ++j) {
            mh[j] = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        }
        auto x = min_element(mh.begin(), mh.end());
        cout << x - mh.begin() + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
 
const int N = int(2e5) + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e18; 
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int l, r;
int main (){
    scanf ("%d %d", &l, &r);
    if (r - l > 2019) return !printf ("0\n");
    int res = 2018;
    for (int i = l; i <= r; ++i){
        for (int j = i + 1; j <= r; ++j){
            ll cur = (i * 1ll * j) % 2019;
            res = min(res * 1ll, cur);
        }
    }
    return !printf ("%d\n", res);
}

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


int main(){

	int bobNum, aliceNum;
	cin >> bobNum >> aliceNum;
	
	if (bobNum == 1)bobNum = 14;
	if (aliceNum == 1)aliceNum = 14;

	if (bobNum > aliceNum){
		cout << "Alice" << endl;
	}
	else if (aliceNum > bobNum){
		cout << "Bob" << endl;
	}
	else{ cout << "Draw" << endl; }

	return 0;
}

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

namespace mondai0010
{
	class Program
	{
		static void Main(string[] args)
		{
			var	n	= int.Parse( Console.ReadLine() );
			for( int i = 0; i < n; i++ ) {
				var	str	= Console.ReadLine().Split();
				var	x1	= double.Parse( str[ 0 ] );
				var	y1	= double.Parse( str[ 1 ] );
				var	x2	= double.Parse( str[ 2 ] );
				var	y2	= double.Parse( str[ 3 ] );
				var	x3	= double.Parse( str[ 4 ] );
				var	y3	= double.Parse( str[ 5 ] );

				double	d1	= x1 - x2;
				double	d2	= y1 - y2;
				double	d3	= x2 - x3;
				double	d4	= y2 - y3;
				double	d5	= x3 - x1;
				double	d6	= y3 - y1;
				double	xp	= (((x1 * x1 + y1 * y1) * d4) + ((x2 * x2 + y2 * y2) * d6) + ((x3 * x3 + y3 * y3) * d2)) /
							   ((x1 * d4) + (x2 * d6) + (x3 * d2)) *
							   0.5;
				double	yp	= (((x1 * x1 + y1 * y1) * d3) + ((x2 * x2 + y2 * y2) * d5) + ((x3 * x3 + y3 * y3) * d1)) / 
							   ((y1 * d3) + (y2 * d5) + (y3 * d1)) * 
							   0.5;
				
				double	r	= Math.Sqrt( ((d1 * d1) + (d2 * d2)) * ((d3 * d3) + (d4 * d4)) * ((d5 * d5) + (d6 * d6)) ) /
							  Math.Abs( (x1 * d4) + (x2 * d6) + (x3 * d2) ) *
							  0.5;

				Console.WriteLine( "{0:f3} {1:f3} {2:f3}", xp, yp, r );
			}
		}
	}
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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 C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define MAX_N 100
#define N_PERIOD 10
#define INF 1152921504606846976
i64 F[MAX_N][N_PERIOD];
i64 P[MAX_N][N_PERIOD + 1];

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

    REP(i, N) {
        REP(j, N_PERIOD) {
            cin >> F[i][j];
        }
    }

    REP(i, N) {
        REP(j, N_PERIOD + 1) {
            cin >> P[i][j];
        }
    }

    i64 maxv = -INF;
    for (i64 bit = 1; bit < (1 << 10); bit++) {
        i64 v = 0;
        REP(i, N) {
            i64 cnt = 0;
            REP(j, 10) {
                if (bit >> j & 1) {
                    cnt += F[i][j];
                }
            }
            v += P[i][cnt];
        }
        chmax(maxv, v);
    }
    cout << maxv << endl;

    return 0;
}

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

int main()
{
    int N;
    cin >> N;
    string S;
    map<string, int> mp;
    int maxCount = 0;
    for (int i = 0; i < N; i++) {
        cin >> S;
        mp[S]++;
        maxCount = max(maxCount, mp[S]);
    }
    for (auto i = mp.begin(); i != mp.end(); i++) {
        if (maxCount == i->second) {
            cout << i->first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 19228
from functools import lru_cache

N = int(input())
K = int(input())

@lru_cache(None)
def f(n, k):
  if k < 0:
    return 0
  if n < 10:
    if k == 0:
      return 1
    elif k == 1:
      return n
    else:
      return 0
  a, b = divmod(n, 10)
  return f(a, k) + f(a, k-1) * b + f(a-1, k-1) * (9-b)
  
print(f(N, K))

Measured memory_bytes: 9656
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int n;
vector<int> xa, ya, xb, yb;
vector<int> ret;
int c;

void solve(bitset<10> bs)
{
    if(bs.none())
        return;
    if(bs.count() == 1){
        int i = 0;
        while(!bs[i])
            ++ i;
        ret[i] = ++ c;
        return;
    }

    int k = -1;
    for(int i=0; i<n; ++i){
        if(!bs[i])
            continue;
        if(k == -1 || (xb[i] > xb[k]) || (xb[i] == xb[k] && yb[i] > yb[k]))
            k = i;
    }

    ret[k] = ++ c;
    bs[k] = false;

    int left = INT_MIN;
    for(int i=0; i<n; ++i){
        if(!bs[i])
            continue;
        if(xb[i] < xb[k] && ya[i] < ya[k] && ya[k] < yb[i])
            left = max(left, xb[i]);
    }

    bitset<10> bs2;
    for(int i=0; i<n; ++i){
        if(!bs[i])
            continue;
        if(ya[i] >= ya[k] && left <= xa[i] && xb[i] <= xb[k]){
            bs2[i] = true;
            bs[i] = false;
        }
    }

    solve(bs2);
    solve(bs);
}

int main()
{
    bool isFirst = true;

    for(;;){
        cin >> n;
        if(n == 0)
            return 0;

        if(isFirst)
            isFirst = false;
        else
            cout << endl;

        xa = ya = xb = yb = vector<int>(n);
        for(int i=0; i<n; ++i){
            cin >> xa[i] >> ya[i] >> xb[i] >> yb[i];
            xa[i] = 500 - xa[i];
            ya[i] = 500 - ya[i];
            xb[i] = 500 - xb[i];
            yb[i] = 500 - yb[i];
            if(xa[i] > xb[i])
                swap(xa[i], xb[i]);
            if(ya[i] > yb[i])
                swap(ya[i], yb[i]);
        }

        bitset<10> bs;
        for(int i=0; i<n; ++i)
            bs[i] = true;
        ret.resize(n);
        c = 0;
        solve(bs);

        for(int i=0; i<n; ++i)
            cout << ret[i] << endl;
    }
}

Measured memory_bytes: 1220
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline T int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif


int pow_mod(int val, int ite){
	ll sum = 1;
	for(int i=0; i<ite; i++){
		sum = (sum * val) % MOD;
	}
	return (int)sum;
}

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int N; cin >> N;
	if(N == 1) {
		cout << 0 << endl;
		return 0;
	}

	int oth = pow_mod(8, N);
	int no_zero = pow_mod(9, N);
	int no_nine = pow_mod(9, N);
	int all = pow_mod(10, N);
	// print(no_zero, no_nine, oth, all);
	int ans = all - no_zero - no_nine + oth;
	// print(ans);
	while(ans < 0) ans += MOD;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;
class Main {
	int[][][] t = new int [5][5][11];
	int n = 0, b = 0, f = 0, r = 0, v = 0, i = 0, k = 0;
	public void of() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for(i = 1; i <= n; i++) {
			b = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			v = sc.nextInt();
			switch(b) {
				case 1:
					t[1][f][r] += v;
					break;
				case 2:
					t[2][f][r] += v;
					break;
				case 3:
					t[3][f][r] += v;
					break;
				case 4:
					t[4][f][r] += v;
					break;
				default:
					break;
			}
		}
		
		for(n = 1; n <= 4; n++) {
			for(i = 1; i < 4; i++) {
				for(k = 1; k < 11; k++) {
							System.out.printf(" %d",t[n][i][k]);
				}
				System.out.println();
			}
			if(n < 4) {
				System.out.println("####################");
			}
		}
	}
	public static void main(String[] args) {
		new Main().of();
	}
}

Measured memory_bytes: 23188
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;

int main(){
    int a,b,k;
    cin>>a>>b>>k;
    vector<int>w;
    for(int i=1;i<=min(a,b);i++){
        if(a%i==0&&b%i==0){
                w.push_back(i);
        }
    }
    OUT(w[SZ(w)-k]);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define STRMAX 21
int main(void) {
    char str[STRMAX],temp;
    int i=0,strsize;
    scanf("%s",str);
    for(i=0;str[i]!=0;i++){
    }
    strsize=i;
    for(i=0;i<(strsize/2);i++){
        temp=str[i];
        str[i]=str[strsize-i-1];
        str[strsize-i-1]=temp;
    }
    printf("%s\n",str);
    return 0;
}

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

int main(void){
    string str;
    
    cin >> str;
    for(int i = 0 ; i < str.size() ; i++){
        cout << (char)('A'+(str[i]-'A'+26-3)%26);
    }
    puts("");
    
    return 0;
}

Measured memory_bytes: 1160
N = int(input())
A = list(map(int, input().split()))
# ex. 24 11 8 3 16
A.sort()
# ex. 3 8 11 16 24
cnt = 0
# Aの最大値が24なら25個用意する感じ
# indexと考える値を一致させて分かりやすくしている
# Trueで初期化
# 最後のインデックスはA[-1]
dp = [True] * (A[-1] + 1)

# エラトステネスの篩っぽいやつ
for i in range(N):
    if dp[A[i]] == True:
        # dp[A[i]], dp[2*A[i]], dp[3*A[i]],...をFalseにする
        for j in range(A[i], A[-1] + 1, A[i]):
            dp[j] = False

        if i < N - 1:
            # 次も同じ数字が存在するなら数えない、最後でcntを増やす
            # 前との比較で考えても良さそう、その場合はN-1ではなく0を例外処理？
            if A[i] != A[i + 1]:
                cnt += 1
        # i=N-1の時は次がないので無条件でcntを増やす
        # elseの方が良さそうだが明示的にするためにelifを使った
        elif i == N - 1:
            cnt += 1

print(cnt)


Measured memory_bytes: 33064
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n=pI(readline())
  d,x=pM(split(readline()))
  for i=1:n
    a=pI(readline())
    x+=1+fld((d-1),a)
  end
  println(x)
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 166588
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll Q;

int main(){


    string S;
    
    cin >> S;
    cin >> Q;

    string head;
    string back;

    int flag = 1;
    int T;
    int F;
    string C;
    rep(qi,Q){
        cin >> T;
        if(T==1){
            flag = flag * -1;
        }else{
            cin >> F;
            cin >> C;
            if(F==1){
                if(flag==1){
                    head = C + head;
                }else{
                    back = back + C;
                }

            }else{
                if(flag==1){
                    back = back + C;
                }else{
                    head = C + head;
                }
            }
        }
    }
    ll index;
    if(flag==-1){
        reverse(back.begin(),back.end());
        reverse(S.begin(),S.end());
        reverse(head.begin(),head.end());
        cout << back << S << head;

    }else{
        cout << head << S << back;
    }

    

    

}

Measured memory_bytes: 1208
#include "stdio.h"

#include "stdbool.h"

int N;

bool cd = true;

int number_operation(int A[]){
  int i = 0;
  int j = 0;
  while (cd) {
    if(!(A[j] & 1U)){
      A[j] = A[j] >> 1;
      j++;
    } else{
      cd = false;
      break;
    }

    if(j > N - 1){
      i++;
      j = 0;
    }
  }
  return i;
}

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

  int A[N];

  for(int i = 0; i < N; i++){
    scanf("%d", &A[i]);
  }

  printf("%d\n", number_operation(A));

  return 0;
}


Measured memory_bytes: 128