akhauriyash/Code-Regression huggingface dataset:
import sys

input = sys.stdin.readline
n, m = map(int, input().split())

request = []
for _ in range(m):
    a, b = map(int, input().split())
    request.append([a, b])

request.sort(key=lambda x: x[1])
pre = - 1
ans = 0
for a, b in request:
    if pre < a:
        ans += 1
        pre = b - 1

print(ans)


Measured memory_bytes: 21288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 100;
int dp[max_n][max_n];
ll n,m;
int main(){
  cin >> n;
  pair<ll, ll> p[n];
  for(int i=0 ; i<n ; i++){
    cin >> p[i].second >> p[i].first;
  }
  sort(p, p+n);
  ll st = 0;
  for(int i=0 ; i<n ; i++){
    if(st <= p[i].first - p[i].second){
      st += p[i].second;
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;

}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

int N;
int ans = 0;

void dfs(ll n, int a, int b, int c)
{
    if (n > N) return;

    if (a == 1 && b == 1 && c == 1) ans++;
    dfs(10 * n + 3, 1, b, c);
    dfs(10 * n + 5, a, 1, c);
    dfs(10 * n + 7, a, b, 1);
    return;
}

int main()
{
    cin >> N;

    dfs(0, 0, 0, 0);
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll n,k;cin>>n>>k;
    cout<<floor((log(n)/log(k))+1);
    return 0;  
} 

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main()
{
  int a, b, c, d, X, Y;
  int D, G;
  char s[101][101]={};
  char sv[101]={};
  char ss[101]={};
//  char s_temp[101]={};
  char t[101]={};
//  char s[10000000000000000001]={};
//  char s[101]={};
  int len=0;
  int N, M;
//  int A[1000000001]={};
  int A[10001]={};
//  long int A[1001]={};
  int B[20000]={};
  int C[20000]={};
  int i,j,k;
  int flag=0;
  int tmp=0;
  int min=0;
  int cnt=0;
  int max=0;
  int ans=0;
  int str_len=0;

//  long cnt =0;
  long long A_temp;
//    int k=0;

  
   min=101;
   max=-101;

  scanf("%d %d %d %d", &a, &b, &c, &d);
  
  for(i=0;i<a;i++)
  {
    scanf("%d",&tmp);
    if(max<tmp) max=tmp;
    if(max>=d){
      printf("War\n");
      return 0;
    }
  }
  for(i=0;i<b;i++)
  {
    scanf("%d",&tmp);
    if(min>tmp) min=tmp;
    if((min<=c) || (min<=max)){
      printf("War\n");
      return 0;
    }
  } 
  
  printf("No War\n");
  
//  printf("%d\n", (max*10)+tmp+min);
   
//   printf("%d\n",a-b+1);
  
return 0;
}


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

int str_length(string);

int main(void){

  string str_s;
  string str_p;
  int loop;
  int s_num;
  int p_num;
  int first_num;

  loop = 0;
  s_num = 0;
  p_num = 0;
  first_num = 0;

  cin >> str_s;
  cin >> str_p;

  while(loop <= 2){

    if(str_s[s_num] == str_p[p_num]){

      if(p_num == str_length(str_p) - 1){
        cout << "Yes" << endl;
        break;
      }else if(s_num == str_length(str_s) - 1){
        s_num = 0;
        p_num++;
        loop++;
        if(loop >= 2){
          cout << "No" << endl;
          break;
        }
      }else{
        s_num++;
        p_num++;
      }

    }else{

      first_num++;

      s_num = first_num;

      if(s_num > str_length(str_s) - 1){
        cout << "No" << endl;
        break;
      }else{

        p_num = 0;

      }
    }
  }

  return 0;
}

int str_length(string str){

  int strlen;

  strlen = 0;

  while(str[strlen] != '\0'){
    strlen++;
  }

  return strlen;
}

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

using namespace std;
int main() {
	int n;
	cin >> n;

	int a;

	vector<int>m(n);

	for (int i = 0; i < n-1; i++) {
		int a;
		cin >> a;
		a--;
		m[a]++;

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

	return 0;
}

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

using namespace std;

int main()
{
  int R, G, B, N, ans;
  cin >> R >> G >> B >> N;
  ans = 0;
  if(R == 1 && G == 1 && B == 1)
  {
    ans = (N+1)*(N+2)/2;
  }
  else{
      for(int i=0;i*R<=N;++i)
  {
    for(int j=0;j*G+i*R<=N;++j)
    {
      for(int k=0;i*R+k*B+j*G<=N;++k)
      {
        int K = N - i*R - j*G - k*B;
        if(K == 0)ans++;
      }
    }
  }
  }


  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

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

#define fi first
#define se second

using namespace std;

typedef long long ll;

int n, a, b;

void solve() {                   
	scanf("%d %d %d", &n, &a, &b);

    if (a > b) {
    	printf("0\n");
    	return;
    }
	
	if (a == b) {
		printf("1\n");
		return;
	}

	if (a < b && n == 1) {
		printf("0\n");
		return;
	}

	printf("%lld\n", (b - a) * (n - 2ll) + 1);
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
i = input().split()
h = int(i[0])
w = int(i[1])

if h == 1 or w == 1:
  	print(1)
else:
    if h % 2 != 0:
        move_h = int(h / 2)
        if w % 2 == 0:
            print((move_h * w) + int(w /2))
        else:
            print((move_h * w) + int((w /2)+1))
    else:
        move_h = h / 2
        print(int(move_h * w))


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

using namespace std;
vector <int> swim,catchbug,dohom;

int main(void)
{
  int n;
  cin>>n;
  swim.resize(n+1);
  catchbug.resize(n+1);
  dohom.resize(n+1);
  vector <vector<int>> d(n+1,vector<int>(3));
  for(int i=1;i<=n;i++){
    cin>>swim[i]>>catchbug[i]>>dohom[i];
  }
  d[1][0]=swim[1];
  d[1][1]=catchbug[1];
  d[1][2]=dohom[1];
  for(int i=2;i<=n;i++){
    d[i][0]=max(d[i-1][1]+swim[i],d[i-1][2]+swim[i]);
    d[i][1]=max(d[i-1][0]+catchbug[i],d[i-1][2]+catchbug[i]);
    d[i][2]=max(d[i-1][0]+dohom[i],d[i-1][1]+dohom[i]);
  }
  cout<<max(d[n][2],max(d[n][0],d[n][1]));
  return 0;
}

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

int main() {
  int n, d, i, j, k, ans = 0;
  cin >> n >> d;
  
  vector<vector<int>> x(n, vector<int>(d));
  for (i = 0; i < n; i++) {
    for (j = 0; j < d; j++) {
      cin >> x.at(i).at(j);
    }
  }
  
  int sum = 0, y;
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      for (k = 0; k < d; k++) {
        sum += pow(abs(x.at(j).at(k) - x.at(i).at(k)), 2);
      }
      y = sqrt(sum);
      if (y * y == sum) {
        ans++;
      }
      sum = 0;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC target ("avx,avx2,tune=native")
#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define orz ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);    
#define inp freopen("input.txt","r",stdin);freopen("out.txt","w",stdout); 
ll mod=1e9+7;
void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}
const int N=2e5+5;
int a[N],v[N];
int main() {
	//io();
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(i%2){
			if(s[i]=='L' || s[i] == 'U' || s[i] == 'D')
					continue;
			else{
				cout<<"No";
				return 0;
			}
		}
		else{
			if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D')
					continue;
			else{
				cout<<"No";
				return 0;
			}
		}
	}
   
		cout<<"Yes";
}
 

 

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

int main(){
    int n ,k;
    long long ans= 0,ans2 = 0;
    cin >> n >> k;
    if(k % 2){
        for(int i = 1;i <= n;i++){
            if(i % k == 0)ans++;
        }

    }else{
        for(int i = 1;i <= n;i++){
            if(i % k == 0 )ans++;
            if(i % k == k / 2)ans2++;
        }
    }
    cout << ans * ans * ans + ans2 * ans2 * ans2 << endl;
}

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

int main() {
  int n, T;
  cin>>n>>T;
  int min_c = INT_MAX;
  for (int i=0; i<n; i++) {
    int c, t;
    cin>>c>>t;
    if (t <= T) {
      min_c = min(c, min_c);
    }
  }
  if (min_c == INT_MAX) {
    cout<<"TLE"<<endl;
  } else {
    cout<<min_c<<endl;
  }
}

Measured memory_bytes: 256
S = input()

a = int(S[:2])
b = int(S[2:])
a = True if a>0 and a<13 else False
b = True if b>0 and b<13 else False

if a and b:
  str = 'AMBIGUOUS'
elif a and not b:
  str = 'MMYY'
elif not a and b:
  str = 'YYMM'
else:
  str = 'NA'
  
print(str)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b;
    cin >>a >> b;
    if(abs(a+b)%2==1)cout << "IMPOSSIBLE" << endl;
    else{
        cout << abs(a+b)/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>


int main(void){

	long long x;
	std::cin >> x;

	long long sum = 0;
	long long tmp = x;
	while(tmp > 0){
		sum += tmp % 10;
		tmp /= 10;
	}

	std::cout << ( (x % sum) == 0 ? "Yes" : "No" ) << std::endl;

	return 0;
}

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

int main()
{
	int n;

	cin >> n;
	cin.get();

	for( int i = 0; i < n; ++i ){
		string s;
		getline( cin, s );
		int index = 0;
		while( ( index = s.find( "Hoshino", index ) ) != string::npos ){
			s.replace( index, 7, "Hoshina" );
			index += 7;
		}
		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

int n;
string s[100];

int f(string num)
{
    int res = 0;
    rep(i, num.size())
    {
        if (num[i] == '.')
            continue;
        res = 10 * res + (num[i] - '0');
    }
    return res;
}
//op : 0 -> +, 1 -> *
int cal(int pos, int depth, int op)
{
    int res = 0;
    if (op == 1)
        res = 1;
    for (int i = pos; i < n && depth < s[i].size(); i++)
    {
        if (s[i][depth] == '.')
            continue;
        int num = f(s[i]);
        if (s[i][depth] == '+')
            num = cal(i + 1, depth + 1, 0);
        else if (s[i][depth] == '*')
            num = cal(i + 1, depth + 1, 1);
        if (op == 0)
            res += num;
        else
            res *= num;
    }
    return res;
}

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

    while (1)
    {
        cin >> n;
        if (n == 0)
            break;
        rep(i, n) cin >> s[i];
        cout << cal(0, 0, 0) << endl;
    }
}



Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int n;
	cin >> n;
	cout << 10 - n / 200 << '\n';
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){
	long long n,r=0,l=0,a,b;
	char c;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>c>>b;
		if(c==')')r+=b;
		else l+=b;
		if(l==r)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,k,x=0,i;
    int arr[1000];
    cin>>a>>b>>k;
    for (i=1;i<=min(a,b);i++)
    {
        if (a%i==0 && b%i==0)
        {
            arr[x]=i;
            x++;
        }
    }
    sort(arr,arr+x);
    reverse(arr,arr+x);
    cout<<arr[k-1]<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    long long int N;
    cin>>N;
    char ans[30];
    //N--;
    int keta=0;
    while(1){
        ans[keta]='a'+N%26;
        if(N%26==0){
            ans[keta]='z'+1;
            N-=26;
        }
        N/=26ll;
        keta++;
        if(N==0)break;
    }
    for(int i=keta-1;0<=i;i--)cout<<(char)(ans[i]-1);
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
    int n;
    cin >> n;
    vector <ll> nums(n);
    for (int i=0;i<n;i++){
        cin >> nums[i];
    }
    sort(nums.begin(), nums.end());
    ll cnt1 = 0, cnt2 = 0;
    int i=0;
    if (n % 2 == 0){
        for (i;i<n/2-1;i++)
            cnt1 -= 2 * nums[i];
        cnt1 -= nums[i++];
        cnt1 += nums[i++];
        for (i;i<n;i++)
            cnt1 += 2 * nums[i];
        cnt2 = cnt1;
    }
    else{
        for (i;i<n/2;i++)
            cnt1 -= 2 * nums[i];
        cnt1 += nums[i++];
        cnt1 += nums[i++];
        for (i;i<n;i++)
            cnt1 += 2 * nums[i];
            
        i=n-1;
        for (i;i>n/2;i--)
            cnt2 += 2 * nums[i];
        cnt2 -= nums[i--];
        cnt2 -= nums[i--];
        for (i;i>=0;i--)
            cnt2 -= 2 * nums[i];
    }
    cout << max(cnt1,cnt2);
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>

int main(void){
  int n,i,s;
  scanf("%d",&n);
  if(n<1)
     return 0;
  int a[n];
  
  for(i=0;i<n;i++){
   scanf("%d",&a[i]);
   if(a[i]>100)
     return 0;
  }

  s=0;
  for(i=0;i<n;i+=2){
    if(a[i]%2==1){
      s++;
    }
  }
  printf("%d",s);
  return 0;
}


Measured memory_bytes: 2152
X = int(input())
if X > 2 and not X % 2: X += 1

while True:
    i = 3

    f = True
    while i ** 2 <= X:
        if not X % i:
            f = False
            break
        i += 2
        
    if f and X > 1: break

    X += 2
    
print(X)

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

		#define ll long long int 
		#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);


		int main()
		{
			string str;
			int i,j;
			cin>>str;
			i=str[3]-'0'+(str[2]-'0')*10;
			j=str[1]-'0'+(str[0]-'0')*10;
			bool a,b;
			b=(i>=1&&i<=12);
			a=(j>=1&&j<=12);
			if(a&&b)cout<<"AMBIGUOUS";
			else if(a&&!b)cout<<"MMYY";
			else if(!a&&b)cout<<"YYMM";
			else cout<<"NA";

		}

Measured memory_bytes: 256
n = gets.chomp.to_i
cards = Hash.new
%w(S H C D).each { |f|
  cards[f] = Array.new
}
(1..n).each {
  card = gets.chomp.split(' ')
  cards[card[0]] << card[1].to_i
}
%w(S H C D).each { |f|
  (1..13).each { |i|
    unless cards[f].include?(i) then puts "#{f} #{i}" end
  }
}

Measured memory_bytes: 6100
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<cmath>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<stdio.h>
#include<queue>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  a=a*b;
  if(a%2)
    cout<<"Odd\n";
  else
    cout<<"Even\n";
  system("pause");
  return 0;
}


Measured memory_bytes: 504
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;
const int INF = 1e9;

int main(){
	long long ans = 0;
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; ++i){
		cin >> a[i];
		ans += a[i]-1;
	}
	cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
#define MOD 1000000007

int main()
{
  ll x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> as = {};
  vector<ll> bs = {};
  vector<ll> cs = {};
  for (auto i = 0; i < a; i++)
  {
    ll x;
    cin >> x;
    as.push_back(x);
  }
  for (auto i = 0; i < b; i++)
  {
    ll x;
    cin >> x;
    bs.push_back(x);
  }
  for (auto i = 0; i < c; i++)
  {
    ll x;
    cin >> x;
    cs.push_back(x);
  }
  sort(as.begin(), as.end());
  sort(bs.begin(), bs.end());
  sort(cs.begin(), cs.end());
  reverse(as.begin(), as.end());
  reverse(bs.begin(), bs.end());
  reverse(cs.begin(), cs.end());

  ll total = 0;
  vector<ll> ans = {};
  for (auto i = 0; i < x; i++)
  {
    ans.push_back(as[i]);
    total += as[i];
  }
  for (auto i = 0; i < y; i++)
  {
    ans.push_back(bs[i]);
    total += bs[i];
  }
  sort(ans.begin(), ans.end());
  ll cs_p = 0;
  for (auto i = 0; i < ans.size(); i++)
  {
    if (ans[i] < cs[cs_p])
    {
      total -= ans[i];
      total += cs[cs_p];
      cs_p++;
    }
  }

  cout << total << endl;

  return 0;
}


Measured memory_bytes: 4724
package main
 
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)
 
var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func main() {
  HWhw := NextIntVec()
  H := HWhw[0]
  W := HWhw[1]
  h := HWhw[2]
  w := HWhw[3]
  y := H / h
  b := H % h
  x := W / w
  a := W % w
  if a == 0 && b == 0 {
    Write("No")
  } else {
    Write("Yes")
    p := x * y / (a * H + b * W - a * b) + 1
    P := strconv.Itoa(p)
    m := -p * (h * w - 1) - 1
    M := strconv.Itoa(m)
    for i := 0; i < H; i++ {
      A := make([]string, W)
      for j := range A {
        A[j] = P
        if (i + 1) % h == 0 && (j + 1) % w == 0 {
          A[j] = M
        }
      }
      Write(strings.Join(A, " "))
    }
  }
  Output()
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).begin(),(x).rend()

typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;


int main(){
	int N;
	ll T,t[200000];
	cin>>N>>T;
	for (int i = 0; i < N; ++i){
		cin>>t[i];
	}

	ll sum=T;
	for (int i = 1; i < N; ++i){
		sum+=min(T,t[i]-t[i-1]);
	}

	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) {return a / GCD(a, b) * b;}

int main()
{
	int N,M;
	cin >> N >> M;
	vector<pair<int,int> > a(M);
	vector<bool> reach(N,false);
	for(int i = 0; i < M; i++)
	{
		cin >> a[i].first >> a[i].second;
		if(a[i].second == N) reach[a[i].first] = true;
	}
	sort(a.begin(),a.end());
	bool ok = false;
	int A = 0;
	for(int i = 0; i < M; i++)
	{
		if(a[i].first == 1)
		{
			if(reach[a[i].second]) ok = true;
		}
	}
	if(ok) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

struct data_t{
  string str;
  int num;
  int num2;

  bool operator<( const data_t& right ) const{
    return str == right.str ? num > right.num : str < right.str;
  }
};

int main(){
    int N;

    cin >> N;
    vector<data_t> data_array(N);

    for (int i = 0; i < N; i++){
        cin >> data_array[i].str >> data_array[i].num;
        data_array[i].num2 = i+1;
    }

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

    for (int i = 0; i < N; i++)
            cout << data_array[i].num2 << endl;
    return 0;
}

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
   string s;
   ll ans = 0;
   cin >> s;
   int len = s.size();
   for (int t = 0; t < (1 << (len - 1)); t++) {
      ll num = s[0] - '0';
      for (int i = 0; i < len - 1; i++) {
         if (t & (1 << i)) {
            ans += num;
            num = 0;
         }
         num = num * 10 + s[i + 1] - '0';
      }
      ans += num;
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B = map(int, readline().split())

    def f(x):
        r = (x + 1) % 4
        ans = 0
        for i in range(x, x - r, -1):
            ans ^= i

        return ans

    if A == 0:
        print(f(B))
    else:
        print(f(B) ^ f(A - 1))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <cmath>         // sqrt
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

// Greatest Common Divisor (最大公約数)
ll gcd(ll a, ll b)
{
  // Eucledean algorithm
  while (a)
  {
    if (a < b)
    {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}

// Least Common Multiple 最小公倍数
ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

// key: value of prime factor素因数分解
// value: number of prime factor
map<ll, ll> prime_factorization(ll n)
{
  map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

// 約数リスト約数の列挙
vector<ll> get_divisors(const ll n)
{
  vector<ll> divs;
  for (ll i = 1; i < (ll)sqrt((ld)n) + 1; i++)
  {
    if (n % i == 0)
    {
      divs.push_back(i);
      if (i != n / i)
      {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  // sort(divs.begin(), divs.end());

  return divs;
}

int main()
{
  long double A, B;
  cin >> A >> B;

  ll ans = A * B;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a)      cout<<a<<" "
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll minize(ll& a,ll b){return a=(a>b?b:a);}
inline ll maxize(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	
	sc2(n,k);
	pr(n-k+1);

	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

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

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a, b) for(int i=a;i<b;++i)
#define fj(a, b) for(int j=a;j<b;++j)
#define fk(a, b) for(int k=a;k<b;++k)
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
////////////////////////////////

int const N = 1e6 + 41;
int const MOD = 1e9 + 7;

void add(ll &a, ll b){
	a += b;
	a %= MOD;
	if(a < 0) a += MOD;
}

ll sum(ll a, ll b){
	return (a + b) % MOD;
}

ll mul(ll a, ll b){
	return (a * 1LL * b % MOD);
}



ll d[N];
ll F[N];

void upd(int x, int v){
	while(x < N){
		add(F[x], v);
		x |= (x + 1);
	}
}

ll get(int x){
	ll ret = 0;
	while(x >= 0){
		add(ret, F[x]);
		x = (x&(x+1)) -1;
	}
	return ret;
}

void solve(){
	int n;
	cin >> n;
	if(n == 1){
		cout << 1 << endl;
		return;
	}

	ll ans = 1;
	ll cur = 1;
	for(int i=1;i<=n;++i){
		add(cur, get(i-1));
		if(i < n){
			add(ans, mul(cur, mul(n-1, n)));
		}else{
			add(ans, mul(cur, i-1));
		}
		upd(i+2, cur);
	}
	printf("%lld\n",ans);
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();



	return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	ll n;
	cin >> n;
	
	ll tmp = n;
	string ans = "";
	
	while( tmp ) {
		ans += (char)(((tmp - 1) % 26) + 'a');
		tmp = (tmp - 1) / 26;
	}
	
	reverse(ans.begin(), ans.end());
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3608
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=5000+10;
const int mod=1e9+7;

struct edge { int v,nxt; } e[N<<1];
int head[N];

inline void addEdge(int u,int v) {
    static int e_cnt=0;
    e[++e_cnt]=(edge){v,head[u]},head[u]=e_cnt;
}

int n,sz[N];
int f[N][N],g[N],tmp[N];

inline void dfs(int u,int fa) {
    sz[u]=f[u][1]=1;
    for (re int i=head[u];i;i=e[i].nxt) {
        int v=e[i].v; if (v==fa) continue;
        dfs(v,u);
        for (re int j=1;j<=sz[u]+sz[v];++j) tmp[j]=0;
        for (re int j=1;j<=sz[u];++j)
            for (re int k=0;k<=sz[v];++k)
                tmp[j+k]=(tmp[j+k]+1ll*f[u][j]*f[v][k])%mod;
        sz[u]+=sz[v];
        for (re int j=1;j<=sz[u];++j) f[u][j]=tmp[j];
    }
    for (re int i=2;i<=sz[u];i+=2)
        f[u][0]=(f[u][0]-1ll*f[u][i]*g[i]%mod+mod)%mod;
}

int main() {
    n=read();
    for (re int i=1;i<n;++i) {
        int u=read(),v=read();
        addEdge(u,v),addEdge(v,u);
    }
    g[0]=1;
    for (re int i=2;i<=n;i+=2) g[i]=1ll*g[i-2]*(i-1)%mod;
    dfs(1,0); printf("%d\n",mod-f[1][0]);
    return 0;
}
//qwq

Measured memory_bytes: 97024
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

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

  int n;
  cin >> n;

  ll tot = 0;
  REP(i, n) {
    int a, k;
    cin >> a >> k;
    // a -> a - a/k
    while(a%k && a >= 2*k) {
      int cost = a/k + 1;
      int dif = a-a/k*k;
      a -= ceil(dif,cost)*cost;
    }
    if(a >= 2*k) tot ^= a/k;
    else if(a >= k) {
      tot ^= !((a-k)%2);
    } else {
      tot ^= 0;
    }
    // cout << a << " " << tot << endl;
  }

  if(tot) cout << "Takahashi" << endl;
  else cout << "Aoki" << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

const ll p = 1e9 + 7;

int n, l, r;
int used[100001];

long long f[200000 + 1];
long long fi[200000 + 1];
long long bp[40];

long long binpow(long long a, long long b)
{
    bp[0] = 1;
    bp[1] = a;
    for (int i = 2; i < 40; i++)
    {
        bp[i] = (bp[i - 1] * bp[i - 1]) % p;
        //cout << bp[i] << endl;
    }

    int d = 1;
    long long res = 1;

    while (b)
    {
        if (b & 1)
        {
            res = (res * bp[d]) % p;
        }
        d++;
        b = b >> 1;
    }
    return res;
}

void make_ftable(int n)
{
    f[0] = 1;
    fi[0] = 1;
    f[1] = 1;
    fi[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        f[i] = i * f[i - 1] % p;
        fi[i] = binpow(f[i], p - 2) % p;
    }
}

long long C(long long n, long long r)
{
    if (n < 0 || r < 0 || r > n)
    {
        return 0LL;
    }
    return (f[n] * ((fi[r] * fi[n - r]) % p)) % p;
}

int main()
{
    cin >> n;

    make_ftable(n + 1);

    for (int i = 0; i < 100001; i++)
    {
        used[i] = -1;
    }
    for (int i = 0; i < n + 1; i++)
    {
        int t;
        cin >> t;
        if (used[t] != -1)
        {
            l = used[t];
            r = i;
        }
        used[t] = i;
    }

    ll nC;
    ll mC;
    ll m = l + n - r;

    //cout << "l : " << l << " r : " << r << " m = " << m << endl;

    for (int i = 1; i <= n + 1;i++)
    {
        nC = C(n + 1, i);
        mC = C(m, i - 1);
        cout << (nC - mC + p) % p << endl;
    }

    return 0;
}

Measured memory_bytes: 3200
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main(void) {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }
    int ans = 0;
    for (int is = 0; is < (1 << h); is++) {
        for (int js=0; js < (1 << w); js++) {
            int cnt = 0;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (is >> i & 1) {
                        continue;
                    }
                    if (js >> j & 1) {
                        continue;
                    }
                    if (s[i][j] == '#') {
                        cnt++;
                    }

                    
                }
            }
            if (cnt != k) {
                continue;
            }
            else {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3588
# dame datta...
def main():
    A, B = map(int, input().split())
    t = [[0] * 100 for _ in range(50)] + [[1] * 100 for _ in range(50)]
    x = 0
    b = False
    for i in range(0, 50, 2):
        for j in range(0, 100, 2):
            if x == A - 1:
                b = True
                break
            t[i][j] = 1
            x += 1
        if b:
            break
    x = 0
    b = False
    for i in range(51, 100, 2):
        for j in range(0, 100, 2):
            if x == B - 1:
                b = True
                break
            t[i][j] = 0
            x += 1
        if b:
            break
    print(100,100)
    for i in range(100):
        print(''.join('.' if i == 1 else '#' for i in t[i]))
main()


Measured memory_bytes: 3188
import sys
import math
import collections
import itertools
import array
import inspect
import copy

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(input().split())
    return li

# --------------------------------------------

dp = None

def A_is_connected(A, edge, n_V):
    A[edge[0]][edge[1]] = False
    A[edge[1]][edge[0]] = False

    queue = [1]
    reached = [1]

    while len(queue) != 0:
        new_queue = []
        for q in queue:
            for i, is_connected in enumerate(A[q]):
                if is_connected and i not in reached:
                    new_queue.append(i)
                    reached.append(i)

        queue = new_queue

    return len(reached) == n_V


def main():
    n_V, n_E = list(map(int, input().split()))

    A = []
    for i in range(n_V+1):
        A.append([])
        for j in range(n_V+1):
            A[i].append(False)

    edges = []
    for _ in range(n_E):
        edges.append(list(map(int, input().split())))

    for edge in edges:
        A[edge[0]][edge[1]] = True
        A[edge[1]][edge[0]] = True

    n_bridge = 0

    for edge in edges:
        origin_A = copy.deepcopy(A)
        if not A_is_connected(A, edge, n_V):
            n_bridge += 1
        A = origin_A

    print(n_bridge)


main()


Measured memory_bytes: 5140
N = int(input())
A = list(map(int, input().split()))
A.sort(key=lambda a: abs(a))

minus_count = sum(a < 0 for a in A)
has_zero = (0 in A)
abs_sum = sum(abs(a) for a in A)

if has_zero or minus_count%2==0:
    print(abs_sum)
else:
    print(abs_sum - 2*abs(A[0]))


Measured memory_bytes: 14284
import java.util.*;

public class Main
{
    static int N;
    static int W;
    static int w0;
    static ArrayList<Integer>[] v = new ArrayList[4];

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

        N = sc.nextInt();
        W = sc.nextInt();

        for (int i = 0; i < v.length; ++i)
        {
            v[i] = new ArrayList<Integer>(N);
        }

        w0 = sc.nextInt();
        v[0].add(sc.nextInt());

        for (int i = 1; i < N; ++i)
        {
            int w = sc.nextInt();
            v[w - w0].add(sc.nextInt());
        }

        for (int i = 0; i < v.length; ++i)
        {
            v[i].sort(Comparator.reverseOrder());
        }

        System.out.println(solve(0, N, 0));
    }

    static int solve(int startIndex, int numLeft, int totalW)
    {
        if (startIndex >= v.length)
        {
            return 0;
        }

        int vi = 0;
        int wi = totalW;
        int max_v = 0;
        for (int n = 0; n <= numLeft && n <= v[startIndex].size(); ++n)
        {
            if (n >= 1)
            {
                vi += v[startIndex].get(n - 1);
                wi += w0 + startIndex;
            }

            if (wi > W)
            {
                break;
            }

            max_v = Integer.max(max_v, vi + solve(startIndex + 1, numLeft - n, wi));
        }

        return max_v;
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		String str;
		Scanner sc = new Scanner(System.in);
		str = sc.nextLine();
		StringBuilder sb = new StringBuilder(str);
		for(int i = 0; i < str.length(); ++i){
			char judge = sb.charAt(i);
			if(Character.isLowerCase(judge)){
				char tmp = Character.toUpperCase(judge);
				sb.setCharAt(i,tmp);
			}
			else if(Character.isUpperCase(judge)){
				char tmp = Character.toLowerCase(judge);
				sb.setCharAt(i,tmp);
			}
		}
		System.out.println(sb);
		sc.close();
	}

}

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

using namespace std;

int main(void){
  int N;
  long long K;
  cin >> N >> K;
  vector<long long> H(N);
  for(int i = 0; i < N; i++) cin >> H[i];
  sort(H.begin(), H.end());
  long long ans = 0;
  for(int i = 0; i < N - K; i++) ans += H[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <unordered_map>
using namespace std;
#define INF 100000000
typedef long long ll;
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)

int main(){
    vector<int> vertex(3,0);
    cin>>vertex[0]>>vertex[1]>>vertex[2];
    sort(vertex.begin(),vertex.end());
    cout<< vertex[0] *vertex[1] /2 <<endl;
}

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

int main() {
	// your code goes here
    int n;
    cin >> n;
    int dp[n];
    int h[n];
    for (int i = 0; i < n;i++) {
        cin >> h[i];
    }
    dp[1] = abs (h[1] - h[0]);
    dp[0] = 0;
    for (int i = 2; i < n;i++) {
        dp[i] = min (dp[i - 1] + abs(h[i] - h[i - 1]),dp[i - 2] + abs (h[i - 2] - h[i]));
    }
    cout << dp[n - 1] << endl;
}


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

long long int factorial(long long int N){
    for(int i=N-1;1<i;i--){
        N *= i;
        N %= 1000000007;
    }
    return N;
    // 1000000007
}
 
int main(){
    long long int N,M;
    cin >> N >> M;
    if(1<abs(N-M)){
        cout << "0" << endl;
    }else if(abs(N-M) == 1){
        cout << factorial(N)*factorial(M)%1000000007;
    }else{
        cout << 2*factorial(N)*factorial(M)%1000000007;
    }
}

Measured memory_bytes: 764
function main()
    L,R,d = reads(Int,Int,Int)
    c = 0
    for i in L:R
        if i % d == 0
            c += 1
        end
    end
    println(c)
end

import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str
isdelim(x::UInt8, xs::Set{UInt8}) = x in xs
const delimset = Set([0x0a, 0x20])

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        !isdelim(c, delims) && break
    end
    push!(out, c)
    eof(s) && return out
    while !eof(s)
        c = read(s, UInt8)
        isdelim(c, delims) && break
        push!(out, c)
    end
    return out
end

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

function readvec(tys::Tuple , len::Signed)::Tuple{map(x -> Vector{x},tys)...}
    rv = Tuple{map(x -> Vector{x},tys)...}(Vector{ty}(undef,len) for ty in tys)
    for i in 1:len
        for j in 1:length(tys)
            @inbounds rv[j][i] = pread(tys[j])
        end
    end
    rv
end

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i in 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

main()


Measured memory_bytes: 193548
building=[[[0]*10 for i in range(0,3)] for i in range(0,4)]
n=int(input())
for i in range(0,n):
    b,f,r,v=map(int,input().split())
    building[b-1][f-1][r-1]+=v
for i in range(0,4):
    for j in range(0,3):
        for k in range(0,10):
            print(f" {building[i][j][k]}",end="")
        print()
    if(i!=3):
        print("{}".format("#"*20))


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  int i=A;
  int sum=0;
  int k=0;
  while(i<=B){
    if((i%10==i/10000)&&(((i%100-i%10)/10)==i/1000-(i/10000)*10)){
      sum++;
    }
    i++;
  }
  cout<<sum<<endl;
}
    
    
  
  


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

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

	if (s[0] == 'R') {
		if (s[1] == 'R') {
			if (s[2] == 'R') {
				cout << 3 << endl;
			}
			else {
				cout << 2 << endl;
			}
		}
		else {
			cout << 1 << endl;
		}
	}
	else if (s[1]== 'R') {
		if (s[2] == 'R') {
			cout << 2 << endl;
		}
		else {
			cout << 1 << endl;
		}
	}
	else {
		if (s[2] == 'R') {
			cout << 1 << endl;
		}
		else {
			cout << 0 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3624
package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)

    for i := 0;i < 10; i++  {
        for j := 0;j < 10; j++  {
            var result int = i * j
            if result == n {
                fmt.Println("Yes")
                return
            }
        }
    }
    fmt.Println("No")
}



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

int main(){
	
	int n;
	cin>>n;
	if (n==1){
		cout<<"Hello World"<<endl;
	}else{
		int a,b;
		cin>>a>>b;
		cout<<a+b<<endl;
	}
	
}
 

Measured memory_bytes: 384
#include<iostream>
#include<queue>
using namespace std;
const int MAXN=110;
const int INF=1000000000;
struct Node{
	int u,d;
	bool operator < (const Node a) const{
		return this->d<a.d;
	}
	bool operator > (const Node a) const{
		return this->d>a.d;
	}
};
priority_queue<Node ,vector<Node>, greater<Node> > q;
int lowcost[MAXN],used[MAXN];
int n;
int k,v;
int uu;
int map[MAXN][MAXN];
Node mp(int x,int c)
{
	Node tmp;
	tmp.u=x;tmp.d=c;
	return tmp;
}

void input()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>uu>>k;
		for(int j=0;j<k;j++){
		    int c;
	        cin>>v>>c;
	        map[uu][v]=c;
	    }
	}
	for(int i=0;i<n;i++)
	    lowcost[i]=INF;
}

void init()
{
	lowcost[0]=0;
	used[0]=1;
	for(int i=0;i<n;i++)
	    if(map[0][i]) {lowcost[i]=map[0][i];q.push(mp(i,lowcost[i]));}
}

void xxj()
{
	init();
	for(int i=0;i<n-1;i++)
	{
		while(used[q.top().u]) q.pop();
		Node tmp=q.top();q.pop();
		used[tmp.u]=1;
		int ts=tmp.d;
		for(int j=0;j<n;j++)
		{
			if(used[j])continue;
			if(map[tmp.u][j] && map[tmp.u][j]+ts<lowcost[j]) {lowcost[j]=map[tmp.u][j]+ts;q.push(mp(j,lowcost[j]));}
		}
	}
}

void output()
{
	for(int i=0;i<n;i++)
	    cout<<i<<' '<<lowcost[i]<<endl;
}

int main()
{
	input();
	xxj();
	output();
    return 0;
}

Measured memory_bytes: 3088
from collections import deque

#キューを使った幅優先探索の実装
l = int(input())
rlist = []
for i in range(l):
    li = list(map(int, input().split()))
    rlist.append(deque([ll-1 for ll in li[2:]]))


color = ['white'] * l
queue = deque([])
d = [10000000] * l

def bfs(u):
    color[u] = 'gray'
    d[u] = 0
    queue.append(u)

    while(len(queue) > 0):
        u = queue.popleft()
        for rl in rlist[u]:
            if color[rl] == 'white':
                color[rl] = 'gray'
                d[rl] = d[u] + 1
                queue.append(rl)
        color[u] = 'black'

bfs(0)

for i in range(l):
    if d[i] == 10000000:
        d[i] = -1

for i in range(l):
    print(str(i+1) + ' ' + str(d[i]))


Measured memory_bytes: 6048
# include <bits/stdc++.h>
using namespace std; 
int main(){
  string str, strr,ans; 
   int n, m, i, j,k; 
  cin>>str; 
  cin>>strr; 
  n=str.length();
  m=strr.length();
  int dp[n+1][m+1]={0};
  for(i=0;i<=n; i++){
    for(j=0;j<=m; j++){
      dp[i][j]=0;
    }
  }
  for(i=1;i<=n;i++){
    for(j=1;j<=m;j++){
      if(str[i-1]==strr[j-1]){
        dp[i][j]=dp[i-1][j-1]+1;
      }
      else{
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      }
    }
  }
  k=dp[n][m];
  i=n;
  j=m;
  ans="";
  while(k>0){
    if(str[i-1]==strr[j-1]){
      ans=ans+str[i-1];
      i--;
      j--;
      k--;
    }
    else{
      if(dp[i][j-1]>dp[i-1][j]){
        j--;
      }
      else{
        i--;
      }
    }
  }
  reverse(ans.begin(),ans.end());
  cout<<ans; 
  return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<tuple<string, int, int>> ranking;
  for(int i=1; i<=N; i++){
    string S;
    int P;
    cin>>S>>P;
    ranking.push_back(make_tuple(S, (-1)*P, i));
  }
  sort(ranking.begin(), ranking.end());
  
  for (tuple<string, int, int> t : ranking) {
    string x;
    int y, z;
    tie(x, y, z) = t;
    cout << z << endl;
  }
}
 

Measured memory_bytes: 256