akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public final class Main {
    
    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        final int i = fs.nextInt();
        System.out.println(n - i + 1);
    }

    static final class Util {
        public static void shuffleSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffleSort(long[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void shuffle(long[] x) {
            final Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                final int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            final int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        public static void swap(long[] x, int i, int j) {
            final long t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Util() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}


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

int main(void)
{
    int n, a, x1=0, x2=0;
    cin >> n;
    x1=n;
    while(n--)
    {
        cin >> a;
        if(a%2==0)
        {
            if(a%3==0 || a%5==0)
            {
                x2++;
            }
        }
        else
            x2++;
    }

    if(x1==x2)
        cout << "APPROVED" << endl;
    else
        cout << "DENIED" << endl;
}


Measured memory_bytes: 256
n,m,x,y=map(int,input().split())
x1=sorted(list(map(int,input().split())))
y1=sorted(list(map(int,input().split())))
x_=x1[n-1]
y_=y1[0]
for i in range(x_+1,y_+1):
  if x<i<=y:
    print('No War')
    exit()
print('War')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;

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

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

    int count=1;

    for (int i=0;i<n-1;i++) {
        if(d[i]!=d[i+1]){
            count++;
        }
    }

    cout<<count<<endl;
}


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

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

/*********** Constants ***********/
const auto INF = static_cast<ll>(1e15);
const auto MOD = static_cast<ll>(1e9 + 7);

/************* Utils *************/

/*********** Variables ***********/
string S;
ll A, K;
stack<ll> S1;
stack<pair<ll, ll>> S2;
vector<ll> ANS;

/*********** Functions ***********/
bool init() {
    cin >> S;
    return true;
}

void solve() {
    for (ll i = 0; i < S.length(); i++) {
        if (S[i] == '_') {
            continue;
        }
        if (S[i] == '\\') {
            S1.push(i);
        }
        if (S[i] == '/') {
            if (S1.empty()) {
                continue;
            }
            ll j = S1.top(); S1.pop();
            A += i - j;
            ll a = i - j;
            while (!S2.empty() && S2.top().first > j) {
                a += S2.top().second; S2.pop();
            }
            S2.emplace(j, a);
        }
    }
    K = S2.size();
    while (!S2.empty()) {
        ANS.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ANS.begin(), ANS.end());
}

void output() {
    cout << A << endl;
    cout << K;
    for (const auto& LAKE: ANS) {
        cout << " " << LAKE;
    }
    cout << endl;
}

int main() {
    init();
    solve();
    output();
    return 0;
}


Measured memory_bytes: 3316
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
#from scipy.misc import comb

H,W = map(int, input().split())

if H%3 == 0:
    print(0)
elif W%3 == 0:
    print(0)
else:
    ans = H*W
    A = [0]*3
    for i in range(1,H):
        A[0] = i*W
        A[1] = (H-i)*(W//2)
        A[2] = (H-i)*(W-W//2)
        A.sort()
        ans = min(ans,A[2]-A[0])
    
    for j in range(1,W):
        A[0] = H*j
        A[1] = (H//2)*(W-j)
        A[2] = (H-H//2)*(W-j)
        A.sort()
        ans = min(ans,A[2]-A[0])

    ans = min(ans, H, W)

    print(ans)

Measured memory_bytes: 14260
<?php
  $input_line = trim(fgets(STDIN));
  $arr = [];
  $arr = str_split($input_line);
  $sum = 0;
  for ($i = 0; $i < count($arr); $i++) {
    if ($arr[0] == 'R' && $arr[2] == 'R' &&  $arr[1] != 'R') {
        $sum = 1;
    } else if ($arr[$i] == 'R') {
      	$sum += 1;
   	}
    
  }
  echo($sum);
?>


Measured memory_bytes: 16128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int N;

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

int main() {
    cin >> N;
    
    int s = sumofdigits(N);
    if (N % s == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
 int a,b,c;

 scanf ("%d %d", &a, &b);
 
 if (b > a) {
	c = a;
	a = b;
	b = c;
}

 while (b != 0) {
  c = b;
  b = a%b;
  a = c;
 }
 
 printf("%d\n", a);
 return 0;

}

Measured memory_bytes: 2728
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    priority_queue<int, std::vector<int>, std::greater<int>> right;
    priority_queue<int> left;
    int q;
    cin >> q;
    int mi = 0;
    for (int i = 0; i < q; i++) {
        int flag;
        cin >> flag;
        if (flag == 2) {
            if (left.empty()) {
                cout << 0 << " " << mi << endl;
            } else {
                cout << left.top() << " " << mi << endl;
            }
        } else {
            int a, b;
            cin >> a >> b;
            if (left.empty()) {
                mi = b;
                left.push(a);
                right.push(a);
            } else {
                if (left.top() <= a && right.top() >= a) {
                    left.push(a);
                    right.push(a);
                    mi += b;
                } else if (left.top() > a) {
                    int tor = left.top();
                    left.pop();
                    mi += abs(tor - a) + b;
                    left.push(a);
                    left.push(a);
                    right.push(tor);
                } else {
                    int tor = right.top();
                    right.pop();
                    mi += abs(tor - a) + b;
                    right.push(a);
                    right.push(a);
                    left.push(tor);
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
   string s;
   cin >> s;
   rep(i, s.length())
   {
      if (s[i] == ',')
      {
         cout << " ";
      }
      else
      {
         cout << s[i];
      }
   }
   cout << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;

    map<int, int> cnt;
    int inA;
    for (int i = 0; i < N; i++)
    {
        cin >> inA;
        cnt[-inA]++;
    }
    
    int i = 0;
    int ans[2] = {};
    for (pair<const int, int>& item : cnt)
    {
        if (item.second >= 2)
        {
            if (i == 0 && item.second >= 4)
            {
                ans[0] = item.first;
                ans[1] = item.first;
                break;
            }
            ans[i] = item.first;
            i++;

        }
        if (i > 1) break;
        
    }
    
    cout << (long long)ans[0] * (long long)ans[1] << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#define eps 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)

#define pause cout << " press ansy key to continue...",  cin >> chh
#define file_r(x) freopen(x,  "r",  stdin)
#define file_w(x) freopen(x,  "w",  stdout)
#define lowbit(x) ((x) & (-x))
#define repit(i, c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repe(i, u) for (int i = head[u]; i != -1; i = nxt[i])
#define repd(i, n) for (int i = (n - 1); i >= 0; i--)
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define FORD(i, n, m) for (int i = (n); i >= (m); i--)
#define pb push_back
#define X first
#define Y second
#define ins insert
#define rb rbegin
#define be begin
#define er erase
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define SZ(c) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define sqr(r) ((LL) (r) * (r))
#define dis(x1, y1, x2, y2) (((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))
#define FASTIO ios::sync_with_stdio(false);cin.tie(0)

#define sc(x) cout << #x" = " << x << endl, system("pause")
#define sc2(x, y) cout << #x" = " << x << " " << #y" = " << y << endl, system("pause")
#define sc3(x, y, z) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << endl, system("pause")
#define sc4(x, y, z, w) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << " " << #w" = " << w << endl, system("pause")

#define in(n) scanf("%d", &n)
#define in2(n, m) scanf("%d %d", &n, &m)
#define in3(x, y, z) scanf("%d %d %d", &x, &y, &z)

using namespace std;
int chh;

typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<int, pii> pi3;
typedef vector< pair<int, int> > vpii;
typedef long long LL;

int gcd(int x, int y) {
    return x % y ? gcd(y, x % y) : y;
}

int lca(int x, int y) {
    return x * y / gcd(x, y);
}

int main() {
    int x;
    while (~in(x)) printf("%d\n", lca(360, x) / x);
    return 0;
}

Measured memory_bytes: 3732
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

int main() {
  int n;
  string train, tmp1_1, tmp1_2, tmp2_1, tmp2_2;
  cin >> n;
  while (n--) {
    set<string> trains;
    cin >> train;
    for (int i = 1; i < train.length(); i++) {
      tmp1_1 = train.substr(0, i);
      tmp1_2 = tmp1_1;
      reverse(tmp1_2.begin(), tmp1_2.end());
      tmp2_1 = train.substr(i, train.length()-i);
      tmp2_2 = tmp2_1;
      reverse(tmp2_2.begin(), tmp2_2.end());
      trains.insert(tmp1_1+tmp2_1);
      trains.insert(tmp1_1+tmp2_2);
      trains.insert(tmp1_2+tmp2_1);
      trains.insert(tmp1_2+tmp2_2);
      trains.insert(tmp2_1+tmp1_1);
      trains.insert(tmp2_1+tmp1_2);
      trains.insert(tmp2_2+tmp1_1);
      trains.insert(tmp2_2+tmp1_2);
    }
    cout << trains.size() << el;
  }

}

Measured memory_bytes: 1292
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 998244353;
const int N = 200005;

LL rp[N];
LL pre[N];
LL val[N << 2];
int cov[N << 2];
void push_up(int u, int len1) {
    val[u] = (val[u << 1] + val[u << 1 | 1] * rp[len1]) % mod;
    //if (u == 3) printf("$%d %d %d\n", val[u], rp[len1], val[u << 1 | 1]);
}
void push_down(int u, int len1, int len2) {
    if (cov[u]) {
        val[u << 1] = cov[u] * pre[len1 - 1] % mod;
        val[u << 1 | 1] = cov[u] * pre[len2 - 1] % mod;
        // if (u == 3) {
        //     printf("%d\n", cov[u] * pre[len2 - 1]);
        // }
        cov[u << 1] = cov[u << 1 | 1] = cov[u];
        cov[u] = 0;
    }
}
void update(int u, int l, int r, int x, int y, int v) {
    if (x <= l && r <= y) {
        val[u] = v * pre[r - l] % mod;
        //if (l == 5 && r == 6) printf("%lld\n", val[u]);
        cov[u] = v;
        return;
    }
    int mid = l + r >> 1;
    push_down(u, mid - l + 1, r - mid);
    if (u == 3) {
        //printf("%d\n", val[7]);
    }
    if (x <= mid)
        update(u << 1, l, mid, x, y, v);
    if (y > mid)
        update(u << 1 | 1, mid + 1, r, x, y, v);
    push_up(u, mid - l + 1);
}
int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    pre[0] = rp[0] = 1;
    for (int i = 1; i <= n; i++) {
        rp[i] = rp[i - 1] * 10 % mod;
        pre[i] = (pre[i - 1] + rp[i]) % mod;
    }
    update(1, 1, n, 1, n, 1);
    //update(1, 1, n, 7, 8, 1);
    //printf("%lld\n", val[7]);
    while (q--) {
        int x, y, v;
        scanf("%d%d%d", &x, &y, &v);
        x = n - x + 1, y = n - y + 1;
        update(1, 1, n, y, x, v);
        printf("%lld\n", val[1]);
    }
    return 0;
}


Measured memory_bytes: 13112
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);

		int N = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		int[] a = new int[N];
		for (int i = 0; i < N; ++i) {
			a[i] = Integer.parseInt(tokens[i]);
		}
		int[] b = new int[N];
		Arrays.fill(b, 0);

		for (int i = N - 1; i >= 0; --i) {
			int count = 0;
			for (int j = (i + 1) * 2 - 1; j < N; j = j + (i + 1)) {
				count += b[j];
			}
			if (count % 2 == a[i]) {
				b[i] = 0;
			} else {
				b[i] = 1;
			}
		}
		List<Integer> indexes = new ArrayList<>();
		for (int i = 0; i < N; ++i) {
			if (b[i] > 0) {
				indexes.add(i + 1);
			}
		}
		System.out.println(indexes.size());
		if (indexes.size() > 0) {
			StringBuilder strBuilder = new StringBuilder();
			strBuilder.append(Integer.toString(indexes.get(0)));
			for (int i = 1; i < indexes.size(); ++i) {
				strBuilder.append(" " + (indexes.get(i)));
			}
			System.out.println(strBuilder.toString());
		}

	}
}


Measured memory_bytes: 54664
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S, T; cin >> S >> T;
	int ans = INF;
	REP(i, S.size()) {
		int tmp = 0;
		bool F = 1;
		FOR(j, i, i + T.size()) {
			if (j >= S.size()) {
				F = 0;
				break;
			}
			if (S[j] != T[j - i])tmp++;
		}



		if(F)chmin(ans, tmp);
	}


	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define forr(i,a,n) for(ll i=a;i<n;i++)
#define ford(i,a,n) for(ll i=n-1;i>=a;i--)
#define all(v) v.begin(),v.end()
#define testc  ll ts;\
               cin>>ts;\
               while(ts--)
#define arn ll n;\
            cin>>n;\
            ll a[n];\
            forr(i,0,n)cin>>a[i];\
               
#define arr(a,n) ll a[n];\
                 forr(i,0,n)cin>>a[i];\
 
#define sss <<" "<<
#define nnn <<"\n"
#define nl cout<<"\n";
#define prtitr(v) for(auto itr=v.begin(); itr!=v.end() ; itr++)cout<<*itr<<" ";
#define fitr(v) for(auto itr=v.begin(); itr!=v.end() ; itr++)
#define MAXN 1000001
using namespace std;
ll M=1e9+7;
ll cdiv(ll a,ll b){
    return (a%b==0)?a/b:a/b+1;
}
ll myMod(ll a, ll b){
    ll r = a % b;
    return r < 0 ? r + b : r;
}
ll ModPow(ll a,ll b,ll M)
{
    if(M==1)return 0;
    a%=M;
    ll ans=1,t=1;
    while(t>0&&t<=b)
    {
        if(t&b)
        {
            ans*=a;
            ans%=M;
        }
        t<<=1;
        a*=a;
        a%=M;
    }
    return ans;
}


// stores smallest prime factor for every number 
int spf[MAXN]; 
  
// Calculating SPF (Smallest Prime Factor) for every 
// number till MAXN. 
// Time Complexity : O(nloglogn) 
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
  
// A O(log n) function returning primefactorization 
// by dividing by smallest prime factor at every step 


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    map<ll,ll> m;
    arn;
    sieve();
    forr(i,0,n){
        set<ll> s;
        ll x=a[i];
        while (x != 1) 
        { 
            s.insert(spf[x]); 
            x = x / spf[x]; 
        } 
        fitr(s){
            m[*itr]++;
        }
    }
    ll flag1=0,flag2=0;
    fitr(m){
        if((*itr).second>1)flag1=1;
        if((*itr).second>=n)flag2=1;
    }
    if(!flag1)cout<<"pairwise coprime";
    else if(!flag2)cout<<"setwise coprime";
    else cout<<"not coprime";
    return 0;
} 

Measured memory_bytes: 20176
#include <bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
vector<bool> seen;
void dtf(Graph G, int v){
  seen[v]=true;
  for(int next_v: G[v]){
    if(seen[next_v]) continue;
    dtf(G, next_v);
  }
}
int main(){
  int N, M;
  cin >> N >> M;
  Graph G(N+1), H(M+1);
  for(int i=1; i<=M; i++){
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);    
    H[i].push_back(a);    
    H[i].push_back(b);
  }
  int ans=0;
  for(int i=1; i<=M; i++){
    int a=H[i][0], b=H[i][1];
    for(int j=0; j<G[a].size(); j++){
      if(G[a][j]==b){
        G[a].erase(G[a].begin()+j);
        break;
      }
    }
    for(int j=0; j<G[b].size(); j++){
      if(G[b][j]==a){
        G[b].erase(G[b].begin()+j);
        break;
      }
    }
    seen.assign(N+1, false);
    dtf(G, 1);
    int num=0;
    for(int j=1; j<=N; j++){
      if(seen[j]) num++;
    }
    if(num!=N) ans++;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(){
    int i=0,t=0;
    char s[1001]={};
    for(;scanf("%s",s),s[0]!='0';printf("%d\n",t))
        for(i=0,t=0;s[i]!='\0';i++){
            t+=s[i]-'0';
        }
}

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

int main()
{
    ll N; cin >> N;
    double tmp = sqrt(N);
    ll l = (ll)tmp;
    cout << l * l << endl;

}


Measured memory_bytes: 3660
class HowManyDivisors:
    def output(self, a, b, c):
        d = 0
        for i in range(a, b + 1, 1):
            if c % i == 0:
                d += 1
        print d

if __name__ == "__main__":
        hmd = HowManyDivisors()
        a, b, c = map(int, raw_input().split())
        hmd.output(a, b, c)

Measured memory_bytes: 6668
n = input()
if int(n[0]) < int(n[1]):
    print(str(int(n[0]) + 1) * 3)
elif int(n[0]) == int(n[1]) and int(n[0]) < int(n[2]):
    print(str(int(n[0]) + 1) * 3)
else:
    print(str(int(n[0])) * 3)

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) a[i] = 0;
    rep(i,n-1){
        int ai; cin >> ai;
        a[ai-1]++;
    }
    rep(i,n) cout << a[i] << "\n";
}

Measured memory_bytes: 4048
// A - Security
#include <iostream>
#include <vector>
#include <math.h>
#include <string>

using namespace std;

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

    int previous = -1;
    for (int i = 0; i < S.length(); i++) {
        if (previous == S[i] - '0') {
            cout << "Bad";
            return 0;
        }
        previous = S[i]  - '0';
    }
    cout << "Good";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	char sw[2]={'S','W'};
	vector<vector<char>> c(4,vector<char>(n,'A'));
	for(int i=0;i<2;i++){
		for(int j=i;j<i+2;j++){
			c[i+j][0]=sw[i];
			if(sw[i]=='S'&&s[0]=='o' || sw[i]=='W'&&s[0]=='x'){
				if(j==i){
					c[i+j][1]='S';
					c[i+j][n-1]='S';
				}else if(j==i+1){
					c[i+j][1]='W';
					c[i+j][n-1]='W';
				}
			}else{
				if(j==i){
					c[i+j][1]='S';
					c[i+j][n-1]='W';
				}else if(j==i+1){
					c[i+j][1]='W';
					c[i+j][n-1]='S';
				}
			}
		}
	}
	bool ans=false;
	int ansk;
	for(int k=0;k<4;k++){
		bool flag=true;
		for(int i=1;i<n;i++){
			int next;
			if(i==n-1) next=0;
			else next=i+1;
			if(s[i]=='o'){
				if(c[k][i]=='S'){
					if(c[k][next]=='A') c[k][next]=c[k][i-1];
					else if(c[k][next]!=c[k][i-1]) flag=false;
				}else{
					if(c[k][next]=='A') c[k][next]=(c[k][i-1]=='S'?'W':'S');
					else if(c[k][next]==c[k][i-1]) flag=false;
				}
			}else{
				if(c[k][i]=='W'){
					if(c[k][next]=='A') c[k][next]=c[k][i-1];
					else if(c[k][next]!=c[k][i-1]) flag=false;
				}else{
					if(c[k][next]=='A') c[k][next]=(c[k][i-1]=='S'?'W':'S');
					else if(c[k][next]==c[k][i-1]) flag=false;
				}
			}
			if(!flag) break;
		}
		if(flag) {
			ans=true;
			ansk=k;
			break;
		}
	}
	if(ans){
		for(int i=0;i<n;i++) cout << c[ansk][i];
		cout << endl;
	}else
		cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please


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

	int N, M;
	int A[51] = {};
	cin >> N >> M;

	rep(i, M) {
		int a, b;
		cin >> a >> b;

		A[a]++;
		A[b]++;
	}

	rep1(i, N) {
		co(A[i]);
	}
	
	Would you please return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<utility>
#include<queue>
#define mod 1000000007
#define INF 1000000000000000
using namespace std;
typedef long long ll;
int a[100001];
int main(){
    int n,m,b;
    ll dp[100005]={};
    dp[0]=1LL;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d",&b);
        a[b]=1;
    }
    for(int i=0;i<n;i++){
        if(a[i]==1){
            dp[i]=0;
        }
        dp[i]%=mod;
        if(a[i+1]==0){
            dp[i+1]+=dp[i];
            dp[i+1]%=mod;
        }
        if(a[i+2]==0){
            dp[i+2]+=dp[i];
            dp[i+2]%=mod;
        }
    }
    printf("%lld\n",dp[n]);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

struct UnionFind
{
	vector<int> par;
	UnionFind(int n) :par(n, -1) {}
	int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
	void unite(int x, int y)
	{
		x = find(x); y = find(y);
		if (x == y) return;
		if (par[y] < par[x]) swap(x, y);
		if (par[x] == par[y]) par[x]--;
		par[y] = x;
		if (find(x) != find(y)) par[find(y)] = x;
	}
	int count()
	{
		int cnt = 0;
		REP(i, par.size()) if (par[i] < 0) cnt++;
		return cnt;
	}
	bool same(int x, int y)
	{
		return find(x) == find(y);
	}
};

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, m; cin >> n >> m;
	vi p(n); cin >> p;
	for (auto &i : p) i--;
	UnionFind uf(n);
	REP(i, m)
	{
		int a, b; cin >> a >> b;
		a--; b--;
		uf.unite(a, b);
	}
	int ans = 0;
	REP(i, n)
	{
		if (uf.same(i, p[i])) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
a = list(map(int, input().split()))

count = 0
i = 0
d = 0
while i + d < len(a):
    if a[i + d] != i + 1:
        d += 1
        count += 1
    else:
        i += 1
if count < N:
    print(count)
else:
    print(-1)

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

int main() {
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	if (x + r > w || y + r > h || x - r < 0 || y - r < 0)cout << "No" << endl;
	else cout << "Yes" << endl;
}


Measured memory_bytes: 3108
N,W = map(int,input().split())
w=[0]*N
v=[0]*N
for i in range(N):
    w[i],v[i] = map(int,input().split())

dp=[[-1]*(W+1) for _ in range(N+1)]

dp[0]=[0]*(W+1)

for i in range(1,N+1):
    for j in range(W+1):
        if j<w[i-1]:
            dp[i][j]=dp[i-1][j]
        else:
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1])

print(dp[N][W])

Measured memory_bytes: 119144
a = int(input())

x,y = map(int,input().split())

l = list(map(int,input().split()))

c = []

for i in range(a):
    c.append(abs((x - (0.006 * l[i])) - y))

k = min(c)
kk = 0
for i in range(a):
    if k == c[i]:
        kk = i+1



print(kk)


Measured memory_bytes: 3060
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])
ans,j = 0 , M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans,i + j)
print(ans)

Measured memory_bytes: 47372
#include <bits/stdc++.h>
#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define si size
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define er erase
#define in insert
#define em empty
#define ft front
#define fo(i,n) for(i = 0; i < n; i++)
#define ro(i,n) for(i = n - 1; i >= 0; i--)
#define fr(i,j,n) for(i = j; i < n; i++)
#define rf(i,j,n) for(i=n-1;i>=j;i--)
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<std::string> vs;
typedef double dl;
typedef long double ld;
typedef long long ll;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> vll;
#define filename ""
using namespace std;
const int N=(int)1e4;
    int a[N],b[N];
int main()
{
    /*
	freopen(filename".in","r",stdin);
	freopen(filename".out","w",stdout);
	*/
	/*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    */
    int n,i;
    cin>>n;
    fo(i,n)
    {
        scanf("%d",&a[i]);
    }
    ll o=0,o1=0;
    fo(i,n)
    {
        scanf("%d",&b[i]);
        if (a[i]>b[i])
        {
            o+=a[i]-b[i];
        }
        if (b[i]>a[i])
        {
            if ((b[i]-a[i])%2)
            {
                o1+=(b[i]-a[i])+1;
                o++;
            }
            else
            {
                o1+=(b[i]-a[i]);
            }
        }
    }
    if (2*o<=o1)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    re 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;

struct UnionFind{
    vector<ll> link;
    UnionFind(ll n):link(n,-1){}
    ll find(ll v){
        if(link[v]<0) return v;
        else return link[v]=find(link[v]);
    }
    bool unite(ll v,ll w){
        v=find(v),w=find(w);
        if(v==w) return 0;
        if(link[v]>link[w]) swap(v,w);
        link[v]+=link[w];
        link[w]=v;
        return 1;
    }
    bool same(ll v,ll w){
        return find(v)==find(w);
    }
};

int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> p(n),ip(n);
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    UnionFind uf(n);
    rep(i,m){
        ll x,y;
        cin>>x>>y;
        x--,y--;
        uf.unite(x,y);
    }
    ll ans=0;
    rep(i,n){
        if(uf.find(i)==uf.find(p[i])) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5548
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

//gcd,lcm,べき,二進展開
//組み合わせ、mod計算
//最短路問題、bit、union find

///////////////////////////


	
int main() {

	ll D, N;
	cin >> D >> N;
	
	ll v = 1;
	if (D == 1) { v = 100; }
	if (D == 2) { v = 10000; }

	ll ans = v * N;

	if (N == 100) { ans += v; }
	cout << ans;

	system("PAUSE");
}

Measured memory_bytes: 504
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String abcd = sc.next();
		sc.close();
		char[] ch = abcd.toCharArray();
		int a = ch[0] - '0';
		int b = ch[1] - '0';
		int c = ch[2] - '0';
		int d = ch[3] - '0';
		List<Integer> e = new ArrayList<>();
		List<String> f = new ArrayList<>();
		e.add(a+b+c+d);
		e.add(a+b+c-d);
		e.add(a+b-c+d);
		e.add(a+b-c-d);
		e.add(a-b+c+d);
		e.add(a-b+c-d);
		e.add(a-b-c+d);
		e.add(a-b-c-d);
		f.add(a+"+"+b+"+"+c+"+"+d);
		f.add(a+"+"+b+"+"+c+"-"+d);
		f.add(a+"+"+b+"-"+c+"+"+d);
		f.add(a+"+"+b+"-"+c+"-"+d);
		f.add(a+"-"+b+"+"+c+"+"+d);
		f.add(a+"-"+b+"+"+c+"-"+d);
		f.add(a+"-"+b+"-"+c+"+"+d);
		f.add(a+"- "+b+"-"+c+"-"+d);

		for (int i=0; i<8; i++) {
			if (e.get(i)==7) {
				System.out.println(f.get(i)+"=7");
				break;
			}
		}
	}
}

Measured memory_bytes: 22100
import sys
readline = sys.stdin.readline
from collections import deque

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    que = deque([])
    for i, a in enumerate(A):
        if i % 2 == 0:
            que.append(a)
        else:
            que.appendleft(a)
    
    if N % 2 == 1:
        que = list(que)[::-1]
    print(*que)


if __name__ == '__main__':
    main()

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

using namespace std;

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

    int n;
    cin>>n;

    if(n<1200)
        cout<<"ABC";
    else if(n>=1200 && n<2800)
        cout<<"ARC";
    else 
        cout<<"AGC";
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        long ans =0;
        long sub=0;
        List<Integer> list = new ArrayList<>();
        for(int i=0;i<N;++i){
            A[i] = scan.nextInt();
            B[i] = scan.nextInt();
            if(B[i]>=A[i]){
                ans+=B[i];
                sub+=B[i]-A[i];
            }else{
                list.add(B[i]);
            }
        }
        if(sub==0){
            System.out.println(0);
            return;
        }
        Collections.sort(list);
        for(int i=1;i<list.size();++i)ans+=list.get(i);
        System.out.println(ans);
    }
}

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

int main(void){
    long long int i=0,j,N;
    int b;
    char a[100];
    scanf("%lld",&N);

    while(N != 0){
        N--;
        b = N%26;
        a[i] = 'a' + b;
        N /= 26;
        i++;
    }

    for(j=i-1;j>=0;j--){
        printf("%c",a[j]);
    }

    return 0;
}




Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
bool pd(int k)
{
	if((int)(sqrt(k))-(double)(sqrt(k))==0) 
		return false;
	return true;
}
int main()
{
	int cnt=0,n,m;
	cin>>n>>m;
	int m1=m;
	while(m1>0)
	{
		cnt++;
		m1/=10;
	}
	for(int i=0;i<cnt;++i) n*=10;
	n+=m;
	!pd(n)?cout<<"Yes"<<endl:cout<<"No"<<endl;
	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int k,n;
	cin>>k>>n;
	vector<int>a(n);
	for(auto&i:a)cin>>i;
	a.push_back(a.at(0)+k);
	int mx=0;
	for(int i=1;i<=n;++i){
		mx=max(mx,a.at(i)-a.at(i-1));
	}
	cout<<k-mx<<"\n"s;
}

Measured memory_bytes: 1792
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.util.*;
/**
 *
 * @author arvin
 */
public class Main {
    
    static char a[][];
    static long dp[][];
    static int m,n;
    
    static long rec(int x,int y)
    {
        if(x==n-1 && y==m-1)
            return 1l;
        if(x>=n || y>=m || a[x][y]=='#')
            return 0l;
        if(dp[x][y]!=-1)
            return dp[x][y];
        long ab,ch;
        if(dp[x+1][y]==-1)
            ch=rec(x+1,y);
        else
            ch=dp[x+1][y];
        if(dp[x][y+1]==-1)
            ab=rec(x,y+1);
        else
            ab=dp[x][y+1];
        dp[x][y]=(ch+ab)%1000000007l;
        return dp[x][y];
    }
    
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        n=sc.nextInt();
        m=sc.nextInt();
        a=new char[n+1][m+1];
        dp=new long[n+1][m+1];
        for(int i=0;i<n;i++)
            Arrays.fill(dp[i],-1);
        sc.nextLine();
        for(int i=0;i<n;i++)
        {
            String abc=sc.nextLine();
            for(int j=0;j<m;j++)
                a[i][j]=abc.charAt(j);
        }
        
        System.out.println(rec(0,0));
        
        sc.close();
    }
}


Measured memory_bytes: 51680
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vector<int> width(110);
  vector<int> height(110);
  for (int i = 0; i <= W; i++) width[i] = 1;
  for (int i = 0; i <= H; i++) height[i] = 1;
  
  rep (i, N) {
    int x, y, a;
    cin >> x >> y >> a;

    if (a == 1) {
      for (int i = 0; i < x; i++) width[i] = 0;
    }

    if (a == 2) {
      for (int i = x + 1; i <= 100; i++) width[i] = 0;
    }

    if (a == 3) {
      for (int i = 0; i < y; i++) height[i] = 0;
    }

    if (a == 4) {
      for (int i = y + 1; i <= 100; i++) height[i] = 0;
    }
  }

  int w = 0, h = 0;
  rep (i, 110) if (width[i] == 1) w++;
  rep (i, 110) if (height[i] == 1) h++;

  //cout << w - 1 << " " << h - 1<< endl;
  if ((w - 1) >= 0 && (h - 1) >= 0) {
    cout << (w - 1) * (h - 1) << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
from collections import deque
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
N = int(input())
xseq = []
yseq = []
uf = UnionFind(N)
ans = 0

for i in range(N):
    x,y = (int(x) for x in input().split())
    xseq.append((x,i))
    yseq.append((y,i))
xseq.sort()
yseq.sort()
xdiff = [(xseq[i][0]-xseq[i-1][0],(xseq[i][1],xseq[i-1][1])) for i in range(1,N)]
ydiff = [(yseq[i][0]-yseq[i-1][0],(yseq[i][1],yseq[i-1][1])) for i in range(1,N)]
diff = xdiff + ydiff
diff.sort()
d = deque(diff)

for i in range(len(d)):
    temp = d.popleft()
    if uf.find(temp[1][0]) != uf.find(temp[1][1]):
        uf.union(temp[1][0],temp[1][1])
        ans += temp[0]
print(ans)

Measured memory_bytes: 66364
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define maxN 200007
using namespace std;
int main() {
  fastio;
  ll n = 0, k = 0;
  cin >> n >> k;
  vector<ll>ar(n), dp(n, INF);
  for (ll i = 0; i < n; ++i)
    cin >> ar[i];
  dp[0] = 0;
  for (ll i = 1; i < n; ++i) {
    for (ll j = i - 1; j >= max(0ll, i - k); --j) {
      dp[i] = min(dp[i], dp[j] + abs(ar[i] - ar[j]));
    }
  }
  cout << dp[n - 1];
}

Measured memory_bytes: 4768
import sys
n=int(input())
def unite(x,y):
	if same(x,y)==False:
		rx=root(x);ry=root(y)
		if rank[rx]>rank[ry]:
			parent[ry]=rx
			size[rx]+=size[ry]
		else:
			parent[rx]=ry
			size[ry]+=size[rx]
			if rank[rx]==rank[ry]:
				rank[ry]+=1
def root(x):
	if x!=parent[x]:
		return root(parent[x])
	return x
def same(x,y):
	return root(x)==root(y)
parent=list(range(n))
rank=[0]*n
size=[1]*n

xy=[]
for i in range(n):
	x,y=map(int,input().split())
	xy.append((x,y,i))
xy.sort()
LIS=[[xy[0][1],xy[0][2]]]#y,i
from heapq import heappop,heappush
for x,y,i in xy[1:]:
	flag=False
	now=LIS[0]
	while LIS and LIS[0][0]<y:
		flag=True
		unite(i,LIS[0][1])
		heappop(LIS)
	if flag:
		heappush(LIS,now)
	else:
		heappush(LIS,[y,i])
for i in range(n):
	print(size[root(i)])

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

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rInt(a) scanf("%d",&a);

struct program{
    int s, t, c;
    program(int _s,int _t, int _c) : s(_s), t(_t), c(_c) {}
};

bool fun(program th, program other){
    if(th.s<other.s) return true;
    else if(other.s<th.s) return false;
    else if(th.t<other.t) return true;
    else if(other.t<th.t) return false;
    else return th.c<other.c;
}

main(){
    int n, C;
    scanf("%d %d",&n,&C);
    int s,t,c;
    bool v[n];
    vector<program> arr; 
    rep(i,n){
        scanf("%d %d %d",&s,&t,&c);
        arr.push_back(program(s,t,c)); v[i] = false;
    }
    int counter = 0;
    sort(arr.begin(),arr.end(), fun);
    //rep(i,n) printf("%d %d %d\n",arr[i].s,arr[i].t,arr[i].c);
    rep(i,n){
        if(v[i]) continue;
        v[i] = true;
        int lt = arr[i].t;
        int lc = arr[i].c;
        //cout << lt << " " << lc << endl;
        counter++;  
        for(int j=i+1;j<n;++j){
            if(v[j]) continue;
            if(arr[j].s>=lt and lc==arr[j].c) v[j] = true;
            else if(arr[j].s>lt) v[j] = true;
            if(v[j]) lt = arr[j].t, lc=arr[j].c;
        }
    }
    cout << counter << endl;
}

Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll mod = 1000000007;

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a) {
    return modpow(a, mod - 2);
}

ll choose(ll a, ll b){
    if(b == 0) return 1;
    ll x = 1;
    rep(i, b){
        x *= (a - i);
        x %= mod;
        x *= modinv(b-i);
        x %= mod;
    }
    return x;
}
int main(){
    ll n, k;
    cin >> n >> k;
    rep(i, k){
        ll ans;
        ans = choose(n - k + 1, i + 1);
        ans *= choose(k - 1, i);
        ans %= mod;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
ans = 'No'

(0..25).each do |i|
  (0..14).each do |j|
    sum = 4 * i + 7 * j
    if sum > n || sum < n
      next
    else
      if sum == n
        ans = 'Yes'
        break
      end
    end
  end
end

puts ans

Measured memory_bytes: 1916
K = int(input())
mod = int(1e9) + 7
X = [0 for _ in range(K)]
def doubling(n, m):
  y = 1
  base = n
  while m != 0:
    if m % 2 == 1:
      y *= base
      y %= mod
    base *= base
    base %= mod
    m //= 2
  return y
SS = 0
for i in range(K, 0, -1):
  d = K // i
  S = doubling(d, 3)
  if d > 1:
    for j in range(2, d+1):
      S -= X[j*i-1]
      S %= mod
  X[i-1] = S
  SS += i * S
  SS %= mod
print(SS)

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

int main()
{
	long long n,a[500005];
	cin>>n;
	
	for(int i=1;i<=n;i++)
	   cin>>a[i];
	   
	for(int i=1;i<=n;i++)
	   if(a[i]==0)
	   {
	   	 cout<<0;
	   	 return 0;
	   }
	
	long long sum=1;
	for(int i=1;i<=n;i++)
	{
		if(a[i]<=1000000000000000000/sum)
		  sum=sum*a[i];
		else
		{
		  cout<<-1;
		  return 0;
		}  
	}
	
	cout<<sum;
	
	return 0;
	
}

Measured memory_bytes: 4420
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
 
 
 
int main(){
	fast;
	int x, y, z;
	cin>>x>>y>>z;
	swap(x,y);
	swap(x,z);
	cout<<x<<" "<<y<<" "<<z;
	return 0;
}

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

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  char c;
  cin >> c;
  cout << (c >= 'a' ? 'a' : 'A') << '\n';
}


Measured memory_bytes: 3644
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

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 dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> h;
map<ll,ll> m;


int main()
{
	ll n;
	ll ans=0;
	ll tmp=0;

	cin >> n;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		h.push_back(tmp);
	}

	for (int i = 0; i < n; i++) {
		tmp = 0;
		if ((n - i) <= ans) {
			break;
		}
		for (int j = i; j < n - 1; j++) {
			if (h[j] >= h[j + 1]) {
				tmp++;
			}
			else {
				break;
			}
		}
		if (tmp > ans) {
			ans = tmp;
		}
	}

	cout << ans << endl;

	return 0;
}





Measured memory_bytes: 1400
sx, sy, tx, ty = map(int, input().split())
dx = tx - sx
dy = ty - sy
print("U"*dy + "R"*dx, end="")
print("D"*dy + "L"*dx, end="")
print("L" + "U"*(dy+1) +"R"*(dx+1) +"D", end="")
print("R" + "D"*(dy+1) +"L"*(dx+1) +"U", end="")

Measured memory_bytes: 9088
n = gets.to_i
abc = gets.split.map(&:to_i)
dp=Array.new(n){ Array.new(3) }
dp[0][0] = abc[0]
dp[0][1] = abc[1]
dp[0][2] = abc[2]

for i in 1...n
  abc = gets.split.map(&:to_i)
  dp[i][0] = [dp[i-1][1],dp[i-1][2]].max + abc[0]
  dp[i][1] = [dp[i-1][2],dp[i-1][0]].max + abc[1]
  dp[i][2] = [dp[i-1][0],dp[i-1][1]].max + abc[2]
end
p dp[n-1].max


Measured memory_bytes: 9340