akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

int N;
const int MAX_E=100;
int label[MAX_E];
priority_queue<int,vector<pair<int,pair<int,int> > >,greater<pair<int,pair<int,int> > > > pq;

int main(){
  cin>>N;
  REP(i,N)
    label[i]=i;
  REP(i,N){
    REP(j,N){
      int a;cin>>a;
      if(a>=0&&i>j){
	pq.push(make_pair(a,make_pair(i,j)));
      }
    }
  }
  int size=0;
  while(!pq.empty()){
    int cost=pq.top().first;
    pair<int,int> e=pq.top().second;
    //printf("%d,%d,%d\n",cost,e.first,e.second);
    pq.pop();
    if(label[e.first]!=label[e.second]){
      int tmp=label[e.second];
      size+=cost;
      REP(i,N){
	if(label[i]==tmp)
	  label[i]=label[e.first];
	//printf("%d ",label[i]);
      }
      //printf("\n");
    }
  }
  printf("%d\n",size);
}

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

int main(){

    int N;
    string S;
    cin >> N;
    cin >> S;


    int ans = 3e+5;
    int w[300000] = {}, e[300000] = {};

    for( int i = 0; i < N-1; i++ ){
        w[i+1]= w[i];
        if( S[i] == 'W' ) w[i+1]++;
    }

    for( int i = N-1; i > 0; i-- ){
        e[i-1]= e[i];
        if( S[i] == 'E' ) e[i-1]++;
    }

    for( int i = 0; i < N; i++ ){
        ans = min( ans, w[i]+e[i] );
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3076
D={}
R=range(8)
def f1(i,p):
  dp=0
  if i==0 and p%4<3: dp=1
  elif i==1 and p%4>0: dp=-1
  elif i==2 and p<4: dp=4
  elif i==3 and p>3: dp=-4
  return dp
  
def f():
  global D
  D={tuple(R):0}
  SP=[R]
  while SP:
    a=SP.pop(0)
    p=a.index(0)
    for i in R[:4]:
      dp=f1(i,p)
      if dp==0: continue
      x=a[:]
      x[p],x[p+dp]=x[p+dp],x[p]
      tx=tuple(x)
      if tx in D: continue
      SP.append(x)
      D[tx]=D[tuple(a)]+1
  return

import sys
f()
for x in sys.stdin:
  A=map(int,x.split(" "))
  print D[tuple(A)]

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n,k;cin>>n>>k&&n|k;){
		vl a(n);
		rep(i,n) cin>>a[i];
		vl sum(n+1),psum(n+1);
		rep(i,n){
			sum[i+1]=sum[i]+a[i];
			psum[i+1]=psum[i]+max(a[i],0ll);
		}
		ll res=0;
		rep(i,n-k+1)
			res=max(res,psum[i]+max(sum[i+k]-sum[i],0ll)+psum[n]-psum[i+k]);
		cout<<res<<endl;
	}
}


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


int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;
  if(n <= k) cout << n*x << endl;
  else cout << k*x + (n-k)*y << endl;
  return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(n); for(auto&&i:a)cin>>i;
	vector<int64_t>sum(n+2); sum.at(0)=sum.at(1)=0;
	sum.at(2)=a.at(0),sum.at(3)=a.at(1);
	for(int i=4;i<n+2;++i){
		sum.at(i)=sum.at(i-2)+a.at(i-2);
	}
	cout<<sum.at(n+1)-sum.at(0)-sum.at(n)+sum.at(1)+sum.at(1)-sum.at(0);
	for(int i=3;i<n+2;++i){
		if(i&1)cout<<" "s<<sum.at(n)-sum.at(i-2)-sum.at(n+1)+sum.at(i-1)+sum.at(i-1)-sum.at(i-2);
		else cout<<" "s<<sum.at(n+1)-sum.at(i-2)-sum.at(n)+sum.at(i-1)+sum.at(i-1)-sum.at(i-2);
	}
	cout<<"\n"s;
}


Measured memory_bytes: 4484
import java.util.Scanner;

class Main{

	static char[][] map;
	static int H;
	static int W;
	static	int D ;
	static	int G ;
	static	int[] p;
	static	int[] c;
	static int ans = 100000000;

	public static void main(String[] args) {



		Scanner sc = new Scanner(System.in);			//文字の入力
		String S = sc.next();
		String T = sc.next();
		
		for(int i = 0;i < S.length();i++){
			
			int[] data = new int[10000000];
			for(int j = i;j < S.length();j++){
				if(S.charAt(i) == S.charAt(j))
				data[j] = 1;
			}
			
			
			
			for(int j = i;j < S.length();j++){
				if(data[j] == 1){
					if(T.charAt(i) != T.charAt(j)){
//						System.out.println("1");
//
						System.out.println("No");
						return;
					}
				}else{
					
					if(T.charAt(i) == T.charAt(j)){
//						System.out.println("i  "+i+" j "+j);
//
						System.out.println("No");
						return;
					}
				}
			}
			
			String del =String.valueOf(S.charAt(i));
			S = S.replace(del, "");
			
			
			
			String dele =String.valueOf(T.charAt(i));
			T = T.replace(dele, "");
			
		


			
			i--;
			
			
		}
		System.out.println("Yes");


	}



}





Measured memory_bytes: 679508
#include<iostream>
using namespace std;
int main(){
  int a;
  cin>>a;
  int b[3];
  for(int i=0;i<3;i++){
    b[i]=a%10;
    a=a/10;
    if(b[i]==1)
      b[i]=9;
    else
      b[i]=1;
  }
  
  for(int i=2;i>=0;i--){
    cout<<b[i];
  }
  return 0;
}


Measured memory_bytes: 3572
#include<cstdio>
long long const p=1000000007;
long long factorial(long long n){
    if(n<=1)return 1;
    else return n*factorial(n-1)%p;
}
int main(){
    long long n;
    scanf("%lld",&n);
    printf("%lld",factorial(n));
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define FORR(I,A,B) for(int I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<long double> a(n);
	FOR(i,0,n)cin>>a[i];
	long double heikin=0;
	FOR(i,0,n)heikin+=a[i];
	ll ans = 0;
	long double ansp = a[0];
	heikin /= (long double)n;
	FOR(i,0,n){
		if(abs(heikin-a[i])<abs(heikin-ansp)){ans=i;ansp=a[i];}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
/*vector<Type> v;
vector<Type> v();
vector<Type> v(n);
vector<Type> v(n, d);
vector<vector<Type>> vv;
vector<vector<Type>> vv();
vector<vector<Type>> vv(n);
vector<vector<Type>> vv(n, vector<Type>(m));
vector<vector<Type>> vv(n, vector<Type>(m, d));*/

int main() {
 char a;
 cin >> a;
 a+=1;
 cout<<a;
}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>//sort
#include <vector>
#include <string>
#include <map>//pair
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
  string S;
  cin >> S;
  rep(i, S.length())cout << "x";
  cout << endl;
}


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

using namespace std;

int k, a[200007];

int ok(int g)
{
    if (g < 0) return g + k;
    return g;
}

int main()
{
//    freopen("TEST.INP", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> k >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    a[n + 1] = a[1];
    int ans = INT_MAX;
    for (int i = 2; i <= n + 1; ++i)
        ans = min(ans, k - ok(a[i] - a[i - 1]));
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
# https://atcoder.jp/contests/agc013/tasks/agc013_a

n = gets.to_i
nums = gets.split.map(&:to_i)

res = 1

is_incrementing = nil
prev = nums[0]

nums[1..-1].each do |i|
  # if prev.nil?
  #   prev = i
  #   next
  # end]
  next if i == prev
  if is_incrementing.nil?
    is_incrementing = i > prev
  else
    if is_incrementing != i > prev
      is_incrementing = nil
      res += 1
    end
  end
  prev = i
end

puts res

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

int main () {
  int N, K;
  cin >> N >> K;
  //cout << N << K << endl;
  
  int ans = 1;
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      ans *= K;
    } else {
      ans *= (K - 1);
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int n, v;
  cin >> n;
  vector<vector<int>> V(2, vector<int>(100001));
  for (int i = 0; i != n; ++i) {
    cin >> v;
    ++V[i % 2][v];
  }

  vector<vector<int>> I(2, vector<int>(100001));
  for (auto i : {0, 1}) {
    iota(begin(I[i]), end(I[i]), 1);
    sort(begin(I[i]), end(I[i]),
         [&](int a, int b) { return V[i][a] > V[i][b]; });
  }
  auto ans = n - ((I[0][0] != I[1][0]) ? V[0][I[0][0]] + V[1][I[1][0]]
                                    : max(V[0][I[0][0]] + V[1][I[1][1]],
                                          V[0][I[0][1]] + V[1][I[1][0]]));
  cout << ans << endl;
}


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

using ll=long long;
const ll MOD=1e9+7;

ll powm(ll x,ll k){
    ll res=1;
    while(k){
        if(k&1) res=res*x%MOD;
        k>>=1;
        x=x*x%MOD;
    }
    return res;
}
ll modInv(ll x){
    return powm(x,MOD-2);
}
int main(){
    int n;
    cin>>n;
    vector<ll> fact(n+1);
    fact[0]=1;
    for(int i=1;i<=n;i++){
        fact[i]=fact[i-1]*i%MOD;
    }
    vector<ll> factInv(n+1);
    factInv[n]=modInv(fact[n]);
    for(int i=n-1;i>=0;i--){
        factInv[i]=factInv[i+1]*(i+1)%MOD;
    }
    vector<ll> pow2(n+1);
    pow2[0]=1;
    for(int i=1;i<=n;i++){
        pow2[i]=pow2[i-1]*2%MOD;
    }
    ll res=fact[n-1];
    auto comb=[&](int n,int k){
        return fact[n]*factInv[k]%MOD*factInv[n-k]%MOD;
    };
    auto cnt=[&](int k){
        int q=n-2-(k-1);
        int p=2*(k-1)-(n-2);
        if(q<=0) return 0LL;
        else if(p<0) return comb(n-1,k);
        else return ((comb(n-1,k)-comb(p+q,p))%MOD+MOD)%MOD;
    };
    for(int k=1;k<=n-1;k++){
        res+=cnt(k)*fact[n-1-k]%MOD*fact[k]%MOD;
        res%=MOD;
    }
    cout<<res<<endl;
    
    return 0;
}

Measured memory_bytes: 23680
#include<iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main()
{
    int x[5];
    int k;

    for(int i = 0; i < 5; i++){
        cin >> x[i];
    }
    cin >> k;

    for(int i = 0; i < 4; i++){
        for(int j = i + 1; j < 5; j++){
            if(abs(x[i]-x[j]) > k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }

    cout << "Yay!" << endl;

    return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce
n = int(input())
a_list = list(map(int,input().split()))

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def lcm_base(a,b):
    return a*b//gcd(a,b)

def lcm(numbers):
    return reduce(lcm_base,numbers,1)

m = lcm(a_list)-1
cost = 0
for a in a_list:
    cost += m%a
print(cost)

Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< long long > vll;
typedef pair< int,int > ii;
typedef long long ll;
#define fast_cin() ios_base::sync_with_stdio(0); cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = n-1; i>=0 ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define sz(a) int(a.size())
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(container,it) for(auto it=container.begin();it!=container.end();it++)
#define present(container, element) (container.find(element) != container.end())
#define vpresent(container, element) (find(all(container),element) != container.end()) //for vectors
 
int main()
{
   /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); 
    #endif*/
    fast_cin();
    int n,k;cin>>n>>k;
    vi a(n);
    rep(i,n)
    cin>>a[i];
    sort(all(a));
    if(lower_bound(a.begin(),a.end(),k)!=a.end())
        cout<<a.end()-lower_bound(a.begin(),a.end(),k);
    else
        cout<<0;

    return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();

        double total_rate = 0;

        for (int p = 1; p <= n; p++){
            double rate = 1.0/n;
            int now = p;
            while(now <= k-1){
                now = now * 2;
                rate = rate/2;
            }
            total_rate += rate;
        }

        System.out.print(total_rate);

    }
}




Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define LLI long long int
#define pii pair<int,int>
#define fst first
#define sec second
#define ULTRA 2134567890
#define de(x) if(x!=0 && MODE==x)
#define MODE 0
using namespace std;

int main() {
    int i,j;
    LLI N;

    scanf("%lld", &N);
    LLI len = 0;
    LLI add = 1;
    LLI maxi = 0;
    for( len = 0; maxi < N; len++) {
        add *= 26;
        maxi += add;
    }
    maxi -= add;
    N -= maxi;
    add /= 26;
    de(1) printf("%lld %lld\n", len, add);
    string ans;
    N--;
    for( i=0; i<len; i++) {
        for( j=0; j<26 && N - (j+1)*add >= 0; j++);
        ans.push_back( 'a' + j);
        N -= j*add;
        add /= 26;
    }
    cout<<ans<<"\n";


    return 0;
}

//
//          ___ ___  __________  __________
//         /////\  \/\   ______\/\\\\\\\\\\\  Code by ~Ice Tea~ of
//        //// \ \  \ \  \_____/\ \\\\_____/      New Empire of CHSH ...
//       ////   \ \  \ \  \      \ \\\\\\\\\\\
//      ////__   \ \  \ \  \      \ \\\\_____/
//     ///////\   \ \  \ \  \______\ \\\\_______   ________
//    ////____/    \ \__\ \___   ___\ \\\\\\\\\\\ _\  ___  \_
//   /__/           \/__/\/__/\  \__/\ \\\\_____//\  .\_/\_  \
//                           \ \  \   \ \\\\\\\\\\\\  \_\/_\  \
// ... with the AC Power of   \ \  \   \ \\\\_____/ \   _____  \
//   The Great Tsundere Doggy. \ \  \   \ \\\\     \ \  \  \ \  \
//                              \ \__\   \ \\\\\\\\\\ \__\  \ \__\
//                               \/__/    \/________/\/__/   \/__/
//


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

//1-indexedであることに注意

inline int Calcu(int a,int b){
    return std::min(a,b);
}

class SegTree{
    private:
        int n;
        int g;
        std::vector<int> data;
    public:

        SegTree(std::vector<int> a, int _g){
            g = _g;
            for (n = 1; n < (int) a.size(); n *= 2);
            data.resize(n * 2, g);
            for (int i = 0; i < (int) a.size(); i++) data[i + n] = a[i];
            for (int i = n - 1; i >= 1; i--)
                data[i] = Calcu(data[i * 2], data[i * 2 + 1]);
        }
        int min_rec(int l, int r, int node, int node_l, int node_r) {
            if (node_r <= l || node_l >= r) return g;
            if (node_l >= l && node_r <= r) return data[node];
            int mid = (node_l + node_r) / 2;
            return Calcu(
                min_rec(l, r, node * 2, node_l, mid),
                min_rec(l, r, node * 2 + 1, mid, node_r));
        }

        int min(int l,int r){
            return min_rec(l,r,1,0,n);
        }

        void assign(int index, int val){
            data[index += n] = val;
            for(;index /= 2;)
                data[index] = Calcu(data[index * 2],data[index * 2 + 1]);
        }
};



int main()
{
    int n,q;
    std::cin >> n >> q;
    std::vector<int> tmp(n,2147483647);
    SegTree tree(tmp,2147483647);
    std::vector<int> ans;
    for(int i = 0; i < q; i++){
        int flag; std::cin >> flag;
        int x,y;
        std::cin >> x >> y;

        if(flag == 0){
            tree.assign(x,y);
        }else{
            ans.push_back(tree.min(x, y + 1));
        }
    }
    for(int i = 0; i < (int)ans.size(); i++)std::cout << ans[i] << std::endl;
}


Measured memory_bytes: 4748
#B
n = int(input())
count=0
mcount=0
for i in range(n):
    a,b = list(map(int, input().split()))
    if a==b:
        count+=1
        if mcount<count:
            mcount = count
            if mcount==3:
                break
    else:
        count=0
if mcount==3:
    print("Yes")
else:
    print("No")

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


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a + w >= b && b + w >= a) {
			System.out.println(0);
		} else if (a + w < b) {
			System.out.println(b - (a + w));
		} else if (a > b + w) {
			System.out.println(a - (b + w));
		}
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

string LCS(string& s, string& t) {
    vector<vector<long long>> dp(t.size(), vector<long long>(s.size(), 0));

    for(long long i = 0LL; i < t.size(); ++i) {
        if (s[0] != t[i] and (i == 0 or dp[i-1][0] == 0)) dp[i][0] = 0;
        else dp[i][0] = 1;
    }
    for(long long j = 0; j < s.size(); ++j) {
        if (t[0] != s[j] and (j == 0 or dp[0][j-1] == 0)) dp[0][j] = 0;
        else dp[0][j] = 1;
    }

    for(long long j = 1; j < s.size(); ++j) {
        for(long long i = 1; i < t.size(); ++i) {
            if (t[i] == s[j]) dp[i][j] = dp[i-1][j-1] + 1;
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    string LCS = "";
    long long nowi = t.size()-1, nowj = s.size()-1, nowLCS = dp[nowi][nowj];

    while(nowi >= 0 and nowj >= 0 and nowLCS > 0) {
        if (t[nowi] == s[nowj]) {
            LCS += t[nowi];
            --nowi; --nowj; --nowLCS;
            continue;
        }
        else if (nowi > 0 and dp[nowi-1][nowj] == dp[nowi][nowj]) { --nowi; continue; }
        else if (nowj > 0 and dp[nowi][nowj-1] == dp[nowi][nowj]) { --nowj; continue; }
    }

    reverse(LCS.begin(), LCS.end());
    return LCS;
}

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

    string s, t;
    cin >> s >> t;
    
    cout << LCS(s, t) << endl;
}

Measured memory_bytes: 70784
n = int(input())
a = []
b = []
for i in range(n):
    a.append(int(input()))

next = a[0] - 1
b.append(next + 1)
for i in range(n):
    next = a[next] - 1
    b.append(next + 1)
print(b.index(2) + 1) if 2 in b else print(-1)

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

len_s = len(S)
len_t = len(T)


def calc_diff(s1, s2):
    c = 0
    for i in range(len_t):
        if s1[i] != s2[i]:
            c += 1
    return c


ans = float('inf')
for i in range(len_s - len_t + 1):
    sub_s = S[i:i + len_t]
    c = calc_diff(sub_s, T)
    ans = min(ans, c)

print(ans)

Measured memory_bytes: 9132
#include <stdio.h>

#define ARRAY_MAX 101												/* ??°???????????§????´???° */
#define ZERO 0														/* 0??????????????? */
#define ONE 1														/* 1??????????????? */

static void view_array( void );

unsigned short usG_Darray[ ARRAY_MAX ];								/* ?????????????±???°??? */
unsigned char ubG_Dcount;											/* ????´???° */

int main( void )
{
	unsigned char ubW_Ci;											/* ????????????i */
	unsigned char ubW_Cj;											/* ????????????j */
	unsigned short usW_Dtrade;										/* ???????????¨?????° */

	scanf("%d", &ubG_Dcount);										/* ????´???°???????????? */
	/* ??°?????????????????¨????????? */
	for( ubW_Ci = ZERO; ubW_Ci < ubG_Dcount; ubW_Ci++){
		scanf("%d", &usG_Darray[ ubW_Ci ]);							/* ??°??????????????? */
	}

	/* ?????\???????????¨????????? */
	for( ubW_Ci = ONE; ubW_Ci < ubG_Dcount; ubW_Ci++){
		view_array();														/* ??????????????¨??? */
		usW_Dtrade = usG_Darray[ ubW_Ci ];							/* ???????????¨?????°????????????????±???????????????? */
		ubW_Cj = ubW_Ci;											/* ?????\?????????????????? */
		/* ????????????j???0??\?????????????????????????±???????[ j-1 ]??????????????¨?????°????????§????????´???????????? */
		while( ( ubW_Cj > ZERO ) && ( usG_Darray[ ubW_Cj - ONE ] > usW_Dtrade ) ){
			usG_Darray[ ubW_Cj ] = usG_Darray[ ubW_Cj - ONE ];		/* ?????????????±???????[ j ]????????????????±???????[ j - 1 ]???????????? */
			ubW_Cj--;												/* ????????????j????????????????????? */
		}
		usG_Darray[ ubW_Cj ] = usW_Dtrade;							/* ?????????????±???????[ j ]??????????????¨?????°???????????? */
	}

	view_array();															/* ?????????????????¨??? */
	return ZERO;
}

static void view_array( void )
{
	unsigned char ubW_Cvi;											/* view???????????????????????????i */
	unsigned char ubW_Cvj;											/* view???????????????????????????j */

	/* ??°?????¨?????¨????????? */
	for( ubW_Cvi = ZERO; ubW_Cvi < ubG_Dcount; ubW_Cvi++){
		/* ??°???????????????????´??????´??? */
		if( ubW_Cvi == ubG_Dcount - ONE ){
			printf("%d\n", usG_Darray[ ubW_Cvi ]);					/* ??°?????¨???????????? */
		}
		else{
			printf("%d ", usG_Darray[ ubW_Cvi ]);					/* ??°?????¨??? */
		}
	}
}

Measured memory_bytes: 600
from fractions import gcd
a,b,c,d = map(int,input().split())
n = (a-1)//c #1~a-1までのcで割り切れる数
m = b//c #1~bまでのcで割り切れる数
ck = m - n #a~bまでのcで割り切れる数

o = (a-1)//d #1~a-1までのdで割り切れる数
p = b//d #1~bまでのdで割り切れる数
dk = p - o #a~bまでのdで割り切れる数

#cでもdでも割り切れる場合
e = (c * d) // gcd(c, d) #cとdの最小公倍数
q = (a-1)//e #1~a-1までのeで割り切れる数
r = b//e #1~bまでのeで割り切れる数
ek = r - q #a~bまでのeで割り切れる数

#cまたはdで割り切れる数
cord = ck + dk - ek

ans = b - a + 1 - cord
print(ans)

Measured memory_bytes: 5176
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int l = a+b;
  int r = c+d;
  string ans = "Balanced";
  if(l>r)ans = "Left";
  if(l<r)ans = "Right";
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
ll mod=1000000007;
#define vl vector<ll>
#define pl pair<ll,ll>
#define rep(i,b) for(ll i=0;i<b;i++)
#define all(v) (v).begin(),(v).end()
using namespace std;

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll lcm(int a, int b){
    return (ll)a * b / __gcd(a, b);
}
ll t[100005];
int main(){
    ll n,a,b; cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        t[a-1]++;
        t[b]--;
    }
    ll ans=0;
    for(int i=1;i<=100000;i++){
        t[i]+=t[i-1];
        if(i<=t[i])ans=i;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3860
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef tuple<int, int, int> T;

int N;
int xyt;
vector<T> l;
 
signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) {
        int a, b; cin >> a >> b;
        l.pb(T(a, b, 0));
    }
    rep(i, N) {
        int c, d; cin >> c >> d;
        l.pb(T(c, d, 1));
    }
    sort(l.begin(), l.end());
    
    multiset<int> s;
    int ans = 0;
    rep(i, 2*N) {
        if (get<2>(l[i])==0) s.insert(get<1>(l[i]));
        else {
            auto it = s.lower_bound(get<1>(l[i]));
            if (it==s.begin()) continue;
            ans++;
            s.erase(--it);
        }
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;


const int INF = 100000;
const int V = 10;
int d[V][V];

void warshall_floyd(){
  for(int k=0;k<V;k++){
    for(int i=0;i<V;i++){
      for(int j=0;j<V;j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
  }
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int H, W; cin >> H >> W;
  for(int i=0;i<=9;i++){
    for(int j=0;j<=9;j++){
      cin >> d[i][j];
    }
  }
  warshall_floyd();
  int wall[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> wall[i][j];
    }
  }
  ll total = 0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(wall[i][j] != -1) total += d[wall[i][j]][1];
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

lli pot(lli x)
{
  return x*x*x*x*x;
}

lli bs(lli res)
{
  lli lo = 0, hi = 1000;
  while (lo < hi)
  {
    lli mid = (lo + hi) >> 1;
    if (pot(mid) >= res) hi = mid;
    else lo = mid + 1;
  }
  if (pot(lo) == res) return lo;
  lo = -1000, hi = 0;
  while (lo < hi)
  {
    lli mid = (lo + hi + 1) >> 1;
    if (pot(mid) <= res) lo = mid;
    else hi = mid - 1;
  }
  return lo;
}

int main()
{
  lli x;
  while (scanf("%lld", &x) != EOF)
  {
    lli a, b;
    for (a = -1000; ; a++)
    {
      lli res = pot(a) - x;
      b = bs(res);
      DEBUG printf("\t%lld %lld\n", a, b);
      if (pot(b) == res)
        break;
    }
    printf("%lld %lld\n", a, b);
  }
  return 0;
}

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

using namespace std;

int main () {
  int n, k;
  cin >> n >> k;
  vector <int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  vector <int> dp(k + 1, 0);
  for (int stone: arr) if (stone <= k) dp[stone] = 1;
  for (int i = 1; i <= k; i++) {
    if (dp[i] == 0) {
      bool win = false;
      for (int stone: arr) if (0 <= i - stone) win |= (dp[i - stone] == 0);
      dp[i] = win;
    }
  }
  puts(dp[k] ? "First" : "Second");
  return (0);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int make[100005] , ans;
signed main(){
  int n , a;
  cin>>n;

  for(int i=0;i<n;i++){
    cin>>a;
    a++;
    make[a]++;
    ans = max(ans , make[a]);
    make[a+1]++;
    ans = max(ans , make[a+1]);
    make[a-1]++;
    ans = max(ans , make[a-1]);
  }

  cout<<ans<<endl;

  return(0);
}
  


Measured memory_bytes: 640
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  list.unshift(0);
  var count = new Array(N + 1).fill(0);
  var outputM = 0;
  var outputlist = [];
  for(var i = N; i > 0; i--){
    var sum = 0;
    var j = 1;
    while(i * j <= N){
      sum += count[i * j];
      j++;
    }
    if(sum % 2 != list[i]){
      count[i]++;
      outputM++;
      outputlist.push(i);
    }
  }
  myout(outputM);
  if(outputM > 0){
  	myout(myconv(outputlist,8));
  }
}

Measured memory_bytes: 31948
x = int(input())

rs = [i ** 5 for i in range(300)]

for r in rs:
    if r <= x:
        if x - r in rs:
            print(rs.index(r), - rs.index(x - r))
            break
    if r > x:
        if r - x in rs:
            print(rs.index(r), rs.index(r - x))
            break


Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
const int INF = 1000100100;


int main(){
    ll x,y,a,b,c,k=0,p[100005],q[100005],r[100005],sum=0;
    cin>>x>>y>>a>>b>>c;
    rep(i,a){
        cin>>p[i];
    }
    sort(p,p+a, greater< int >());
    rep(i,b){
        cin>>q[i];
    }
    sort(q,q+b, greater< int >());
    rep(i,c){
        cin>>r[i];
    }
    sort(r,r+c, greater< int >());
    x--;
    y--;
    if(x>=0&&y>=0){
        while(p[x]<r[k]||q[y]<r[k]){
            if(p[x]<r[k]&&q[y]<r[k]){
                if(p[x]<q[y]){
                    sum+=r[k];
                    x--;
                    k++;
                }else{
                    sum+=r[k];
                    y--;
                    k++;
                }
            }else if(p[x]<r[k]){
                sum+=r[k];
                x--;
                k++;
            }else if(q[y]<r[k]){
                sum+=r[k];
                y--;
                k++;
            }
            if(x<0||y<0) break;
        }
    }
    if(x>=0){
        while(p[x]<r[k]){
            sum+=r[k];
            x--;
            k++;
            if(x<0) break;
        }
    }
    if(y>=0){
        while(q[y]<r[k]){
            sum+=r[k];
            y--;
            k++;
            if(y<0) break;
        }
    }
    for(int i=x;i>=0;i--){
        sum+=p[i];
    }
    for(int i=y;i>=0;i--){
        sum+=q[i];
    }
    cout<<sum;
}

Measured memory_bytes: 5968
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n;cin>>n;
    ll l;cin>>l;
    vector<ll>a(n);
    rep(i,n){
        cin>>a[i];
    }
    ll k=0;
    rep(i,n-1){
        if(a[i]+a[i+1]>=l){
            k=i+1;
            break;
        }
    }
    if(k){
        cout<<"Possible"<<endl;
        rep(i,k-1){
            cout<<i+1<<endl;
        }
        rep(j,n-k){
            cout<<n-1-j<<endl;
        }
    }else{
        cout<<"Impossible"<<endl;
    }
}

Measured memory_bytes: 1664
N = int(input())
ary = list(map(int, input().split()))

count = 0
while True:
    flag = True
    for i in range(len(ary)):
        v = ary[i]
        if v % 2 == 0:
            v //= 2
            ary[i] = v
        else:
            flag = False
    if flag is False:
        break
    count += 1
print(count)

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <vector>

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

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

	rep(i, K) {
		int a, b;
		scanf("%d %d", &a, &b);
		printf("%d\n", (min({ a,b, N - a + 1,N - b + 1 }) - 1) % 3 + 1);
	}
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    string s[N];

    for(int i = 0; i < N; i++){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }

    long long count = 0;

    sort(s, s + N);

    for(int i = 0; i < N;){
        long long j = 0;
        while(s[i] == s[i+j]){
            j++;
            if(i+j == N){
                i = N;
                break;
            }
        }
        i += j;
        count += (j*(j-1)/2);
    }

   cout << count << endl;

}

Measured memory_bytes: 7296
import copy

n = int(input())
li = list(map(int,input().split()))

if all([li[i] < li[i+1] for i in range(n-1)]):
    print('YES')
    exit()
for i in range(n):
    for j in range(i+1,n):
        a = copy.copy(li)
        a[i],a[j] = a[j],a[i]
        if all([a[i] < a[i+1] for i in range(n-1)]):
            print('YES')
            exit()

print('NO')


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

int N, Z, W;
int a[2001];

int main() {
	cin >> N >> Z >> W;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	if (N == 1) cout << abs(a[N - 1] - W) << endl;
	else cout << max(abs(a[N - 1] - W), abs(a[N - 1] - a[N - 2])) << endl;
}


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

int main() {
	int n,k,b[2000000]={0},c=0,d=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
	    int a;
	    cin>>a;
	    b[a-1]++;
	    if(b[a-1]==1){
	        d++;
	    }
	}
	
	sort(b,b+2000000);
	for(int i=0;d>k;i++){
	    if(b[i]>0){
	        c+=b[i];
	        d--;
	    }
    }
    cout<<c<<endl;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main() {
	int n;
	CI n;
	vector<int> a(n);
	CI a;
	int ans = 1;
	int max = a[0];

	FOR(i,1, n-1) {
		if (max <= a[i]) {
			ans++;
			max = a[i];
		}
	}

	CO ans EN;
	return 0;
}

Measured memory_bytes: 256
// ITP_1_9_D
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
namespace you {
    std::string to_string(char val) {
        return std::string(1, val);
        // return std::string{val};
        // you::to_string(char)
    }
}

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

    string s;
    cin>>s;
    int num;
    cin>>num;
    for(int i=0;i<num;i++){
        string what;
        cin>>what;
        if(what=="replace"){
            int a,b;
            cin>>a>>b;
            string chan;
            cin>>chan;
            int nan=0;
            for(int j=a;j<=b;j++){
                s[j]=chan[nan];
                nan+=1;
            } 
        }else if(what=="reverse"){
            int a,b;
            cin>>a>>b;
            int nan=b;
            string copy=s;
            for(int j=a;j<=b;j++){
                s[j]=copy[nan];
                nan--;
            }
        }else{
            int a,b;
            cin>>a>>b;
            for(int j=a;j<=b;j++){
                cout<<s[j];
            }
            cout<<endl;
        }
    }
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#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 OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

double v_pro(double a[], double b[])
{
    return a[0] * b[1] - a[1] * b[0];
}

int main()
{
    double v[3][2], p[2];
    while (cin >> v[0][0] >> v[0][1] >> v[1][0] >> v[1][1] >> v[2][0] >> v[2][1] >> p[0] >> p[1])
    {
        double w[3][2];

        rep(i, 3)
        {
            rep(j, 2)
            {
                w[i][j] = p[j] - v[i][j];
            }
        }

        if ((v_pro(w[0], w[1]) > 0 && v_pro(w[1], w[2]) > 0 && v_pro(w[2], w[0]) > 0) || (v_pro(w[0], w[1]) < 0 && v_pro(w[1], w[2]) < 0 && v_pro(w[2], w[0]) < 0))
        {
            OP("YES")
        }
        else
        {
            OP("NO")
        }
    }
    return 0;
}


Measured memory_bytes: 3152
#include <iostream>

using namespace std;

int main(void){
	while(true){
		int h, w;
		cin >> h >> w;
		if(h == 0 && w == 0){
			break;
		}
		for(int i = 0;i < h; ++i){
			for(int j = 0;j < w; ++j){
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

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

// n個の重複しない整数(min ~ max)の和としてsを表す組み合わせの数
int ci(int n, int s, int min, int max) {
  // 特殊なパターンを処理
  if (s < min || n < 1) return 0;
  if (n == 1) return (s > max)? 0: 1;
  
  // 最も小さい数で場合分けし再帰処理
  int r = 0;
  for (int i=min; i<s && i<=max; i++) r += ci(n - 1, s - i, i + 1, max);
  return r;
}

int main() {
  while (true) {
    int n, s;
    cin >> n >> s;
    if (!n && !s) break;
    cout << ci(n, s, 0, 9) << endl;
  }
  return 0;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define int long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

vector<bool> visited;
vector<vector<int>> adj; // Outside main
vector<int> res;

void dfs(int v) {
    visited[v] = true;
    for (int to : adj[v]) {
        if (!visited[to]) {
            res[to] += res[v];
            dfs(to);
        }
    }
}

signed main()
{
    int n, q;
    cin >> n >> q;
    adj.resize(n); // Inside main
    visited.resize(n); // Inside main
    rep(i, 0, n-1)
    {
        int a, b;
        cin >> a >> b;
        a--; b--; // To have graph indexed from 0
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    res.resize(n); // Inside main
    rep(i, 0, q)
    {
        int p, x;
        cin >> p >> x;
        res[p-1] += x;
    }
    dfs(0);
    // cout << "ab";
    rep(i, 0, n)
        cout << res[i] << " ";
    return 0;
}

Measured memory_bytes: 25072
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,ans;
    cin >>a>>b;
    if(a>12){
      ans=b;
    }
  else if(a>=6&&a<=12){
    ans=b/2;
  }
    else{
      ans=0;
    }
    cout<<ans<<endl;    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

int beki(int a,int b){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=mod(x*a);
		}
		a=mod(a*a);
		b>>=1;
	}
	return x;
}

struct matrix{
	vector<vector<long long>> value;
	
	matrix(int height,int width){
		value.resize(height,vector<long long>(width,0));
		if(height==width){
			for(int i=0;i<get_width();i++){
				value[i][i] = 1;
			}
		}
	}
	
	void resize(int height,int width){
		value.resize(height,vector<long long>(width,0));
		for(int i=0;i<get_width();i++){
			value[i][i] = 1;
		}
	}
	
	void set_value(vector<vector<long long>> &V){
		value = V;
	}
	
	void set_value(initializer_list<long long> list){
		auto it = list.begin();
		for(int i=0;i<get_height();i++){
			for(int j=0;j<get_width();j++){
				value[i][j]=*it;
				if(i!=get_height()-1||j!=get_width()-1)it++;
			}
		}
	}
	
	int get_width(){
		return value[0].size();
	}
	
	int get_height(){
		return value.size();
	}
	
	void print(){
		for(int i=0;i<get_height();i++){
			for(int j=0;j<get_width();j++){
				if(j!=0)cout<<' ';
				cout<<value[i][j];
			}
			cout<<endl;
		}
	}
	
};

matrix matrix_multiple(matrix &A,matrix &B){

	matrix R(A.get_height(),B.get_width());
	int multi_cnt;
	if(A.get_width()!=B.get_height()){
		assert(false);
	}
	else multi_cnt = A.get_width();
	
	for(int i=0;i<R.get_height();i++){
		for(int j=0;j<R.get_width();j++){
			R.value[i][j]=0;
			for(int k=0;k<multi_cnt;k++){
				
				R.value[i][j] = mod(R.value[i][j] + mod(A.value[i][k] * B.value[k][j]));
	
			}
		}
	}
	return R;
	
}

matrix matrix_beki(matrix A,long long cnt){
	if(A.get_width()!=A.get_height())assert(0);
	matrix R(A.get_width(),A.get_width());
	while(cnt!=0){
		if(cnt&1){
			R=matrix_multiple(R,A);
		}
		A=matrix_multiple(A,A);
		cnt>>=1;
	}
	return R;
}

int main(){
	
	int T;
	cin>>T;
	
	vector<vector<long long>> t(32,vector<long long>(32,0));
	for(int i=0;i<32;i++){
		int s = i/2;
		int p = i%2;
		t[i][s*2 + (p^1)]++;
		if(p==0||s>=5){
			if(s!=15){
				t[i][((s+1)*2)]++;
			}
		}
	}
	
	matrix M(32,32);
	M.set_value(t);
	
	matrix MM(1,32);
	MM.value[0][0] = 1;
	
	for(int _=0;_<T;_++){
		long long N;
		cin>>N;
		
		matrix X(32,32);
		X = matrix_beki(M,N+10);
		matrix Y(1,32);
		Y = matrix_multiple(MM,X);
		cout<<mod(Y.value[0].back()+Y.value[0][Y.value[0].size()-2])<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <vector>

#include <climits>


using namespace std;

int S(long long n){
  long long nn = n;
  int s = 0;
  while(nn > 0){
    s += (nn % 10);
    nn = nn / 10;
  }
  return s;
}

int main(){

  string n;
  cin >> n;
  long long nn = stoll(n);
  int s = S(nn);
  if(nn % s == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
var stdin = require("fs").readFileSync("/dev/stdin", "UTF-8");
var lines = stdin.split("\n");
var N = lines[0];
var L = lines[1].split(" ");

var sum = sum(L);
var max = Math.max(...L);

sum - max > max ? Yes() : No();

function sum(arr) {
  return arr.reduce(function(prev, current, i, arr) {
    return +prev + +current;
  });
}

function Yes() {
  console.log("Yes");
}

function No() {
  console.log("No");
}

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int a, b;
    scan(a, b);
    if (9 < a || 9 < b)
        print(-1);
    else
        print(a * b);

    return 0;
}

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


int main(){

	ll n;
	cin>>n;
	ll key = 1;
	ll sum = 0;
	while(n>0){
		if(key%3!=0 && key%5!=0 && key%15!=0){
			// cout<<"KEY "<<key<<endl;
			sum = sum + key;
		}
		n--;
		key++;
	}

	cout<<sum;

}

Measured memory_bytes: 3612
from collections import deque

H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
C_Count = [[1 for _ in range(W)] for _ in range(H)]
num = 0
goal_flag = False

def bfs(x,y,S):
    que = deque()
    que.append((x,y))

    while que:
        x,y = que.popleft()
        if S[x][y] == "#":
            continue
        if x == (H - 1) and y == (W - 1):
            return C_Count[x][y]
        S[x][y] = "#"
        for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
            sx = x + dx
            sy = y + dy
            if sx < 0 or sx >= H or sy < 0 or sy >= W:
                continue
            que.append((sx,sy))
            C_Count[sx][sy]=C_Count[x][y] + 1
    return -1

for i in S:
    num += i.count("#")

tmp = bfs(0,0,S)
if tmp == -1:
    print(tmp)
else:
    print(H * W - tmp - num)

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




int32_t main()
{
    
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int dp[n];
    dp[n - 1] = 0;
    dp[n - 2] = abs(a[n - 2] - a[n - 1]);
    for (int i = n - 3; i >= 0; i--)
    {
        dp[i] = min(dp[i + 1] + abs(a[i] - a[i + 1]), dp[i + 2] + abs(a[i] - a[i + 2]));
    }
    cout << dp[0];
    return 0;
}

Measured memory_bytes: 1024
import sys

n,k = map(int,input().split())
a = list(map(int,input().split()))

array = [-1] * (n+1)
array[1] = 0

li = []
li.append(1)

tmp = -1
index = 0
for i in range(2 * (10**5)):
  if array[a[index]] != -1:
    tmp = array[a[index]]
    break
    
  if i == k:
    print(index+1)
    sys.exit(0)
    
  li.append(a[index])
  array[a[index]] = i+1
  index = a[index] -1
  
k -= tmp
d = len(li) - tmp

k %= d

print(li[k+tmp])

Measured memory_bytes: 94192
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time

input = sys.stdin.readline

# input = sys.stdin.readline
sys.setrecursionlimit(2147483647)


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
iinf = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


def main():
    S = input()
    ans = iinf

    for i in range(len(S)-2):
        ans = min(ans, abs(753 - int(S[i:i+3])))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38892
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define se set<ll>
#define vec vector<ll>
#define inf 10000000000000000
bool mark[100005];
vec adj[100005];
ll counter;
vec cnt;
vector<string> forsubs;
ll b=1000000000000;
ll a[100005];
ll ans=0;
ll n;

	

int main()
{    
 

	#ifdef APNA_IO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
		    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 

string s;
cin>>s;
ll win=0;

for(ll i=0;i<s.length();i++)
	{
		if(s[i]=='o')
			win++;
		else
			continue;
	}

if(win+15-s.length()>=8)
	cout<<"YES"<<endl;
else
	cout<<"NO"<<endl;

}		





Measured memory_bytes: 2560