akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void){
    int n;
    int s[100];
    int sum=0;
    int min=100;
    
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&s[i]);
        sum+=s[i];
        s[i]%10 && (min=fmin(min,s[i]));
    }
    min>=100&&(sum=min);
    printf("%d",sum%10?sum:sum-min);
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  string S;
  IN(S);
  ll ans = 0;
  ll L = S.size();
  REP(i,L){
    ll j = L-i-1;
    if(j<i) break;
    if(S[i]!=S[j]) ans++;
  }

  OUT(ans);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<queue>
#include<stack>
#include<map>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int>P;

int main(){
    string s;
    cin>>s;
    cout<<(s.substr(0,4)=="YAKI"?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
from functools import lru_cache
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 998244353

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def to_char(a):
    return chr(a + ord("a"))

def main():
    N, K = read_values()
    P = read_list()
    P.sort()
    print(sum(P[:K]))


if __name__ == "__main__":
    main()



Measured memory_bytes: 68820
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <map>

using namespace std;

map<int, int> dist;

typedef struct status {
    int p[2][4];
    int x;
    int y;
} status;


int hash(const int p[2][4])
{
    return ((((((p[0][0] * 8 + p[0][1]) * 8 + p[0][2]) * 8 + p[0][3]) * 8 +
                    p[1][0]) * 8 + p[1][1]) * 8 + p[1][2]) * 8 + p[1][3];
}


void copy(const int src[2][4], int dst[2][4])
{
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 4; j++) {
            dst[i][j] = src[i][j];
        }
    }
}


void bfs(void)
{
    status s;

    s.x = s.y = 0;
    for (int i = 0; i < 8; i++) {
        int r = i / 4;
        int c = i % 4;
        s.p[r][c] = i;
    }

    queue<status> q;
    q.push(s);
    dist[hash(s.p)] = 0;

    while (!q.empty()) {
        static const int dx[] = {-1, 0,  0, 1};
        static const int dy[] = { 0, 1, -1, 0};

        status s = q.front();
        q.pop();

        for (int i = 0; i < 4; i++) {
            status ns;
            ns.x = s.x + dx[i];
            ns.y = s.y + dy[i];
            copy(s.p, ns.p);
            if (ns.x >= 0 && ns.x < 4 && ns.y >= 0 && ns.y < 2) {
                ns.p[s.y][s.x] = ns.p[ns.y][ns.x];
                ns.p[ns.y][ns.x] = 0;
                if (dist.count(hash(ns.p)) == 0) {
                    dist[hash(ns.p)] = dist[hash(s.p)] + 1;
                    q.push(ns);
                }
            }
        }
    }
}

int main(int argc, char ** argv)
{
    bfs();

    while (!cin.eof()) {
        int puzzle[2][4];

        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 4; j++) {
                cin >> puzzle[i][j];
            }
        }
        if (cin.eof()) {
            break;
        }
        cout << dist[hash(puzzle)] << endl;
    }

    return 0;
}

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

#define ll long long int
// ll mod=1e9+7;

ll modd(string num,ll a)
{ 
    // Initialize result 
    ll res = 0; 
  
    // One by one process all digits of 'num' 
    for (ll i = 0; i < num.length(); i++) 
         res = (res*2 + (ll)num[i] - '0') % a; 
  
    return res; 
} 

ll modular_exponentiation(ll base, ll power, ll mod)
{
    ll ans = 1;
    base = base % mod;
    while (power > 0)
    {
        if (power & 1)
        {
            ans = (ans * base) % mod;
        }

        power /= 2;
        base = (base * base) % mod;
    }
    return ans;
}


int main()
{
    /* Faster input ouput */
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);

    /* To read input from a file and output to a file */
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    ll t = 1;
    // cin >> t;
    ll i,j;
    ll arr[200005];
    arr[0] = 0;
    for(i=1;i<200005;i++)
    {
        ll temp = i;
        ll ops = 0;
        while(temp > 0)
        {
            ll bits = __builtin_popcount(temp);
            temp %= bits;
            ops++;
        }

        arr[i] = ops;
    }

    while(t--)
    {        

        ll n;
        string x;
        cin >> n;
        cin >> x;

        ll nn = n;
        ll popc = 0;

        if(n == 1)
        {
            if(x == "0")
            {
                cout << 1 << '\n';
            }
            else
            {
                cout << 0 << '\n';
            }
            continue;
        }

        for(i=0;i<n;i++)
        {
            if(x[i] == '1') popc++;
        }

        string temp = x;
        ll popci = popc;

        if(popci == 0)
        {
            // cout << 1 << '\n';
            for(i=0;i<n;i++)
            {
                cout << 1 << '\n';
            }
            continue;
        }

        ll num = modd(temp,popci);
        ll numm1;
        if(popci > 1)
        {
            numm1 = modd(temp,popci-1);
        }
        
        ll numm2 = modd(temp,popci+1);

        // cout << arr[num] + 1 << '\n';

        for(i=0;i<n;i++)
        {
            
            if(temp[i] == '0')
            {
                // add this power
                // popci increased by 1
                ll newbits = popci + 1;
                ll add = modular_exponentiation(2,(n-i-1),(newbits));
                ll fnum = (numm2+add) % (newbits);
                cout << arr[fnum] + 1 << '\n';
                
            }
            else
            {
                if(popci == 1)
                {
                    cout << 0 << '\n';
                }
                else
                {
                    ll newbits = popci - 1;
                    ll sub = modular_exponentiation(2,(n-i-1),(popci-1));
                    ll fnum = ((numm1-sub)) % (newbits);
                    fnum += (newbits);
                    fnum %= (newbits);
                    cout << arr[fnum] + 1 << '\n';    
                }
                
                
            }

            
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 5436
#include<stdio.h>
int main()
{
    char m[3];
    gets(m);
   if(m[0]=='R'&&m[1]=='R'&&m[2]=='R') printf("3\n");
   if(m[0]=='R'&&m[1]=='R'&&m[2]=='S') printf("2\n");
   if(m[0]=='R'&&m[1]=='S'&&m[2]=='R') printf("1\n");
   if(m[0]=='S'&&m[1]=='S'&&m[2]=='S') printf("0\n");
   if(m[0]=='S'&&m[1]=='R'&&m[2]=='R') printf("2\n");
   if(m[0]=='S'&&m[1]=='R'&&m[2]=='S') printf("1\n");
   if(m[0]=='S'&&m[1]=='S'&&m[2]=='R') printf("1 \n");
   if(m[0]=='R'&&m[1]=='S'&&m[2]=='S') printf("1\n");
   return 0;
}


Measured memory_bytes: 1532
h,w=map(int,input().split())
import sys
import queue
mok=queue.Queue()
s = [[str(c) for c in l.strip()] for l in sys.stdin]
dx=[1,0,-1,0]
dy=[0,1,0,-1]

maxx=0
for i in range(h):
  for j in range(w):
    d=[[-1]*w for k in range(h)]
    d[i][j]=0
    if s[i][j]=='.':
      mok.put([i,j])
      while not mok.empty():
        [nx,ny]=mok.get()
        for k in range(4):
          if 0<=nx+dx[k]<h and 0<=ny+dy[k]<w and s[nx+dx[k]][ny+dy[k]]=='.' and d[nx+dx[k]][ny+dy[k]]==-1:
            d[nx+dx[k]][ny+dy[k]]=d[nx][ny]+1
            if d[nx+dx[k]][ny+dy[k]]>maxx:
              maxx=d[nx+dx[k]][ny+dy[k]]
            mok.put([nx+dx[k],ny+dy[k]])

print(maxx)         
    

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++) cin >> vec.at(i);
  int count = 0;
  int ans = 0;
  int answer = 0;
  for(int i = 0; i < N; i++){
    ans++;
    if(vec.at(count) == 2){
      answer = ans;
      break;
    }
    count = vec.at(count) - 1;
  }
  cout << (answer == 0 ? -1 : answer) << endl;
}


Measured memory_bytes: 3192
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    long n, m, k;
    readlnTo(n, m, k);

    foreach(i; iota(n+1)) {
        foreach(j; iota(m+1)) {
            if(i * m + j * n - 2 * i * j == k) {
                writeln("Yes");
                return;
            }
        }
    }
    writeln("No");

}




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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    long n;

    cin >> n;

    pair<long, long> p[n];
    long m = 0;
    long c = 1;

    long i, len = n - 1;

    rep(i, n) {
        cin >> p[i].X;

        p[i].Y = i;
    }

    sort(p, p + n);

    rep(i, len) {
        if (p[i].Y < p[i + 1].Y) {
            c++;
        } else {
            Max(m, c);
            c = 1;
        }
    }

    Max(m, c);

    Out(n - m);

    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const int MOD = 1e9+7;
static const ll INF = 1ll<<60;

int main(){
    int N,X,T;
    cin>>N>>X>>T;
    int cnt = 0;
    while(N > 0){
        cnt++;
        N -= X;
    }

    cout<<cnt*T<<endl;

}

Measured memory_bytes: 3588
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 500005
using namespace std;
int n,l;
struct point{
	double x,y;
	point(){}
	point(double x,double y):x(x),y(y){}
	friend point operator+(const point &a,const point &b)  {return point(a.x+b.x,a.y+b.y);}
	friend point operator-(const point &a,const point &b)  {return point(a.x-b.x,a.y-b.y);}
	friend double dot(const point &a,const point &b)  {return a.x*b.x+a.y*b.y;}
	friend double cross(const point &a,const point &b)  {return a.x*b.y-a.y*b.x;}
}p[N],Q[N];
int main(){
	int x,y,L=0,R=0;
	scanf("%d%d",&n,&l);
	point O=point(0,0);
	for(int i=1;i<=n;++i){
		scanf("%d%d",&y,&x);
		p[i]=point(O.x-x,O.y-(1.0*x*y)),O=p[i];
		while(L<R&&Q[L+1].x-p[i].x>=l)  L++;
		if(L!=R&&Q[L].x-p[i].x>l){
			double slope=(Q[L].y-Q[L+1].y)/(Q[L].x-Q[L+1].x);
			Q[L]=point(p[i].x+l,Q[L+1].y+(l-(Q[L+1].x-p[i].x))*slope);
		}
		while(L<R&&cross(Q[R]-p[i],Q[R-1]-p[i])>=0)  R--;
		Q[++R]=p[i];
		printf("%lf\n",(Q[L].y-p[i].y)/l);
	}
	return 0;
}

Measured memory_bytes: 24064
import itertools

def solve():
    a, b, c, d, e, f = map(int, input().split())
    water_pair = []
    a_list = [a * i * 100 for i in range(f//(a * 100) + 1)]
    b_list = [b * i * 100 for i in range(f//(b * 100) + 1)]
    for elem in list(itertools.permutations(a_list + b_list, 2)):
        water_pair.append(elem[0] + elem[1])
    
    solt_max = int(f * ((100 * e) / (100 + e) / 100))
    water_pair = [i for i in set(water_pair) if f > i > 0]
    solt_pair = []
    c_list = [c * i for i in range(solt_max//c + 1)]
    d_list = [d * i for i in range(solt_max//b + 1)]
    for elem in list(itertools.permutations(c_list + d_list, 2)):
        solt_pair.append(elem[0] + elem[1])
    solt_pair = [i for i in set(solt_pair) if solt_max >= i]
    
    water_pair.sort()
    solt_pair.sort()
    max_pair = 0
    ans = [a * 100, 0]
    for water in water_pair:
        limit_solt = e * (water // 100)
        for solt in solt_pair:
            if solt > limit_solt:
                break
            if water + solt > f:
                break
            if (100 * solt) / (water + solt) > max_pair:
                max_pair = (100 * solt) / (water + solt)
                ans = [water + solt, solt]
    print(ans[0], ans[1])
    

if __name__=="__main__":
    solve()

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



using namespace std;



//t-(ｎ人の参加者が食べた日数=a)=X
//t=X+a

int main(){
int n,d,x;
cin>>n>>d>>x;
int a[n];
int data=0;
for(int i=0;i<n;i++){
cin>>a[i];

}

for(int i=0;i<n;i++){
 for(int r=1;r<=d;r+=a[i]){
    if(r<=d){
     data++;
    
    }
 
 }
}

int choco=data+x;
cout<<choco<<endl;

}


Measured memory_bytes: 256
n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=0

for i in range(1,(n-1)//2+1):
    for k in range(n-2*i):
        if s[k]!=s[k+i] and s[k+i]!=s[k+2*i] and s[k+2*i]!=s[k]:
            ans-=1
print(r*g*b+ans)

Measured memory_bytes: 9096
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class E
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (X, Y, A, B, C) = Scanner.Scan<int, int, int, int, int>();
            var P = Scanner.ScanEnumerable<long>().OrderByDescending(x => x).Take(X);
            var Q = Scanner.ScanEnumerable<long>().OrderByDescending(x => x).Take(Y);
            var R = Scanner.ScanEnumerable<long>().OrderByDescending(x => x);

            var answer = P.Concat(Q).Concat(R).OrderByDescending(x => x).Take(X + Y).Sum();
            Console.WriteLine(answer);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 65784
for t in xrange(input()):
    x0, y0, x1, y1, x2, y2, x3, y3 = map(int, raw_input().split())
    dx0 = x1 - x0
    dy0 = y1 - y0
    dx1 = x3 - x2
    dy1 = y3 - y2
    ov = dx0*dy1 - dy0*dx1
    iv = dx0*dx1 + dy0*dy1
    if iv == 0:
        print 1
    elif ov == 0:
        print 2
    else:
        print 0

Measured memory_bytes: 6424
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(int arr[], int n) {
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};
vector<int> G[200010];
vector<int> c(10010, 0);
int num[200010];
bool used[200010];
int now_c = 0;

int dfs(int s) {
    if (used[s]) {
        return 0;
    } else {
        used[s] = true;
    }

    num[s] = c[now_c];
    now_c++;

    for (int i = 0; i < G[s].size(); i++) {
        dfs(G[s][i]);
    }
    return 0;
}

int main() {
    int N; cin >> N;
    vector<double> v(N);
    double ans=0;
    rep(i,N){
        cin >> v[i];
    }

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

    ans=v[0];

    for(int i=1; i<N; i++){
        ans=(ans+v[i])/2;
    }
    cout << setprecision(20) << ans << endl;
    return 0;
}

Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }





int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (n % 2) { cout << "No" << endl; return 0; }
    string t = s.substr(0, n / 2);
    string u = s.substr(n / 2, n / 2);
    cout << (t == u ? "Yes" : "No") << endl;
}



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

int main()
{
	int i,j;
	for (i = 1; i <= 9; i++) {
		for (j = 1; j <= 9; j++) {
			cout << i << 'x' << j << '=' << i*j << endl;
		}
	}
	return 0;
}

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

using namespace std;

void dijkstra(int start, vector<int> &costs,
              unordered_map<int, vector<int>> &edges) {
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  costs[start] = 0;
  q.push(make_pair(0, start));
  while (!q.empty()) {
    auto v = q.top();
    q.pop();
    for (const auto &e : edges[v.second]) {
      if (v.first + 1 < costs[e]) {
        costs[e] = v.first + 1;
        q.push(make_pair(costs[e], e));
      }
    }
  }
}

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

  int n;
  cin >> n;
  unordered_map<int, vector<int>> e;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    e[a].emplace_back(b);
    e[b].emplace_back(a);
  }
  vector<int> black(n + 1, INT_MAX), white(n + 1, INT_MAX);
  dijkstra(1, black, e);
  dijkstra(n, white, e);

  int blacks = 0;
  for (int i = 1; i < n + 1; ++i) {
    if (black[i] <= white[i]) {
      blacks++;
    }
  }
  int whites = n - blacks;
  if (whites < blacks) {
    cout << "Fennec\n";
  } else {
    cout << "Snuke\n";
  }
}


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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR (i, 0, n)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

typedef pair<int, int> P;

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

    int N, X;
    cin >> N >> X;
    vector<int> x(N);
    int tmp;
    rep (i, N) {
        cin >> tmp;
        x[i] = abs(tmp - X);
    }

    int min = *min_element(all(x));
    int res = 1;
    FORR (i, min + 1, 1) {
        bool all_ok = true;
        repall (elem, x) {
            if (elem % i != 0) {
                all_ok = false;
                break;
            }
        }
        if (all_ok) {
            res = i;
            break;
        }
    }

    print(res);

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    repall (i, vec)
        cout << i << ' ';
    cout << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var S = sc.next().ToCharArray();
        if ((S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) ||
            (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) ||
            (S[0] == S[3] && S[1] == S[2] && S[0] != S[1])) {
            WriteLine("Yes");
        } else {
            WriteLine("No");
        }
    }
}


class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


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

using namespace std;

typedef long long ll;

ll k[100001][101], wi[101], vi[101];

ll knapsack(ll w, ll n)
{
	if(n <= 0 || w <= 0)
		return 0;

	if(k[w][n] != 0)
		return k[w][n];

	if(wi[n-1] > w)
		return k[w][n] = knapsack(w,n-1);
	
	return k[w][n] = max( knapsack(w,n-1), vi[n-1] + knapsack(w-wi[n-1],n-1) );
}

int main()
{
	ll n,w;
	cin >> n >> w;
	for(ll i = 0; i < n; i++)
		cin >>  wi[i] >> vi[i];
	cout << knapsack(w,n) << endl;
	return 0;
}

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

int main() {
    int h1,m1,h2,m2,k,length;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    h1 *= 60; 
    h2 *= 60;
    length = h2+m2-h1-m1-k;
    cout << length << endl;
}


Measured memory_bytes: 3584
/// time is tough.....so don't stop ...keep learning ...keep growing :)

#include <bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef long double ld ;
const int N = 1e5+5 ;
const int K = 50 ;
const ll mod =  1e9+7 ;
#define pb push_back
#define ft first 
#define sd second 
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll poww(ll a,ll b){ll res=1;while(b){if(b&1){res*=a;}a=a*a;b>>=1;}return res;}
ll poww(ll a,ll b,ll mod){ll res=1;while(b){if(b&1){res*=a;res%=mod;}a=a*a;a%=mod;b>>=1;}return res;}
const int INF = 2e9 ;
int n, m, u, v, k;
ll dp[3005][3005];// pre[105][N];
ll a[3005];
ll f(int i, int j){
   
}
int main(){
    cin >> n ;
    for(int i=1;i<=n;i++) {
        cin >> a[i];
    }
   // memset(dp, -1, sizeof dp);
    for(int len = 1;len <= n; len++) {
        for(int st = 1; st + len -1 <= n; st++) {
            int en = st + len - 1;
            if(len % 2 == n % 2) dp[st][en] = max(dp[st + 1][en] + a[st], dp[st][en - 1] + a[en]);
            else dp[st][en] = min(dp[st + 1][en] - a[st], dp[st][en - 1] - a[en]);
        }
    }
    cout << dp[1][n] << '\n';
    return 0;
}
 

Measured memory_bytes: 70016
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

int s[1024], a[1024];
int dp[1024][1<<12];

int32_t main()
{
	IO_OP;
	
	int n, m;
	cin >> n >> m;
	for(int i=1;i<=m;i++) {
		int t;
		cin >> a[i] >> t;
		for(int j=0;j<t;j++) {
			int tt;
			cin >> tt;
			s[i] += 1 << (tt - 1); 
		}
	}
	memset(dp, 0x3f, sizeof dp);
	dp[0][0] = 0;
	for(int i=0;i<m;i++) {
		for(int j=0;j<(1<<n);j++) {
			if(dp[i][j] == 0x3f3f3f3f) continue;
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
			dp[i+1][j|s[i+1]] = min(dp[i+1][j|s[i+1]], dp[i][j] + a[i+1]);
		}
	}
	if(dp[m][(1<<n)-1] == 0x3f3f3f3f) dp[m][(1<<n)-1] = -1;
	cout << dp[m][(1<<n)-1] << endl;
}





Measured memory_bytes: 16640
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple< int,int,int > T;
const int MAX_N=55555;
bool is_prime[MAX_N];
int prime[MAX_N];
int sieve(int n){
    
    ll p=0;
    for(ll i=0;i<=n;i++) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(ll i=2;i<=n;i++){
        if(is_prime[i]){
            prime[p++]=i;
            for(ll j=i*2;j<=n;j+=i){
                is_prime[j]=false;
            }
        }
    }
    return p;
}
map<int,int> primefactor(int n){
  map<int,int> res;
  for( int i=2 ;i*i<=n;i++){
    while(n%i==0){
      ++res[i];
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}
bool flag=true;
int now[56];
int g;
void dfs(int no,int se,int sum){
  if(no==5){
    if(is_prime[sum])flag=false;
    return ;
  }
  for(int i=0;i<g;i++){
    if(!(se>>i & 1 )){
      dfs(no+1,se&1<<i,sum+now[i]);
    }
  }
}
bool used[55555];

int main(){
  int p=sieve(55555);
  int n;
  fill(used,used+55555,false);
  cin>>n;
  int x=0;
  for(int i=0;i<55555;i++){
    if(x==n)break;
    if(is_prime[i] and i%5==1){
      now[x++]=i;
    }
  }
  for(int i=0;i<n-1;i++)cout<<now[i]<<" ";
  cout<<now[n-1]<<endl;

  return 0;
}


Measured memory_bytes: 384
/*---> 11 May 2020 <--- > 01:37:16 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;

int32_t main(){__
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int ini=k;
	k-=a;
	if(k<=0){
		cout<<ini<<"\n";
	}
	else{
		k-=b;
		if(k<=0){
			cout<<a<<"\n";
		}
		else{
			cout<<a-k<<"\n";
		}
	}
return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N; cin >> N;

	VI p(N);
	int sum = 0;
	REP(i,N){
		cin >> p[i];
		sum += p[i];
	}

	SORT(p);
	int ans = sum - p.back() + p.back()/2;
	cout << ans << endl;


	return 0;

}


Measured memory_bytes: 256
N = int(input())
P = [int(s) for s in input().split()]
index = []
for i in range(N):
    index.append(P.index(i+1))
count = 0
for i, j in enumerate(index):
    if i != j:
        count += 1
if count > 2:
    print("NO")
else:
    print("YES")


Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

struct LowLink {
    int N;
    vector<vector<int>> G;
    vector<int> low,ord,articulation;
    vector<P> bridge;

    LowLink(int N, vector<vector<int>> &G): N(N),G(G),low(N,-1),ord(N,-1) {}

    void dfs(int v,int time,int p = -1) {
        ord[v] = low[v] = time;
        ++time;

        bool isArticulation = false;
        int cnt = 0;

        for (int e:G[v]) {
            if (low[e] < 0) {
                ++cnt;
                dfs(e,time,v);
                low[v] = min(low[v],low[e]);
                if (p != -1 && ord[v] <= low[e]) isArticulation = true;
                if (ord[v] < low[e]) bridge.push_back({v,e});
            }
            else if (p != e) {
                low[v] = min(low[v],ord[e]);
            }
        }

        if (p == -1 && cnt >= 2) isArticulation = true;
        if (isArticulation) articulation.push_back(v);
    }

    void build() {
        dfs(0,0);
    }
};

int main() {
    int V,E; cin >> V >> E;
    vector<vector<int>> G(V);
    rep(_,E) {
        int a,b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    LowLink lol(V,G);
    lol.build();
    vector<int> ans = lol.articulation;
    sort(ans.begin(),ans.end());
    rep(i,ans.size()) {
        cout << ans[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 5192
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_2_A&lang=jp
# Spanning Tree - Minimum Spanning Tree

class PriorityQueue
  def initialize()
    @data = []
  end

  def push(x)
    i = @data.bsearch_index { |y| y > x }
    if i
      @data.insert(i, x)
    else
      @data.push(x)
    end
  end

  def length()
    @data.length
  end

  def pop()
    @data.shift
  end
end

class St
  attr :p, :cost

  def initialize(p, cost)
    @p = p
    @cost = cost
  end

  def >(other)
    @cost > other.cost
  end
end

class MST
  def initialize(nv)
    @adj = Array.new(nv) { Array.new }
    @nv = nv
  end

  def connect(a, b, w)
    @adj[a].push({ to: b, cost: w })
    @adj[b].push({ to: a, cost: w })
  end

  def calc
    que = PriorityQueue.new
    que.push(St.new(0, 0))
    visited = Array.new(@nv, false)
    sum = 0
    while que.length > 0
      cur = que.pop
      next if visited[cur.p]
      visited[cur.p] = true
      sum += cur.cost
      @adj[cur.p].each do |e|
        que.push(St.new(e[:to], e[:cost])) if !visited[e[:to]]
      end
    end
    sum
  end
end

nv, ne = gets.split.map(&:to_i)
mst = MST.new(nv)
ne.times do
  a, b, w = gets.split.map(&:to_i)
  mst.connect(a, b, w)
end

puts mst.calc



Measured memory_bytes: 57484
n = int(input())
a = list(map(int, input().split()))
M = max(a)
ok = [0]*(M+1)
a.sort()

for i in range(n):
    ok[a[i]] += 1
    if ok[a[i]] == 1:
        for g in range(a[i], M+1, a[i]):
            if g != a[i]:
                ok[g] += 2


print(ok.count(1))

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

int main(void){
    int n,flagA,flagB,flagC,i;
    flagA = 0; flagB = 0, flagC = 0;
    string s;
    cin >> s;
    n = s.size() - 1;

    //1st condition
    for(i=0; i <= n/2 ; i++){
        if(s.at(i) != s.at(n-i)){
            flagA = 1;
            break;
        }
    }

    //2nd condition
    n = (n-1) / 2;
    for(i=0; i <= n/2; i++){
        if(s.at(i) != s.at(n-i)){
            flagB = 1;
            break;
        }
    }

    //3rd condition
    n = s.size() - 1;
    for(i = (n + 3) / 2; i <= n; i++){
        if(s.at(i) != s.at(n-i)){
            flagC = 1;
            break;
        }
    }

    if(flagA == 0 && flagB == 0 && flagC == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
//        cout << flagA << flagB << flagC << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int i = int.Parse(input[1]);
            Console.WriteLine(N - i + 1);
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
//dp[i][j][k] 長さiでj個の点が含まれていて1を含む強連結点数がk個
ll dp[305][305][305];
ll mod = 1e9+7;
int main(){
    int n, m;
    cin >> n >> m;
    if(m<n){
        puts("0");
        return 0;
    }
    dp[0][1][1]=1;
    rep(i,m+1){
        rep(j,n+1){
            rep(k,j+1){
                dp[i+1][j+1][k] += dp[i][j][k]*(n-j)%mod;
                dp[i+1][j][k] += dp[i][j][k]*(j-k)%mod;
                dp[i+1][j][j] += dp[i][j][k]*k%mod;
                
            }
        }
    }
    cout << dp[m][n][n]%mod << endl;
}


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

vector <int> v;
vector <int> s;
int solve(int a){
    if(a<=1) return 0;
    if(v[a]!=-1) return v[a];
    if(a==2) v[a]= abs(s[a]-s[a-1]);
    else if(a>2) v[a]= min(solve(a-1)+abs(s[a]-s[a-1]),solve(a-2)+abs(s[a]-s[a-2]) );
    return v[a]; 
}
int main(){
    // int t,n;
    cin>>n;
    v.resize(n+1,-1);
    s.resize(n+1,-1);
    for(int i=1;i<=n;i++) cin>>s[i];
    cout<<solve(n)<<endl;
    // cout<<v[n]
    return 0;
}

Measured memory_bytes: 3328
function Main(input) {
input = input.split("\n");
input[0] = input[0].split(" ").map(Number);
var arr = input[1].split(" ").map(Number);
var nowsum = 0;
var maxsum = 0;
for(var i=0;i<input[0][1];i++){
	nowsum += arr[i];
}
maxsum = nowsum;
var maxpoint = 0;
for(var j=input[0][1]-1;j<arr.length;j++){
 // console.log(j,nowsum,j-input[0][1]+1)
	nowsum -= arr[j-input[0][1]+1];
	nowsum += arr[j+1];
	if(maxsum<nowsum){
		maxsum= nowsum;
		maxpoint = j-input[0][1]+1;
	}
}
//console.log(maxsum)
  console.log((maxsum-0+input[0][1])/2)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 32716
#pragma GCC optimize("Ofast") 
#include<algorithm>
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long 
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    int n,k;
    in(n)>>k;
    int dp[n+1],ar[n+1];
    l(i,1,n+1)
    {
        in(ar[i]);
        dp[i]=100001;
    }
    dp[1]=0;
    l(i,2,n+1)
    {
        dp[i]=dp[i-1]+abs(ar[i]-ar[i-1]);
        l(j,1,k+1)
        {
            if((i-j)<1)
            break;
            dp[i]=min(dp[i-j]+abs(ar[i]-ar[i-j]),dp[i]);
        }
    }
    o(dp[n]);
}

Measured memory_bytes: 1024
N,W=map(int,input().split())
WV=[list(map(int,input().split())) for i in range(N)]
import numpy as np
V=N*1000+1
dp=np.ones(V,dtype=np.int64)*(W+1)
dp[0]=0
for w,v in WV:
    dp[v:]=np.minimum(dp[v:],dp[:-v]+w)
print(max([i for i in range(V) if dp[i]<=W]))

Measured memory_bytes: 21440
// https://atcoder.jp/contests/abc152/tasks/abc152_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, minv = 1e9, ans = 0;
    cin >> N;
    REP(i, N) {
        int t;
        cin >> t;
        if (t < minv) {
            ans++;
            minv = t;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

/*
	一年 10ヵ月 （大の月＝20日、小の月＝19日）
1年	大の月、小の月、大の月、小の月、大の月、小の月、大の月、小の月、大の月、小の月、195 日
2年	大の月、小の月、大の月、小の月、大の月、小の月、大の月、小の月、大の月、小の月、195 日
3年	大の月、大の月、大の月、大の月、大の月、大の月、大の月、大の月、大の月、大の月、200 日
4年	大の月、小の月、大の月、小の月、大の月、小の月、大の月、小の月、大の月、小の月、195 日
5年	大の月、小の月、大の月、小の月、大の月、小の月、大の月、小の月、大の月、小の月、195 日
6年	大の月、大の月、大の月、大の月、大の月、大の月、大の月、大の月、大の月、大の月、200 日
...
*/

int main()
{
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	while (n-- ){
		int y, m, d; cin >> y >> m >> d;
		int res = 0;

		if (y % 3 != 0 ){
			if (m % 2 != 0 ){	// 大の月
				res = 20 - d + 1;
			}else{			// 小の月
				res = 19 - d + 1;
			} // end if
		}else{
			res = 20 - d + 1;
		} // end if

		for (int nm = m + 1; nm < 11; nm++ ){
			res += (y % 3 == 0 ? 20 : (nm % 2 != 0 ? 20 : 19 ) );
		} // end for

		for (int ny = y+1; ny < 1000; ny++ ){
			res += (ny % 3 == 0 ? 200 : 195 );
		} // end for
		cout << res << endl;
	} // end while
		
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#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 VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int main(void){
	int min,c[3][3];

	REP(i,3){
		min=INF;
		REP(j,3){
			cin>>c[i][j];
			chmin(min,c[i][j]);
		}
		REP(j,3) c[i][j]-=min;
	}
	
	REP(j,3){
		int tem=c[0][j];
		if(tem!=c[1][j]||tem!=c[2][j]){
			print("No");
			return 0;
		}
	}
	print("Yes");
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
int n, k;
long long ans;
int main() {
	scanf("%d%d", &n, &k);
	if(k & 1) ans = (long long) pow(n / k, 3);
	else ans = (long long) pow(n / k, 3) + (long long) pow(n / k + (n % k >= k / 2), 3);
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;

void AGC033B()
{
	int H, W, N;
	cin >> H >> W >> N;
	int sr, sc;
	cin >> sr >> sc;
	string S, T;
	cin >> S;
	cin >> T;

	int x = sc;
	for (int i = 0; i < N; ++i)
	{
		if (S[i] == 'R')
			++x;
		if (x > W)
		{
			cout << "NO" << endl;
			return;
		}
		if (x > 1 && T[i] == 'L')
			--x;
	}
	x = sc;
	for (int i = 0; i < N; ++i)
	{
		if (S[i] == 'L')
			--x;
		if (x < 1)
		{
			cout << "NO" << endl;
			return;
		}
		if (x < W && T[i] == 'R')
			++x;
	}

	x = sr;
	for (int i = 0; i < N; ++i)
	{
		if (S[i] == 'D')
			++x;
		if (x > H)
		{
			cout << "NO" << endl;
			return;
		}
		if (x > 1 && T[i] == 'U')
			--x;
	}

	x = sr;
	for (int i = 0; i < N; ++i)
	{
		if (S[i] == 'U')
			--x;
		if (x < 1)
		{
			cout << "NO" << endl;
			return;
		}
		if (x < H && T[i] == 'D')
			++x;
	}
	cout << "YES" << endl;
}
int main()
{
	AGC033B();
	return 0;
}

Measured memory_bytes: 776
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

long long calc(const vector<int>& v, long long b)
{
	long long ret = 0;
	for(int i=0; i<v.size(); i++)
		ret += abs(v[i] - b);

	return ret;
}

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

	vector<int> A(N);
	for(int i=0; i<N; i++)
		cin >> A[i];

	for(int i=0; i<N; i++)
		A[i] -= i+1;

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

	int index = N / 2;
	//if(N%2 == 0)
	//	cout << min(calc(A, A[index]-1), calc(A, A[index]+1)) << endl;
	//else
		cout << calc(A, A[index]) << endl;

	return 0;
}


Measured memory_bytes: 1024