akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int mincost(int i,int n,int a[],int dp[])
{
    if (i==n)
    return 0;
    if(dp[i]!=-1)
    return dp[i];
  int ans1,ans2;
  ans1=ans2=INT_MAX;
   if(i+1<=n)
     ans1=mincost(i+1,n,a,dp)+abs(a[i+1]-a[i]);
    if(i+2<=n)
    ans2=mincost(i+2,n,a,dp)+abs(a[i+2]-a[i]);
     return dp[i]=min(ans1,ans2);
}
int main() {
    int i,j,k,n;
    cin>>n;
    int a[n+1];
    int dp[n+1];
  for(i=1;i<=n;i++)
    dp[i]=-1;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    cout<<mincost(1,n,a,dp);
}


Measured memory_bytes: 8832
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1 << 30

int MOD = 1000000007;



int main(){
    std::ios_base::sync_with_stdio(false);

    ll K,A,B; cin >> K >> A >> B;

    if(B-A <= 1){
        cout << K+1LL << endl;
    } else {

        ll ans = 0LL;
        if( K-A+1LL-2LL >= 0LL){
            ans = B;
            ans += (B-A)*((K-A+1LL-2LL)/2LL);

            if((K-A+1LL-2LL) % 2LL == 1LL){
                ans++;
            }
        } else {
            ans = K+1LL;
        }

        cout << max(ans, K+1LL) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <cstdio>

using namespace std;

int main(void) {

    while (true) {
        int H, W;
        cin >> H >> W;

        if (H == 0 || W == 0) { break; }

        for (int h = 0; h < H; ++h) {
            char c = h % 2 != 0 ? '#' : '.';
            for (int w = 0; w < W; ++w) {
                c = c == '#' ? '.' : '#';
                putchar(c);
            }
            putchar('\n');
        }

        putchar('\n');
    }

    return 0;
}

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

int main(){
  int h, w;
  char s[60][60];
  int c[60][60];
  cin >> h >> w;
  
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      cin >> s[i][j];
      if(s[i][j] == '.')
        c[i][j] = 0;        
    }
  }
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(s[i][j] == '#'){
        for(int k = i - 1 ; k <= i + 1; ++k){
          for(int l = j - 1; l <= j + 1; ++l){
            if(s[k][l] != '#')
              c[k][l] += 1;
          }
        }
      }     
    }
  }
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(s[i][j] == '#')       
        cout << s[i][j];
      else
        cout << c[i][j];
    }
    cout << endl;
  }
}

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

class Program
{
    static void Main(string[] args)
    {
        var l = Console.ReadLine().Split(' ')
            .Select(x => int.Parse(x)).ToArray();
        var n = l[0]; var k = l[1];
        var hl = Console.ReadLine().Split(' ')
            .Select(x => long.Parse(x))
            .OrderBy(x => x)
            .ToList();
        if (n < k)
        {
            Console.WriteLine(0);
            return;
        }

        long count = 0;

        count += hl.Take(hl.Count - k).Sum();
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 51260
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld  = long double;
using pll = pair<ll, ll> ;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=1LL<<60;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用（EPSより小さいと0と判定など）
 
#define gcd __gcd //llは受け取ってくれない
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define ALL(a) a.begin(),a.end() //sort(ALL(vec));
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define PB push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

//最大値、最小値を更新する。aよりbのが大きい（小さい）か等しければaを更新してtrueを返す。そうでなければ何もせずfalseを返す chmax(nowmax,x);
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
// ----- template end ---- //
 
// ------- library ------- //



// ----- library end ----- //



int main() {

  char c;
  vector<bool> ccnt(128, 0);

  while (cin >> c){
    ccnt.at(c) = true;
  }

  bool ans;
  ans = !((ccnt.at('N') ^ ccnt.at('S')) || (ccnt.at('W') ^ ccnt.at('E')));

  cout << (ans ? "Yes" : "No") << endl;
  

// -- main() end -- //
}


 

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

int main() {
	int N, A[100010] = {};
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	if (N == 2) {
		cout << max(A[0], A[1]) - min(A[0], A[1]) << endl;
		cout << max(A[0], A[1]) << " " << min(A[0], A[1]) << endl;
		return 0;
	}
	sort(A, A + N);
	int Plus = 0, Minus = 0;
	for (int i = 0; i < N; i++) {
		if (0 <= A[i]) Plus++;
		else Minus++;
	}
	if (Plus == 0) Plus = 1, Minus = N - 1;
	if (Minus == 0) Plus = N - 1, Minus = 1;
	int COUNT = 0;
	for (int i = 0; i < Minus; i++) COUNT -= A[i];
	for (int i = Minus; i < N; i++) COUNT += A[i];
	cout << COUNT << endl;
	for (int i = Minus; i < N - 1; i++) {
		cout << A[0] << " " << A[i] << endl;
		A[0] -= A[i];
	}
	for (int i = 0; i < Minus; i++) {
		cout << A[N - 1] << " " << A[i] << endl;
		A[N - 1] -= A[i];
	}
}

Measured memory_bytes: 2304
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)
	result := 0

	for i := 1; i <= n; i++ {
		si := strconv.Itoa(i)
		if len(si)%2 == 1 {
			result = result + 1
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 2276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n; cin >> n;
	ll a[n]; zep(i, 0, n)cin >> a[i];
	
	map<ll, ll> mp;
	ll ans = 0;
	
	zep(i, 0, n){
		if(mp.find(i-a[i]) != mp.end()){
			ans += mp[i-a[i]];
		}
		
		if(mp.find(a[i]+i) == mp.end()){
			mp[a[i]+i] = 0;
		}
		mp[a[i]+i]++;
	}
	print(ans)
	return 0;
}

Measured memory_bytes: 17520
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(){
	int a,b;
	scanf("%d%d", &a, &b);
	int count=0, kuti=1;
	while(kuti<b){
		count++;
		kuti+=a-1;
	}
	printf("%d", count);
	
	return 0;
}

Measured memory_bytes: 128
def Amount(i, j, k):
    return 10000*i + 5000*j + 1000*k

N = input().split()
N = [int(n) for n in N]
b_flag = False
flag = False
for i in range(N[0]+1):
    for j in range(N[0]+1-i):
        k = N[0]-i-j
        if(Amount(i, j, k) == N[1]):
            print(i, j, k)
            flag = True
            b_flag = True
            break
    if(b_flag):
        break

if(flag==False):
    print(-1, -1, -1)


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

void solve(){
    ll a;
    cin >> a;
    ll cnt = a + a*a + a*a*a;
    cout << cnt<< endl;
}


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  //int t;cin>>t;while(t--)
  solve();
  return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
using namespace std;
#define N 5010
set<string> p;
char a[N],b[N];
int main()
{
    int i,j,k,n;
    scanf("%s%d",a,&n);
    k=strlen(a);
    for(i=0;i<k;i++)
    {
        for(j=i;j<i+min(k,n);j++)
        {
            b[j-i]=a[j];
            b[j-i+1]='\0';
            p.insert(b);
        }
    }
    j=1;
    set<string>::iterator it;
    it=p.begin();
    while(j<n)
    {
        it++;
        j++;
    }
    cout<<*it<<endl;
    return 0;
}


Measured memory_bytes: 1664
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

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

    vector<ll> A(N);
    vector<ll> B(M);
    rep(i, N) { cin >> A[i]; }
    rep(i, M) { cin >> B[i]; }

    ll a_maxidx = 0;
    ll b_maxidx = 0;
    vector<ll> a_sum(N + 1);
    vector<ll> b_sum(M + 1);
    a_sum[0] = 0;
    b_sum[0] = 0;
    reps(i, 0, N) {
        a_sum[i + 1] = a_sum[i] + A[i];
        a_maxidx = i + 1;
    }

    reps(i, 0, M) {
        b_sum[i + 1] = b_sum[i] + B[i];
        b_maxidx = i + 1;
    }

    // repv(a_sum) cout << *it << " ";
    // cout << endl;

    // repv(b_sum) cout << *it << " ";
    // cout << endl;

    ll max_sum = 0;
    ll ans = 0;

    for (ll i = 0; i < N + 1; i++) {
        ll res = K - a_sum[i];
        auto it = upper_bound(b_sum.begin(), b_sum.end(), res);
        ll idx = it - b_sum.begin() - 1;
        if (idx < 0) continue;

        // cout << "a[" << i << "]: " << a_sum[i] << ", b[" << idx
        //      << "]: " << b_sum[idx] << ", sum: " << a_sum[i] + b_sum[idx]
        //      << endl;

        ans = max(ans, i + idx);
    }
    cout << ans << endl;

    return 0;
}


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

int main() {

	int N, T,ans;
	cin >> N >> T;

	int c[100];
	int t[100];
	ans = 10000;

	cin >> c[0] >> t[0];

	if (t[0] < T) {
		ans=min(ans, c[0]);
	}

	for (int i = 1; i < N; i++) {

		cin >> c[i] >> t[i];

		if (t[i] <= T) {
			ans = min(ans, c[i]);
		}
		
	}
	if (ans == 10000) {
		cout << "TLE" << endl;
	}
	else {
		cout << ans << endl;
	}

		return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace C_ABC161
{
    class MainClass
    {

        static long[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
            long a = s[0];
            long b = s[1];
            if(a<b){
                WriteLine(Min(b-a,a));
            }else if(a==b){
                WriteLine(0);
            }else{
                a = a - (a/b)*b;
                WriteLine(Min(b-a,a));
                
            }

        }
    }
}


Measured memory_bytes: 13268
N=int(input())
H=[int(i) for i in input().split()]
S=[0 for i in range(N+1)]
for i in range(N):
    S[i+1]=max(S[i],H[i])
for i in range(N):
    if S[i]<=H[i]+1:
        continue
    else:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 14396
import sys
sys.setrecursionlimit(10 ** 7)

def dfs(v, p, dist):
    for u, w in tree[v]:
        if u == p:
            continue
        else:
            dist[u] = dist[v] + w
            dfs(u, v, dist)
 
 
n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    tree[u - 1].append((v - 1, w))
    tree[v - 1].append((u - 1, w))
 
dist = [0 for _ in range(n)]
dfs(0, -1, dist)
 
for i in dist:
    if i % 2 == 0:
        print(0)
    else:
        print(1)

Measured memory_bytes: 82300
#include <iostream>
#include <vector>

int main() {
    int N, M; std::cin >> N >> M;
    int H[N], is_good_hill[N];
    int i, temp, total = 0, A, B;

    for (i = 0; i < N; i++) {
        is_good_hill[i] = 1;
    }

    for (i = 0; i < N; i++) {
        std::cin >> H[i];
    }

    for (i = 0; i < M; i++) {
        std::cin >> A >> B;
        if (H[A-1] >= H[B-1]) {
            is_good_hill[B-1] = 0;
        }

        if (H[B-1] >= H[A-1]) {
            is_good_hill[A-1] = 0;
        }
    }

    for (i = 0; i < N; i++) {
        total += is_good_hill[i];
    }

    std::cout << total << std::endl;

    return 0;
}

Measured memory_bytes: 3948
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
const int N=100005;
char s[N];
int fa[N];
int main()
{
//freopen("input.txt","r",stdin);
ios::sync_with_stdio(false);
int n;
cin >>s+1;
n=strlen(s+1);
for(int i=1;i<=n;i++)s[i]-='0';
if(s[1]!=1||s[n]!=0)
	{
	cout <<-1;
	return 0;
	}
for(int i=1;i<n;i++)
	if(s[i]!=s[n-i])
		{
		cout <<-1;
		return 0;
		}
s[n]=1;
int tmp=0;
for(int i=n;i>=1;i--)
	{
	fa[i]=tmp;
	if(s[i]==1)
		tmp=i;
	}
for(int i=1;i<n;i++)
	cout <<i<<" "<<fa[i]<<endl;
return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vvin=vector<vector<int>>;
using vll=vector<long long>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;
vin dy={0,1,0,-1};
vin dx={1,0,-1,0};

int main(){
    int n;cin>>n;
    vll a(n);rep(i,n)cin>>a[i];
    vll dp(n+1);//i日目に売るときの手持ちの金の最大値
    dp[0]=1000;ll m;ll M;
    rep2(i,1,n+1){
        M=0;
        rep(j,i){//最後に売るのがj日目
            m=inf;
            rep2(k,j+1,i)m=min(m,a[k-1]);
            M=max(M,max(dp[j],dp[j]%m+(dp[j]/m)*a[i-1]));
        }
        dp[i]=M;
    }
    M=1000;
    rep(i,n)M=max(M,dp[i+1]);
    cout<<M<<endl;
    //rep(i,n)cout<<dp[i+1]<<" ";cout<<endl;
}

Measured memory_bytes: 3624
from functools import reduce
l = [int(input()) for _ in range(5)]
r = [10 if i % 10 == 0 else i %  10 for i in l]
m = [i  if i % 10 == 0 else i // 10 * 10 + 10 for i in l]
print(sum(m) + min(r) - 10)

Measured memory_bytes: 38256
S_hn = input().split(" ") #標準入力（H, N）
S_a = input().split(" ") #標準入力（必殺技）

H = int(S_hn[0]) #モンスターのHP
N = int(S_hn[1]) #技の種類
A = [] #必殺技
for i in range(N):
  A.append(int(S_a[i]))
  
if H <= sum(A):
  print("Yes")
else:
  print("No")

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

int main(){
  char c;
  int a = 0;
  for(int i = 0; i < 3; i++){
    cin >> c;
    if(c == 'o') a++;
  }
  cout << 700 + 100*a << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(n) n.begin(),n.end()
#define yn(x) cout << (x ? "Yes":"No") << endl;

int main() {
  string s,s1;
  int q;
  cin >> s >> q;
  rep(i,q){
    int t;
    cin >> t;
    if(t == 1) swap(s,s1);
    else{
      int f; char c;
      cin >> f >> c;
      if(f == 1) s1 += c;
      else s += c;
    }
  }
  reverse(all(s1));
  s1 += s;
  cout << s1 << endl;
}


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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define INF (1 << 29)
const int mod = 1000000007;

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

    vector<int> p(n);
    vector<int> q(n);

    for(int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> q[i];
    }

    vector<int> v = p;
    asort(v);

    int cnt, p_cnt, q_cnt;
    cnt = 1;
    do {
        if(p == v) {
            p_cnt = cnt;
        }
        if(q == v) {
            q_cnt = cnt;
        }
        cnt++;
    } while(next_permutation(all(v)));

    cout << abs(p_cnt - q_cnt) << endl;

    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define ll long long
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}
const ll MOD = 1e9+7;
long long Comb(int n, int i){long long ans = 1; if(i == 0 || i == n) return 1; else {for(int j = 1; j <= i; ++j){
      ans *=(n+1-j);
      ans /= j;
      ans %= MOD;} }return ans;}

int main(void){
    int n; cin >> n;
    int masu[2020] = {};
    masu[2020] = -1;
    for(int i = 1; i <= n; ++i){
        int tmp; cin >> tmp;
        masu[tmp] = i;
    }
    int q; cin >> q;
    while(q--){
        int koma; cin >> koma;
        for(int j = 1; j <= 2019; ++j){
            if(masu[j] == koma){
                if(masu[j+1] == 0){
                    swap(masu[j], masu[j+1]);
                    break;
                }
            }
        }
    }
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= 2019; ++j){
            if(masu[j] == i) cout << j << endl;
        }
    }
}



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

int main() {
  int A,B,C,D,E,i,last;
 cin >> A;
 cin >>B;
  cin >>C;
  cin >>D;
  cin >>E;
  last =10;	
 int AA,BB,CC,DD,EE,Count,x;

  if(A%10 !=0){
  AA=A+10-A%10;
    if(last>A%10){ 
 last=A%10;
   Count=1;
  	}
  }
  else{
  AA=A;
  }
  
  
  if(B%10 !=0){
  BB=B+10-B%10;
    if(last>B%10){   
 	last=B%10;
     Count=2;
	 }
  }
  else{
  BB=B;
  }
  
 if(C%10 !=0){
 CC=C+10-C%10;
 if(last>C%10){ 
 last=C%10;
   Count=3;
 }
 }else{
  CC=C;
  }

  
if(D%10 !=0){
  DD=D+10-D%10;
    if(last>D%10){ 
 last=D%10;
     Count=4;
 		}          
     }else{
DD=D;
}

  if(E%10 !=0){
    EE=E+10-E%10; 
 if(last>E%10){   
 last=E%10;
    Count=5;
 }
  }
  else{
    EE=E;
  }

  

  
  if( Count==1){
  x=A+BB+CC+DD+EE;
  }
  
  if( Count==2){
  x=AA+B+CC+DD+EE;
  }
   
  if( Count==3){
  x=AA+BB+C+DD+EE;
  }
  
  if( Count==4){
  x=AA+BB+CC+D+EE;
  }
  
   if( Count==5){
  x=AA+BB+CC+DD+E;
  }

  cout << x << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
	int n;
    cin >> n;
    int t=n,w=0;
    while(t>0){
        w+=t%10;
        t/=10;
    }
    if(n%w==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

using namespace std;

int main(void){
  int n, k;
  cin >> n >> k;

  vector<int> h(n);
  long long int s = 0;
  for (int i = 0; i < n; i++)
    cin >> h[i];

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

  for (int i = 0; i < n - k; i++){
    s += h[i];
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < 20;i++){
			sb.append("#");
		}
		String sepalator = sb.toString();
		sb = null;
		
		Building[] buildings = new Building[4];
		for(int i = 0;i < buildings.length;i++){
			buildings[i] = new Building();
		}
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		for(int i = 0;i < n;i++){
			String[] tmp = br.readLine().split(" ");
			int building = Integer.parseInt(tmp[0]);
			int floor = Integer.parseInt(tmp[1]);
			int room = Integer.parseInt(tmp[2]);
			int visitor = Integer.parseInt(tmp[3]);
			//1 Baseの数字を0 Baseに変換
			buildings[--building].add(--floor, --room, visitor);
		}
		for(int i = 0;i < buildings.length;i++){
			buildings[i].write();
			if(i >= buildings.length - 1)
				break;
			System.out.println(sepalator);
		}
	}

}

class Building {

	Floor[] floors;
	{
		floors = new Floor[3];
		for (int i = 0; i < floors.length; i++) {
			floors[i] = new Floor();
		}
	}

	public void add(int floor, int room, int visitor) {
		floors[floor].add(room, visitor);
	}
	
	public void write(){
		for(int i = 0;i < floors.length;i++){
			floors[i].write();
		}
	}

	private class Floor {
		int[] people;
		{
			people = new int[10];
			for (int i = 0; i < people.length; i++) {
				people[i] = 0;
			}
		}

		public void add(int room, int visitor) {
			people[room] += visitor;
		}
		
		public void write(){
			StringBuilder sb = new StringBuilder();
			for(int i = 0;i < people.length;i++){
				sb.append(" ");
				sb.append(people[i]);
			}
			System.out.println(sb.toString());
		}
	}
}

Measured memory_bytes: 19240
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const ld EPS=1.0e-15;
const double PI=M_PI;

int main(){
    ll X; scanf("%lld", &X);
    ll Y = 100;
    ld res = 100.0L, p = 1.01L;
    int count = 0;
    while(Y < X){
        res *= p;
        Y = (ll)res;
        res = (ld)Y;
        count ++;
    }
    printf("%d\n", count);
}

Measured memory_bytes: 3768
// ayy
// ' lamo
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld; //CARE
typedef complex<ld> pt;
#define fi first
#define se second
#define pb push_back
const ld eps=1e-8;
const int inf=1e9+99;
const ll linf=1e18+99;
const int P=1e9+7;










void fail() {
	cout<<"No"<<endl;
	exit(0);
}

int32_t main() {
	int n,m; cin>>n>>m;
	map<char,int> mm;
	string s;
	for(int i=0;i<n;i++) {
		cin>>s;
		for(int j=0;j<m;j++) mm[s[j]]++;
	}

	static int ct[4];
	for(const auto &P:mm) ++ct[P.se%4];
	if(ct[1]+ct[3]>1) fail();
	if(n%2==1 && m%2==1) assert(ct[1]+ct[3]==1);
	else assert(ct[1]+ct[3]==0);

	if(n%2==1 && m%2==1 && ct[3]==1) ++ct[2],--ct[3];
	else ++ct[0],--ct[1];

	int fr=0;
	if(n%2) fr+=m/2;
	if(m%2) fr+=n/2;
	if(ct[2]>fr) fail();

	cout<<"Yes"<<endl;
}













Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  if(S=="RRR"){
    cout<<3<<endl;
  }
  if(S=="RRS"||S=="SRR"){
    cout<<2<<endl;
  }
  if(S=="RSS"||S=="SRS"||S=="SSR"||S=="RSR"){
    cout<<1<<endl;
  }
  if(S=="SSS"){
    cout<<0<<endl;
  }
}

Measured memory_bytes: 3616
#include <string>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string.h>
#include <utility>
#include <queue>
#include <stack>
#include <iomanip>
#include <ctype.h>
#include <map>
#include <set>
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <sstream>
#include <math.h>
#include <time.h>
#include <iostream>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <tuple>
#include <cmath>
#include <stdio.h>      /* printf, fgets */
#include <stdlib.h>
#include <fstream>

using namespace std;

typedef long long LL;

#define FOR(i,n) for(int i = 0;i < n;i++)
#define MP make_pair
#define PB push_back
#define ALL(a) (a).begin(),(a).end()
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define CLEAR(a) memset(a, 0, sizeof(a))
#define INF 2000000007LL
#define y1 uu1
#define y2 uu2
const double EPS = 1E-12;
const double PI = acos(-1.0);
const LL mod = 1000000007;

using namespace std;

int r;

int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin >> r;
  cout << r * r << endl;

  return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K,H,W,L,R,l,r,mi1,mi2,sum,Q;
LL ans;
LL no;
bool b,bb[100001];
string s,t;

int main() {
	cin >> N;
	ans = INF;
	for (int i = 1; i <= sqrt(N); i++) {
		if (N%i == 0)ans = min(ans, i + N / i - 2);
	}

		cout <<ans<< endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define fi first
#define se second
#define mp make_pair
#define SZ(x) ((int)(x.size()))
#define FOI(i,a,n) for(int (i)=int(a);(i)<=int(n);++(i))
#define FOD(i,a,n) for(int (i)=int(a);(i)>=int(n);--(i))
#define IN(x,y) ((y).find((x))!=(y).end())
#define ALL(t) t.begin(),t.end()
#define MSET(tabl,i) memset(tabl, i, sizeof(tabl))
#define PSET(x,y) fixed<<setprecision(y)<<lf(x)
#define DBG(c) cout<<#c<<" = "<<c<<endl;
#define RTIME ((double)clock()/(double)CLOCKS_PER_SEC)

template<typename T,typename S>inline bool REMIN(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool REMAX(T&a,const S&b){return a<b?a=b,1:0;}

typedef long long ll;
typedef long double lf;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;

int bit(ll x, int pos){ return (x >> pos) & 1; }
ll power(ll base, ll exp, ll c = 1e9 + 7) { if(!exp) return 1; ll r = power(base, exp >> 1, c); r=(r*r)%c; if(exp&1) r=(r*base)%c; return r; }

ll T,N,M,K;  
int a,b,c;
string s1,s2;

const lf PI = 2*acos(0);
const ll INF = 1e9 + 4;
const int NMAX = 3e5+5;
const ll MOD = 1000000007;

int ar[NMAX];

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	cin >> ar[0] >> ar[1] >> ar[2];
	sort(ar, ar + 3);
	cout << ar[0] + ar[1];
	
	return 0;
}


Measured memory_bytes: 256
N= int(input())
c=list(str(input()))
#N=4
#c=['W', 'W', 'R', 'R']
#c.reverse()
#print(c)

t1=t2=True

n1=0
n2=0
num=0
while t1:
    t2=True
    if not 0<=N-1-n1<=N-1:
        t1=False
    if c[N-1-n1]=='W':
        n1+=1
        continue
    else:
        while t2:
            if c[n2]=='W':
                if n2<N-1-n1:
                    c[N-1-n1]='W'
                    c[n2]='R'
                    num+=1
                    t2=False
                    continue
                else:
                    t1=False 
            n2+=1
            if not 0<=n2<=N-1:
                t1=False
                t2=False
print(num)  

Measured memory_bytes: 83920
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <iomanip>
using namespace std;

#define B

#ifdef B
static const double PI = 3.141592653589793; 
double ST_PI = PI / 180;

int main(void) {
	double a, b, c, ab, s, l, h;
	cin >> a >> b >> ab;

	s = a * b * sin(ST_PI * ab) * 0.5;

	l = sqrt(a*a + b*b - 2 * a*b*cos(ST_PI * ab)) + a + b;

	h = b * sin(ST_PI * ab);

	cout << fixed << setprecision(12) << s << endl;
	cout << fixed << setprecision(12) << l << endl;
	cout << fixed << setprecision(12) << h << endl;

	return 0;
}
#endif // B

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

int read() {
	char c = getchar();
	int x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (; isdigit(c); c = getchar())
		x = x * 10 + c - 48;
	return x * f;
}
string s;
int main() {
	cin >> s;
	int len = s.size();
	for (int i = 0; i < len; ++i)
		if (s[i] == '?')
			s[i] = 'D';
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3712
n=int(input())
s=list(map(int, input().split()))
count=0

for i in range(1, n-1):
    if s[i]<s[i+1] and s[i]>s[i-1]:
        count = count+1
    if s[i]>s[i+1] and s[i]<s[i-1]:
        count = count+1
print(count)

Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>
int main(){
    int a;
    int b,c;
    scanf("%d",&a);
    if (a==1) printf("Hello World");
    else{
         scanf("%d",&b);
         scanf("%d",&c);
         printf("%d",b+c);
    } 
    return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pii pair<string,ll>
using namespace std;
ll dp[4];
int main()
{
    fast;
  
    ll n,i,j,ans=0;
    cin>>n;
    vector<pii> ma;
    string x;
    for(i=0;i<n;i++)
    {
    	string s;
    	ll ti;
    	cin>>s>>ti;
    	ma.pb({s,ti});
    }
    cin>>x;
    bool ha = false;
    for(auto u: ma)
    {
    	if(u.fi==x)
    	{
    		ha = true;
    		continue;
    	} 
    	if(ha) ans += u.se;
    }
    cout<<ans;

}
    


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int n,b,i,j;
	while(scanf("%d",&n),n){
		int a[100010]={};
		int c[100010]={};
		for(i=1;i<n;i++)a[i*i%n]=1;
		for(i=0;i<n;i++){
			if(a[i]==0)continue;
			for(j=0;j<n;j++){
				if(a[j]==0)continue;
				b=(i-j+n)%n;
				if(b>n/2)b=n-b;
				c[b]++;
			}
		}
		for(i=1;i*2<n;i++)printf("%d\n",c[i]);
	}
	return 0;
}

Measured memory_bytes: 1388
#include <iostream>
using namespace std;
int main()
{
  string S, T;
  cin >> S >> T;
  string ans = "No";
  for (int i = 0; i < S.length(); i++)
  {
    S = S.back() + S.substr(0, S.length() - 1);
    if (S == T)
      ans = "Yes";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


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

    ll x = 0;
    for(int i = 0; i < n; i++){
        if(i % 2) x -= a[i];
        else x += a[i];
    }

    V<ll> ans(n);
    ans[0] = x / 2;
    for(int i = 0; i < n - 1; i++){
        ans[i + 1] = a[i] - ans[i];
    }

    for(int i = 0; i < n; i++){
        cout << ans[i] * 2 << endl;
    }


    return 0;
}


Measured memory_bytes: 4772
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 200007;
const int MOD = 1000000007;

void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    unsigned long long a[MAX], b[MAX], t, currA = 0, currB = 0;
    for (int i = 1; i <= n; i++) {
        cin >> t;
        currA += t;
        a[i] = currA;
    }
    for (int i = 1; i <= m; i++) {
        cin >> t;
        currB += t;
        b[i] = currB;
    }
    a[0] = 0; b[0] = 0;
    unsigned long long mx = 0, ind = m;
    for (int i = 0; i <= n; i++) {
        if (a[i] > k) {break;}
        while (b[ind] > k - a[i]) {ind--;}
        mx = max(mx, i + ind);
    }
    cout << mx;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve(); cout << endl;}
    solve();
}

Measured memory_bytes: 6756
import java.util.*;
import java.lang.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
        int G = sc.nextInt();
        int B = sc.nextInt();

        int N = sc.nextInt();

        int ans=0;
        for(int red=0; red<=N/R; red++) for(int green=0; green<=N/G; green++){
            if(N-R*red-G*green>=0 && (N-R*red-G*green)%B==0){
                ans++;
            }
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 21844
n=int(input())
d=list(map(int,input().split()))

if d[0] != 0:
  print(0)
  exit()

ans=1

a=[0]*(n+1)

for i in d:
  a[i] += 1

if a[0] != 1:
  print(0)
  exit()

for j in range(n):
  if j!=0 and a[j] == 0:
    for k in range(j+1,n):
      if a[k] != 0:
        print(0)
        exit()
    break
  else:
    ans*=(a[j]**a[j+1])
    ans%=998244353

print(ans)

Measured memory_bytes: 13892
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
using P = pair <int,int>; //to, cost
using WeightedGraph = vector<vector <P>>; //to cost
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    vector <int> ans(n);
    rep(i,m){
        int a,b; cin>>a>>b;
        a--; b--;
        ans[a]++;
        ans[b]++;
    }
    rep(i,n){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 256
k,n = map(int,input().split())
a_list = list(map(int,input().split()))

a_list_sorted = sorted(a_list)

max_distance = 0
for i in range(1, len(a_list_sorted)):
    tmp_max_distance = a_list_sorted[i] - a_list_sorted[i-1]
    if max_distance < tmp_max_distance:
        max_distance = tmp_max_distance

tmp_max_distance_last = a_list_sorted[0] + (k - a_list_sorted[-1])
if max_distance < tmp_max_distance_last:
    max_distance = tmp_max_distance_last

print(k-max_distance)

Measured memory_bytes: 26444
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var Ai = Slist();
            Ai.Sort();
            var BC = new List<Tuple<long, long>>();
            for (var i = 0; i < M; ++i)
            {
                var bc = Sarray();
                BC.Add(Tuple.Create(bc[0], bc[1]));
            }
            BC.Sort((l, r) => (int)(r.Item2 - l.Item2));
            var ac = 0;
            for (var i = 0; i < M; ++i)
            {
                var b = BC[i].Item1;
                var c = BC[i].Item2;
                for (var j = 0; j < b; ++j)
                {
                    if (N <= ac) break;
                    if (c <= Ai[ac]) break;
                    Ai[ac++] = c;
                }
                if (N <= ac) break;
            }
            WriteLine(Ai.Sum());
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 32592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

string s;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> s;
  if (s[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }

  int cnt = 0;
  for (int i = 2; i < s.size()-1; i++) {
    cnt += s[i] == 'C';
  }
  if (cnt != 1) {
    cout << "WA" << endl;
    return 0;
  }
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != 'C' && !('a' <= s[i] && s[i] <= 'z')) {
      cout << "WA" << endl;
      return 0;
    }
  }
  cout << "AC" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
ll getPow(ll a,ll p){
  ll ret = 1,cp = a;
  while(p){
    if(p&1) ret = (ret*cp)%MOD;
    p >>= 1;
    cp = (cp*cp)%MOD;
  }
  return ret;
}
int main(){
  ll n,m,k;
  cin >> n >> m >> k;
  ll t = n*m,ans = 0;
  ll n2 = (n*n)%MOD,m2 = (m*m)%MOD,t2 = 1,k2 = 1;
  for(int i = 1; i <= k-2; ++i){
    k2 = (k2*i)%MOD;
    t2 = (t2*(t-k+i))%MOD;
  }
  ll C = (t2*getPow(k2,MOD-2))%MOD;
  for(int d = 1; d < n; ++d){
    ans = (ans + ((d*(n-d))%MOD)*((m2*C)%MOD))%MOD;
  }
  for(int d = 1; d < m; ++d){
    ans = (ans + ((d*(m-d))%MOD)*((n2*C)%MOD))%MOD;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long int
#define fr(i,n) for(ll i=0; i<n; i++)
#define fre(i,n) for(ll i=1; i<=n; i++)
#define pb push_back
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define pii pair<ll,ll>
#define ve vector
#define piii pair<pii, ll>
#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

ll a[25][25], mod=1e9+7;
ll dp[25][5000000];

ll ways(ll ind, ll n, ll visited){
    if( ind >= n )
      return 1;
    if( dp[ind][visited] != -1)
      return dp[ind][visited];

    ll ans = 0;
    for(int i=0; i<n; i++){
        if( ((visited>>i)&1) == 0 && a[ind][i] == 1){
          visited |= (1<<i);
          ans += ways(ind+1, n, visited );
          ans %= mod;
          visited ^= (1<<i);
        }
    }
    dp[ind][visited] = ans;
    return ans;
}
int main(){
   
   for(int i=0; i<25; i++){
      for(int j=0; j<5000000; j++){
          dp[i][j] = -1;
      }
   }
   ll n;
   cin>>n;

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

   ll ans = ways(0, n, 0);
   cout<<ans<<endl;
} 

Measured memory_bytes: 980184
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

char s[210];
int main(){
	scanf("%s",s);
	ll n=strlen(s);
	if(n%2==1)n--;
	else n-=2;
	while(1){
		int flag=1;
		rep(i,0,n/2){
			if(s[i]!=s[i+n/2]){
				flag=0;
				break;
			}
		}
		if(flag){
			printf("%lld",n);
			return 0;
		}
		n-=2;
	}
}

Measured memory_bytes: 128
object Main extends App {
    var n = readInt
  	var get = readLine.split(" ")
  	var sum1 = 0
  	var sum2 = 0
  var sum3 = 100
  for(i <- 0 to n-2) {
    sum1 = sum1 + get(i).toInt
    for(j <- i+1 to n-1){
      sum2 = sum2 + get(j).toInt
    }
    sum3 = math.min(sum3,math.abs(sum1-sum2))
    sum2=0
  }
       println(sum3)
}

Measured memory_bytes: 27444
import java.util.Scanner;

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

    int x, y, a;

      while(true){

        x = sc.nextInt();
        String op = sc.next();
        y = sc.nextInt();

        if(op.equals("+")){
          a = x + y ;
        }else  if(op.equals("-")){
          a = x - y ;
        }else  if(op.equals("*")){
          a = x * y ;
        }else  if(op.equals("/")){
          a = x / y ;
        }else{
          break;
        }

        System.out.println( a );

      }

    } 
}


Measured memory_bytes: 26252
n, k = map(int,input().split())
s = input()

if n == 1:
        print(0)
else:        
        t = []
        tt = 0
        ss = s[0]
        for i in range(1,n):
                if s[i] != ss:
                        t.append(i - tt)
                        tt = i
                        ss = s[i]
        t.append(n - tt)
        cnt = sum(t) - len(t) 

        if len(t) % 2 == 0:
                if k <= (len(t) - 2)/2:
                        cnt += 2 * k
                else:
                        cnt += 2 * (len(t) - 2)/2 + 1
        else:
                if k <= (len(t) - 1)/2:
                        cnt += 2 * k
                else:
                        cnt += 2 * (len(t) - 1)/2
        print(int(cnt)) 

Measured memory_bytes: 4092
S = input()
T = input()

moji = []

for i in range(len(S)):
    j = 0
    cnt = 0
    
    while j < len(T) and i+len(T)-1 < len(S):
        if S[i+j] == T[j] or S[i+j] == '?':
            cnt += 1

        else:
            break
        j += 1
    
    if cnt == len(T):
        moji0 = ''
        if i == 0: moji0 = T+S[i+len(T):len(S)]
        elif i+len(T) > len(S)-1: 
            moji0 = S[0:i]+T
        else:
            moji0 = S[0:i]+T+S[i+len(T):len(S)]

        
        moji1 = moji0.replace('?', 'a')
        moji.append(moji1)

print(min(moji) if moji != [] else "UNRESTORABLE")

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

using namespace std;

#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010

void solve() {
    int n, m;
    cin >> n >> m;

    vector<int> v(m);
    for (int i = 0; i < m; i++) {
        cin >> v[i];
    }

    vector<int> dp(n + 1, INT_MAX);
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            if (i >= v[j])
                dp[i] = min(dp[i], 1 + dp[i - v[j]]);
        }
    }
    cout << dp[n] << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}


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

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

typedef long long ll;

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

  int result = 0;

  if(b==1){
    cout << result << endl;
  }else {
    while(true){
      result++;
      b = b - a;
      if(b <= 0) break;
      else b++;
    }
    cout << result << endl;
  }

  return 0;
}

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

using namespace std;

int main()
{
    string s;
    getline(cin, s);

    stringstream ss(s);
    string buf;
    stack<double> values;
    double a, b;
    while (getline(ss, buf, ' ')){
        if (buf[0] < '0' || buf[0] > '9'){
            b = values.top();
            values.pop();
            a = values.top();
            values.pop();

            switch (buf[0]){
              case '+':
                values.push(a + b);
                break;
              case '-':
                values.push(a - b);
                break;
              case '*':
                values.push(a * b);
                break;
            }
        } else values.push(stod(buf));
    }

    cout << values.top() << endl;

    return 0;
}




Measured memory_bytes: 3300
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define MAXLEN 100000
#define MAXQ 200000

struct Cha{
	char c;
	struct Cha *pre;
	struct Cha *next;
};

int main(){
	struct Cha *head = NULL;
	struct Cha *last = NULL;
	char s[MAXLEN+5] = "\0";
	int len, q, i;
	int t, f, rev = 0;
	char c;
	struct Cha *tmp;

	scanf("%s", s);
	len = strlen(s);
	head = (struct Cha *)malloc(sizeof(struct Cha));
	head->c = s[0];
	head->pre = NULL;
	head->next = NULL;
	last = head;
	for(i=1; i<len; i++){
		tmp = (struct Cha *)malloc(sizeof(struct Cha));
		tmp->c = s[i];
		tmp->pre = last;
		tmp->next = NULL;
		last->next = tmp;
		last = tmp;
	}

	scanf("%d", &q);
	for(i=0; i<q; i++){
		scanf("%d", &t);
		if(t == 1){
			tmp = head;
			head = last;
			last = tmp;
			rev = 1 - rev;
		}else{
			scanf("%d %c", &f, &c);
			tmp = (struct Cha *)malloc(sizeof(struct Cha));
			tmp->c = c;
			if(f == 1){
				if(rev == 0){
					tmp->pre = NULL;
					tmp->next = head;
					head->pre = tmp;
					head = tmp;
				}else{
					tmp->next = NULL;
					tmp->pre = head;
					head->next = tmp;
					head = tmp;
				}
			}else{
				if(rev == 0){
					tmp->next = NULL;
					tmp->pre = last;
					last->next = tmp;
					last = tmp;
				}else{
					tmp->pre = NULL;
					tmp->next = last;
					last->pre = tmp;
					last = tmp;
				}
			}
		}
	}

	for(tmp=head; tmp!=NULL; tmp=(rev == 0) ? tmp->next : tmp->pre){
		printf("%c", tmp->c);
	}

	return 0;
}


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

int main (){
	int a[10][10],x,y,ans=0;
	cin>>x>>y;
	for(int i=0;i<x;i++)for(int j=0;j<y;j++)cin>>a[i][j];
	for(int i=0;i<x;i++){
		for(int j=i+1;j<x;j++){
			int cnt=0;
			for(int k=0;k<y;k++){
				cnt+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			if(int(sqrt(cnt))*int(sqrt(cnt))==cnt)ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
} 

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

int main(void) {
    string s, ans = "None";
    bool zohe[26] = {};
    cin >> s;
    for (int i = 0; i < s.size(); i++) zohe[s[i] - 'a'] = true;
    for (int i = 0; i < 26; i++) {
        if (!zohe[i]) {
            ans.clear();
            ans += (char)(i + 'a');
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
import math

a, b, x = map(int, input().split())

if((a*a*b)/2 < x):
    y = 2 * ((a**2)*b - x) / (a**2)
    ans = 90- math.degrees(math.atan2(a, y))
elif((a*a*b)/2 == x):
    ans = 45
else:
    y = 2*x / (b*a)
    ans = math.degrees(math.atan2(b, y))

print(ans)



Measured memory_bytes: 3060