akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int MAX = 200002;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll mod_pow(ll base, ll pow, ll m = MOD)
{
  if (pow == 0)
    return 1;

  ll res = mod_pow(base, pow / 2);
  res = res * res % m;
  if (pow & 1)
    res *= base;
  return res % m;
}

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

  COMinit();
  ll ans = 0;
  for (auto k = 0; k <= K; k++)
  {
    ll base = (M * mod_pow(M - 1, N - k - 1)) % MOD;
    ll com = COM(N - 1, k);
    ll a = base * com;
    // printf("a: %lld, k: %lld, base: %lld, com: %lld\n", a, k, base, com);

    a %= MOD;
    ans += a;
    ans %= MOD;
  }

  if (ans < 0)
  {
    cout << ans + MOD << endl;
  }
  else
  {
    cout << ans << endl;
  }

  return 0;
}


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

int main()
{
    int n;
    int a[100];
    cin>>n;

    int small = INT_MAX;
    int large = INT_MIN;
    forn(i,n)
    {
        cin>>a[i];
        small = min(small, a[i]);
        large = max(large, a[i]);
    }

    int sum = INT_MAX;
    for(int i = small; i<=large; i++)
    {
        int temp = 0;
        forn(j,n) temp += pow(i-a[j], 2);
        sum = min(sum, temp);
    }

    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  int H, W, D;
  cin >> H >> W >> D;
  vector<vector<int>> A(H, vector<int>(W));
  rep(i, 0, H) rep(j, 0, W) { cin >> A[i][j]; }
  int Q;
  cin >> Q;
  vector<int> L(Q), R(Q);
  rep(i, 0, Q) { cin >> L[i] >> R[i]; }
  map<int, pair<int, int>> mp;
  rep(i, 0, H) rep(j, 0, W) { mp[A[i][j]] = make_pair(i + 1, j + 1); }
  vector<int> check(H * W + 1);
  map<int, vector<int>> sum;
  int ans = 0;
  auto cal = [&](pair<int, int> &a, pair<int, int> &b) {
    return abs(a.first - b.first) + abs(a.second - b.second);
  };
  rep(d, 0, D) {
    if (check[d])
      continue;
    check[d] = 1;
    sum[d].push_back(0);

    int x = d;
    while (x + D <= H * W) {
      check[x] = 1;
      sum[d].push_back(cal(mp[x], mp[x + D]));
      x += D;
    }
  }

  for (auto &y : sum) {
    vector<int> &v(y.second);
    rep(i, 1, v.size()) v[i] += v[i - 1];
    dump(v);
  }

  rep(i, 0, Q) {
    int re = L[i] % D;
    dump(sum[re]);

    ans = sum[re][R[i] / D] - sum[re][L[i] / D];
    cout << ans << endl;
  }

  return 0;
}


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

#define int long long
#define counter(m)     for(int i=0;i<m;i++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    int n;
    cin>>n;
    vector<int>v(1000001,0);
    bool real=false;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(v[a]==0)
        v[a]=1;
        else if(a!=1){
            real=true;
        }
    }
    int primes[1000001];
    for(int i=2;i<=1000000;i++)
    {
        primes[i]=1;
    }
    for(int i=2;i<=1000000;i++)
    {
        if(primes[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
                primes[j]=0;
        }
    }
    bool flag=false;
    for(int i=2;i<=1000000;i++)
    {
        if(primes[i])
        {
            int cnt=0;
            for(int j=i;j<=1000000;j+=i) {
                if (v[j] == 1)
                    cnt++;
            }
            if(cnt>=2)
                flag=true;
        }
    }
    if(real)
        flag=true;
    int g=0;
    for(int i=1;i<=1000000;i++)
    {
        if(v[i])
            g=gcd(g,i);
    }
    if(g==1)
    {
        if(flag)
        {
            cout<<"setwise coprime"<<endl;
        }
        else{
            cout<<"pairwise coprime"<<endl;
        }
    }
    else{
        cout<<"not coprime"<<endl;
    }
    return 0;
}

Measured memory_bytes: 18772
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define MOD 1000000007
#define INT long long int
#define REP(i,n) for(int(i)=0;(i)<(n);(i)++) 
using namespace std;
const long long INF = numeric_limits<long long>::max();


int main()
{
    INT Q,H,S,D;
    INT N;
    cin>>Q>>H>>S>>D;
    cin>>N;
    if (Q*4 < S || H*2 < S) S = min(Q*4,H*2);   
    if (S*2<D) D = S*2;
    INT ans=0;
    ans += D * (N/2);
    if (N%2==1) ans += S;
    cout<<ans<<endl;   
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define pb push_back
using namespace std;
typedef long long ll;

int main(){

	fastio;
	ll n,m,k; cin >> n >> m >> k;
	int ib=0,r,a;
	vector <ll> sb,sa; sa.pb(0); sb.pb(0);

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

	for (int i=0 ; i<m ; i++){
		cin >> a;
		sb.pb(a+sb[i]);
	}

	for (int i=1 ; i<=m ; i++){
		if (sb[i] > k){
	 	ib = i-1; break;
		}
		if (i == m) ib = m;
	}

	r = ib;

	for (int i=1 ; i<=n ; i++){
		if (k >= sa[i]){
			for (int j=ib ; j>=0 ; j--)
				if (sa[i] + sb[j] <= k){
					ib = j;
					r = max(r,ib+i); break;
				}
		}
	}

	cout << r << "\n";

	return 0;
}


Measured memory_bytes: 7940
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#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 init(a, x) memset(a,x,sizeof(a))
#define ld long double
#define dd double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector<pll> vplll;
ll mod = 1e9+7;
const ld PI = 2 * acos(0.0);
const vector<ll> dx = {1, -1, 0, 0};
const vector<ll> dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,t,n,m,k,q; 
    t = 1;
    // cin>>t;
    while(t--)
    {
    	cin>>n;
    	ll ar[n][2];
    	for(int i=0;i<n;i++)
    	{
    		cin>>ar[i][0]>>ar[i][1];
    	}
    	int fl = 0;
    	for(int i=0;i<n-2;i++)
    	{
    		if(ar[i][0]==ar[i][1]&&ar[i+1][0]==ar[i+1][1]&&ar[i+2][0]==ar[i+2][1])
    			fl = 1;
    	}
    	if(fl)
    	{
    		cout<<"Yes"<<endl;
    	}
    	else
    	{
    		cout<<"No"<<endl;
    	}
    }
    return 0;
}

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

int foo(string a){
  int i, size =  (int)a.size();
  
  for(i = 0; i < size; i++){
    if(!('0' <= a[i] && a[i] <= '9' ))return 0;
  }
  return 1;
}

int huga(int pl[], int count , int m){
  int k = 1;
  while(k <= m){
    if(count == m)count = 1;
    else count++;
    if(pl[count] != -1) return count;
    k++;
  }

  return -1;
}

int hoge(string str, int i){
  int keta = log10(i) + 1, size = (int)str.size(), an = 0, k, j = 1;


  if(keta != size)return 0;
  for(k = size - 1; k >= 0; k--){
    an += (str[k] - '0') * j;
    j *= 10;
  }  if(an == i)return 1;
  else return 0;
}


int main(){
  string str[10010];
  int m, n, temp;
  int i, j, k;

  while(1){
    int count = 1, pl [1010] ={};
    cin>>m>>n;
    if(m == 0 && n == 0) break;

    for(i = 1; i <= n; i++){
      cin>>str[i];
    }

    
    for(i = 1; i <= n; i++ ){
      if(i%5 == 0 && i%3 == 0){
	if(str[i] != "FizzBuzz"){
	  pl[count] = -1;
	}
      }else if(i%5 == 0){
	if(str[i] != "Buzz"){
	  pl[count] = -1;
	}
      } else if(i%3 == 0){
	if(str[i] != "Fizz"){
	  pl[count] = -1;

	}
      }else{

	if(foo(str[i]) == 1){
	  if(hoge(str[i], i) == 0){
	    pl[count] = -1;
	  }
	}else{
	  pl[count] = -1;

	}
      }
      
      count = huga(pl, count , m);
      
      k = 0;
      for(j = 1; j <= m; j++){
		if(pl[j] != -1)k++;
	}
      if(k == 1){
		break;
      }
      
    }

    k = 0;
    
    for(i = 1; i <= m; i++){
      if(pl[i] != -1){
	if(k) {cout<<" ";}
	cout<<i;
	k++;
      }
    }cout<<endl;
  }


  return 0;
}





Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int,int>     pii;
typedef pair<char,int>    pci;
typedef pair<char,char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
    int flag=0;
    for(long long i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            flag=1;
            break;
        }
    }
    if(n==1)
	   return false;
    else if(flag==0 || n==2 ||n==3)
    {
        return true;
    }
    else
    {
        return false;
    }

}

int BE(int x,int n,int m)//function to calculate x raise to power n modulo m
{
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x%m;
        x=x*x%m;
        n=n/2;
    }
    return result;
}

int32_t main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(0);
   #ifndef ONLINE_JUDGE
    if(fopen("input.txt","r"))
    {
    freopen ("input.txt" , "r" , stdin);
    freopen ("output.txt" , "w" , stdout);
    }
   #endif
    //_______________________________-code starts-_______________________________________________

  int n;
  cin>>n;
  int range=pow(10,6)+2;
  int ans = 0;
  rep(i,2,range)
  {
  	int cur=0;
  	while(n%i==0)
  	{
  		n=n/i;
  		cur++;
	  }
	  rep(j,1,10000)
	  {
	  	if(cur<j)
	  	{
	  		break;
		  }
		  ans++;
		  cur-=j;
	  }
  }
  if(n>1)
    ans++;
    cout<<ans<<en;

  return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn = 100000;
int n, flag = 1, num;
int a[maxn + 5];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	int last = 0;
	for (int i = 1; i < n; i++) {
		if (a[i] - a[i + 1] > 1) {
			flag = 0;
			break;
		}
		if (a[i] - a[i + 1] == 1 && !last) {
			last = 1;
			num = a[i] - 1;
			continue;
		} 
		if (a[i] - a[i + 1] == 1) {
			flag = 0;
			break;
		}
		if (a[i] - a[i + 1] < 0) last = 0;
	}
	if (flag) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define REEP(i, N) for(ll i = N - 1; i >= 0; --i)
#define FOR(i,m,n) for(ll i = m; i < n; ++i)
#define RFOR(i,m,n) for(ll i = n - 1; i >= m; --i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define PB push_back
#define KIRIAGE(a, b) a += (b - a % b) % b // a ??? b ????????°????????§?¢???????
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;} // a / b ??\??????????°???´??°
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
int main(void) {
    while(true) {
        int n;
        cin>>n;
        if(!n)return 0;
        vector<int> s(n);
        ll sum = 0;
        REP(i, n) {
            cin>>s[i];
            sum += s[i];
        }
        sort(ALL(s));
        sum -= s[0];
        sum -= s[n - 1];
        cout<<sum / (n - 2)<<endl;
    }
}


Measured memory_bytes: 3080
# coding: utf-8
import numpy as np
from numba import b1, i8, njit, types


@njit(types.Tuple((i8[:], b1))(i8[:]), cache=True)
def f(A):
    n = len(A)
    ret = np.zeros_like(A)
    for x, p in enumerate(A):
        ret[max(0, x-p)] += 1
        if x+p+1 < n:
            ret[x+p+1] -= 1

    satulated = True
    for i in range(1, n):
        ret[i] += ret[i-1]
        satulated &= ret[i] == n
    return ret, satulated


def solve(*args: str) -> str:
    n, k = map(int, args[0].split())
    A = np.array(tuple(map(int, args[1].split())))

    for _ in range(k):
        A, satulated = f(A)
        if satulated:
            break

    return ' '.join(map(str, A))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

int main()
{
    ll k,sum=0;
    cin>>k;
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=k;j++)
        {
            for(int x=1; x<=k;x++)
            {
                sum+=__gcd(i,__gcd(j,x));
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3624
import java.util.*;
public class Main {
	public static void main(String arg[]) {
		Scanner sc = new Scanner(System.in);
		String s1 = sc.next();
		String s2 = sc.next();
 
		s2 = s2.substring(0, s2.length()-1);
		if(s1.equals(s2)) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
ll MAX=9223372036854775807;

int n,k;
multiset<ll>s;
ll ans=0;

bool f(int id){
	int tot=0;
	for(auto i:s){
		if((i&(1ll<<id))) tot++;
	}
	return tot>=k;
}

int main(){
    fast_io;
    cin>>n>>k;
    ll a[n];
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    }
    for (int i = 0; i < n; ++i)
    {
    	ll curr=0;
    	fo(j,i,n-1){
    		curr+=a[j];
    		s.insert(curr);
    	}
    }
    rf(i,50,0){
    	multiset<ll>temp;
    	if(f(i)){
    		for(auto it:s){
    			if((it&(1ll<<i))) temp.insert(it);
    		}
    		s=temp;
    		ans+=(1ll<<i);
    	}
    }
    show(ans);
    return 0;
}

Measured memory_bytes: 29056
#include <iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

long long MX = 1e18;

int main()
{
    int n;
    long long a;
    cin >> n;
    long long ans =1;
    bool flag = false;
    for(int i = 0; i<n;i++){
        cin >> a;
        if(a==0){
            cout << 0 << endl;
            return 0;
        }
        if(flag || MX/ans < a){
            flag = true;
        }
        ans *= a;
    } 
    if(flag) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a.at(i);
    vi x(n);
    rep(i,n){
        if(i%2==0){
            x.at(0) += a.at(i);
        }else{
            x.at(0) -= a.at(i);
        }
    }
    rep(i,n-1) x.at(i+1) = 2*a.at(i) - x.at(i);
    rep(i,n) cout << x.at(i) << " ";
    cout << endl;
}

Measured memory_bytes: 4776
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
    char s[201], p[101], t[101];
    
    scanf("%s %s", s , p);
    strcpy(t,s);
    strcat(s,t);
    
    if( strstr(s,p) == NULL ) printf("No\n");
    else printf("Yes\n");
    
    return 0;
    
}


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

int main(){
    char a; cin>>a;
    for(char c='a';c<='z';c++){
        if(a==c){
            cout<<"a"<<endl;
            return 0;
        }
    }
    cout<<'A'<<endl;
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();

        int[] dp = new int[N + 1];
        dp[1] = 1;

        for (int i = 1; i <= N; i++) {
            dp[i] = 1 + min(dp[i - 1], dp[i - f(6, i)], dp[i - f(9, i)]);
        }

        out.println(dp[N]);
    }

    static int f(int a, int b) {
        int x = 1;
        while (x <= b) {
            x *= a;
        }
        return x / a;
    }

    static int min(int a, int b, int c) {
        return Math.min(a, Math.min(b, c));
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 33076
import java.util.Scanner;
public class Main{
	static int func(int a)
	{	
		return a=(a==0||a==1)?1:func(a-1)+func(a-2);
	}
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		if(n==44){
			System.out.println(1134903170);
			System.exit(0);
		}
		System.out.println(func(n));
	}

}

Measured memory_bytes: 18604
import java.io.*;
import java.util.*;
public class Main { // "Main" should be used for most online judges
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int nums[][] = new int[2][n];
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < n; j++) {
				nums[i][j] = sc.nextInt();
			}
		}
		System.out.println(max(1, n - 1, nums));
	}
	public static int max(int y, int x, int[][] nums) {
		if(x == 0 && y == 0) return nums[0][0];
		if (x == 0) return nums[y][x] + nums[0][0];
		if (y == 0) return nums[y][x] + max(0, x - 1, nums);
		int num1 = max(0, x, nums);
		int num2 = max(1, x - 1, nums);
		return nums[y][x] + (num1 > num2 ? num1 : num2);
	}
}

Measured memory_bytes: 23764
#!/usr/bin/env python

def figure(s, p):
    if p in s:
        return True

    i = 0
    while True:
        idx = p[i:].find(s[-1]+s[0])
        if idx == -1:
            break
        idx += i
        if s[-(idx+1):]+s[:len(p)-(idx+1)] == p:
            return True
        i = idx+1
    return False

if __name__ == '__main__':
    s, p = raw_input(), raw_input()
    print 'Yes' if figure(s, p) else 'No'


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

int main(){
	int N, i;
	scanf("%d", &N);
	vector<int> H(N);
	for(i = 0; i < N; i++){
		scanf("%d", &H[i]);
	}
	H[0]--;
	for(i = 1; i < N; i++){
		if(H[i] < H[i - 1]){
			printf("No\n");
			return 0;
		}
		if(H[i] > H[i - 1]){
			H[i]--;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
int abs(int a,int b){
  int c=max(a,b)-min(a,b);
  return c;
}
signed main(){
  string a,b;
  int c=1,q=1;
  int d=0,e=0;
  cin>>a;
  for(int i=1;i<a.size();i++){
    if(a[i]!=a[i-1]) d++;
  }
  cout<<d<<"\n";
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << A << endl; exit(0);}

int main()
{
  ll N, A, B;
  cin >> N >> A >> B;
  vector<ll> X(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> X.at(i);
  }

  ll ans = 0;
  for (ll i = 0; i < N - 1; i++)
  {
    ans += min(A * (X.at(i + 1) - X.at(i)), B);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.PrintWriter
import kotlin.math.min

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (N, X, Y) = nextIntList()
    val a = X
    val b = Y - X
    val c = N - Y
    val ans = IntArray(N)
    for (i in 1..a) {
        for (j in i + 1..a) {
            ans[j - i]++
        }
        for (j in 1..c) {
            ans[a - i + 1 + j]++
        }
        for (j in 1..b / 2) {
            ans[a - i + j] += 2
        }
        if (b and 1 != 0) {
            ans[a - i + (b + 1) / 2]++
        }
    }
    val bmax = (b + 1) / 2
    for (i in 1..b) {
        val b1 = b - i
        val b2 = i + 1
        val bb = min(b1, b2)
        if (b1 == bb) {
            for (j in 1..bb) {
                ans[j]++
            }
        } else {
            for (j in 1..bmax) {
                ans[j]++
            }
            for (j in 0 until b - i - bmax) {
                ans[bb + j]++
            }
        }
        for (j in 1..c) {
            ans[bb + j]++
        }
    }
    for (i in 1..c) {
        for (j in i + 1..c) {
            ans[j - i]++
        }
    }
    println(ans.drop(1).joinToString("\n"))
}

Measured memory_bytes: 43588
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int M=1000;

void dfs(int &id,int &I,vip &a,string &s){
	int t=id;
	id++;
	I++;
	if(I<s.size()&&s[I]!=')'){
		a[t].second.first=id;
		dfs(id,I,a,s);
	}
	I+=2;
	a[t].first=0;
	while(isdigit(s[I])){
		a[t].first=10*a[t].first+(s[I]-'0');
		I++;
	}
	I+=2;
	if(I<s.size()&&s[I]!=')'){
		a[t].second.second=id;
		dfs(id,I,a,s);
	}
	I++;
}

vip f(string s){
	vip a(M,{-1,{-1,-1}});
	int id=0,I=0;
	dfs(id,I,a,s);
	return a;
}

void DFS(int u,int v,int &id,vip& a,vip& b,vip& c){
	c.push_back({a[u].first+b[v].first,{-1,-1}});
	int t=id;
	if(a[u].second.first>=0&&b[v].second.first>=0){
		c[t].second.first=id+1;
		id++;
		DFS(a[u].second.first,b[v].second.first,id,a,b,c);
	}
	if(a[u].second.second>=0&&b[v].second.second>=0){
		c[t].second.second=id+1;
		id++;
		DFS(a[u].second.second,b[v].second.second,id,a,b,c);
	}
}

void Dfs(int v,vip& a,string& s){
	s+='(';
	if(a[v].second.first>=0){
		Dfs(a[v].second.first,a,s);
	}
	s+=')';
	s+='[';
	s+=to_string(a[v].first);
	s+=']';
	s+='(';
	if(a[v].second.second>=0){
		Dfs(a[v].second.second,a,s);
	}
	s+=')';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s,t;
	cin>>s>>t;
	vip a=f(s),b=f(t);
	vip c;
	int id=0;
	DFS(0,0,id,a,b,c);
	string res;
	Dfs(0,c,res);
	cout<<res<<endl;
/*	for(auto p:a) if(p.first>=0) cout<<p.first<<' '<<p.second.first<<' '<<p.second.second<<endl;
	cout<<endl;
	for(auto p:b) if(p.first>=0) cout<<p.first<<' '<<p.second.first<<' '<<p.second.second<<endl;
	cout<<endl;
	for(auto p:c) cout<<p.first<<' '<<p.second.first<<' '<<p.second.second<<endl;
	cout<<endl;*/
}


Measured memory_bytes: 3328
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,dp[3][105]={0};
    cin>>n;
    for (int i=1; i<=2; i++)
    {
    	for (int j=1; j<=n; j++)
    	{
	    	scanf("%d",&dp[i][j]);
		dp[i][j]+=max(dp[i-1][j],dp[i][j-1]);
	    }           
    }
	cout<<dp[2][n]<<endl;
	return 0;
} 

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int m,M,d,D;

signed main() {
    cin >> m >> d >> M >> D;
    if (m != M) cout << 1 << endl;
    else cout << 0 << endl;
}





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

int n, place;

struct node
{
	int id, pid;
	int lc, rc;
}N[10000];

void Preorder(node root)
{
	cout << " " << root.id;

	if (root.lc != -1)
		Preorder(N[root.lc]);
	if (root.rc != -1)
		Preorder(N[root.rc]);
}

void Inorder(node root)
{
	if (root.lc != -1)
		Inorder(N[root.lc]);

	cout << " " << root.id;

	if (root.rc != -1)
		Inorder(N[root.rc]);
}
	
void Postorder(node root)
{
	if (root.lc != -1)
		Postorder(N[root.lc]);
	if (root.rc != -1)
		Postorder(N[root.rc]);

	cout << " " << root.id;
}

void print()
{
	node root;

	for (int i = 0; i < n; i++)
		if (N[i].pid == -1)
			root = N[i];

	cout << "Preorder\n";
	Preorder(root);  
	cout << endl;

	cout << "Inorder\n";
	Inorder(root);
	cout << endl;

	cout << "Postorder\n";
	Postorder(root);;
	cout << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	;
	cin >> n;
	for (int i = 0; i < n; i++)
		N[i].pid = -1;

	for (int i = 0; i < n; i++)
	{
		cin >> place;
		N[place].id = place;

		cin >> N[place].lc >> N[place].rc;
		N[N[place].lc].id = N[place].lc;
		N[N[place].rc].id = N[place].rc;

		if (N[place].lc != -1 && N[place].rc != -1)
		{
			N[N[place].lc].pid = N[place].id;
			N[N[place].rc].pid = N[place].id;
		}

		if (N[place].lc != -1 && N[place].rc == -1)
			N[N[place].lc].pid = N[place].id;

		if (N[place].rc != -1 && N[place].lc == -1)
			N[N[place].rc].pid = N[place].id;
	}

	print();

	return 0;
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  string S;
  cin >> S;
  int w;
  cin >> w;

  string ret = "";
  int base = 0;
  while(base < S.size()){
    ret += S[base];
    base += w;
  }

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



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
    int n;
    int F[50];

    cin >> n;

    F[0] = F[1] = 1;

    for (int i = 2; i <= n; i++)
        F[i] = F[i - 2] + F[i - 1];

    cout << F[n] << endl;

    return 0;
}



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

using namespace std;

const int N = 500010;

char s[N];

int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  long long ans = 0, last = 0;
  for (int i = 1; i <= n;) {
    int j = i; 
    while (j <= n and s[j] == s[i]) ++j;
    long long amt = j - i;
    if (s[i] == '<') ans += amt * (amt + 1) / 2, last = amt;
    else if (amt > last) {
      ans -= last, ans += amt * (amt + 1) / 2, last = 0;
    } else {
      ans += amt * (amt - 1) / 2, last = 0;
    }
    i = j;   
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define INF 1e9

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

    int n;
    cin >> n;
    map<int, int> dico{};
    map<int, int> dice{};
    int num;
    for (int i = 1; i <= n; i++) {
        cin >> num;
        if (i%2!=0) {
            dico[num]++;
        } else {
            dice[num]++;
        }
    }

    map<int, int>::iterator it;
    int maxo = 0;
    int maxo_key = 0;
    int maxo2 = 0;
    for (it = dico.begin(); it!=dico.end(); it++) {
//        cout << it->first << endl;
        if (maxo < it->second) {
            maxo2 = maxo;
            maxo = it->second;
            maxo_key = it->first;
        } else if (maxo2 < it->second) {
            maxo2 = it->second;
        }
    }

    int maxe = 0;
    int maxe_key = 0;
    int maxe2 = 0;
    for (it = dice.begin(); it!=dice.end(); it++) {
        if (maxe < it->second) {
            maxe2 = maxe;
            maxe = it->second;
            maxe_key = it->first;
        } else if (maxe2 < it->second) {
            maxe2 = it->second;
        }
    }

    if (maxo_key == maxe_key) {
        if (maxo2==0&&maxe==0) cout << n/2 + n/2 - maxo << endl;
        cout << n/2 - maxo + n/2 - max(maxo2, maxe2) << endl;
    } else {
        cout << n/2 - maxo + n/2 - maxe << endl;
    }
}

Measured memory_bytes: 4992
// This code writed by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
bool vis[1000000000];
inline bool isprime(int x)
{
	if(x==1)
		return false;
	reg int maxi=sqrt(x);
	for(int i=2;i<=maxi;++i)
		if(!(x%i))
			return false;
	return true;
}
signed main(void)
{
	int n,m;
	cin>>n>>m;
	int g=__gcd(n,m);
	reg int maxi=sqrt(g);
	reg int ans=0;
//	cout<<g<<endl;
	for(int i=1;i<=maxi;++i)
		if(!(g%i))
		{
			if(isprime(i))
				++ans;
			else
				vis[i]=true;
			if(i*i!=g)
			{
				if(isprime(g/i))
					++ans;
//				else
//					vis[g/i]=true;
			}
		}
	for(int i=2;i<=maxi;++i)
	{
		if(vis[i]&&i*i!=g)
			++ans;//,cout<<"passed "<<i<<endl;
		for(int j=1;i*j<=maxi;++j)
			vis[i*j]=false;
	}
	cout<<ans+1<<endl;
	return 0;
}



Measured memory_bytes: 1280
#include <stdio.h>
  
int main(){
  
  int x=1,y=1,z;
  
  while(1){
  
    scanf("%d %d", &x, &y);
  
    if(x == 0  && y == 0){
  
      break;
  
    } else {
  
    if(x > y){
  
      z = x;
  
      x = y;
  
      y = z;
  
    }
  
    printf("%d %d\n",x,y);
  }
  
  }
  
  return 0;
  
}

Measured memory_bytes: 600
#include<iostream>
#include<string>
#include<vector>
#include<tuple>
#include<stack>
using namespace std;

int main() {
	string q; cin >> q;
	vector<string> qs;
	string tmp;
	for (auto c : q) {
		if (c == '.') {
			if (tmp.size())
				qs.push_back(tmp);
			tmp.clear();
		}
		else
			tmp.push_back(c);
	}
	if (tmp.size())qs.push_back(tmp);

	//for (auto x : qs)
	//	cerr << x << endl;

	using T = tuple<int, string, string>;
	vector<T> v;
	cin.ignore();
	for (string s; getline(cin, s) && s != "$";) {
		int indent = 0;
		string key;
		string str;

		bool k = true;
		bool isobj = s.back() == ':';

		for (int i = 0; i < s.size(); i++) {
			char c = s[i];
			if (c == ' ' && key.empty())
				indent++;
			else if (c != ':' && k)
				key.push_back(c);
			else if (c == ':') {
				if (!isobj)i++;
				k = false;
			}
			else {
				str = s.substr(i);
				break;
			}

		}
		v.emplace_back(indent, key, str);
	}

	using P = pair<int, int>;
	stack<P> st;

	int qi = 0;
	for (int i = 0; i < v.size(); i++) {
		int indent; string key; string str;
		tie(indent, key, str) = v[i];
		if (st.size() && indent <= st.top().second) {
			break;
		}
		if (key == qs[qi]) {
			if (qi == qs.size() - 1) {
				if (str.size())
					cout << "string " << '"' << str << '"' << endl;
				else
					cout << "object" << endl;
				return 0;
			}
			else {
				st.emplace(i, indent);
				qi++;
			}
		}
		else {
			if (str.size() == 0) {
				int j = i + 1;
				while (j < v.size() && get<0>(v[j]) > indent) {
					j++;
				}
				i = j - 1;
			}
		}
	}

	cout << "no such property" << endl;
	return 0;
}


Measured memory_bytes: 3264
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 11 12:42:46 2020

@author: liang
"""

import math

A, B, C, D = map(int, input().split())
E = C * D // math.gcd(C,D)

B_ans = B - B//C - B//D + B//E
#print(B_ans)
A -= 1
A_ans = A - A//C - A//D + A//E
#print(A_ans)
ans = B_ans - A_ans
print(ans)

Measured memory_bytes: 62096
n,m = map(int,input().split())

a = [1]*n
#print(a)
a = [int(s) for s in input().split()]

a_half = [s//2 for s in a]
#print(a)

def check(x):
    while (all(c%2 == 0 for c in x)):
        x = [s//2 for s in x]
        if any(c%2 == 1 for c in x) and any(c%2 == 0 for c in x):
            return 0
        
    
    return 1

def gcd(x,y):
    #print(x,y)
    if(x%y == 0):
        #print(y)
        return y
    else:
        return gcd(y,x%y)


def lcm(x,y):
    return x//gcd(x,y)*y

if(check(a)== 1):
    x = a_half[0]
    for i in range(1,n):
        y = a_half[i]
        x = lcm(x,y)
    if(x > m):
        print(0)
    else:
        res = int((m//x+1)//2)
        print(res)
else:
    print(0)
    
    


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

int power(int a,int n)
{
  if(n==0)
    return 1;
  
  int smaller_ans=power(a,n/2);
  smaller_ans*=smaller_ans;
  
  if(n&1)
     return a*smaller_ans;
    
     return smaller_ans;
     }
     
int main()
{
  int n;
  cin>>n;
  int sum=0;
  sum+= power(n,1)+power(n,2)+power(n,3);
  
  cout<<sum<<endl;
}
  

Measured memory_bytes: 3592
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
  	int N;
  	cin >> N;
  	
    cout << (N+1)/2 <<endl;

  	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    if(s == "Sunny") {
        cout << "Cloudy" << endl;
    }else if(s == "Cloudy") {
        cout << "Rainy" << endl;
    }else {
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{

 int a,b;

	scanf("%d",&a);
	scanf("%d",&b);

	if(a < b){
		printf("a < b\n");
}
	else if(a > b){
		printf("a > b\n");
}
else
		printf("a == b\n");

return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s;
	cin>>t;
	vector<string> possible;
	for(int i=0;i+t.size()<=s.size();i++){
		bool can = 1;
		for(int j = 0;j<t.size();j++){
			if (s[i+j]!= '?' && s[i+j] != t[j]){
				can = 0;
				break;
			}
		}
		if (can){
			string news = s;
			for(int j=0;j<t.size();j++){
				news[i+j] = t[j];
			}
			for(int i=0;i<news.size();i++){
				if (news[i] == '?'){
					news[i] = 'a';
				}
			}
			possible.push_back(news);
		}
	}
	if (possible.size() == 0){
		cout<<"UNRESTORABLE"<<endl;
		return 0;
	}
	string res = possible[0];
	for(int i=1;i<possible.size();i++){
		if (possible[i] <res){
			res = possible[i];
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[25],b[25],c[25],ans,l=1000;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<n;i++)
		cin>>c[i];
	for(int i=1;i<=n;i++)
	{
		ans+=b[a[i]];
		if (a[i]-1==l)
			ans+=c[l];
		l=a[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	while(scanf("%d %d",&n,&m),n){
		vvi in(n,vi(n));
		vvi pic(m,vi(m));
		rep(i,n)rep(j,n)scanf("%d",&in[i][j]);
		rep(i,m)rep(j,m)scanf("%d",&pic[i][j]);
		pii out(inf,inf);
		rep(e,4){
			int N=n-m+1,M=n-m+1;
			rep(i,N)rep(j,M){
				pii t(inf,inf);
				rep(k,m)rep(l,m)
					if(pic[k][l]!=-1){
						if(in[i+k][j+l]!=pic[k][l])goto en;
						t=min(t,pii(i+k,j+l));
					}
				out=min(out,t);
				N=t.first;
				M=t.second;
				goto end;
				en:;
			}
			end:;
			vvi tmp=pic;
			rep(i,m)rep(j,m)pic[i][j]=tmp[j][m-i-1];
		}
		if(out.first==inf)cout<<"NA"<<endl;
		else cout<<out.second+1<<" "<<out.first+1<<endl;
	}
}

Measured memory_bytes: 1296
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;


int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	while (N) {
		string s;
		int bef = 0;
		ans = 0;
		L = 0;
		R = 0;
		for (int i = 0; i < N; i++) {
			cin >> s;
			if (s[0] == 'l')L ^= 1;
			else R ^= 1;
			if (L == R&&bef != L) {
				bef ^= 1;
				ans++;
			}
		}
		cout << ans << endl;
		cin >> N;
	}
	return 0;
}

Measured memory_bytes: 3144
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#define maxn 1000010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define IL inline
#define ss system
using namespace std;

int n, h, d;
ll f[maxn], s[maxn], fac[maxn], sum = 0;
const ll p = 1e9 + 7;
template <class T> void read(T &x) {
  char ch = x = 0;
  bool fl = false;
  while (!isdigit(ch))
    fl |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = fl ? -x : x;
}
int main() {
  cin >> n >> h >> d, fac[0] = 1;
  for (int i = 1; i <= n; i++) {
    fac[i] = fac[i - 1] * i % p;
  }
  f[0] = s[0] = fac[n];
  for (int i = 1; i <= n; i++) {
    sum = (sum + fac[i]) % p;
  }
  for (int i = 1; i <= h; i++) {
    f[i] = (s[i - 1] - (i > d ? s[i - d - 1] : 0) + p) % p * (i == h ? 1 : sum) % p;
    s[i] = (s[i - 1] + f[i]) % p;
  }
  cout << f[h] << endl;
  return 0;
}

Measured memory_bytes: 23680
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b;
  scanf("%d %d", &a,&b);
  if (a<b)
    printf ("a < b\n");
else if (a>b)
    printf ("a > b\n");
else if (a==b)
    printf ("a == b\n");
else
    printf ("none\n");
return 0;
  

}


Measured memory_bytes: 2028
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 998244353;

int main()
{
    int N, K, S;
    cin >> N >> K >> S;
    string ans;
    if (S == 1000000000)
    {
        for (int i = 0; i < K; ++i)
        {
            ans += to_string(S) + ' ';
        }
        for (int i = K; i < N; ++i)
        {
            ans += to_string(S - 1) + ' ';
        }
    }
    else
    {
        for (int i = 0; i < K; ++i)
        {
            ans += to_string(S) + ' ';
        }
        for (int i = K; i < N; ++i)
        {
            ans += to_string(S + 1) + ' ';
        }
    }
    ans.pop_back();
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef long double dd;



int main() {
	int A,B,C;
	cin >> A>>B>>C;
	int ans = C - (A - B);
	if (ans < 0) ans = 0;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
a = []
ans=0
n=gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
for i in 0...n do
  for j in i...n do
    if ans<(a[i]-a[j]).abs then
      ans=(a[i]-a[j]).abs
    end
  end
end
p ans


Measured memory_bytes: 1788
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<time.h>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
#include<ext/rope>
#define ll long long
#define oo 0x7fffffff
using namespace std;
using namespace __gnu_cxx;
inline int read()
{
	int out=0,fh=1;
	char cc=getchar();
	while ((cc>'9'||cc<'0')&&cc!='-')
		cc=getchar();
	if (cc=='-')
		{
			fh=-1;
			cc=getchar();
		}
	while (cc>='0'&&cc<='9')
		{
			out=out*10+cc-'0';
			cc=getchar();
		}
	return out*fh;
}

int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	printf("%d",read()-read()+1);
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}


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

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] line = br.readLine().split(" ");
        
        int f = 0;
        int r = Integer.parseInt(line[0]);
        int c = Integer.parseInt(line[1]);
        int num[][] = new int[r][c];
        int sum_r[] = new int[r];
        int sum_c[] = new int[c];

        for (int a = 0; a < r; a++) {
            String[] line1 = br.readLine().split(" ");
            for (int b = 0; b < c; b++) {                
                num[a][b] = Integer.parseInt(line1[b]);
            }
        }
        
        for (int a = 0; a < r; a++) {
            for (int b = 0; b < c; b++) {                
                sum_r[a] += num[a][b];
            }            
        }
        
        for (int b = 0; b < c; b++) {
            for (int a = 0; a < r; a++) {                
                sum_c[b] += num[a][b];
            }            
        }
        
        for(int a = 0; a < r; a++) {
            f += sum_r[a];
        }

        for(int x = 0; x < r + 1; x++) {
            if(x != r) {               
                for(int y = 0; y < c + 1; y++) {
                    if(y != c) { System.out.print(num[x][y] + " "); }
                    else { System.out.println(sum_r[x]); }
                }                            
            }
            
            else {
                for(int z = 0; z < c + 1; z++) {
                    if(z != c){
                        System.out.print(sum_c[z] + " ");
                    }
                    else {
                        System.out.println(f); 
                    }
                }
            }
        }
        

    }

}

Measured memory_bytes: 30136
// 3A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <algorithm>
#include<cstdio>
using namespace std;
#define MAX 1400


int dp[MAX][MAX], G[MAX][MAX];

int getLargestSquare(int H, int W) {
    int maxWidth = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            dp[i][j] = (G[i][j] + 1) % 2;
            maxWidth |= dp[i][j];
        }
    }

    for (int i = 1; i < H; i++) {
        for (int j = 1; j < W; j++) {
            if (G[i][j]) {
                dp[i][j] = 0;
            }
            else {
                dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
                maxWidth = max(maxWidth, dp[i][j]);
            }
        }
    }

    return maxWidth * maxWidth;
}
int main()
{
    int H, W;
    cin >> H >> W;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++)cin >> G[i][j];
    }

    printf("%d\n", getLargestSquare(H, W));

    return 0;
}



Measured memory_bytes: 18528