akhauriyash/Code-Regression huggingface dataset:
/*
    Author - Param Kothari
    Ah shit, here we go again
*/
 
/* Ordered Set Implementaton:

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;

typedef tree<
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair 
 
typedef long long ll;
typedef long double ld;

void solve(){
    int a[3][3] = {0}, b[3][3] = {0};
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> a[i][j];
        }
    }
    int n = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(a[j][k] == x){
                    b[j][k] = 1;
                }
            }
        }
    }
    for(int i = 0; i < 3; i++){
        if(b[i][0] == b[i][1] && b[i][1] == b[i][2] && b[i][0] == 1){
            cout << "Yes\n";
            return;
        }
        if(b[0][i] == b[1][i] && b[1][i] == b[2][i] && b[0][i] == 1){
            cout << "Yes\n";
            return;
        }
    }
    if(b[0][0] == b[1][1] && b[1][1] == b[2][2] && b[0][0] == 1){
        cout << "Yes\n";
        return;
    }
    if(b[2][0] == b[1][1] && b[1][1] == b[0][2] && b[2][0] == 1){
        cout << "Yes\n";
        return;
    }
    cout << "No\n";
}

int main(){
    IOS;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000000
#define mp make_pair
#define pb push_back

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

void increaseNum(string &seq) {
  for (int i = seq.size() - 1; i >= 0; i--) {
    int num = seq[i] - '0',
        res = num + 1;
    if (res >= 10) {
      seq[i] = '0';
      if (i == 0) {
        seq = "1" + seq;
      }
    } else {
      seq[i] = res + '0';
      break;
    }
  }
}

int main() {
  int N;
  cin >> N;
  string seq = "";
  set<string> exists;
  for (int i = 0; i < N; i++) {
    string num;
    cin >> num;
    seq = seq + num;
  }

  for (int i = 0; i < seq.size(); i++) {
    if (seq[i] == '0') {
      exists.insert("0");
      continue;
    }
    for (int j = 1; i + j <= seq.size(); j++) {
      string num = seq.substr(i, j);
      exists.insert(num);
    }
  }

  string pos = "0";
  while (1) {
    if (exists.count(pos) == 0) {
      cout << pos << endl;
      break;
    }
    increaseNum(pos);
  }
}

Measured memory_bytes: 192764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll ans=0,c1=0;
  string s;
  cin>>s;
  ll n=s.size();
  for(ll i=0;i<n;i++){
    if(s[i]=='1'){
      c1++;
    }
  }
  cout<<2*min(c1,n-c1)<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll p_1=a*c;
  ll p_2=b*d;
  ll p_3=a*d;
  ll p_4=b*c;
  vector<ll> vec;
  vec={p_1,p_2,p_3,p_4};
  sort(vec.begin(),vec.end());
  cout << vec.at(3) << endl;
  return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 998244353;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll fact[300009], invFact[300009]; 

long long power(long long x, long long c) {
    if(c==0) return 1;
    if(c==1) return x;
    if (c%2==1) return (power( (x*x)%MOD, c/2)*x)%MOD;
    else return power( (x*x)%MOD, c/2)%MOD;
}

void make_combT(ll n){
    fact[0]=1;
    rep1(i,n) fact[i]= fact[i-1]*i%MOD;
    
    invFact[n] = power(fact[n],MOD-2);
    rrep(i,n-1) invFact[i] = invFact[i+1] * (i+1) %MOD;
}

ll comb(ll n, ll m){
    if(n<m||n<0||m<0) return 0;
    return (fact[n] * invFact[m] %MOD) * invFact[n-m] %MOD;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    make_combT(300009);
    
    ll N,A,B,K;
    cin>>N>>A>>B>>K;
    
    ll ans=0;
    rep(i,N+1){
        ll k=K-A*i;
        
        if(k<0) break;
        if(k%B==0){
            ll j=k/B;
            if(N<j) continue;
            ll tmp=comb(N,i)*comb(N,j)%MOD;
            ans=(ans+tmp)%MOD;
        }
    }
    cout1(ans)
}

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

using namespace std;

int main() {
    string str,str1;
    int n,i;
    while(cin >> n) {
        int ans = 0;
        for( i = 1; i * i <= n; i++) {

        }
        cout << (i - 1) * (i - 1) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*
AtCoder Beginner Contest 101 B - Digit Sums
結果:
*/

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

#define max(x,y)(x<y?y:x)
#define int long long

int compare(const void *a, const void *b) {
	return *(int*)b - *(int*)a;
}

//尺取法
//scanf("%d", &N);
//for (i; i < N; ++i) {
//	scanf("%d", &A[i]);
//	if (b[A[i]] == 1) {
//		ans = max(ans, i - j);
//		while (b[A[i]] == 1) {
//			b[A[j++]] = 0;
//		}
//	}
//	b[A[i]] = 1;
//}
//ans = max(ans, i - j);
//printf("%d\n", ans);

//文字列の最大出現
//static int N, i, j, ans;
//static int A, B;
//static char A[50][51];
//static int cnt, max;
//char *max_name;
//
//scanf("%d", &N);
//for (i = 0; i < N; i++) {
//	scanf("%s", A[i]);
//}
//max_name = A[0];
//for (i = 0; i < N; i++) {
//	cnt = 0;
//	for (j = 0; j < N; j++) {
//		if (strcmp(A[i], A[j]) == 0) {
//			cnt++;
//		}
//		if (cnt > max) {
//			max = cnt;
//			max_name = A[i];
//		}
//	}
//}
//printf("%s\n", max_name);

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF

int main() {
	//static int N, i, j, ans;
	static int A, B,D, i = 0, j = 0, digit = 0, cnt = 0, ans = 0;
	//static int A, B;
	//static int A, B, C;
	static int c[10] = { 0 };
	//static char A[50][51];
	//static int cnt, max;
	//char *max_name;
	//static int ans;
	scanf("%d", &A);
	B = A;
	D = A;
	while (A != 0) {
		A = A / 10;
		++digit;
	}
	i = digit - 1;
	while (i != -1) {
		c[j] = B / pow(10, i);
		B = B - (c[j] * pow(10, i));
		cnt = cnt + c[j];
		i--;
		j++;
	}
	if( D%cnt==0 ){ printf("%s\n", "Yes"); }
	else{ printf("%s\n", "No"); }


	//ans = 0;
	//qsort(A, N, sizeof(int), compare);

	//ans = ;
	//printf("%d\n", ans);
	//printf("%s\n", max_name);

#ifdef DEBUGF
	getch();
#endif
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
string convertToTitle(int n) {
    string s="";
    int r;
    if(n<27)
    {
        s+=(char)(n-1+'a');
        return s;
    }
    while(n>0)
    {
        r=n%26;
        if(r==0)
        {
            s='z'+s;
            n=(int)((n-26)/26);
        }
        else
        {
            s=(char)(r-1+'a')+s;
            n=(int)(n/26);
        }
    }
    return s;
}
signed main()
{
  int n;
  cin>>n;
  cout<<convertToTitle(n)<<endl;
  return 0;
}

Measured memory_bytes: 3556
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


g = defaultdict(list)
n = 0
ans = defaultdict(int)
def bfs(x):
    q = deque([(x, 0)])
    w = set([x])
    while q:
        v, dis = q.popleft()
        if v > x:
            ans[dis] += 1
        for to in g[v]:
            if to not in w:
                w.add(to)
                q.append((to, dis + 1))
    

def solve():
    # n, m = [int(x) for x in input().split()]
    n, X, Y = [int(x) for x in input().split()]
    X -= 1
    Y -= 1
    g[X].append(Y)
    g[Y].append(X)
    for i in range(1, n):
        g[i].append(i-1)
        g[i-1].append(i)
    
    for i in range(n-1):
        bfs(i)

    for i in range(1, n):
        print(ans[i])

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

azyxwvutsrqponmlkjihgfedcb

"""


Measured memory_bytes: 10604
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int count = 0;
    for (int i=0; i<2; i++){
        if (S.at(0) == '9' || S.at(1)=='9'){
            cout << "Yes" << endl;
            break;
        }
        else{
            cout << "No" << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int x, y, z = 0;
	
	while(1){
		scanf("%d%d", &x, &y);
		if ((x == 0) && (y == 0)) break;
		if (x > y) {
			z = x;
			x = y;
			y = z;
		}
		printf("%d %d\n", x, y);
	}
	
	return 0;
}




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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n,m;
vi g[352521];
int dist[352521];

int main(){
    scanf("%d%d",&n,&m);
    REP(i,m){
        int u,v;
        scanf("%d%d",&u,&v);
        --u;--v;
        g[u].push_back(v+n);
        g[u+n].push_back(v+2*n);
        g[u+2*n].push_back(v);
    }
    int s,t;
    scanf("%d%d",&s,&t);
    --s;--t;
    queue<pii> Q;
    fill(dist,dist+3*n,1<<30);
    dist[s] = 0;
    Q.push(pii(-0,s));
    while(!Q.empty()){
        pii P = Q.front(); Q.pop();
        int p = P.second;
        if(dist[p] != -P.first)continue;
        for(int to : g[p]){
            int nd = dist[p] + 1;
            if(nd>=dist[to])continue;
            dist[to] = nd;
            Q.push(pii(-nd,to));
        }
    }
    if(dist[t]==(1<<30)){
        puts("-1");
    }else{
        printf("%d\n",dist[t]/3);
    }
    return 0;
}


Measured memory_bytes: 19072
# -*- coding: utf-8 -*-

import math

N, M = map(int, input().split())
start = [False] * N
goal = [False] * N
for i in range(M):
    a1, a2 = map(int, input().split())
    if (a1 == 1):
        start[a2 - 1] = True
    if (a2 == N):
        goal[a1 - 1] = True

def check():
    for i in range(N):
        if (start[i] & goal[i]):
            return('POSSIBLE')
    return('IMPOSSIBLE')

print(check())


Measured memory_bytes: 6132
/**
    A	Darker and Darker    	C++14 (GCC 5.4.1)
    Accept
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>    // std::copy
#include <iterator>     // std::back_inserter
#include <set>
using namespace std;
 
int mmax(vector<int> A, int N,int k){
    int max = 0;
    for (int i = 0 ; i < N ; i++){
        if(max < A[i] && i != k){
            max = A[i];
        }
    }
    return max;
}

int main(){
    int N ;
    cin >> N;

    vector<int > A(N);
    for (int i = 0 ; i < N ; i++){
        cin >> A[i];
    }
    int m = *max_element(A.begin(), A.end());
    bool b = true;
    for(int i = 0 ; i < N; i++){
        if(A[i] == m && b){
           cout << mmax(A,N,i) << endl;
           b = false;
        }
        else {
           cout << m << endl;
        }
    }
     
    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    ll n,k;
    cin>>n>>k;
    vector<pair<ll,ll>> v(n);
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        v[i]=make_pair(a,b);
    }
    sort(ALL(v));
    for(int i=0;i<v.size();i++){
        k-=v[i].second;
        if(k<=0){
            cout<<v[i].first<<endl;return 0;
        }
    }
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b;
  cin >> a >> b;
  if(string(b, char(a + '0')) < string(a, char(b + '0'))) {
    cout << string(b, char(a + '0')) << '\n';
  } else {
    cout << string(a, char(b + '0')) << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main (){
        long long N;
        long long arr[100005];
        long long Max = 0;
        long long money;
        scanf("%lld", &N);

        arr[0] =0;
        for (long long i = 1; i <= N; i++) {
                scanf("%lld", &arr[i]);
                Max += labs(arr[i-1] - arr[i]);
        }
        arr[N+1] =0;
        Max += labs(arr[N] - arr[N+1]);

        for (long long i = 1; i <= N; i++) {
                money = Max-labs(arr[i-1]-arr[i])-labs(arr[i]-arr[i+1])+labs(arr[i-1]-arr[i+1]);
                printf("%lld\n",money);
        }

        return 0;
}


Measured memory_bytes: 1920
#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<int,int>;

int main() {
  int n; cin >> n;
  vector<int> a(n); rep(i, n) cin >> a[i];
  map<int, int> mp;
  rep(i, n) mp[a[i]]++;
  int ans = 0;
  rep(i, n) {
    bool f = 1;
    int aa = a[i];
    mp[aa]--;
    for (int i = 1; i*i <= aa; i++) {
      if (aa % i == 0) {
        if (mp[i] > 0) {
          f = 0;
        }
        if (i != aa/i) {
          if (mp[aa/i] > 0) {
            f = 0;
          }
        }
      }
    }
    if (f) ans++;
    mp[aa]++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    if(N%10==3){
        cout << "bon" << endl;
    }else if(N%10 == 0 || N%10==1 || N%10==6 || N%10==8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3624
#include <stdio.h>
#define MAX 100000
int main(void){
  int N,i,count[4]={0};
  char S[MAX][4],judge[4][4]={"AC","WA","TLE","RE"};
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s",S[i]);
    if(S[i][0] == 'A'){
      count[0]++;
    }
    else if(S[i][0] == 'W'){
      count[1]++;
    }
    else if(S[i][0] == 'T'){
      count[2]++;
    }
    else{
      count[3]++;
    }
  }
  for(i=0;i<4;i++){
    printf("%s x %d\n",judge[i],count[i]);
  }
  return 0;
}

Measured memory_bytes: 2124
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define debug cout << "here!"
#define pii pair<int , int>
#define pdd pair<double , double>
#define F first
#define S second
const int maxn = 1e5 * 5 + 10 , inf = 1e9 , pi = 3.14159265;

void solve(){
    
}
void in(){
    string s; cin >> s;
    if (s[2] == s[3] && s[4] == s[5]){
        cout << "Yes"; return ;
    }
    cout << "No";
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    in();
    return 0;
}


Measured memory_bytes: 3640
class Player:
    def __init__(self,name,hands):
        self.name=name
        self.hands=hands

def discard(player):
    if len(player.hands)==0:
        return player.name
    tmp=player.hands.pop(0)
    if tmp=="a":
        return discard(A)
    if tmp=="b":
        return discard(B)
    if tmp=="c":
        return discard(C)


A=Player("A",list(input()))
B=Player("B",list(input()))
C=Player("C",list(input()))
print(discard(A))

Measured memory_bytes: 9112
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  long long int sum=0;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    if((i%3!=0)&&(i%5!=0))
    {
      sum+=i;
    }
  }
  cout<<sum;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
bool is_prime[1000000];
int main() {
    for(int i=2;i<1000000;i++) is_prime[i]=1;
    for(int i=2;i*i<1000000;i++) {
        if(!is_prime[i]) continue;
        for(int j=i*2;j<1000000;j+=i) is_prime[j]=0;
    }
    int a,d,n;
    while(scanf("%d %d %d",&a,&d,&n),a) {
        int cnt=0;
        while(1) {
            if(is_prime[a]) cnt++;
            if(cnt==n) break;
            a+=d;
        }
        printf("%d\n",a);
    }
}

Measured memory_bytes: 4120
#include <iostream>
#include <vector>
#include <array>
#include <cmath>

int main(){
    int n, x, a;
    std::array<long int, 21> box, tmp;
    std::cin >> n;
    std::cin.ignore();
    for(int i = 0;i < 21;i++){
        box.at(i) = 0;
        tmp.at(i) = 0;
    }
    std::cin >> x;
    box.at(x) = 1;
    for(int i = 0;i < n - 2;i++){
        std::cin >> x;
        for(int j = 0;j < 21;j++){
            if(box.at(j) != 0){
                if (j + x < 21) {
                    tmp.at(j + x) += box.at(j);
                }
                if (j - x > -1) {
                    tmp.at(j - x) += box.at(j);
                }
                box.at(j) = 0;
            }
        }
        for(int j = 0;j < 21;j++){
            box.at(j) = tmp.at(j);
            tmp.at(j) = 0;
        }
    }
    std::cin >> a;
    std::cout << box.at(a) << std::endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 6;
int gcd(int a, int b) {
  return (b ? gcd(b, a % b) : a);
}
int main() {
  int n;
  cin >> n;
  vector<int> del(N);
  for (int i = 2; i < N; ++i) {
    if (!del[i])
      for (int j = i; j < N; j += i)
        del[j] = i;
  }
  vector<int> kek(n);
  set<int> st;
  bool ok = true;
  for (int i = 0; i < n; ++i) {
    cin >> kek[i];
    int vl = kek[i];
    while (vl > 1) {
      int lol = del[vl];
      while (vl > 1 && del[vl] == lol)
        vl /= lol;
      if (st.find(lol) != st.end())
        ok = false;
      st.insert(lol);
    }
  }
  if (ok) {
    cout << "pairwise coprime";
    return 0;
  }
  int gg = kek[0];
  for (int i = 1; i < n; ++i)
    gg = gcd(gg, kek[i]);
  if (gg == 1)
    cout << "setwise coprime";
  else
    cout << "not coprime";
}

Measured memory_bytes: 14656
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}


// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
};

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}



// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    if(s.size() < 4){
        print("No");
        return 0;
    }
    Yes(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I');


}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int x[100], y[100];
int main() {
    int n,m,X,Y;
    int z[4];
    cin >> n >> m >> X >> Y;
    for (int i =0;i<n;i++) {
        cin >> x[i];
    }
    for (int i =0;i<m;i++) {
        cin >> y[i];
    }
    if (Y<=X) {
        cout <<"War\n";
        return 0;
    }
    z[0]=X+1;
    z[1]=Y;
    sort(x,x+n);
    sort(y,y+m);
    if (y[0]<=x[n-1]) {
        cout <<"War\n";
    }
    else {
        z[2]=x[n-1]+1;
        z[3]=y[0];
        if (z[1] < z[2] || z[3] < z[0])
            cout <<"War\n";
        else
            cout << "No War\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
using namespace std;

int n,m,cnt,vis[100];
vector <int> e[10];

bool pd()
{
	for (register int i=1;i<=n;i++) if (vis[i]==0) return false;
	return true;
}

void dfs(int x)
{
	vis[x]=1;
	if (pd())
	  {
	  	cnt++;
	  	vis[x]=0;
	  	return;
	  }
	int emm=e[x].size();  
	for (register int i=0;i<emm;i++)
	  {
	  	if (vis[e[x][i]]) continue;
	  	dfs(e[x][i]);
	  }
	vis[x]=0;
	return;  
}

int main()
{
	scanf("%d%d",&n,&m);
	for (register int i=1;i<=m;i++)
	  {
	  	int a,b;
	  	scanf("%d%d",&a,&b);
	  	e[a].push_back(b);
	  	e[b].push_back(a);
	  }
	dfs(1);  
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<cctype>
#include <fstream>
#include <time.h>
#include <iterator>





#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define fil(x,y) memset(x,y,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
//typedef pair<int, int>P;
const int MAX = 500000;

int N;
int A[100010];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	REP(i, N) {
		cin >> A[i];
	}
	int ans = 0;
	int mn = 0;
	ans = A[0] - 1;
	mn = 1;
	FOR(i,1, N) {
		int cnt = (A[i] - 1) / (mn + 1);
		if (cnt == 0) {
			if (A[i] == mn + 1)mn++;
		}
		else {
			ans += cnt;
		}
	}
	print(ans);
}

Measured memory_bytes: 1024
#include <cstring>
#include <cstdio>
#include <algorithm>
#define ll long long
const int MAXN = 200010;
const int INF = 0x3f3f3f3f;
using namespace std;

int N, A[MAXN], T[MAXN], Tmin[MAXN];

int main() {
	int i;
	bool Ok = 1;
	scanf("%d", &N);
	memset(Tmin, INF, sizeof(Tmin));

	for(i = 1; i <= N; i++) {
		scanf("%d", &A[i]);

		int z = i - A[i];
		if(z >= 1) {
			T[z] = max(T[z], i);
			Tmin[z] = min(Tmin[z], i);
		}
		else Ok = 0;
	}

	ll Ans = 0;
	int last = INF;
	for(i = N; i >= 1; i--) if(T[i]) {
		if(T[i] >= last) Ok = 0;
		last = min(last, Tmin[i]);

		Ans += T[i] - i;
	}

	if(!Ok) Ans = -1;
	printf("%lld", Ans);
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define REP(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define dup(x, y) (((x) + (y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
typedef vector<vector<int>> Graph;
template <class T> inline void chmax(T &a, T b) {
    if(a < b) {
        a = b;
    }
}
template <class T> inline void chmin(T &a, T b) {
    if(a > b) {
        a = b;
    }
}
template <class T> inline T gcd(T x, T y) {
    if(y == 0) {
        return x;
    } else if(x == 0) {
        return y;
    }
    return gcd(y, x % y);
}
template <class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template <class T> inline vector<T> convert_to_binary_number(T x) {
    vector<T> binary_num;
    while(x != 1) {
        binary_num.push_back(x % 2);
        x /= 2;
    }
    binary_num.push_back(1);
    return binary_num;
}
template <class T> inline void print_vector(vector<T> vec) {
    for(int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    cout << endl;
}
vector<LL> make_divisors(LL n) {
    vector<LL> divisors;
    for(int i = 1; i <= sqrt(n); i++) {
        if(n % i == 0) {
            divisors.push_back(i);
            if(i != n / i) {
                divisors.push_back(n / i);
            }
        }
    }
    return divisors;
}
const LL MOD = 1e9 + 7;
const int INF = 1 << 30;
const LL LLINF = 1LL << 60;
using namespace std;

int main(void) {
    int N;
    cin >> N;

    cout << N * N << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl
int main(){

    int N, D; cin>>N>>D;
    int X[N], Y[N];
    int cnt=0;

    for(int i=0; i<N; i++){
        cin>>X[i]>>Y[i];
    }

    for(int i=0; i<N; i++){
        if( sqrt(pow(X[i], 2) + pow(Y[i], 2) ) <=D ) cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 5216
main(){float a,b,c,d,e,f,g,h;while(~scanf("%f%f%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f,&g,&h)){puts((c-a)*(g-e)+(d-b)*(h-f)?"NO":"YES");}exit(0);}

Measured memory_bytes: 608
def maybe_prime(d,s,n):
    for a in (2,3,5,7):
        p = False
        x = pow(a,d,n)
        if x==1 or x==n-1:
            continue
        for i in range(1,s):
            x = x*x%n
            if x==1: return False
            elif x == n-1:
                p = True
                break
        if not p: return False
    return True

def is_prime(n):
    if n in (2,3,5,7): return True
    elif 0 in (n%2,n%3,n%5,n%7): return False
    elif 0 in [ n%i for i in range(11,min(n-1,1000),2) ]:return False
    else:
        d,s = n-1, 0
        while not d%2:
            d,s = d>>1,s+1
        return maybe_prime(d,s,n)
cnt = 0
n = int(input())
for i in range(n):
  n = int(input())
  if is_prime(n): cnt+=1

print(cnt)

Measured memory_bytes: 7776
n=int(input())
li=list(map(int,input().split()))
ans=1
if 0 in li:
    print('0')
    import sys
    sys.exit()
    
for l in li:
    ans*=l
    #print(ans)
    if ans > 10**18:
        print('-1')
        break
else:
    print(ans)

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

using namespace std;

typedef long long ll;

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

    if (S[1] == 'R') {
        if (S[0] == 'R' && S[2] == 'R') {
            cout << '3';
        } else if (S[0] == 'R' || S[2] == 'R') {
            cout << '2';
        } else {
            cout << '1';
        }
    } else {
        if (S[0] == 'R' || S[2] == 'R') {
            cout << '1';
        } else {
            cout << '0';
        }
    }
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ----------------------------------------------------------------------------

int main(){
  while(1){
    int H,W;
    cin >> H >> W;
    if(H == 0 && W == 0){
      break;
    }
    for(int i=0; i<H; i++){
      for(int j=0; j<W; j++){
        if(i%2 == j%2){
          cout << "#";
        }else{
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3104
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
C=[list(map(int,input().split())) for i in range(M)]

r=min(a)
d=min(b)

W=[]
for i in C:
    w=a[i[0]-1]+b[i[1]-1]-i[2]
    W.append(w)

print(min(r+d,min(W)))

Measured memory_bytes: 42404
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#include<ext/rope>
#define endl '\n'
#define int long long
using namespace std;
using namespace __gnu_cxx;
typedef long long LL;
const int MAXN = 1e5+5;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
int c[3],a[MAXN];
signed main(){
#ifndef ONLINE_JUEDE
    //freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
#endif // ONLINE_JUEDE
    int n,id,res=1; cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++){
        int cnt=0;
        if(a[i]==c[0]) { ++cnt; id=0; }
        if(a[i]==c[1]) { ++cnt; id=1; }
        if(a[i]==c[2]) { ++cnt; id=2; }
        if(!cnt) { puts("0");return 0; }
        res = (res*cnt)%MOD;
        ++c[id];
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1024
#ifndef KHOKHO
//#pragma GCC optimize("O3")
#endif
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
//#define CHKR
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define ARRS int(1e6+500)
#define MAX ((long long)(1e18+1))
#define EP ((double)(1e-12))
#define HS1 ((ll)(1000001329))
#define HS2 ((ll)(1000001531))
#define MOD ((long long)1000000007ll)
#define AT9 ((long long)1000000000ll)
#define PI 3.14159265358979323846264338327950288419716939937510
#define LG 20


ll dp[ARRS];
vector<pair<ll,ll> > v[ARRS];
ll pc=0,pas=0,prasi=MAX,dr=0;
ll n;
pair<ll,ll> pr={MAX,MAX};
void go(ll x,ll p,ll pc){
	dp[x]=1;
	bool re=1;
	for(auto y:v[x]){
		if(y.fr==p)continue;
		go(y.fr,x,y.sc);
		dp[x]+=dp[y.fr];
		if(dp[y.fr]>n/2)re=0;
	}
	if(n%2==0&&dp[x]==n/2){
		//cout<<"--"<<dr<<endl;
		dr=1;
		prasi=pc;
	}
	if(n-dp[x]>n/2)re=0;
	if(!dr&&re){
			//cout<<x<<endl;
		for(auto y:v[x]){
			prasi=min(prasi,y.sc);
		}
	}
	//cout<<x<<" "<<dp[x]<<endl;
	if(min(dp[x],n-dp[x])&1)
	pr=min(pr,{1,pc});
    pas+=(min(dp[x],n-dp[x])*2)*pc;
}

int main(){
	#ifdef KHOKHO
		freopen("in.in","r",stdin);
		freopen("out.out","w+",stdout);
	#endif //KHOKHO
	ll k,p,c;
	cin>>n;
	for(int i=0; i<n-1; i++){
		cin>>k>>p>>c;
		v[k].pb({p,c});
		v[p].pb({k,c});
	}
    go(1,0,0);
    cout<<pas-prasi;
	return 0;
}


Measured memory_bytes: 38016
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

const mod = 1000000007

func mpow(a, b int) int {
	if b == 0 {
		return 1
	} else if b%2 == 0 {
		tmp := mpow(a, b/2)
		return tmp * tmp % mod
	}
	return mpow(a, b-1) * a % mod
}

var fracMemo = []int{1, 1}

func mfrac(n int) int {
	if len(fracMemo) > n {
		return fracMemo[n]
	}
	if len(fracMemo) == 0 {
		fracMemo = append(fracMemo, 1)
	}
	for len(fracMemo) <= n {
		size := len(fracMemo)
		fracMemo = append(fracMemo, fracMemo[size-1]*size%mod)
	}
	return fracMemo[n]
}

var ifracMemo = []int{1, 1}

func mifrac(n int) int {
	if len(ifracMemo) > n {
		return ifracMemo[n]
	}
	if len(ifracMemo) == 0 {
		fracMemo = append(ifracMemo, 1)
	}
	for len(ifracMemo) <= n {
		size := len(ifracMemo)
		ifracMemo = append(ifracMemo, ifracMemo[size-1]*mpow(size, mod-2)%mod)
	}
	return ifracMemo[n]
}

func nCr(n, r int) int {
	if n == r {
		return 1
	}
	if n < r || r < 0 {
		return 0
	}
	ret := 1
	ret *= mfrac(n)
	ret %= mod
	ret *= mifrac(r)
	ret %= mod
	ret *= mifrac(n - r)
	ret %= mod
	return (ret)
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)

	n, k := getInt(), getInt()
	k = min(k, n-1)

	ans := 0
	for i := 0; i <= k; i++ {
		ans += (nCr(n, i) * nCr(n-i-1+i, i)) % mod
		ans %= mod
	}
	out(ans)
}


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

using namespace std;

int main(){
	int n,a;
	cin>>n>>a;
	while(n>=500)
	{
		n-=500;
	}
	if(n<=a)
	{
		cout<<"Yes";
	}
	else cout<<"No";
	return 0; 
}

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

using namespace std;

const int ms = 1e5 + 7;
const int eps = 1e-4;
int v[ms];
vector<int> arr[ms];
bool used[ms];
int comp[ms];

void dfs(int v, int com)
{
    comp[v] = com;
    used[v] = true;

    for(int i = 0; i < arr[v].size(); ++i)
    {
        int go = arr[v][i];

        if(!used[go])
            dfs(go, com);
    }
}

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

    int n, m;
    cin >> n >> m;

    for(int i = 1; i <= n; ++i)
        cin >> v[i];

    for(int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;

        arr[a].push_back(b);
        arr[b].push_back(a);
    }

    //let`s find comp of svyaz
    int vv = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(!used[v[i]])
            dfs(v[i], ++vv);
    }

    int answer = 0;
    for(int i = 1; i <= n; ++i)
    {
        if(v[i] == i || comp[i] == comp[v[i]])
            ++answer;

    }

    cout << answer << '\n';
}


Measured memory_bytes: 9600
#include <stdio.h>

#define MAX 100005

int max(int a, int b) {
    return a > b ? a : b;
}

int min(int a, int b) {
    return a < b ? a : b;
}

int abs(int a) {
    return a >= 0 ? a : -a;
}

int main() {
    int N, K;
    int h[MAX];
    int opt[MAX];
    opt[0] = 0;
    
    scanf("%d %d", &N, &K);
    
    for (int i=0; i < N; i++) {
        scanf("%d", &h[i]);
        int mm = -1;
        int set = 0;
        for (int b=i-1; b >= max(0, i-K); b--) {
            if (!set) {
                mm = opt[b] + abs(h[i] - h[b]);
                set = 1;
            }
            else {
                mm = min(mm, opt[b] + abs(h[i] - h[b]));
            }
            
        }
        if (i > 0)
            opt[i] = mm;
    }
    printf("%d\n", opt[N-1]);
    return 0;
}


Measured memory_bytes: 896
/*****Here we go again!******/

#include<bits/stdc++.h>
using namespace std;

#define pi 3.1415926535
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ll long long
#define llu unsigned long long
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define tc int test_case; cin >> test_case; while(test_case--)
#define f(i,a,n) for(int i = a ; i < n ; i++)
#define rf(i,n,a) for(int i = n-1 ; i >= a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define get(a,n) f(i,0,n) cin >> a[i];
#define show(a,n) f(i,0,n) cout << a[i] << " "; cout << endl;
#define fast ios:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trace(x) cerr << '>' << #x << ':' << (x) << "\n"
#define trace2(x,y) cerr<< '>' << #x << ':' << (x) << " | " << #y << ':' << (y) << "\n"
#define trace3(a,b,c) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
typedef map<int,int> mii;
typedef map<ll,ll> mll;

const int inf = 1e9;
const ll inf64 = 1e18;
const int mod = inf + 7;
const int N = 1e5 + 10;

int main()
{
    fast;
    int n;
    cin >> n;
    vl a(n);
    get(a,n);

    ll ans = 0, mx = -1;
    f(i,0,n)
    {
        mx = max(mx,a[i]);
        if(a[i] < mx)
            ans += mx - a[i];
    }
    cout << ans;
}


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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
template<class T = int> using V = vector<T>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T& x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

int dp[100100];

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

  int N,K;
  cin >> N >> K;
  int h[N];
  REP(i,N) cin >> h[i];

  REP(i,N) dp[i] = MOD;
  dp[0] = 0;

  REP(i,N) {
    EACH(k,1,K) {
      if (i-k < 0) break;
      chmin(dp[i], dp[i-k] + abs(h[i] - h[i-k]));
    }
  }

  print(dp[N-1]);

  return 0;
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>

using namespace std;

const int INF=1<<30;

int main(){
	int N,W;
	int dp[10001];
	scanf("%d %d",&N,&W);
	for(int i=0;i<10001;i++) dp[i]=INF;
	dp[0]=0;
	
	for(int i=0;i<N;i++){
		int v,w;
		scanf("%d %d",&v,&w);
		for(int j=10000;j>=v;j--){
			dp[j]=min(dp[j],dp[j-v]+w);
		}
	}
	int tmp;
	for(int i=0;i<10001;i++){
		if(dp[i]<=W) tmp=max(tmp,i);
	}
	printf("%d\n",tmp);
}


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

int main(){
	int height, width;
	cin >> height >> width ;
	char canvas[height+2][width+2];
	
	for(int h=1; h<=height; ++h){
		for(int w=1; w<=width; ++w){
			cin >> canvas[h][w];
		}
	}
	bool can=true;
	for(int h=1; h<=height; ++h){
		for(int w=1; w<=width; ++w){
			if(canvas[h][w]=='#'){
				if( canvas[h-1][w  ]!='#' && canvas[h+1][w  ]!='#' &&
					canvas[h  ][w-1]!='#' && canvas[h  ][w+1]!='#'    ){
					can = false;
					goto END;
				}
			}
		}
	}

	END:
	if(can){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}

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

#define pb push_back 
#define pf push_front 
#define pbp pop_back
#define pfp pop_front 
#define sz(x) x.size()
#define all(x) x.begin(),x.end() 
#define ios_base ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define open(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)

using namespace std;

typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;
typedef int I;

const int mod = 1e9 + 7;
const int N = 1e6 + 123;
const int inf = 1e9 + 123;
const long long INF = 1e18;
const double eps = 1e-5;
int n, t;
ll a[N], ans;

int f(int x){
	int s = 0;
	while(x){
		s+=x%10;
		x/=10;
	}
	return s;
}

int main (){
 ios_base
 cin >> n;
 int mn = inf;
 for(int i = 1; i <= n / 2; i ++){
 	mn = min(mn,f(i)+f(n-i));
	}
	cout << mn;
	return 0;
}



Measured memory_bytes: 256
S = input()

List = []
pos = []
for i in range(len(S)):
    if i == 0:
        List.append(1)
        s = "R"
    else:
        if S[i] == "R":
            if s == "R":
                List[-1] += 1
            else:
                List.append(1)
                s = "R"
                pos.append(i)
        else:
            if s == "L":
                List[-1] += 1
            else:
                List.append(1)
                s = "L"
                pos.append(i)

ans = [0]*len(S)
for i in range(len(List)):
    if i%2 == 0:
        if List[i] % 2 == 0:
            ans[pos[i]-1] += List[i]//2
            ans[pos[i]] += List[i]//2
        else:
            ans[pos[i]-1] += (List[i]//2+1)
            ans[pos[i]] += List[i]//2
    else:
        if List[i] % 2 == 0:
            ans[pos[i-1]-1] += (List[i]//2)
            ans[pos[i-1]] += List[i]//2
        else:
            ans[pos[i-1]] += (List[i]//2+1)
            ans[pos[i-1]-1] += List[i]//2

for i in range(len(ans)):
    ans[i] = str(ans[i])
print(" ".join(ans))

Measured memory_bytes: 15032
h, w = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
a = [list(map(int, input().split())) for _ in range(h)]

cost = [[float("inf")]*10 for _ in range(10)]
#cost[k][i][j]はｋ個までの頂点を経由して、頂点iから頂点jへ行くときの最小コスト
#cost[0][i][j]は何も経由しないのでc_ijと等しい
#ｋのところは省略できる
for i in range(10):
    for j in range(10):
        cost[i][j] = c[i][j]


for k in range(10):
    for i in range(10):
        for j in range(10):
            cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
#print(cost)
ans = 0
for i in range(h):
    for j in range(w):
        a_ij = a[i][j]
        if a_ij == -1 or a_ij == 1:
            continue
        ans += cost[a_ij][1]
print(ans)





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

int main(){
    int max=0,count=0;
    string str;
    cin >> str;

    for(int i=0;i<str.length();i++){
        if(str[i]=='A'||str[i]=='T'||str[i]=='C'||str[i]=='G'){
            count++;
        }else{
            if(max<count){
                max=count;
            }
            count=0;
        }
    }
    //最後にATCGだった時用
    if(max<count){
        max=count;
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, n) for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (i64 i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (i64 i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<>>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
inline i64 sigma(i64 n) { return n * (1 + n) >> 1; }
inline i64 updiv(i64 n, i64 d) { return (n + d - 1) / d; }
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

#ifndef DEBUG
#define dump(...)
#endif

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

inline void outs() { cout << "\n"; }
template <class Head, class... Tail>
inline void outs(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? " " : "");
    outs(forward<Tail>(tail)...);
}

template <class T>
inline void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e == &vec.back()]; }

template <class T>
inline void outs(vector<vector<T>> &df) { for (auto &vec : df) outs(vec); }

inline void outl() { cout << "\n"; }
template <class Head, class... Tail>
inline void outl(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? "\n" : "");
    outl(forward<Tail>(tail)...);
}

template <class T>
inline void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

inline void outn() {}
template <class Head, class... Tail>
inline void outn(Head&& head, Tail&&... tail) {
    cout << head;
    outn(forward<Tail>(tail)...);
}

template <class T>
inline void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    const auto lcm = [&](intmax_t a, intmax_t b) { return a / __gcd(a, b) * b; };

    var(intmax_t, a, b);
    outl(lcm(a, b));

    return 0;
}


Measured memory_bytes: 256