akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mx 10000000000008
#define mod 1000000007
ll n,t,arr[sz],brr[sz],vis[sz],crr[sz];
vector<pair<pair<ll,ll>,ll> >v;
char c[sz];
vector<ll>v1[sz];
vector<pair<ll,ll> >v2;
void bfs(ll node,ll par)
{
    crr[par]++;
    vis[node]=par;
    for(int i=0;i<v1[node].size();i++)
    {
        ll x=v1[node][i];
        if(vis[x])
            continue;
        bfs(x,par);
    }
    return;
}
int main()
{
   scanf("%lld",&n);
   for(int i=1;i<=n;i++)
   {
       ll a,b;
       scanf("%lld %lld",&a,&b);
       v.push_back({{a,b},i});
   }
   sort(v.begin(),v.end());
   for(int i=0;i<v.size();i++)
   {
       arr[i+1]=v[i].first.second;
       //printf("     %lld\n",arr[i+1]);
   }
   for(int i=n;i>=1;i--)
   {
    brr[i]=max(brr[i+1],arr[i]);
   // printf("    %lld\n",brr[i]);
   }
   for(int i=1;i<=n;i++)
   {
       if(v2.empty())
       {
           if(brr[i+1]>arr[i])
            v2.push_back({arr[i],i});
          // printf("      %d\n",v2.size());
       }
       else
       {
           if(arr[i]>v2.back().first)
           {
               v1[i].push_back(v2.back().second);
               v1[v2.back().second].push_back(i);
               if(brr[i+1]<v2.back().first)
                v2.pop_back();
           }
           else
           {
               if(brr[i+1]>v2.back().first)
               {
                    v1[i].push_back(v2.back().second);
               v1[v2.back().second].push_back(i);
               v2.pop_back();
               v2.push_back({arr[i],i});
               }
               else{
                v2.pop_back();
                 if(brr[i+1]>arr[i])
            v2.push_back({arr[i],i});
               }
           }
       }
   }
   for(int i=1;i<=n;i++)
   {
       if(!vis[i])
       {
         //  printf("       dd\n");
           vis[i]=i;
           bfs(i,i);
           //printf("    %lld %lld\n",crr[i],vis[i]);
       }
   }
   for(int i=1;i<=n;i++)
   {
       crr[i]=crr[vis[i]];
       //printf("%lld\n",crr[i]);
       //vis[v[i].second]=crr[i];
   }
   for(int i=1;i<=n;i++)
    vis[v[i-1].second]=crr[i];
   for(int i=1;i<=n;i++)
    printf("%lld\n",vis[i]);
    return 0;
}


Measured memory_bytes: 27156
def card_check(alice,bob):
    if alice > bob:
        print("Alice")
    elif alice < bob:
        print("Bob")
    else:
        print("Draw")

    return

a,b = map(int,input().rstrip().split(' '))

if a == 1:
    a = 14
else:
    pass

if b == 1:
    b = 14
else:
    pass

card_check(a,b)

Measured memory_bytes: 3060
n = int(input())
line = input().split()
t = int(line[0])
a = int(line[1])
temps = map(int,input().split())
temps = list(temps)
places = {}
count = len(temps)
for i in range(count):
  places[i] = abs(a - (t - 0.006 * temps[i]))
answer = min(places.items(),key = lambda x:x[1])[0] + 1
print(answer)

Measured memory_bytes: 3188
s = input().split('><')
if len(s) > 1:
  l = [s[0]+'>'] + list(map(lambda x: '<'+x+'>', s[1:-1])) + ['<'+s[-1]]
else:
  l = s
ans = 0
for block in l:
  left = block.count('<')
  right = block.count('>')
  m = max(left, right)
  ans += left * (left-1) // 2 + right * (right-1) // 2 + m
print(ans)

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);

  for(int i = 0; i < N; i++){
    a.at(i) = i + 1;
  }

  for(int i = 0; i < N; i++){
    cin >> b.at(i);
  }

  int ans = 0;
  for(int i = 0; i < N; i++){
    if(a.at(i) != b.at(i)){
      ans++;
    }
  }

  if(ans == 2 || ans == 0){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())

if a == 0 or b == 0:
    print(0, 0)

elif n > a+b:
    max_ab = min(a, b)
    print(max_ab, 0)

else:
    max_ab = min(a, b)
    print(max_ab, a+b-n)


Measured memory_bytes: 9104
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000000;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N, M; cin >> N >> M;
	vector<vector<int>>AW(N, vector<int>(2, 0));
	rep(i, M) {
		int a; cin >> a;
		--a;
		string s; cin >> s;
		if (AW[a][0] == 0) {
			if (s == "AC")AW[a][0]++;
			else AW[a][1]++;
		}
	}
	int AC = 0, WA = 0;
	rep(i, N) {
		if (AW[i][0] == 1) {
			AC++;
			WA += AW[i][1];
		}
	}
	cout << AC << " " << WA << "\n";


	return 0;
}

Measured memory_bytes: 5760
#include<iostream>

using namespace std; 

int main(){
int A , B ; 
  cin >> A >> B ; 
  if(A%2==0 && B%2==0 || A%2!=0 && B%2!=0){
  	cout << (A+B)/2 ; 
  }
  else{
    cout << "IMPOSSIBLE" ; 
  }
  
  return 0 ; 
  
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		for(int z=0;z<n;z++){
			int[][] map = new int[5][5];
			
			int wid, p;
			int max = 0;
			for(int i=0;i<5;i++){
				for(int j=0;j<5;j++){
					wid = 8;
					p = sc.nextInt();
					if(p==1){
						if(j==0) map[i][j]=1;
						else map[i][j] = map[i][j-1]+1;
						for(int k=i;k>=0;k--){
							if(map[k][j]==0) break;
							wid = Math.min(wid, map[k][j]);
							max = Math.max(max, wid*(i+1-k));
						}
					}
				}
			}
			System.out.println(max);
		}	
	}	
}

Measured memory_bytes: 26344
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	long long int h, w;

	cin>> h >> w;

	if (h == 1 || w == 1) {
		cout << "1" << endl;
		return 0;
	}

	if (h % 2 == 0 || w % 2 == 0) {
		cout << h * w / 2 << endl;
		return 0;
	}

	cout<< h * w / 2+1 << endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
 
using namespace std;
//初始化 
void initial(string &a, string &b){
	while (a.size()<b.size())a = '0' + a;
	while (b.size()<a.size())b = '0' + b;
}
//找出最大的字符串 
void findMax(string &a, string &b){
	string tmp;
	if (a<b){
		tmp = b;
		b = a;
		a = tmp;
	}
}
//删除第一个字符'0' 
bool del(string &a){
	if (a[0] == '0'){
		a.erase(0, 1);
		return true;
	}
	else
		return false;
}
//删除前面所有的 0 
void delAllZroe(string &a){
	while (del(a)){
		del(a);
	};
}
//大数加法 
string bigItergeAdd(string a, string b){
	initial(a, b);
	a = '0' + a;
	b = '0' + b;
	for (int i = a.size() - 1; i >= 0; i--){
		int num1 = a[i] - '0';
		int num2 = b[i] - '0';
		if (num1 + num2>9){
			a[i - 1] = a[i - 1] - '0' + 1 + '0';
			a[i] = (num1 + num2) - 10 + '0';
		}
		else{
			a[i] = (num1 + num2) + '0';
		}
	}
	del(a);
	//	cout<<a<<endl;
	return a;
}
//大数乘法(大数加法实现) 
void bigItergeMul(string a, string b){
	delAllZroe(a);
	delAllZroe(b);
	if (a == "" || b == ""){ printf("0\n"); return; }
	initial(a, b);
	findMax(a, b);
	string res = "0";
	int count = 0;
	delAllZroe(b);
	for (int i = b.size() - 1; i >= 0; i--){
		int num1 = b[i] - '0';
		if (i != b.size() - 1)		a = a + '0';
		for (int i = 1; i <= num1; i++){
			res = bigItergeAdd(res, a);
		}
	}
	delAllZroe(res);
	if (res.size()<3){ printf("0\n"); return; }
	res=res.erase(res.size()-2,2);
	cout << res << endl;
}
 
int main(){
	string a, b, t=".";
	cin>>a>>b;
	int p=b.find(t);
	b=b.erase(p,1);
	bigItergeMul(a,b);	
	return 0;
}

Measured memory_bytes: 3600
S = gets.chomp
N = S.length

dp = Array.new(4, 0)
dp[0] = 1

MOD = 10 ** 9 + 7

N.times do |i|
  p = dp.dup
  if S[i] == 'A'
    dp[1] += p[0]
  elsif S[i] == 'B'
    dp[2] += p[1]
  elsif S[i] == 'C'
    dp[3] += p[2]
  elsif S[i] == '?'
    dp[1] = p[1] * 3 + p[0]
    dp[2] = p[2] * 3 + p[1]
    dp[3] = p[3] * 3 + p[2]
    dp[0] *= 3
  end
  dp.each_with_index do |v, i|
    dp[i] %= MOD
  end
end
puts dp[3]

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



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

    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    string ans = "";
    for(int i=0;i<n;i++){
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
function S(n) {
    var ret = 0;
    while (n > 0) {
        ret += n % 10;
        n = parseInt(n / 10);
    }
    return ret;
}
function Main(N) {
    console.log(N % S(N) == 0 ? "Yes" : "No");
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int f(int v) {
  int res = 0;
  while (v) {
    res += v % 10;
    v /= 10;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  cout << (n % f(n) ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
K,A,B=map(int,input().split())

if B - A <= 2:
    print(K+1)
elif K <= A:
    print(K+1)
elif A % 2 == 1 and K % 2 == 1:
    print(B+(B-A)*((K-A-2)//2)+1)
elif A % 2 == 1 and K % 2 == 0:
    print(B+(B-A)*((K-A-1)//2))
elif A % 2 == 0 and K % 2 == 1:
    print(B+(B-A)*((K-A-1)//2))
else:
    print(B+(B-A)*((K-A-2)//2)+1)

Measured memory_bytes: 3064
#include <cstdio>

int main()
{
	int a, b, c, d, e = 0;
	scanf("%d %d %d", &a, &b, &c);

	for(int i = 1; i <= c; i++){
		d = c % i;
		if(d == 0 && i >= a && i <= b) e++;
	}
	printf("%d\n", e);
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
    ll n;
    cin >> n;
    vector<pair<ll,ll>> vec(n);
    vector<ll> vec1(n),vec2(n);
    ll minx = INFLONG;
    ll miny = INFLONG;
    ll maxx = -INFLONG;
    ll maxy = -INFLONG;
    rep(i,n){
        cin >> t1 >> t2;
        vec[i].first = t1;
        vec[i].second = t2;
        vec1[i] = (t1 + t2);
        vec2[i] = (t1 - t2);
    }
    sort(all(vec));
    sort(all(vec1));
    sort(all(vec2));
    ll ans = 0;
    chmax(ans,vec1[n-1]-vec1[0]);
    chmax(ans,vec2[n-1]-vec2[0]);
    cout << ans << endl;
}

Measured memory_bytes: 9536
import Control.Applicative
import qualified Control.Monad as Monad

main = loopPutNumbers

loopPutNumbers :: IO ()
loopPutNumbers = do
    [x,y] <- map (read :: String -> Int) . words <$> getLine
    Monad.when (x /= 0 || y /= 0) $ do
        putStrLn $ if (x < y)
                    then unwords $ show <$> [x,y]
                    else unwords $ show <$> [y,x]
        loopPutNumbers


Measured memory_bytes: 4016
a, b, c, d, e, f = map(int, input().split())
a, b = 100*a, 100*b

dp = [[0, 0] for _ in range(f+1)]
dp[a][0] = a
if b <= f:
    dp[b][0] = b
memo = {(a, 0):0}
for i in range(1, f):
    w, s = dp[i]
    if w:
        for ab in (a, b):
            if i+ab <= f:
                dp[i+ab][0] = w + ab
                dp[i+ab][1] = s
        for cd in (c, d):
            if i+cd <= f and s + cd <= w * e // 100:
                x = dp[i+cd][0] = w
                y = dp[i+cd][1] = s + cd
                memo[(x+y, y)] = y/(x+y)
_, z, y = max([(val, z, y) for (z, y), val in memo.items()])
print(z, y)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

/*
GF(p)
inverse:O(log p) based on Fermat's little theorem (a^(p-1)=1 mod p)
*/

template<int32_t mod>
struct ModInt{
	int32_t a;
	ModInt(const int64_t a=0):a(a){}

	ModInt& operator+=(const ModInt &x){
		a+=x.a;
		a=(a<mod)?a:a-mod;
		return *this;
	}
	ModInt& operator-=(const ModInt &x){
		a-=x.a;
		a=(a<0)?a+mod:a;
		return *this;
	}
	ModInt& operator*=(const ModInt &x){
		a=(int64_t)a*x.a%mod;
		return *this;
	}
	ModInt& operator/=(const ModInt &x){
		*this*=x.inv();
		return *this;
	}

	ModInt operator+(const ModInt x){return ModInt(*this)+=x;}
	ModInt operator-(const ModInt x){return ModInt(*this)-=x;}
	ModInt operator*(const ModInt x){return ModInt(*this)*=x;}
	ModInt operator/(const ModInt x){return ModInt(*this)/=x;}
	bool operator==(const ModInt x){return a==x.a;}
	bool operator!=(const ModInt x){return a!=x.a;}

	ModInt operator-(){return ModInt(0)-ModInt(*this);}
	ModInt pow(int64_t ex)const{
		int64_t x=a;
		int64_t res=1;
		while(ex){
			if(ex&1)res=res*x%mod;
			x=x*x%mod;
			ex>>=1;
		}
		return ModInt(res);
	}
	ModInt inv()const{return pow(mod-2);}
};

template<int32_t mod>
istream& operator>>(istream& in,ModInt<mod>& a){
	return (in>>a.a);
}
template<int32_t mod>
ostream& operator<<(ostream& out,const ModInt<mod>& a){
	return (out<<a.a);
}

using mint=ModInt<998244353>;


template<class Mint>
struct Combinations{
	int N;
	vector<Mint>facts,finvs,invs;
	Combinations(int n):N(n),facts(n),finvs(n),invs(n){
		facts[0]=finvs[0]=1;
		for(int i=1;i<N;i++){
			facts[i]=facts[i-1]*i;
			invs[i]=Mint(i).inv();
			finvs[i]=finvs[i-1]*invs[i];
		}
	}
	inline Mint fact(int n){return facts[n];}
	inline Mint finv(int n){return finvs[n];}
	inline Mint inv(int n){return invs[n];}
	inline Mint binom(int n,int k){return facts[n]*finvs[k]*finvs[n-k];}
};
Combinations<mint>C(555555);


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

	vector<mint>poN(555555),poM(555555);
	poN[0]=1;
	poM[0]=1;
	for(int i=1;i<555555;i++){
		poN[i]=poN[i-1]*(N+1);
		poM[i]=poM[i-1]*(M+1);
	}

	mint ans=0;

	for(int i=0;i<=N&&i<=M;i++){
		auto tmp=C.binom(N,i);
		tmp*=C.fact(M)*C.finv(M-i);
		tmp*=poM[N-i];
		tmp*=poN[M-i];
		if(i&1)ans-=tmp;
		else ans+=tmp;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    int min = *min_element(A.begin(), A.end());
    int max = *max_element(A.begin(), A.end());

    cout << max - min;
}

Measured memory_bytes: 3612
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;


public class Main {
	 static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 
	public static boolean solve(long r, long g, long b, long w) {
		 if((r%2+g%2+b%2+w%2)>1)return false;
		 else return true;
	}
	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();		
		int n = s.nextInt(); 
		long sum=0;
        long[] ar = new long[n];
        for (int i=0; i<n; i++) {
        	ar[i]=s.nextLong();
        	
        }
        for (int i=1; i<n; i++) {
        	if(ar[i-1]>ar[i]) {
        		sum+=ar[i-1]-ar[i];
        		ar[i]=ar[i-1];
        		
        	}
        }
        System.out.println(sum);
        
      
	}
	
}


Measured memory_bytes: 55364
import java.util.*;

class Main{

    LinkedList<int[]> list;
    PriorityQueue<int[]> empty;

    void solve(){
        Scanner sc = new Scanner(System.in);
        int INF = Integer.MAX_VALUE;

        while(true){
            int n = sc.nextInt();
            if(n==0) break;

            list = new LinkedList<int[]>(); // from, to, id
            empty = new PriorityQueue<int[]>(10, new Comparator<int[]>(){
                    public int compare(int[] a, int[] b){
                        return a[0] - b[0];
                    }
                });
            empty.add(new int[]{0, INF});

            for(int i=0; i<n; i++){
                char command = sc.next().charAt(0);
                if(command=='R') print(sc.nextInt());
                if(command=='W') write(sc.nextInt(), sc.nextInt());
                if(command=='D') delete(sc.nextInt());
            }
            System.out.println();
        }
    }

    void print(int idx){
        for(int i=0; i<list.size(); i++){
            int[] one = list.poll();
            if(one[0]<=idx && idx<=one[1]){
                System.out.println(one[2]);
                list.add(one);
                return;
            }
            list.add(one);
        }
        System.out.println(-1);
    }

    void write(int idx, int length){
        while(length>0){
            int[] one = empty.poll();
            int from = one[0], to = Math.min(one[0]+length-1, one[1]);
            list.add(new int[]{from, to, idx});
            length -= Math.min(length, to-from+1);
            if(to<one[1]) empty.add(new int[]{to+1, one[1]});
        }
    }

    void delete(int idx){
        int size = list.size();
        for(int i=0; i<size; i++){
            int[] one = list.poll();
            if(one[2]==idx) empty.add(new int[]{one[0], one[1]});
            else list.add(one);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 207096
while 1:
    n=int(input())
    if n==0:break
    A=[list(map(int,input().split())) for _ in range(n)]
    ans=0
    while 1:
        score=ans
        for i in range(n):
            cnt,num=0,A[i][0]
            for j in range(5):
                if A[i][j]==num:cnt +=1
                else:
                    if cnt>=3:
                        ans +=num*cnt
                        for k in range(cnt):A[i][j-k-1]=0
                    num=A[i][j]
                    cnt=1
                if j==4 and cnt>=3:
                    ans +=num*cnt
                    for k in range(cnt):A[i][j-k]=0
        B=[[-1 for _ in range(5)] for _ in range(n)]
        for i in range(5):
            cnt=n-1
            for j in range(n)[::-1]:
                if A[j][i]!=0:
                    B[j][i]=cnt
                    cnt -=1
        C=[[0 for _ in range(5)] for _ in range(n)]
        for i in range(5):
            for j in range(n):
                if B[j][i]!=-1:
                    C[B[j][i]][i]=A[j][i]
        A=C
        if score==ans:break
    print(ans)


Measured memory_bytes: 5632
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second > b.second; }

int main(){
    ll n;cin>>n;
    cout<<n*n<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc135/tasks/abc135_c
# 前から倒せるだけ倒していくのが最適
N = read_a_int()
A = read_ints()
B = read_ints()
ans = 0
for i in ra(N):
    power = B[i]
    left = max(A[i] - power, 0)  # 残りのモンスター数
    used = A[i] - left
    ans += used  # 減った数
    power -= used

    # 二体目の処理
    left = max(A[i + 1] - power, 0)
    used = A[i + 1] - left
    A[i + 1] = left
    ans += used  # 減った数
print(ans)


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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

template<i64 M>
struct modint {
    i64 x;

    constexpr modint(const i64 y = 0) noexcept : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

    constexpr modint operator-() const noexcept { return modint(-x); }
    constexpr modint operator+(const modint &rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept { return modint(*this) /= rhs; }

    constexpr modint &operator+=(const modint &rhs) noexcept {
        x += rhs.x;
        if (x >= M) x -= M;
        return *this;
    }

    constexpr modint &operator-=(const modint &rhs) noexcept {
        if (x < rhs.x) x += M;
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint &rhs) noexcept {
        x = x * rhs.x % M;
        return *this;
    }

    constexpr modint &operator/=(const modint &rhs) noexcept {
        i64 a = rhs.x, b = M, u = 1, v = 0;
        while (b > 0) {
            i64 t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        *this *= u;
        return *this;
    }

    friend ostream &operator<<(ostream &os, const modint &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, modint &a) {
        i64 t;
        is >> t;
        a = modint(t);
        return is;
    }
};

constexpr i64 MOD = 1 ? 1'000'000'007 : 998'244'353;
using m64 = modint<MOD>;
constexpr m64 operator"" _m(unsigned long long n) { return m64(n); }

i64 n;
vector<vector<i64>> a;
vector<optional<m64>> dp;

m64 dfs(i64 depth, i64 used) {
    if (depth == n) return used == (1 << n) - 1;
    if (dp[used]) return *dp[used];

    m64 res = 0;
    for (i64 i = 0; i < n; i++) {
        if ((used >> i) & 1) continue;
        if (!a[depth][i]) continue;
        res += dfs(depth + 1, used | (1 << i));
    }
    return dp[used].emplace(res);
}

void solve() {
    cin >> n;
    a.resize(n, vector<i64>(n));
    for (auto& e : a) for (auto& f : e) cin >> f;
    dp.resize(1 << n);
    cout << dfs(0, 0) << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 35916
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

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

  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  rep(i, n) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());

  int ans = 0;
  rep(i, n-1) {
    if (x >= a.at(i)) {
      x -= a.at(i);
      ans++;
    }
  }

  if (x == a.at(n-1)) {
    ans++;
  }

  cout << ans << endl;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,x;
int l[125];
int d[125];

int main(){
    cin>>n>>x;
    REP(i,n)cin>>l[i];
    d[0] = 0;
    FOR(i,1,n+1)d[i] = d[i-1]+l[i-1];
    int ans = 0;
    REP(i,n+1)ans += (d[i]<=x);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

int main(){
    int n, h[105];
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        scanf("%d", &h[i]);
    }
    int c=1;
    for(int i=1;i<n;i++){
        bool b=true;
        for(int j=i;j>=0;j--){
            if(h[i]<h[j]){
                b=false;
            }
        }
        if(b)
            c++;
    }
    printf("%d", c);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>

int main(){
  char arrayA[36][3];
  char arrayB[36][3];
  char str[3];

  int i,num,j,tmp,min,ans = 1;
  int arrayC[36];
  int arrayD[36];

  scanf("%d",&num);
  for(i = 0;i < num;i++){
    scanf("%s",arrayA[i]);
    strcpy(arrayB[i],arrayA[i]);
    arrayC[i] = arrayD[i] = arrayA[i][1] - '0';
  }

  for(i = 0;i < num;i++){
    for(j = num - 1;j > i;j--){
      if(arrayC[j] < arrayC[j - 1]){
        tmp = arrayC[j];
        arrayC[j] = arrayC[j - 1];
        arrayC[j - 1] = tmp;

        strcpy(str,arrayA[j]);
        strcpy(arrayA[j],arrayA[j - 1]);
        strcpy(arrayA[j - 1],str);
      }
    }
  }

  for(i = 0;i < num;i++){
    if(i != num - 1){
      printf("%s ",arrayA[i]);
    }
    else{
      printf("%s\n",arrayA[i]);
      puts("Stable");
    }
  }

  for(i = 0;i < num - 1;i++){
    min = i;
    for(j = i + 1;j < num;j++){
      if(arrayD[j] < arrayD[min]){
        min = j;
      }
    }
    if(min != i){
      tmp = arrayD[i];
      arrayD[i] = arrayD[min];
      arrayD[min] = tmp;

      strcpy(str,arrayB[i]);
      strcpy(arrayB[i],arrayB[min]);
      strcpy(arrayB[min],str);
     }
  }

  for(i = 0;i < num;i++){
    if(strcmp(arrayA[i],arrayB[i])){
      ans = 0;
    }
    if(i != num - 1){
      printf("%s ",arrayB[i]);
    }
    else{
      printf("%s\n",arrayB[i]);
    }
  }

  if(ans){
    puts("Stable");
  }
  else{
    puts("Not stable");
  }
  return 0;
}



Measured memory_bytes: 2112
#include<iostream>
#include<string>
typedef long long ll;

using namespace std;

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


Measured memory_bytes: 3124
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    string s;
    scan(s);

    int n = s.length.to!int;

    auto set = redBlackTree!dchar('A', 'C', 'G', 'T');

    int ans;

    foreach (l ; 0 .. n) {
        foreach (r ; l + 1 .. n + 1) {
            bool ok = true;

            foreach (ch ; s[l .. r]) {
                if (!(ch in set)) ok = false;
            }

            if (ok) chmax(ans, r - l);
        }
    }

    writeln(ans);
}








void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
  #define DUMP(i) 
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());

using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

struct Edge{
public:
  int from,to,cost;
  Edge(){}
  Edge(int _from,int _to,int _cost){
    from = _from;
    to = _to;
    cost = _cost;
  }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

const int EPS = 1e-9;
const int MOD = 1e9+7;


int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,l;
  cin >> n >> l;
  vector<string> S;
  REP(i,n){
    string s;
    cin >> s;
    S.push_back(s);
  }
  sort(ALL(S));
  REP(i,n){
    cout << S[i];
  }
  cout << endl;
  return 0;
}



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

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        private struct Pos
        {
            public int row;
            public int col;
        }
        private const long MOD = 1000000007;
        static void SolveA(string[] args)
        {
            var hwd = ReadAndParseIntArr();
            int h = hwd[0];
            int w = hwd[1];
            int d = hwd[2];
            int[,] A = new int[h, w];
            for (int i = 0; i < h; ++i)
            {
                var a = ReadAndParseIntArr();
                for (int j = 0; j < w; ++j)
                {
                    A[i, j] = a[j];
                }
            }
            var coordinate = new Pos[h * w + 1];
            for(int i=0;i<h;++i)
            {
                for(int j=0;j<w;++j)
                {
                    coordinate[A[i, j]] = new Pos() { row = i, col = j };
                }
            }
            // 累積和テーブル
            var table = new long[h * w + 1];
            for(int i=d+1;i<=h*w;++i)
            {
                Pos spos = coordinate[i - d];
                Pos dpos = coordinate[i];
                table[i] = table[i - d] + Math.Abs(dpos.row - spos.row) + Math.Abs(dpos.col - spos.col);
            }

            int q = ReadAndParseInt();
            int[] L = new int[q];
            int[] R = new int[q];
            for(int i=0;i<q;++i)
            {
                var lr = ReadAndParseIntArr();
                L[i] = lr[0];
                R[i] = lr[1];
            }

            for(int i=0;i<q;++i)
            {
                long cost = 0;
                int l = L[i];
                int r = R[i];

                int idx = l % d;
                cost = table[r] - table[l];
                Console.WriteLine(cost);
            }
        }
        private static void Find(int x, Pos[] coordinate, out int row, out int col)
        {
            row = coordinate[x].row;
            col = coordinate[x].col;
        }
    }
}

Measured memory_bytes: 18492
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,x;
	cin>>n>>m>>x;
	int b[m];
	int s1=0,s2=0,s=0;
	for(int i=1;i<=m;i++) cin>>b[i];
	int a[n]={0};
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(i==b[j]) a[i]=1;
		}
	} 
	for(int i=x;i<=n;i++){
		if(a[i]==1) s1++;
	}
	for(int i=x;i>=1;i--){
		if(a[i]==1) s2++;
	}
	if(s1>=s2) cout<<s2;
	else cout<<s1;
	return 0;
}

Measured memory_bytes: 256
X = int(input())

dp = [0] * (X + 105 + 1)
dp[0] = 1

for i in range(X):
    if dp[i] == 1:
        for c in [100, 101, 102, 103, 104, 105]:
            dp[i+c] = 1

print(dp[X])

Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	string s;
	cin >> s;
	cout << s[0] << s.length()-2 << s[s.length()-1] << endl;
}

Measured memory_bytes: 3620
import java.util.Scanner;

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

        long prime = 1000000007;
        
		if((X + Y) % 3 != 0){
			System.out.println(0);
		}
		else{
			long n = (X + Y) / 3;
			if(Math.abs(X - Y) > n)
				System.out.println(0);
			else{
				long e = X - n;
				long n1 = 1;
				long e1 = 1;
				for(int i = 0; i < e; i++){
					n1 = (n1 * (n - i)) % prime;
					e1 = (e1 * (e - i)) % prime;
				}
				long nCe = (n1 * modPow(e1, prime - 2, prime))%prime;

				System.out.println((nCe >= 0)?nCe:nCe+prime);
			}
		}
	}
	
    private static long modPow(long a, long n, long p){
    	long ans = 1;
    	while (n > 0){
    		if((n & 1) == 1){
    			ans = (ans * a) % p;
    		}
			a = (a * a) % p;
			n >>= 1;
    	}
    	return(ans);
    }
}

Measured memory_bytes: 21972
#include<iostream>
using namespace std;
int main() {
    int n, x, count = 0;
    while (1) {
        cin >> n >> x;
        count = 0;
        if (n==0 && x==0) break;
        for(int i=1; i<=n; i++) {
            for (int j=i+1; j<=n; j++) {
                if(x-i-j<=n && x-i-j!=i && x-i-j!=j && x-i-j > j) {
                    count += 1;
                }
            }
        }
        cout << count << endl;
    }
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,c,d,e;
  cin>>a>>b;
  c=a*b;
  d=a+b;
  e=a-b;
  if(c>=d && c>=e)
    cout<<c<<endl;
  else if(d>=c && d>=e)
    cout<<d<<endl;
  else 
    cout<<e<<endl;
  
  
  return(0);
}


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

int hmax, wmax;
vector<vector<bool>> mat;

int search(int& hs, int& ws, int& hd, int& wd)
{
	if (mat[hs][ws] || mat[hd][wd]) {
		return 0;
	}

	vector<vector<bool>> check = mat;
	check[hs][ws] = true;
	queue<pair<int ,int>> q;
	q.push(pair<int, int>(hs, ws));

	int count = 0;
	while (1)
	{
		size_t qNum = q.size();
		for (size_t i = 0; i < qNum; ++i) {
			const pair<int,int>& qt = q.front();
			if (qt.first == hd && qt.second == wd) {
				return count;
			}

			if (qt.first != 0 && !check[qt.first - 1][qt.second]) {
				q.push(pair<int, int>(qt.first - 1, qt.second));
				check[qt.first - 1][qt.second] = true;
			}
			if (qt.first != hmax - 1 && !check[qt.first + 1][qt.second]) {
				q.push(pair<int, int>(qt.first + 1, qt.second));
				check[qt.first + 1][qt.second] = true;
			}
			if (qt.second != 0 && !check[qt.first][qt.second - 1]) {
				q.push(pair<int, int>(qt.first, qt.second - 1));
				check[qt.first][qt.second - 1] = true;
			}
			if (qt.second != wmax - 1 && !check[qt.first][qt.second + 1]) {
				q.push(pair<int, int>(qt.first, qt.second + 1));
				check[qt.first][qt.second + 1] = true;
			}
			q.pop();
		}
		++count;
		if (q.empty()) {
			// おかしい
			break;
		}
	}

	return 0;
}

int main()
{
	cin >> hmax >> wmax;
	mat.resize(hmax, vector<bool>(wmax, false));
	for (int h = 0; h < hmax; ++h) {
		string s;
		cin >> s;
		for (int w = 0; w < wmax; ++w) {
			mat[h][w] = (s[w] == '#');
		}
	}

	int ret = 0;
	for (int h = 0; h < hmax; ++h) {
		for (int w = 0; w < wmax; ++w) {
			// h, w
			
			int hd = h;
			int wd = w + 1;
			while (!(hd == hmax -1 && wd == wmax)) {
				if (wd == wmax) {
					++hd;
					wd = 0;
				}
				int temp = search(h,w,hd,wd);
				if (ret < temp) {
					ret = temp;
				}
				++wd;
			}
		}
	}

	cout << ret << endl;
	return 0;
}

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

int main() {
	int W, H, N;
	cin >> W >> H >> N;
	int xf = 0;
	int yf = 0;
	for(int i = 0;i < N;i++){
		int x, y, a;
		cin >> x >> y >> a;
		if(a == 1){
			xf = max(x,xf);
		}
		else if(a == 2){
			W = min(x,W);
		}
		else if(a == 3){
			yf = max(y,yf);
		}
		else if(a == 4){
			H = min(y,H);
		}
	}
	if(W-xf < 1 || H-yf < 1){
		cout << 0 << endl;
		return 0;
	}
	else{
		cout << (W-xf)*(H-yf) << endl;
		return 0;
	}
}

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

int main()
{
    long long n, k, t, i;
    bool check = true;
    cin >> n >> k;
    t = n;
    i = n / k;
    n = n - k * i;
    if (n == 0)
    {
        cout << 0;
    }
    else
    {
        while (check)
        {
            n = abs(n - k);
            if (t <= n)
            {
                check = false;
            }

            t = min(t, n);
        }
        cout << t;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>
#include<queue>


using namespace std;
#define mod 1000000007
#define ll long long 

ll N, x, K;

struct Matrix {

    vector< vector<int> > mat; 
    int n_rows, n_cols;

    Matrix(vector< vector<int> > values): mat(values), n_rows(values.size()),
        n_cols(values[0].size()) {}

    static Matrix identity_matrix(int n){

        vector< vector<int> > values(n, vector<int>(n, 0));
        for(int i = 0; i < n; i++)
            values[i][i] = 1;
        return values;
    }

    Matrix operator*(const Matrix &other) const {
        int n = n_rows, m = other.n_cols;
        vector< vector<int> > result(n_rows, vector<int>(m, 0));
        for(int i = 0; i < n; i++)
            for(int j = 0; j < m; j++) {
                for(int k = 0; k < n_cols; k++) {
                    result[i][j] = (result[i][j] + mat[i][k] * 1ll * other.mat[k][j]) % mod;
                }
            }
        return Matrix(result);
    }

    inline bool is_square() const{
        return n_rows == n_cols;
    }
};

Matrix fast_exponentiation(Matrix m, ll power){
    assert(m.is_square());
    Matrix result = Matrix::identity_matrix(m.n_rows);

    while(power) {
        if(power & 1)
            result = result * m;
        m = m * m;
        power >>= 1;
    }

    return result;
}


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

	vector< vector<int> > mat(N);

	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			cin>>x;
			mat[i].push_back(x);
		}
	}
	Matrix M(mat);


	M = fast_exponentiation(M, K);

	// cout<<"after power"<<endl;
	ll sum = 0;

	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++) {
			sum += M.mat[i][j];
			sum %= mod;
		}
	}
	cout<<sum<<endl;
		

}

Measured memory_bytes: 384
class dice:
	def __init__(self,data):
		self.faces = data
	
	def turn(self,direction):
		if direction == 'N':
			idx = [1,5,2,3,0,4]
			self.faces = [self.faces[i] for i in idx]
		elif direction == 'S':
			[self.turn('N') for i in range(3)]
		elif direction == 'E':
			idx = [3,1,0,5,4,2]
			self.faces = [self.faces[i] for i in idx]
		elif direction == 'W':
			[self.turn('E') for i in range(3)]
		elif direction == 'c':
			self.turn('N')
			self.turn('W')
			self.turn('S')

if __name__ == '__main__':
	data1 = [int(i) for i in input().split()]
	data2 = [int(i) for i in input().split()]
	d1 = dice(data1)
	d2 = dice(data2)
	
	for o in 'cccWcccEcccNcccWcccWccc':
		if d1.faces == d2.faces:
			break
		else:
			d2.turn(o)
	if d1.faces == d2.faces:
		print('Yes')
	else:
		print('No')

Measured memory_bytes: 7780
s = input()
a,b,c,d = int(s[0]),int(s[1]),int(s[2]),int(s[3])
# ++++
if sum([a,b,c,d]) == 7:
  print("{}+{}+{}+{}=7".format(a,b,c,d))
# ----
elif a-b-c-d == 7:
  print("{}-{}-{}-{}=7".format(a,b,c,d))
elif a+b-c-d == 7:
  print("{}+{}-{}-{}=7".format(a,b,c,d))
elif a-b+c-d == 7:
  print("{}-{}+{}-{}=7".format(a,b,c,d))
elif a-b-c+d == 7:
  print("{}-{}-{}+{}=7".format(a,b,c,d))
elif a+b+c-d == 7:
  print("{}+{}+{}-{}=7".format(a,b,c,d))
elif a+b-c+d == 7:
  print("{}+{}-{}+{}=7".format(a,b,c,d))
elif a-b+c+d == 7:
  print("{}-{}+{}+{}=7".format(a,b,c,d))

Measured memory_bytes: 3064
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(arr[k-1])

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

int n;

#define MAX 1002
int room[MAX][MAX];

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			room[i][j]=0;
			if((i+j)&1)continue;
			room[i][j]=true;
		}
	}
	for(int i=0;i<n;i++){
		room[i][0]=true;
	}
	for(int i=0;i<n;i++){
		if(i==n-1||i%3==0){
			
		}
		else{
			continue;
		}
		for(int j=0;j<n;j++){
			room[i][j]=true;
		}
	}
	/*for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cout<<room[i][j];
		}
		cout<<endl;
	}*/
	vector<pair<int,int> > v;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if((i+j)%2==0)continue;
			if(room[i][j]){
				v.push_back(make_pair(i,j));
			}
		}
	}
	cout<<v.size()<<endl;
	for(auto el:v){
		cout<<el.first<<" "<<el.second<<endl;
	}
	return 0;
}


Measured memory_bytes: 6896
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>

#define mod 1000000007
#define MAX_N 100000

using namespace std;

int A[200000], N, i, K;

bool possible(int lenght){
    int counter = 0;
    for(i = 0; i < N; ++i)
        counter += (A[i] + lenght - 1) / lenght - 1;
    return counter <= K;

}

int main()
{
    int d, h, middle;

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

    d = 1; h = 1000000000;
    while(d < h){
        middle = (d + h) / 2;
        if(possible(middle))
            h = middle;
        else
            d = middle + 1;
    }

    printf("%d", d);

    return 0;
}


Measured memory_bytes: 2504
#include <iostream>
#include <algorithm>

using namespace std ;

int powd(int x , int y){
    if(y==0){
        return 1;
    }

    else{
        return x*powd(x,y-1);
    }
}


int main(){
    int r;
    int D;
    int x2000;

    if(scanf("%d %d %d",&r,&D,&x2000) != 3){
        exit(1);
    };

    int s=1;

    for(int i=1;i<11;i++){
        
        printf("%d\n",powd(r,i)*x2000-D*s);
        s+=powd(r,i);
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
void movetoN();
void movetoS();
void movetoE();
void movetoW();
string str;
int frontside,backside,rightside,leftside,upside,downside,yandere;
int main(){
	cin>>upside>>backside>>rightside>>leftside>>frontside>>downside;
	cin>>str;
	for(int i=0;i<str.size();i++){
		switch(str[i]){
		case 'N':
			movetoN();
			break;
		case 'S':
			movetoS();
			break;
		case 'E':
			movetoE();
			break;
		case 'W':
			movetoW();
			break;
		}
	}
	cout<<upside<<endl;
	return 0;
}
void movetoN(){
	yandere=upside;
	upside=backside;
	backside=downside;
	downside=frontside;
	frontside=yandere;
	return;
}
void movetoS(){
	yandere=upside;
	upside=frontside;
	frontside=downside;
	downside=backside;
	backside=yandere;
	return;
}
void movetoE(){
	yandere=upside;
	upside=leftside;
	leftside=downside;
	downside=rightside;
	rightside=yandere;
	return;
}
void movetoW(){
	yandere=upside;
	upside=rightside;
	rightside=downside;
	downside=leftside;
	leftside=yandere;
	return;
}

Measured memory_bytes: 3180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int a; cin >> a;
    set<int> s;
    rep(i,a){
        int b; cin >> b;
        s.insert(b);
    }
    cout << s.size() << endl;

    return 0;
}

Measured memory_bytes: 256