akhauriyash/Code-Regression huggingface dataset:
//Keep Working Hard
  // I__Like__Food  
  #include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast") 
  #pragma GCC optimize("unroll-loops")
  using namespace std;
  using namespace __gnu_pbds;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int mod = 1e9 + 7;
  const int N = 100005;
  const int INF = 1e16;
  const double PI = acos(-1);


int dp[10005][105][2];
// dp[position on the string][digit sum modulo d][if k is set or not]
int32_t main()
{
       


    string s;
    cin >> s;

    int d;
    cin >> d;

    dp[0][0][0] = 1;

    

    for(int i = 0; i < s.length(); i++)
    {
      // i is terating over the string

      for(int j = 0; j < d; j++)
        {
          // j is iterating over the digit sum modulo d

          for(int k = 0; k < 2; k++)
          {
            /*
            if k is zero then we did'nt place a digit so far which 
            is less significant than the digit in the string so 
            */

            /*
            if k is one then we have placed placed a digit earlier 
            such that is less significant than the digit in the string 
            */
            for(int x = 0; x < 10; x++)
            {
              // x iterating over the digits we are placing at the ith position
              if(k == 0 and x > s[i]-'0')
              {
                continue;
                // if k is zero we can only place digits from 0 to the corresponding digit
                //in the string
              }
              int kk = k;
              if(x < s[i]-'0')
              {
                kk = 1;
                // if kk is one now we can only place digits from 0 to 9 due to the less significant digit placed before
              }
              dp[i+1][(j+x)%d][kk] += dp[i][j][k]%mod;
              dp[i+1][(j+x)%d][kk]%=mod;
            }
          }
        }
    }



    cout << (dp[s.length()][0][0]%mod + dp[s.length()][0][1]%mod - 1 + mod)%mod;
  return 0;
} 

Measured memory_bytes: 16640
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#define ll long long
#define oku7 1000000007
using namespace std;
vector<int> v[2000001];

int main(){
	vector<int> v;
	int N, four=0, two=0, NG=0,all;
	cin >> N;
	for (int i = 0; i < N; i++){
		int tnp;
		cin >> tnp;
		v.push_back(tnp);
		if (tnp % 4 == 0){
			four++;
		}
		else if (tnp % 2 == 0){
			two++;
		}
		else{
			NG++;
		}
	}
	all = four + two + NG;
	if (all / 2 <= four){
		cout << "Yes\n";
		return 0;
	}
	else if (two == all){
		cout << "Yes\n";
		return 0;
	}
	else if (NG == four){
		cout << "Yes\n";
		return 0;
	}
	else {
		cout << "No\n";
		return 0;
	}

	

	return 0;
}

Measured memory_bytes: 47740
#include <stdio.h>
int main(void){
    // Your code here!
    int m, f, r, i;
    for(i=0; i<50; i++){
        scanf("%d %d %d", &m, &f, &r);
        if(m==-1 && f==-1 && r==-1) break;
        if(m==-1 || f==-1){
            printf("F\n");
        }
        else if(m+f >=80){
            printf("A\n");
        }
        else if(65<= m+f && m+f <80){
            printf("B\n");
        }
        else if(50<= m+f && m+f <65){
            printf("C\n");
        }
        else if(30<= m+f && m+f <50 && 50<=r){
            printf("C\n");
        }
        else if(30<= m+f && m+f <50){
            printf("D\n");
        }
        else if(m+f <30){
            printf("F\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2084
#include<iostream>

using namespace std;

int main()
{
	int n,cnt;
	
	while (1) {
		cin >> n;
		if (n == 0) {
			break;
		}
		
		cnt = 0;
		while (n >= 5) {
			cnt += n / 5;
			n /= 5;
		}

		cout << cnt << endl;
	}
	return 0;
}


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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;




int main() {

	string s;
	cin >> s;
	int n = s.size();
	string t = s;
	reverse(ALL(t));

	if (t != s) {
		cout << "No" << endl;
		return 0;
	}

	string ss = "";
	string tt;
	REP(i, (n - 1) / 2) {
		ss += s[i];
	}

	tt = ss;
	reverse(ALL(tt));
	if (tt != ss) {
		cout << "No" << endl;
		return 0;
	}

	
	string sss = "";
	string ttt;
	FOR(i, (n + 1) / 2, n) {
		sss += s[i];
	}
//cout << sss << endl;
	ttt = sss;
	reverse(ALL(ttt));
	if (ttt != sss) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;


}

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

int main(){
	vector<int> primes={2};
	int X;
	cin >> X;
	if(X==2){
		cout << 2 << endl;
		return 0;
	}

	for(int i=3;;i++){
		bool isPrime=true;
		for(const auto& p : primes){
			if(i%p==0){
				isPrime=false;
				break;
			}
		}
		if(isPrime){
			if(i>=X){
				cout << i << endl;
				break;
			}
			primes.push_back(i);
		}
	}
	return 0;
}


Measured memory_bytes: 384
MOD = 10**9+7
n = int(input())
xs = list(map(int, input().split()))
cnt = [0 for _ in range(n)]
for x in xs:
    cnt[x] += 1

res = 1
if n % 2 == 0:
    s = 1
else:
    s = 2
    if cnt[0] != 1:
        res = 0
for i in range(s,n,2):
    if cnt[i] != 2:
        res = 0
    res *= 2
    res %= MOD
    
print(res)


Measured memory_bytes: 14008
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;

string str;
int idx;

int getn() {
    int res = 0;
    while (true) {
        char c = str[idx];
        if (isdigit(c)) {
            idx++;
            res *= 10;
            res += c-'0';
        } else {
            break;
        }
    }
    return res;
}

ll calc() {
    idx++;
    vector<ll> v;
    while (true) {
        char c = str[idx];
        if (c == ']') {
            idx++;
            break;
        }
        if (isdigit(c)) {
            int u = getn();
            v.push_back(u/2+1);
        } else {
            v.push_back(calc());
        }
    }
    sort(v.begin(), v.end());
    ll res = 0;
    //cout << v.size() << endl;
    for (int i = 0; i < v.size()/2+1; i++) {
        res += v[i];
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> str;
        idx = 0;
        cout << calc() << endl;
    }
}

Measured memory_bytes: 1304
from collections import deque

N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]

links = [[] for _ in range(N + 1)]
for a, b in AB:
    links[a].append(b)
    links[b].append(a)

result = [-1] * (N + 1)
q = deque([1])
while q:
    i = q.popleft()
    for j in links[i]:
        if result[j] == -1:
            result[j] = i
            q.append(j)
print('Yes')
print('\n'.join(str(i) for i in result[2:]))




Measured memory_bytes: 106380
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>

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

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

  int a, b;
  cin >> a >> b;

  cout << a*b-a-b+1 << endl;
  return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin>>s;
    int n = s.size(), ans = s.size();
    FOR(i, 0, n-1) {
    	if(s[i] != s[i+1]) {
    		ans = min(ans, max((int)i + 1, n - (int)i - 1));
    	}
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 512
import math
import sys

n = 999999
nums = [1] * (n+1)
nums[:2] = [0,0]
    
cnt = 0
while cnt <= math.sqrt(n):
    flg = nums[cnt]
    if flg == 1:
        k = 2
        while k*cnt <= n:
            nums[k*cnt] = 0
            k += 1
    cnt += 1


for line in sys.stdin:
    n = int(line)
    print sum(nums[:n+1])

Measured memory_bytes: 20696
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    a,b,m=map(int, input().split())
    la=list(map(int,input().split()))
    lb=list(map(int,input().split()))
    lm=[list(map(int,input().split())) for i in range(m)]
    nowari=min(la)+min(lb)
    warians=10**10
    for i in range(m):
        wari=la[(lm[i][0])-1]+lb[(lm[i][1])-1]-lm[i][2]
        if wari<warians:
            warians=wari
    print(min(nowari,warians))
resolve()

Measured memory_bytes: 38568
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int c=0;
	unordered_map<int,int> paper;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		paper[x]++;
	}
	for(auto it:paper)
	{
		if(it.second&1) 
			c++;
	}
	cout<<c;
	return 0;
}


Measured memory_bytes: 7288
//B - Tap Dance
//2019/9/20

#include <stdio.h>

int main(void) {
    char move[101];
    int i=0,judge=0;
    scanf("%s",move);
    while (move[i]!='\0') {
        if (i%2==0 && move[i]=='L') {
            judge--;
            break;
        }
        else if (i%2==1 && move[i]=='R') {
            judge--;
            break;
        }
        i++;
    }
    if (judge==0) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
using namespace std;

#define lint long long int
#define Q_MAX 50
#define N_MAX 10
#define M_MAX 10

int n, m, q;
int a[N_MAX];
int max_score = -1;

typedef struct {
    int a, b, c, d;
} SC;
SC sc[Q_MAX];


void get_ar(int *head, int n_ar, int mini, int maxi)
{
    for (int i = mini; i <= maxi; i++) {
        *head = i;
        
        if (n_ar != 1) get_ar(&head[1], n_ar-1, i, maxi);
        else {
            int sum = 0;
            for (int j = 0; j < q; j++) {
                if (a[sc[j].b-1] - a[sc[j].a-1] == sc[j].c) sum += sc[j].d;
            }
            max_score = max(max_score, sum);
        }
    }
}


int main()
{
    cin >> n >> m >> q;
    for (int i = 0; i < q; i++) cin >> sc[i].a >> sc[i].b >> sc[i].c >> sc[i].d;
    
    get_ar(a, n, 1, m);
    cout << max_score << endl;
}


Measured memory_bytes: 3600
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);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Integer[] array = new Integer[m];
		int n = sc.nextInt();
		List<Integer> list_x=new ArrayList<Integer>();
		List<Integer> list_y=new ArrayList<Integer>();
		for(int i=0;n>i;i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			list_x.add(x);
			list_y.add(y);
		}
		double count=0;
		int x = 1;
		for(int i=n;0<i;i--) {
			x = x*i;
		}
		//System.out.println(x);
		for(int i=0;n>i;i++) {
			for(int j=i+1;n>j;j++) {
				double sum = Math.sqrt(Math.pow(list_x.get(i)-list_x.get(j), 2)+
						Math.pow(list_y.get(i)-list_y.get(j), 2));
				//System.out.println(sum);
				count=count+sum;
				//System.out.println(i+"i");
				//System.out.println(j);
			}
		}
		if(n==2)
			System.out.println(count*2/x);
		else if(n==3)
			System.out.println(count*4/x);
		else if(n==4)
			System.out.println(count*12/x);
		else if(n==5)
			System.out.println(count*48/x);
		else if(n==6)
			System.out.println(count*240/x);
		else if(n==7)
			System.out.println(count*1440/x);
		else if(n==8)
			System.out.println(count*10080/x);
	}
}

Measured memory_bytes: 23764
#include "bits/stdc++.h"
using namespace std;
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define fast ios::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fa(v) for(auto &i:v)
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
#define int long long
int32_t main()
{
  int idx[200005]{};int cnt = 1;
  idx[0];
  for(int i=1;i<200005;i+=2){
  	idx[i] = idx[i+1] = cnt++;
  }
  // fr(i,100) cout << idx[i] << " ";
  int n; cin >> n;
  vi v(n);fr(i,n) cin >> v[i];
  sort(all(v));reverse(all(v));
  int sm = 0;fr(i,n-1) sm += v[idx[i]];
  cout << sm;
}

Measured memory_bytes: 6388
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A&lang=jp

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


(0..n-1).each do |i|
    v = a[i]
    j = i-1
    
    while j>=0 && a[j]>v do
        a[j+1] = a[j]
        j-=1
    end

    a[j+1]=v
    
    puts a.join(" ")
end

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

int main()
{
int num,len;
cin>>num>>len;
string s;
vector<string> v;
while(num--)
{
cin>>s;
v.push_back(s);
}

sort(v.begin(),v.end());
for(auto i:v)
cout<<i;
return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;
int mass[150][150];
int dx[6] = {1, 1, 0, -1, -1, 0};
int dy[6] = {0, 1, 1, 0, -1, -1};

void dfs(int x, int y, int turn){
  if(turn == 1) return;
  REP(i, 6){
    int nx = x + dx[i]; int ny = y + dy[i];
    if(mass[nx][ny] < turn-1 and mass[nx][ny] >= 0) { mass[nx][ny] = turn-1; dfs(nx, ny, turn-1); }
  }
}

int main(){
  int t, n;
  while(cin >> t >> n and t + n){
    memset(mass, 0, sizeof(mass));
    REP(i, n){
      int x, y; cin >> x >> y;
      mass[x+75][y+75] = -1;
    }
    int sx, sy;
    cin >> sx >> sy;
    mass[sx+75][sy+75] = t+1;
    dfs(sx+75, sy+75, t+1);
    int res = 0;
    REP(i, 150) REP(j, 150) if(mass[i][j] > 0) res++;
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 3164
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



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

    int K;
    cin >> K;
    string S;
    cin >> S;
    if (S.size() <= K) {
        cout << S << endl;
        return 0;
    }
    string ans = S.substr(0, K) + "...";

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

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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; }

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;


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

	ll n;
	cin >> n;
	ll c = 0;

	ll tmp = n;
	string ans = "";
	

	while (n > 0)
	{
		if (n % 26 == 0)
		{
			ans.push_back('a' + 25);
			n--;
		}
		else
			ans.push_back('a' + n % 26 - 1);
		n /= 26;
	}

	reverse(all(ans));
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<stack>
#include<queue>
#include<cstring>
using namespace std;
typedef long long ll;
#define N 400002
int n,c,a[N];
double dp[2][302][102],ans;
int ct;
int main()
{
	scanf("%d%d",&n,&c);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	sort(a,a+n);
	do
	{//puts("in");
		memset(dp,0,sizeof(dp));
		dp[0][a[n-1]*n][0]=1;int t=0;
		for(int i=1;i<=n*c;i++,t^=1)
		{if(i%n==0)
		{t^=1;continue;
		}int x=i%n-1;
			for(int j=i;j<=n*c;j++)for(int s=0;s<(1<<(n-1));s++)dp[t^1][j][s]=0;
			for(int j=i;j<=n*c;j++)for(int s=0;s<(1<<(n-1));s++)
			{dp[t^1][j][s]+=dp[t][j][s];
				if(!(s&(1<<x)))
			{
				
				dp[t^1][min(c*n,max(j,i+a[x]*n))][s|(1<<x)]+=dp[t][j][s];
			}
			}
			
			//for(int j=0;j<=n*c;j++)printf("(%.1lf %.1lf) ",dp[t][j][0],dp[t][j][1]);puts("from");
			//for(int j=0;j<=n*c;j++)printf("(%.1lf %.1lf) ",dp[t^1][j][0],dp[t^1][j][1]);puts("");
		}
		ans+=dp[t][n*c][(1<<(n-1))-1];ct++;
	}while(next_permutation(a,a+n-1));
	ans/=1.0*ct;
	for(int i=0;i<n-1;i++)ans/=1.0*c;
	printf("%.14lf\n",ans);
}


Measured memory_bytes: 896
n = int(input())

array = input().split()

intarr = [int(x) for x in array]
for x in intarr:
    if x == intarr[-1]:
        print(x)
    else:
        print(x,end=' ')


for c in range(1,n):
    v = intarr[c]
    j = c-1
    while j>=0 and intarr[j]>v:
        intarr[j+1] = intarr[j]
        j -= 1
    intarr[j+1] = v
    for x in intarr:
        if x == intarr[-1]:
            print(x)
        else:
            print(x, end=' ')

Measured memory_bytes: 8104
#include <cstdio>
#include<bits/stdc++.h> 
#define pb          push_back 
#define endl        "\n"
#define mostrar(x,y) cout<<x<<" "<<y<<endl;
#define f           first
#define s           second
using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<pair<int,int>,int> iii;

map<int,vii>  grafo;
map<int,int> grafoColoreado;

void colorear(int vertice,int distAcumulada){
    if(distAcumulada % 2 == 0){
        grafoColoreado[vertice] = 0;
    }
    else{
        grafoColoreado[vertice] = 1;
    }

    ii vecino;
    for(int i = 0; i<grafo[vertice].size(); i++){
        vecino = grafo[vertice][i];
        if(grafoColoreado[vecino.f] == -1){
            colorear(vecino.f, distAcumulada+vecino.s);   
        }
    }

}

int main(){
    ofstream out("output.txt");

    int n,a,b,c;
    cin>>n;
    for(int i = 1; i<=n; i++){
        grafoColoreado[i] = -1;
    }
    for(int i = 1; i<=n-1; i++){
        cin>>a>>b>>c;
        grafo[a].pb({b,c});
        grafo[b].pb({a,c});
    }

    colorear(1,0);

    for(auto it = grafoColoreado.begin(); it!=grafoColoreado.end(); it++){
        cout<<it->s<<endl;
    }

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1000;
const int MOD = 1e9+7;

int N, M;
char S[MAXN+10][MAXN+10];
int dp[MAXN+10][MAXN+10];

int main()
{
    int i, j;

    scanf("%d%d", &N, &M);
    for(i=1; i<=N; i++) scanf("%s", S[i]+1);

    dp[1][1]=1;
    for(i=1; i<=N; i++) for(j=1; j<=M; j++) if(i*j>1 && S[i][j]=='.') dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
    printf("%d", dp[N][M]);
}


Measured memory_bytes: 5248
from string import ascii_uppercase


def main(h, w, s):
    h, w = 1, 0  # height, weight

    for row in s:
        for col in row:
            if col == 'snuke':
                print(ascii_uppercase[w] + str(h))
                return
            w += 1

        h += 1
        w = 0


if __name__ == "__main__":
    h, w = map(int, input().split(' '))

    s = [[i for i in input().split(' ')] for _ in range(h)]

    main(h, w, s)


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

int main(void){
    int t;
    int n,m,p;
    int ans;
    string s;
    string str;
    string c;
    vector<int>x;
    while(true) {
        s="";
        while(true){
            getline(cin,str);
            s+=str;
            if(str.back()!='.')s.push_back(' ');
            else break;
        }
        if(s.front()=='.')break;
        t=0;n=0;m=0;p=0;
        for(int i=0;i<s.length();i++){
            if(s[i]=='('){t++;c.push_back(s[i]);}
            if(s[i]==')'){
                n++;
                if(c.back()=='['){cout<<"no"<<endl;goto invail;}
                else if(c.size()>0)c.pop_back();
            }
            if(s[i]=='['){m++;c.push_back(s[i]);}
            if(s[i]==']'){
                p++;
                if(c.back()=='('){cout<<"no"<<endl;goto invail;}
                else if(c.size()>0)c.pop_back();
            }
            if(t<n){cout<<"no"<<endl;goto invail;}
            if(m<p){cout<<"no"<<endl;goto invail;}
        }
        if(t>n||m>p)cout<<"no"<<endl;
        else cout<<"yes"<<endl;
        invail:;
    }
    return 0;
}


Measured memory_bytes: 3164
from collections import Counter
_ = input().strip()
V = list(map(int, input().strip().split(' ')))
odd_c = Counter(V[0::2]).most_common()
even_c = Counter(V[1::2]).most_common()
if odd_c[0][0] != even_c[0][0]:
  print(len(V)-odd_c[0][1]-even_c[0][1])
else:
  if len(odd_c) == 1 and len(even_c) == 1:
    print(len(V)//2)
  elif len(odd_c) == 1 and len(even_c) != 1:
    print(len(V)//2-even_c[1][1])
  elif len(odd_c) != 1 and len(even_c) == 1:
    print(len(V)//2-odd_c[1][1])
  else:
    print(len(V)-max(odd_c[0][1] + even_c[1][1], odd_c[1][1] + even_c[0][1]))


Measured memory_bytes: 20700
#include<bits/stdc++.h>
using namespace std;
struct unionFind{
  vector<int>par;

  unionFind(int N):par(N){
    for(int i=0;i<N;i++)par[i] = i;
  }

  int root(int x){
    if(par[x] == x)return x;
    else return par[x] = root(par[x]);
  }

  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    else par[rx]=ry;
  }

  bool same(int x,int y){
    return root(x)==root(y);
  }
};

int main(){
  int v,e;
  cin >> v >> e;
  int s,t,w;
  vector<pair<int,pair<int,int> > >path(e);
  int i;
  for(i=0;i<e;i++){
    cin >> s >> t >> w;
    path[i] = make_pair(w,make_pair(s,t));
  }
  unionFind unif = unionFind(v);
  sort(path.begin(),path.end());

  long length = 0;
  for(i=0;i<e;i++){
    int x = path[i].second.first;
    int y = path[i].second.second;
    if(!unif.same(x,y)){
      unif.unite(x,y);
      length += path[i].first;
    }
  }
  cout << length << endl;

}



Measured memory_bytes: 4140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
	if (b==0) return a;
    else{
    	return gcd(b,a%b);
    }
}
 
int main() {
	string s,t;
  	cin >> s >> t;
  	if(s[0]==t[2] && s[1] == t[1] && s[2] == t[0]){
      cout << "YES" << endl;
    }
  	else{
      cout << "NO" << endl;
    }
      
        
}


Measured memory_bytes: 256
N, T = map(int, input().split())
min_c, count = 1000, 0
for n in range(N):
    c, t = map(int, input().split())
    if t <= T:
        count += 1
        min_c = min(min_c, c)

if count != 0:
    print(min_c)
else:
    print('TLE')

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int f(int n) {
	if (n < 10) return 0;
	int next = 0;
	for (int k = 10; n / k >= 1; k *= 10) {
		next = max(next, (n / k) * (n % k));
	}
	return f(next) + 1;
}

int main() {
	int Q; cin >> Q;
	for (int t = 0; t < Q; ++t) {
		int N; cin >> N;
		cout << f(N) << endl;
	}
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define ll long long
#define re register
#define ull unsigned ll
using namespace std;
inline int read(){
	int s=0,t=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*t;
}
const int N=305;
int n,m,P,C[N][N],f[N][N],s[N][N];
int Mod(int x){return x>=P?x-P:x;}
void Pre(int n){
	for(int i=0;i<=n;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++)C[i][j]=Mod(C[i-1][j-1]+C[i-1][j]);
	}
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read(),m=read(),P=read(),Pre(300);
	for(int j=0;j<=m;j++)f[1][j]=1,s[1][j]=m-j+1;
	for(int i=2;i<=n+1;i++){
		for(int j=0;j<=m;j++)
		for(int k=1;k<i;k++)f[i][j]=Mod(f[i][j]+1ll*f[k][j]*s[i-k][j+1]%P*C[i-2][k-1]%P);
		for(int j=m;j>=0;j--)s[i][j]=Mod(s[i][j+1]+f[i][j]);
	}printf("%d",f[n+1][0]);
	return 0;
}


Measured memory_bytes: 4712
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int Maxn=200000+10;
int a[Maxn];
int n;
long long ans;
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
	n=read();
	for(int i=1;i<=n;++i)
	{
		a[i]=read();
		if(a[i]>=a[i-1])continue;
		ans+=(long long)a[i-1]-a[i];
		a[i]=a[i-1];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4528
import sys
input = sys.stdin.readline

n = int(input())
s = list(input())
cnt = 0
ans = 0
for i in range(1,n):
    a = s[:i]
    b = s[i:]

    a = list(set(a))
    b = list(set(b))

    a.sort()
    b.sort()

    for j in range(len(a)):
        if a[j] in b:
            cnt += 1
    
    if ans<cnt:
        ans = cnt

    cnt = 0

print(ans)

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

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef long long ll;
typedef pair<int, int> pii;


int main() {

#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n, m;
    cin >> n >> m;
    if (n * 2 > m) {
        cout << m / 2 << endl;
    } else {
        ll ans = n;
        m -= n * 2;
        ans += m / 4;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

class union_find{
        vector<long> parent, tree_size;
    public:
        union_find(unsigned long _n) : parent(_n), tree_size(_n, 1){
            for(unsigned long i = 0; i < _n; ++i)parent[i] = i;
        }
        ll find(ll x){
            while(parent[x] != x)x = parent[x] = parent[parent[x]];
            return x;
        }
        void merge(ll a, ll b){
            a = find(a);
            b = find(b);
	    if(a==b) return;
            if(tree_size[a] < tree_size[b])swap(a, b);
            tree_size[a] += tree_size[b];
            parent[b] = a;
            return;
        }
	bool same(ll a, ll b){
	    a = find(a);
	    b = find(b);
	    return a == b;
	}
    };
//uf.mergeのように使う
//ufはMAX_N+1でとるか、代入時に0-indexedにする

int main() {
    cin>>Q;
    rep(_, Q){
        cin>>N;
        vec k(N), p(N), ord(N), left(N + 1), right(N + 1), used(N + 1);
        rep(i, N + 1) {
            left[i] = right[i] = i;
            used[i] = 0;
        }
        ll res = 0;
        rep(i,N){
            cin>>k[i]>>A>>B;
            p[i] = A - B;
            ord[i] = i;
            res += B;
        }
        sort(ALL(ord), [&](int x, int y){
            return p[x] > p[y];
        });
        rep(i,N){
            int id = ord[i], place = k[id];
            if(p[id] <= 0) break;
            while(used[place]) place = left[place] = left[left[place]];
            if(place != 0){
                res += p[id];
                used[place] = 1;
                left[place] = place - 1;
            }
        }
        //rep(i,N) --k[i];
        rep(i, N + 1) used[i] = 0;
        Rrep(i, N){
            int id = ord[i], place = k[id];
            if(p[id] >= 0) break;
            while(used[place]) place = right[place] = right[right[place]];
            if(place != N){
                used[place] = 1;
                right[place] = place + 1;
            }else{
                res += p[id];
            }
        }
        cout<<res<<endl;
    }
}


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

int main() {
	ll A,B,M,r,x,y,c;
	cin >> A >> B >> M;
	vector<ll> a(A), b(B), ta(A), tb(B);

	rep(i,A) {
		cin >> a.at(i);
		ta.at(i) = a.at(i);
	}
	rep(i,B) {
		cin >> b.at(i);
		tb.at(i) = b.at(i);
	}

	sort(ta.begin(), ta.end());
	sort(tb.begin(), tb.end());
	r = ta.at(0)+tb.at(0);

	rep(i,M) {
		cin >> x >> y >> c;
		--x, --y;
		r = min(r, a.at(x)+b.at(y)-c);
	}

	cout << r << endl;
}

Measured memory_bytes: 3328
(n,m)=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
s=a.reduce(:+)
r = a.select {|x| x >= s.to_f / (4 * m) }
 
if r.size >= m
    print 'Yes'
else
    print 'No'
end

Measured memory_bytes: 1788
/*Third*/
#include <iostream>
using namespace std;

int main() 
{
    int n;
    cin>>n;
    char arr[n];
    for(int i=0;i<n;i++)
    {
      cin>>arr[i];
    }
    char ch;
    ch=arr[0];
    int sum=1;
    for(int i=1;i<n;i++)
    {
      if(ch==arr[i])
      {
        
      }
      else
      {
        sum++;
        ch=arr[i];
      }
    }
    cout<<sum;
}

Measured memory_bytes: 3680
#include <stdio.h>

int main (void)
{
  int n;
  scanf("%d",&n);
  int t[n];
  for(int i = 0; i < n;i ++){
    scanf("%d",&t[i]);
  }
  
  int m;
  scanf("%d",&m);
  int p[m] , x[m];
  for(int i = 0;i < m;i ++){
    scanf("%d %d",&p[i],&x[i]);
  }
  int ans = 0;
  
  for(int i = 0;i < m;i ++){
    for(int j = 0;j < n;j ++){
      if(j==p[i]-1){
        ans += x[i];
      }
      else{
        ans += t[j];
     }}
    printf("%d\n",ans);
    ans = 0;
    }
  
 return 0;
}
        

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    int n;
    int i,j,k,l;
    int cnt;
    
    while(scanf("%d",&n) != EOF){
        cnt=0;
        for(i=0; i<=9; i++){
            for(j=0; j<=9; j++){
                for(k=0; k<=9; k++){
                    for(l=0; l<=9; l++){
                        if(i+j+k+l == n){
                            cnt++;
                        }
                    }
                }
            }
        }
    printf("%d\n",cnt);
        
    }
    return 0;
}

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

using namespace std;

long long int attack(long long int h){
	if(h==1)
		return 1;
	else {
		h=attack(h/2);
		h*=2;
		h+=1;
		return h;
	}
}
int main(){
	long long int h;
	cin >> h;
	long long int res=attack(h);
	cout<<res<<"\n";
}

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

int main() {
  int N, K;
  string str;
  cin >> N >> K >> str;
  
  vector<int> vec;
  if (str[0] == '0') vec.push_back(0);
  int cnt = 1;
  for (int i = 1; i < N; i++) {
    if (str[i-1] == str[i]) {
      cnt++;
    } else {
      vec.push_back(cnt);
      cnt = 1;
    }
  }
  vec.push_back(cnt);
  auto M = (int) vec.size();
  
  vector<int> S(M + 1, 0);
  for (int i = 0; i < M; i++) S[i+1] = S[i] + vec[i];
  
  int ret = 0;
  for (int i = 0; i < M; i += 2) {
    ret = max(ret, S[min(M, i + 2 * K + 1)] - S[i]);
  }
  cout << ret << endl;
  
  return 0;
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 4e5+9, mod = 998244353;

ll bigmod(ll b, ll n)
{
    b %= mod;
    if(n == -1) n = mod - 2;
    ll ans = 1;
    while(n) {
        if(n & 1) ans = (ans * b) % mod;
        n >>= 1;
        b = (b * b) % mod;
    }
    return ans;
}

ll fac[sz], finv[sz], inv[sz];

void prec()
{
    inv[0] = inv[1] = 1;
    for(int i=2; i<sz; i++)
        inv[i] = mod - mod / i * inv[mod % i] % mod;
    fac[0] = finv[0] = 1;
    for(int i=1; i<sz; i++) {
        fac[i] = fac[i-1] * i % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll cmb(int n, int r)
{
    if(n < r) return 0;
    ll d = finv[r] * finv[n-r] % mod;
    return fac[n] * d % mod;
}

int main()
{
    prec();

    ll n, m, k;
    cin >> n >> m >> k;

    ll ans = 0;
    for(int i=0; i<=k; i++) {
        ll now = bigmod(m, 1) * bigmod(m-1, n-1-i) % mod;
        ll x = now * cmb(n-1, i) % mod;
        ans = (ans + x) % mod;
    }

    cout << ans << endl;
}


Measured memory_bytes: 12940
N,M = [ int(it) for it in input().split() ]
li = [ int(it) for it in input().split() ]
limax = [ it for it in li ]
for i in range(N-2,-1,-1):
  limax[i] = max(limax[i+1],li[i])
ma = -100000000000000000000
for i in range(N-1,-1,-1):
  ma=max(limax[i] - li[i],ma)
s = 0
for i in range(N-1,-1,-1):
  if (limax[i] - li[i]==ma):
    s+=1
print ( s )
  

Measured memory_bytes: 63472
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    string s;
    cin >> s;

    for (int i = 0; i < s.size(); i += 2) {
        cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}

int main(){
  ll N,K,Q; cin>>N>>K>>Q;
  ll p[N] = {0};
  int a;
  REP(i,Q){
    scanf("%d",&a);
    p[a-1]++;
  }
  ll b = Q-K; // K-Q+p > 0 -> p>Q-K
  REP(i,N){
    if(p[i]>b){printf(Liny);}
    else{printf(Linn);}
  }
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long 
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod 1000000009
using namespace std;
bool isprime(ll n)
{
    //if(n<2)
    //return false;
    if(n==1)
    return true;
    if(n==2 || n==3)
    return true;
    if(n%2==0)return false;
    for(ll i=3;i*i<=n;i+=2)
    {
        if(n%i==0)
        return false;
        
    }
    return true;
}
int gcd(ll a,ll b)
{
    if(a==0)
    return b;
    return gcd(b%a,a);
}
int lcm(ll a,ll b)
{
    return a*(b/gcd(a,b));
}
 set<ll> fac;
void allFactors(ll n)
{
   // set<ll> fac;
    for(ll i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            fac.insert(i);
            if(i!=n/i)
            {
                fac.insert(n/i);
               
            }
        }
    }
    //return fac.size();
}
bool threefactors(ll n)//when you have need of a no which is divisible by 1,itself,any other one no.
{
    ll p=sqrt(n);
    if(p*p==n)
    {
        if(isprime(p))
        return 1;
        else
        return 0;
    }
    else
    return 0;
}
unsigned int countSetBits(unsigned int n) //no. of 1's in a binary representation of a number
{ 
    unsigned int count = 0; 
    while (n) { 
        count += n & 1; 
        n >>= 1; 
    } 
    return count; 
} 
int main()
{
     IOS
     int testcases;
    // cin>>testcases;
     //while(testcases--)
     {
       
            int n;
            cin>>n;
            int k;
            cin>>k;
           int h[n];
           for(int i=0;i<n;i++)
           {
               cin>>h[i];
           }
           ll dp[n];
           for(int i=0;i<n;i++)
           {
               dp[i]=mod;
           }
           dp[0]=0;
           for(int i=0;i<n;i++)
           {
               for(int j=i+1;j<=i+k;j++)
               {
                   if(j<n)
                   {
                   dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
                   }
               }
           }
           cout<<dp[n-1];
     }
     return 0;
} 
//ascii of a=97
//ascii of A=65
//ascii of 0=48

Measured memory_bytes: 4892
h, w = map(int, input().split())

num2alpha = lambda c: chr(c+64)

for i in range(h):
  l = list(map(str, input().split()))
  for j in range(w):
    if l[j] == 'snuke':
      y = i+1
      x = num2alpha(j+1)
      print(str(x)+str(y))
      exit()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) a = b;
  return a > b;
}
template<class T> inline bool chmax(T&a, T b) {
  if (a < b) a = b;
  return a < b;
}

signed main() {
  int N; cin >> N;
  vector<int> h(N), dp(N, INF);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  dp[0] = 0;
  for (int i = 1; i < N; i++) {
    chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
    if (i>1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
  }
  cout << dp.back() << endl;
}


Measured memory_bytes: 1792
package main

import "fmt"

func insertionsort(nums []int){
	for i:=1; i<len(nums); i++{
		v := nums[i]
		j := i-1

		for j>=0 && nums[j]>v{
			nums[j+1] = nums[j]
			j--
		}
		nums[j+1] = v

		for k:=0; k<len(nums); k++{
			fmt.Print(nums[k])
			if k != len(nums)-1{
				fmt.Print(" ")
			}
		}
		fmt.Println("")
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	nums := make([]int, n)
	for i:=0; i<len(nums); i++{
		fmt.Scan(&nums[i])
	}
	for k:=0; k<len(nums); k++{
		fmt.Print(nums[k])
		if k != len(nums)-1{
			fmt.Print(" ")
		}
	}
	fmt.Println("")
	
	insertionsort(nums)
}


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

using namespace std;
int main(){
   int t,count=0;
  
   cin>>t;
     vector<string> st(t);

   

   for(int i=0;i<t;i++)
       cin>>st.at(i);
   sort(st.begin(),st.end());
    for(int i=0;i<t;i++){
     count++;
     if(i==t-1)
     break;
     if(st.at(i)==st.at(i+1))
       count--;

   }
    cout<<count<<endl;

}

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

int main()
{
	long long X, Y;
	cin >> X >> Y;

	long long ans = -1;
	if( X % Y ) {
		long long n = 2;
		while( X * n % Y ==  0 ) n++;
		ans = X * n;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	L, R := ReadInt(), ReadInt()
	if R-L+1 >= 2019 {
		fmt.Println(0)
		return
	}
	if L%2019 > R%2019 {
		fmt.Println(0)
		return
	}
	min := 2018
	for i := L % 2019; i < R%2019; i++ {
		for j := i + 1; j <= R%2019; j++ {
			v := i * j % 2019
			if v < min {
				min = v
			}
		}
	}
	fmt.Println(min)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

int main(){
    ll n;
    cin>>n;
    vector<string>s(n);
    rep(i,n) {
        cin>>s[i];
        sort(s[i].begin(),s[i].end());
    }
    sort(s.begin(),s.end());
    ll c=0;
    ll ans=0;
    rep(i,n-1){
        if(s[i]!=s[i+1]) {
            ans=ans+(c*(c+1))/2;
            c=0;
        }else{
        c++;
        }
    }
    ans=ans+(c*(c+1))/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7296
#include <cstdio>

using namespace std;

int main()
{
    int A, B, C;
    scanf("%d%d%d", &A, &B, &C);

    if (A < B + C) {
        printf("%d", C - (A - B));
    } else {
        printf("%d", 0);
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
vector<long long> attack(1000001,-1);
long long solve(long long h)
{
	if(h <= 0)
	{
		return 0;
	}
	else if(h == 1)
	{
		return 1;
	}
	else
	{
		if(h > 1000000)
			return 2 * solve(h/2) + 1;
		else
		{
			if(attack[h] == -1)
				return attack[h] = 2 * solve(h/2) + 1;
				
			return attack[h];
		}
	}	
}

int main()
{
	attack[0] = 0ll;
	attack[1] = 1LL;
	long long h;
	cin>>h;
	cout<<solve(h);
	return 0;
}

Measured memory_bytes: 8064