akhauriyash/Code-Regression huggingface dataset:
// Aizu 0579: Hot days
// 2017.9.24 bal4u@uu

#include <stdio.h>
#include <string.h>
#define abs(a) ((a)>=0?(a):-(a))

typedef struct { int a, b, c; } T;
T clothes[203];		// ?´????
int t[203];			// ???????°????
int dp[2][203];		// ?????????????´??????????????¨?

int main()
{
	int d, n, i, j, k, k1, k2, ans;
	T *p, *q;

	scanf("%d%d", &d, &n);
	for (i = 0; i < d; i++) scanf("%d", t+i);
	for (p = clothes, i = 0; i < n; i++, p++) scanf("%d%d%d", &p->a, &p->b, &p->c);

	memset(dp, -1, sizeof(dp)); dp[0][0] = 0;
	for (k1 = 0, k2 = 1, i = 0; i < d; i++, k1 = k2, k2 = !k2) {
		memset(dp[k2], -1, sizeof(dp[k2]));
		for (p = clothes, j = 0; j < n; j++, p++) {
			if (p->a <= t[i] && t[i] <= p->b) {
				for (q = clothes, k = 0; k < n; k++, q++) {
					if (dp[k1][k] >= 0) {
						int t = 0;
						if (i > 0) t = abs(p->c - q->c) + dp[k1][k];
						if (dp[k2][j] < 0 || t > dp[k2][j]) dp[k2][j] = t;
					}
				}
			}
		}
	}
	for (ans = 0, i = 0; i < n; i++) if (dp[k1][i] > ans) ans = dp[k1][i];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1796
<?php
$x = trim(fgets(STDIN));
$op = ['+', '-'];
for ($i = 0; $i < 2; $i++) {
     for ($j = 0; $j < 2; $j++) {
          for ($k = 0; $k < 2; $k++) {
               $cal = substr($x, 0, 1) . $op[$i] . substr($x, 1, 1) . $op[$j] . substr($x, 2, 1) . $op[$k] . substr($x, 3, 1);
               if (eval('return ' . $cal . ';') == 7) {
                   exit($cal . '=7');
               }
          }
     }
}
?>

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

//++時計回り --反時計回り
// int dx[4] = {1, 0, -1, 0};
// int dy[4] = {0, 1, 0, -1};

int main() {
  int N;
  cin >> N;
  ll H[N];
  bool ans = true;
  REP(i, N) { cin >> H[i]; }
  ll max_ = 0;
  REP(i, N) {
    max_ = max(max_, H[i]);
    if (H[i] < max_ - 1)
      ans = false;
  }
  cout << (ans ? "Yes" : "No") << '\n';
}


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

int main(){
  string s;
  cin >> s;
  if(s=="A"){
    cout << "T" << endl;
  }else if(s=="T"){
    cout << "A" << endl;
  }else if(s=="C"){
    cout << "G" << endl;
  }else if(s=="G"){
    cout << "C" << endl;
  }


  return 0;
}

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

int main()
{
  int n;
  cin >> n;
  n--;
  int a[n], b[n], c[n + 1];
  c[0] = 0;
  int suma = 0, sumb = 0;
  int x, y;
  cin >> x;
  c[0] = 0;
  rep(i, n) {
    cin >> a[i];
    suma += a[i];
  }
  rep(i, n) {
    cin >> b[i];
    sumb += b[i];
    c[i + 1] = c[i] + b[i];
  }
  cin >> y;
  int ans = 0;
  rep(i, n + 1) {
    if(i != 0) suma -= a[n - i];
    ans = max(ans, suma + c[n] - c[n - i]);
  }
  cout << ans + x + y << endl;
    

  return 0;
}


Measured memory_bytes: 3472
// AtCoder_175C. Walking Takahashi
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ALL(v)      v.begin(), v.end()
#define PB          push_back
#define MP          make_pair
#define UB          upper_bound
#define LB          lower_bound
#define PI          2*acos(0.0)
#define MOD         1000000007
#define GCD(a, b)   __gcd(a, b)
#define LCM(a, b)   ((a)*(b)) / GCD(a, b)
#define INPUT       freopen("input.txt", "r", stdin);
#define OUTPUT      freopen("output.txt", "w", stdout);
#define PRINT(a)    for(auto i : a) cout << i << " "; cout << endl;
#define PRINTS(s)   for(auto i=s.begin(); i!=s.end(); i++) cout << *i << " "; cout << endl;
#define PRINTM(m)   for(auto i=m.begin(); i!=m.end(); i++) cout << i->first << " " << i->second << endl;

int month[] = {31,28,31,30,31,30,31,31,30,31,30,31};
string lowerCase = "abcdefghijklmnopqrstuvwxyz";
string upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

/// Graph moves
const int fxKing[] = {+1,+1,+0,-1,-1,-1,+0,+1}; /// King's move
const int fyKing[] = {+0,+1,+1,+1,+0,-1,-1,-1}; /// King's move
const int fxKnight[] = {+2,+1,-1,-2,-2,-1,+1,+2}; /// Knight's move
const int fyKnight[] = {+1,+2,+2,+1,-1,-2,-2,-1}; /// Knight's move

ll q, t=1, a, b, c, d, m, n, k, x;
ll cnt, Mn, Mx, sum, sum1, sum2, ck;
ll arr1[1000], arr2[1000];

map <ll, ll> mp1, mp2;
set <ll> st1, st2;
vector <ll> vec1, vec2;
string str1, str2, str3;

int main()
{
    FIO;
    while(t--)
    {
        ll x, k, d;
        cin >> x >> k >> d ;
        x = abs(x);
        ll a = x / d;
        ll b = min(a, k);
        k -= b;
        ll c = x - d*b;
        if(k && k&1){
            c = d - c;
        }
        cout << c << endl;
    }

    return 0;
}


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

int main() {
    ll r, D, x;
    cin >> r >> D >> x;
    rep(i, 10) {
        x = r*x - D;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<vector>

using namespace std;

#define long long long
#define ft(i, a, b) for (int i = (long)a ; i <= (long)b ; i++)
#define fd(i, a, b) for (int i = (long)a ; i >= (long)b ; i--)

const int mxN = 2e5 + 5;
const long oo = 1e15;

long n , ans;
long a[mxN] , dp[mxN] , pre[mxN];

void Solve() {
    pre[1] = a[1];
    for(int i = 3; i <= n; i+= 2) {
        pre[i] = pre[i - 2] + a[i];
    }
    /*ft(i , 1 , n) if (i % 2 == 1) cout << pre[i] << " ";
    else cout << "  ";
    cout << "\n";*/
    dp[1] = 0;
    dp[2] = max(a[1] , a[2]);
    ft(i , 3 , n) {
        if (i % 2 == 1) {
            dp[i] = max(dp[i - 1] , dp[i - 2] + a[i]);
        }
        else dp[i] = max(pre[i - 1] , dp[i - 2] + a[i]);
    }
    //ft(i , 1 , n) cout << dp[i] << " ";
    cout << dp[n];
}

void FastInput() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
}

void Input() {
    cin >> n;
    ft(i , 1 , n) cin >> a[i];
}

int main() {
    FastInput();
    Input();
    Solve();
}

Measured memory_bytes: 8288
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
static void Main(string[] args){

var RGBN = Console.ReadLine().Split().Select(x => int.Parse(x)).ToList();
var R=RGBN[0];
var G=RGBN[1];
var B=RGBN[2];
var N=RGBN[3];
int cnt=0;
for(int i=0;i<=N/R;i++){
    if(R*i==N){cnt+=1;break;}
    for(int j=0;j<=N/G;j++){
//if(R*i+G*j==N){cnt+=1;break;}
        if(((N-(R*i+G*j))%B==0)&&((N-(R*i+G*j))/B>=0)){
//Console.WriteLine("{0} {1} {2}",i,j,(N-(R*i+G*j))/B);
cnt+=1;}
        }}

Console.WriteLine(cnt);
}
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define lowbit(a) ((a)&(-(a)))
using namespace std;

void file(bool opt)
{
	if (opt&&fopen("in.txt", "r"))
	{
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	}
}

long long n,m;

int main()
{
	//file(1);
	cin >> n>>m;
	cout << (n+2*m)/(2*m+1) << endl;
	return 0;
}

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

using namespace std;

int abs(int x) {
    if (x < 0)
        return -x;
    return x;
}

int main() {
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        A[i] -= i + 1;
    }

    nth_element(A.begin(), A.begin() + N / 2, A.end());
    int64_t answer = 0;
    for (auto &x : A)
        answer += abs(x - A[N / 2]);
    cout << answer << "\n";
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

ll p,q,a;
int n;

inline bool same(ll num, ll den)
{
    return num*q==den*p;
}

ll dfs(ll num, ll den, int dep, ll b)
{
    if(same(num,den)) return 1;

    if(dep==n) return 0;

    // printf(" now: %lld %lld %d %lld\n", num,den,dep,b);
    ll x=q*den,y=p*den-q*num;
    // printf("x=%lld y=%lld\n", x,y);

    ll l=x/y;
    if(x%y!=0) ++l;
    l=max(l,b);
    ll r=a/den;

    ll ret=0;
    for(ll i=l; i<=r; ++i) ret+=dfs(num*i+den, i*den, dep+1, i);
    return ret;
}

int main()
{
    while(cin >>p >>q >>a >>n,p) printf("%lld\n", dfs(0,1,0,1));
    return 0;
}

Measured memory_bytes: 3128
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let h: u32 = read();
    let w: u32 = read();

    let area = h * w;
    let rectangle = 2 * (h + w);

    println!("{} {}", area, rectangle)
}



Measured memory_bytes: 5024
#import <stdio.h>
#import <stdbool.h>
int main() {
	char S[102];
	char *s = S;
	scanf("%s",s);
	bool c = false;
	while(*s!='\0'){
		if(*s=='C') c = true;
		if(c&&*s=='F'){
			puts("Yes");
			return 0;
		}
		s++;
	}
	puts("No");
}

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


int main() {
	int n;
	int a[100];
	int v;
	int j;
	cin >> n;
	for (int i = 0; i<n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i<n; i++)
	{
		cout << a[i];
		if (i < n - 1)
		{
			cout << ' ';
		}
	}
	cout << endl;
	for (int i = 1; i<n; i++)
	{
		v = a[i];
		j = i - 1;
		while (j >= 0 && a[j]>v)
		{
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		for (int k = 0; k<n; k++)
		{
			cout << a[k];
			if (k < n - 1)
			{
				cout << ' ';
			}
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3080
#BFS(幅優先探索のテンプレート)
from collections import deque
inf = float("INF")
 
N,M = map(int,input().split())
path = [[] for i in range(N)]
dist = [inf for i in range(N)]
visited = [0 for i in range(N)]
 
for _ in range(M):
    a,b = map(int,input().split())
    a = a - 1
    b = b - 1
    path[a].append(b)
    path[b].append(a)
 
def bfs(path,root,visited):
    #頂点の距離は0
    dist[root] = 0
    #頂点0を初期ノードに設定、訪問済みにする
    visited[root] = 1
    #初期ノードをキューに追加
    queue = deque([root])
    #BFS開始(キューが空になるまで行う)
    while queue:
        #キューから先頭頂点を取り出す
        current = queue.popleft()
        for i in path[current]:
            #すでに訪問図済みの頂点は探索しない
            if visited[i] == 1:
                continue
            else:
                #新たな頂点iに対して距離情報を更新してキューに追加
                dist[i] = current + 1#距離情報の更新
                visited[i] = 1#訪問済みにする
                queue.append(i)#キューに追加
 
    if all([i == 1 for i in visited]):
        return "Yes"
    else:
        return "No"
 
flag = bfs(path,0,visited)
print(flag)
 
if flag == "Yes":
    for i in range(1,N):
        print(dist[i])

Measured memory_bytes: 100700
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,  ll>;

const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
	ll n, m; string s;
    cin >> n >> m >> s;
    reverse(s.begin(), s.end());
    vector<int> ans;
    for (int i = 0; i < n;) {
        bool flag = true;
        for(int j = m; j >= 1; --j){
           if(i+j>=n+1){continue;}
           if(s[i+j]=='0'){
        	  i += j;
              flag = false;
              ans.push_back(j);
              break;
           }
        }
        if(flag){
          cout << -1 << endl;
          return 0;
        }
    }
    reverse(ans.begin(), ans.end());
    for(int i = 0; i < ans.size(); ++i){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 1144
def update(i, v):
    i += length
    dp[i] = max(v, dp[i])
    while i:
        i //= 2
        dp[i] = max(dp[2 * i], dp[2 * i + 1])


def query(l, r):
    l += length
    r += length
    res = 0
    while l < r:
        if l % 2:
            res = max(dp[l], res)
            l += 1
        l //= 2
        if r % 2:
            res = max(dp[r - 1], res)
            r -= 1
        r //= 2
    return res


N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]
length = 1 << 20
dp = [0] * (2 * length)
res = 0
for a in A:
    cur = query(max(a - K, 0), min(a + K + 1, 300005))
    res = max(res, cur + 1)
    update(a, cur + 1)
print(res)


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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  string s; cin >> s;
  ll k; cin >> k;
  int n = si(s);

  rep(i, n) {
    if (s[i] == 'a') continue;
    
    int dis = 'z' - s[i] + 1;
    if (dis <= k) {
      s[i] = 'a';
      k -= dis;
    }
  }

  if (k) s[n-1] = (s[n-1] - 'a' + k) % 26 + 'a';
  cout << s << endl;
}


Measured memory_bytes: 3676
from collections import deque


def main():
    N = int(input())
    A = [deque(map(lambda x: int(x)-1, input().split())) for _ in range(N)]
    ans = 1
    empty = 0
    candidates = set(range(N))
    while True:
        used = set()
        for i in candidates:
            if len(A[i]) == 0 or i in used:
                continue
            j = A[i][0]
            if len(A[j]) and A[j][0] == i and j not in used:
                used.add(i)
                used.add(j)
                A[i].popleft()
                A[j].popleft()
                if len(A[i]) == 0:
                    empty += 1
                if len(A[j]) == 0:
                    empty += 1
        if empty == N:
            break
        if len(used) == 0:
            ans = -1
            break
        ans += 1
        candidates = used
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 75228
#include <iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	(a + b < a - b) ? (a - b < a*b) ? cout << a * b << endl : cout << a - b << endl : (a + b < a*b) ? cout << a * b << endl : cout << a + b << endl;
	return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define INF LONG_LONG_MAX
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;

double r;

signed main() {
    cin >> r;
    cout << setprecision(20) << r*M_PI*2 << endl;
}




Measured memory_bytes: 3776
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    bool ok = true;
    if(v <= w) ok = false;
    else if((llabs(b-a) + (v - w) - 1) / (v - w) > t) ok = false;
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3608
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys


def solve(s, t):
  tr_s = {} # s -> t
  tr_t = {} # t -> s
  for i in range(len(s)):
    if t[i] not in tr_t:
      tr_t[t[i]] = s[i]
    if s[i] not in tr_s:
      tr_s[s[i]] = t[i]

    if (tr_s[s[i]] != t[i]) or (tr_t[t[i]] != s[i]):
      return False

  return True


S = str(input())
T = str(input())
if solve(S, T):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        String s1 = scan.next();
        String s2 = scan.next();
        String s3 = scan.next();
        //int x = 'a'; //large
        //int y = 'A'; //small
        //System.out.println(x);
        //System.out.println(y);

        System.out.print((char)(s1.charAt(0) - ('a' - 'A')));
        System.out.print((char)(s2.charAt(0) - ('a' - 'A')));
        System.out.print((char)(s3.charAt(0) - ('a' - 'A')) + "\n");
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <cmath>

using namespace std;

size_t calc(string& s, int s_index, size_t acc){
    if(s_index>=s.size()){
        return acc;
    } else{
        size_t digit=s[s_index]-'0';
        size_t result=0;
        result+=calc(s, s_index+1, acc*10+digit);
        result+=calc(s, s_index+1, digit);
        result+=acc*pow(2, s.size()-s_index-1);
        return result;
    }
}

size_t calc(string& s){
    size_t digit=s[0]-'0';
    return calc(s, 1, digit);
}

int main() {
    string s;
    cin >> s;
    cout << calc(s) << "\n";
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cmath>

using namespace std;

int main(){
    string s;
    cin >> s;
    if((s[0]==s[1]) && (s[1]==s[2])){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
    
}

Measured memory_bytes: 3124
n= int(input())
x =[int(s) for s in input().split()]
y =[int(s) for s in input().split()]

#p=1
S = 0
for i in range(n):
	S += abs(x[i]-y[i])
D_1 = S
print("{:.8f}".format(D_1))

#p=2
T = 0
for i in range(n):
	T += (x[i]-y[i])**2
D_2 = T**(1/2)
print("{:.8f}".format(D_2))

#p=3
V = 0
for i in range(n):
	V += abs(x[i]-y[i])**3
D_3 = V**(1/3)
print("{:.8f}".format(D_3))

#p=∞
U = 0
max = 0
for i in range(n):
	if max <= abs(x[i]-y[i]):
		max = abs(x[i]-y[i])
print("{:.8f}".format(max))


Measured memory_bytes: 5656
//#include "Header.h"
#include<iostream>
#include<bits/stdc++.h>

using namespace std;

#define endl '\n'
typedef long long ll;
using namespace std;

int main()
{

	int N, K;
	cin >> N;
	cin >> K;
	vector<ll> A(N);
	int t;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	vector<ll> v(N);
	v[0] = 0;
	v[1] = abs(A[0] - A[1]);

	for (int i = 2; i < N; ++i)
	{
		//v[i] = min(v[i - 1] + abs(A[i] - A[i - 1]), v[i - 2] + abs(A[i - 2] - A[i]));
		ll temp = INT_MAX;
		for (int j = 1; j <= K; ++j)
		{
			if ((i - j) >= 0)
			{
				temp = min(temp, v[i - j] + abs(A[i - j] - A[i]));
			}
		}

		v[i] = temp;
	}

	cout << v[N - 1] << endl;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
    long long n,t,a,b,i,x,y,tt=0,ca,cb,ok=0;
    cin>>n;
    x=y=0;
    for(i=1;i<=n;i++)
    {
        cin>>t>>a>>b;
        if(a>x)
            ca=a-x;
        else
            ca=x-a;
        if(b>y)
            cb=b-y;
        else
            cb=y-b;
        if(ca+cb>t-tt || (ca+cb)%2!=(t-tt)%2)
        {
            ok=1;
            break;
        }
        tt=t;
        x=a;
        y=b;
    }
    if(ok==1)
        cout<<"No";
    else
        cout<<"Yes";
}


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


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

	int s, w;
	cin >> s >> w;
	if (s <= w) cout << "unsafe\n";
	else cout << "safe\n";
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
int main()
{
	/*#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif*/
ios_base::sync_with_stdio(0);
cin.tie(0);


int a,b,c,k;
cin>>a>>b>>c>>k;
if(k<=a){
	cout<<k<<endl;
}
else if(k<=a+b){
	cout<<a<<endl;
}
else{
	cout<<a-(k-a-b)<<endl;
}



return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>

int main() {
    using namespace std;

    string S;
    cin >> S;

    int len = S.length() - 1;
    while (0 <len) {
        if (len % 2 == 0) {
            bool s = true;
            int half = len / 2;
            for (int i=0; i<half; i++) {
                if (S[i] != S[i+half]) {
                    s = false;
                    break;
                }
            }
            if (s) {
                cout << len << endl;
                return 0;
            }
        }

        len--;
    }

    cout << "not found" << endl;
}

Measured memory_bytes: 256
k = input()
D = int(input())
mod = 10 ** 9 + 7
keta = len(k)
dp = [[[0] * (2) for _ in range(D)] for _ in range(keta + 1)]
# dp[keta][D][smaler]
dp[0][0][0] = 1
for i in range(keta):
    num = int(k[i])
    for j in range(D):
        for smaller in range(2):
            for d in range(10):
                ni = i + 1
                nsmaller = smaller
                nj = (j + d) % D
                if smaller == 0:
                    if d < num:
                        nsmaller = 1
                    if d > num:
                        continue
                dp[ni][nj][nsmaller] += dp[i][j][smaller]
                dp[ni][nj][nsmaller] %= mod
print((dp[keta][0][1] + dp[keta][0][0] - 1)%mod)


Measured memory_bytes: 157420
//(クロ)# = 35, (シロ). = 46

import java.util.Scanner;

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

	char[][] X = new char[100][100];

	//左半分シロ
	for(int i = 0; i < 100; i++){
	    for(int j = 0; j < 50; j++){
		X[i][j] = '.';
	    }
	}
	//右半分クロ
	for(int i = 0; i < 100; i++){
	    for(int j = 50; j < 100; j++){
		X[i][j] = '#';
	    }
	}

	int A = scan.nextInt();
	int B = scan.nextInt();
	
	for(int i = 1; i < 100; i+=2){
	    for(int j = 51; j < 100; j+=2){
		if(A > 1){
		    X[i][j] = '.';
		    A--;
		}else{
		    break;
		}
	    }
	    if(A > 1){
	    }else{
		break;
	    }
	}

	for(int i = 1; i < 100; i+=2){
	    for(int j = 1; j < 49; j+=2){
		if(B > 1){
		    X[i][j] = '#';
		    B--;
		}else{
		    break;
		}
	    }
	    if(B > 1){
	    }else{
		break;
	    }
	}
	System.out.println(100 + " " + 100);
	for(int i = 0; i < 100; i++){
	    for(int j = 0; j < 100; j++){
		System.out.print(X[i][j]);
	    }
	    System.out.println();
	}
    }
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    while(1) {
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        int res = 0;
        for (int a = 1; a <= n; ++a) {
            for (int b = a + 1; b <= n; ++b) {
                for (int c = b + 1; c <= n; ++c) {
                    if (a + b + c == x) ++res;
                }
            } 
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
use std::io::{self, BufRead};

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let (n, m) = (xs[0], xs[1]);
  let mut ss: Vec<Vec<usize>> = Vec::new();
  for _ in 0..m {
    let mut xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse::<usize>().unwrap() - 1).collect();
    xs.remove(0);
    ss.push(xs);
  }
  let ps: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let count: usize = (2 as usize).pow(n as u32);
  let mut ans = 0;
  for i in 0..count {
    let mut ok = true;
    for j in 0..m {
      let parity = ss[j].iter().filter(|s| ((1 as usize) << **s) & i != 0).count() % 2;
      if parity != ps[j] {
        ok = false;
        break;
      }
    }
    if ok {
      ans += 1;
    }
  }
  println!("{}", ans);
}

Measured memory_bytes: 4352
import java.util.*;

public class Main{
	public static void main(String[] args){
		List<Integer> list = new ArrayList<Integer>();
		Scanner scan = new Scanner(System.in);

		// input
		for(int i=0; i<10; i++){
			list.add(scan.nextInt());
		}
		// sort
		Collections.sort(list);
		Collections.reverse(list);

		// output
		for(int i=0; i<3; i++){
			System.out.println(list.get(i));
		}

	}
}

Measured memory_bytes: 17176
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,x;cin>>a>>b>>c>>x;
  int sum=0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(500*i+100*j+50*k==x)sum++;
      }
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <memory.h>

using namespace std;

double p[10000];
double dp[10000][10000];
int vis [10000][10000] ; 
int n  ; 

double solve (int idx , int sum )
{
	if (idx ==  n )
	{
		if (sum >= n/2.0)
		return 1.0;
		return 0 ;
	}
	
	if(vis[idx][sum]!=-1)return dp[idx][sum] ;
	double help = 1.0*p[idx]*solve(idx+1 , sum+1 ) + 1.0 * (1-p[idx]) * solve (idx+1, sum) ; 
	vis[idx][sum]=1 ;
	return dp[idx][sum] = help ;
}
int main() {
	memset (vis , -1 , sizeof vis) ; 
	cin >> n ; 
	for (int i=0 ;i<n ; i++)
	cin >> p[i]; 

	double ans = solve (0,0); 	
	printf("%0.9lf",ans) ; 
	return 0;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}
int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}


void solve(int N, vi& a) {
    a.insert(a.begin(), 0);
    a.push_back(0);

    vector<int> d(N+1);
    rep(i, N+1) d[i] = abs(a[i+1] - a[i]);

    vector<ll> dacc(N+2, 0);
    rep(i, N+1){
        dacc[i+1] = dacc[i] + d[i];
    }
#ifdef DEBUG
    cerr << dacc << endl;
#endif

    ll total = dacc.back();

    rep1(i, N) {
        ll d_old = d[i] + d[i-1];
        ll d_new = abs(a[i+1] - a[i-1]);
        cout << (total - d_old + d_new) << endl;
    }
}

int main() {
    vector<int> a;
    int N = loadvec(a);
    solve(N, a);
    return 0;
}


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

int absolute_diff(int x, int y) {
	return ( x < y ) ? y-x : x-y ;
}

int main(){
    int N;
    cin >> N ;
    
    int* spot_coordi = new int[N+2];
    spot_coordi[0] = 0;
	for(int index = 1; index <= N; index++) {
		cin >> spot_coordi[index] ;
	}
	spot_coordi[N+1] = 0;

	int grand_sum, now_coordi;
	grand_sum = 0;
	now_coordi = 0;
	for(int travel = 1; travel <=N; travel++) {
		grand_sum += absolute_diff(spot_coordi[travel] , now_coordi) ;
		now_coordi = spot_coordi[travel] ;
	}
	grand_sum += ( 0 < now_coordi ? now_coordi : -1 * now_coordi );
	
	int sum, skip;
	for(int pattern = 1; pattern <= N; pattern++) {
		skip = absolute_diff( spot_coordi[pattern-1], spot_coordi[pattern] ) 
				+ absolute_diff( spot_coordi[pattern], spot_coordi[pattern+1] ) 
				- absolute_diff( spot_coordi[pattern-1], spot_coordi[pattern+1] ) ;
		cout << grand_sum - skip << endl;
	}
	
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;
// using ld       = long double;

double fastPow(double a, lint n) {
    double res = 1;
    while (n > 0) {
        if (n & 1)
            res *= a;
        a *= a;
        n >>= 1;
    }
    return res;
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, m, d;
    cin >> n >> m >> d;
    double ret = 0;
    if (d == 0)
        ret = n;
    else {
        ret = max(0LL, n - d) * 2;
    }
    ret *= m - 1;
    ret /= double(n * n);
    cout << fixed << setprecision(10) << ret << "\n";
    return 0;
}

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

void dfs(int x, int y, vector<vector<int>> &nl, vector<int> &ct) {
  for(int i = 0; i < nl.at(x).size(); i++) {
    //隣接リストの要素が親(y)の場合は飛ばす
    if(nl.at(x).at(i) == y) {
      continue;
    }
    else {
      //それぞれの要素に自分のカウンター数（ct.at(x)を配る
      ct.at(nl.at(x).at(i)) += ct.at(x);
      //新たな要素についてDFS　親は現在のノード(x)
      dfs(nl.at(x).at(i), x, nl, ct);
    }
  }
}

int main() {
  int N, Q;
  cin >> N >> Q;
  vector<vector<int>> nl(N);
  
  //隣接リスト入力
  
  for(int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    nl.at(a - 1).push_back(b - 1);
    nl.at(b - 1).push_back(a - 1);
  }
  
  //カウンター加算
  
  vector<int> ct(N);
  for(int i = 0; i < Q; i++) {
    int p, x;
    cin >> p >> x;
    ct.at(p - 1) += x;
  }
  
  //ノード　0 親　-1　からDFS
  
  dfs(0, -1, nl, ct);
  
  for(int i = 0; i < N-1; i++) {
    cout << ct.at(i) << " ";
  }
  cout<<ct.at(N-1)<<endl;
}



Measured memory_bytes: 29696
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
count=0
b=4*m
num=sum(a)/b
for i in range(m):
    if a[i]>=num:
        count+=1
        
if count==m:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	var A, B int
	fmt.Scan(&A, &B)

	ans := exec(A, B)
	fmt.Println(ans)
}

func exec(A, B int) int {
	// 現在の差し込み口の数
	now := 1
	// Aプラグの数
	count := 0

	for {
		if B <= now {
			return count
		}

		count++
		now = now - 1 + A
	}

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
  string str;
  cin >> str;
  int Q;
  cin >> Q;
  int T;
  int F;
  string C;
  int R = 1;
  rep(i, Q) {
    cin >> T;
    if (T == 1) {
      R *= -1;
    }
    else {
      cin >> F >> C;
      if (F == 1 and R == 1) {
        str.insert(0, C);
      }
      else if (F == 1 and R == -1) {
        str.append(C);
      }
      else if (F == 2 and R == 1) {
        str.append(C);
      }
      else {
        str.insert(0, C);
      }
    }
  }
  if (R == -1)
    reverse(str.begin(), str.end());
  cout << str << endl;
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
using vertex = struct vertex {ll to,cost;vertex(ll to,ll cost):to(to),cost(cost){}};
using AdjList = vector<vector<vertex>>;
using edge = struct edge{ll from,to,cost;edge(ll from,ll to,ll cost):from(from),to(to),cost(cost){}};
using Edges = vector<edge>;

vector<ll> Dijkstra(AdjList&adj,ll N,ll S){
  vector<ll> dist(N,(1LL<<60));
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>> ,greater<>> que;
  dist[S]=0LL;
  que.emplace(dist[S],S);
  while(!que.empty()){
    ll cost,from;
    tie(cost,from) = que.top();
    que.pop();
    if(dist[from]<cost)continue;
    for(const auto& v:adj[from]){
      if( chmin(dist[v.to],dist[from]+v.cost) )
        que.emplace(dist[v.to],v.to);
    }
  }
  return dist;
}

main(){

  ll n,m,s,t;
  cin>>n>>m>>s>>t;
  s--;t--;
  AdjList x(n),y(n);
  rep(i,m){
    ll u,v,a,b;
    cin>>u>>v>>a>>b;
    u--;v--;
    x[u].emplace_back(v,a);
    x[v].emplace_back(u,a);
    y[u].emplace_back(v,b);
    y[v].emplace_back(u,b);
  }
  auto cs = Dijkstra(x,n,s);
  auto ct = Dijkstra(y,n,t);

  vector<ll> cost(n);
  cost[n-1]=cs[n-1]+ct[n-1];
  for(ll i=n-2;i>=0;--i){
    cost[i]=min(cost[i+1],cs[i]+ct[i]);
  }
  for(auto& ans:cost){
    cout<<(ll)(1e15-ans)<<endl;
  }

}

Measured memory_bytes: 19012
L, R = map(int, input().split())
mod = 2019
ij_mod_min = 2019  # 解答の初期値を2019に設定
for i in range(L, R):  # 二重のforで全探索
    for j in range(i+1, R+1):
        ij_mod = (i*j) % mod
        if ij_mod_min > ij_mod:
            ij_mod_min = ij_mod
        if ij_mod_min == 0:  # もし解が0になったら探索をやめる
            break
    else:
        continue
    break
print(ij_mod_min)


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

int main(){
  int n;
  cin>>n;
  
  int a[100];
  for(int i=0;i<n;i++) cin>>a[i];

  for(int i=0;i<n-1-i;i++) swap(a[i], a[n-1-i]);

  for(int i=0;i<n;i++) {
    if(i != 0) cout<<" ";
    cout<<a[i];
  }

  cout<<endl;
  return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
    int H1, M1, H2, M2, K, ans;
    cin >> H1 >> M1 >> H2 >> M2 >> K ;
    
    if (M2 > M1){
    cout << 60*(H2-H1)+(M2-M1) -K << endl;
    }
      else{
        cout << 60*(H2-H1) - (M1-M2) -K << endl;
      }
    
    }

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
        int i,a,b;
string s;
cin >> a >>b;
cin >> s;
for(i=0;i<a;i++){
if(!(s[i]>='0' && s[i]<='9'))
{
cout << "No" << endl;
return 0;
}
}
if(s[i] != '-'){
cout << "No" << endl;
return 0;
}
b = b+i+1;
for(i=i+1;i<b;i++){
if(!(s[i]>='0' && s[i]<='9'))
{
 cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int k, n;
    cin >> k >> n;

    V res;

    if (k % 2 == 0)
    {
        res.push_back(k / 2);

        REP(i, n - 1)
        res.push_back(k);
    }
    else
    {
        int d = n / 2;

        REP(i, n)
        res.push_back((k + 1) / 2);

        REP(i, d)
        {
            if (res[res.size() - 1] == 1)
                res.pop_back();
            else
            {
                res[res.size() - 1]--;
                while (res.size() < n)
                    res.push_back(k);
            }
        }
    }

    for (int i = 0; i < res.size(); i++)
        cout << res[i] << (i == res.size() - 1 ? "\n" : " ");

    return 0;
}

Measured memory_bytes: 3568
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N;
	cin >> N;
	int kotae = 0;
	rep1(i, N) {
		int a;
		cin >> a;

		if (i % 2 && a % 2) kotae++;
	}
	co(kotae);



	Would you please return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

int N, T;
int A[112345];
int min, tmp = 0, ans = 0;

int main(void) {
	scanf("%d%d", &N, &T);
	for (int i = 0; i < N; ++i) { scanf("%d", &A[i]); }

	for (int j = 0; j < N; ++j) {
		if (j == 0) { min = A[j]; }
		if (min > A[j]) { min = A[j]; }
		else {
			if (tmp < A[j] - min) {
				ans = 1;
				tmp = A[j] - min;
			}
			else if (tmp == A[j] - min) {
				ans++;
			}
		}
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
package main

import(
    "fmt"
    _"bufio"
    _"os"
    "math"
    _"strconv"
    _"strings"
)

func main() {
    
    var a float64
    
    fmt.Scan(&a)
    fmt.Println(a + math.Pow(a,2) + math.Pow(a,3))
}

Measured memory_bytes: 1836
#include <iostream>
#include <algorithm>

using namespace std;
 
const int INF = 1e8;
 
int main() {
    int n, m;
    int c[21];
 
    cin >> n >> m;
 
    for (int i = 0; i < m; i++) {
        cin >> c[i];
    }
 
    int dp[50005];
    // dpテーブルの初期化
    for (int i = 0; i < 50005; i++) {
        if (!i) { dp[i] = 0; }
        else { dp[i] = INF; }
    }
 
    for (int i = 0; i <= 50000; i++) {
        for (int j = 0; j < m; j++) {
            if ( i + c[j] > 50000 ) { continue; }
            dp[i+c[j]] = min(dp[i] + 1, dp[i+c[j]]);
        }
    }
    cout << dp[n] << endl;
 
    return 0;
}


Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  string s;
  cin>>s;
  int a[26];
  rep(i,26) a[i]=0;
  rep(i,s.size()){
    if(a[s[i]-97]){cout<<"no"<<endl;return 0;}
    a[s[i]-97]=1;
  }
  cout<<"yes"<<endl;

  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<pair<string,int>> S(n);
    vector<pair<string,int>> s(n);
    for(int i = 0;i < n;i++){
        cin >> S[i].first >> S[i].second;
        S[i].second = 100 - S[i].second;
        s[i].first = S[i].first;
        s[i].second = S[i].second;
    }
    sort(S.begin(),S.end());
    for(int i = 0;i < n;i++){
        int ans = 0;
        for(int j = 0;j < n;j++){
            if(S[i].first == s[j].first && S[i].second == s[j].second)ans = j+1;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0index
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1index
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //aからb - 1まで
#define mREP(i,a,b) for (int i = a; i > (b); --i)  //逆
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;  //最大値兼MOD
typedef long long ll;
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }  //GCD

bool is_prime(long long n) {  //素数判定
  for(int64_t i = 2; i * i <= n; i++) {
    if(n % i == 0) return false;
  }
  return true;
}

int main(){
  int n;
  cin >> n;
  vector<ll>v(n);
  rep0(i,n)cin >> v[i];
  ll ans = v[0];
  rep0(j,n){
    ans = gcd(ans,v[j]);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int suji=0;
		int res=0;
		while(sc.hasNext()) {
			suji=sc.nextInt();
			res=(suji*suji+suji+2)/2;
			System.out.println(res);
		}
	}
}


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

using pqp = priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>>;
using pqt = priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<>>;

int main()
{
  int n, m;
  cin >> n >> m;

  pqt ans;
  vector<pqp> py(n);

  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    py[p - 1].emplace(y, i);
  }

  for (int p = 0; p < n; p++) {
    int num = 0;
    while (!py[p].empty()) {
      auto a = py[p].top(); py[p].pop();
      ans.emplace(a.second, p + 1, ++num);
    }
  }

  while (!ans.empty()) {
    auto t = ans.top(); ans.pop();
    cout << setfill('0') << setw(6) << get<1>(t)
         << setfill('0') << setw(6) << get<2>(t) << endl;
  }
}


Measured memory_bytes: 9076
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define     FAST        ios_base::sync_with_stdio(false);cin.tie(NULL)
#define     int 	    long long
#define 	pb 	        push_back
#define 	mp 	        make_pair
#define 	pi 	        2*acos(0.0)
#define     scan(i)     scanf("%lld",&i)
#define     scann(i,j)  scanf("%lld%lld",&i,&j)
#define     print(i)    printf("%lld\n",i)
#define     printt(i,j) printf("%lld %lld\n",i,j)
#define     loop(i,n) 	for(int i = 0 ; i <n ; i++)
#define     loopp(i,n) 	for(int i = 1 ; i <=n ; i++)
#define 	vect 	    vector<int>
#define 	vec_it 	    vector<int>::reverse_iterator vi
#define     sorta(v)    sort(v.begin(),v.end())
#define     sortd(v)    sort(v.begin(),v.end(),greater<>())
#define     sorted      is_sorted(v.begin(),v.end())
#define 	mapp 	    map<char,int>
#define 	pairr 	    pair<int,int>
#define 	sett	    set<int>
#define 	set_it 	    set<int>::reverse_iterator si
#define     map_it      map<char,int> :: reverse_iterator mi
#define 	yes 	    cout<<"Yes"<<endl
#define 	no 	        cout<<"No"<<endl
#define 	ff 	        first
#define 	ss 	        second
#define     mx          INT_MAX
#define     lmx         LLONG_MAX
#define     mn          INT_MIN
#define     lmn         LLONG_MIN
#define     GCD         __gcd(a,b)
#define     LCM         (a/GCD)*b
template <typename T> T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
int modulo (int a, int b) { return a >= 0 ? a % b : ( b - abs ( a%b ) ) % b; }

void solve()
{
  //  freopen ("(input).txt" , "r",  stdin) ;
  //  string st,stt ;
  //  int low=0,high=0;
  //  int l=0,r;
    int n,k,t,x,y,z,d=0,temp=0,cnt=0,sum=0,f=0;
    cin>>n  ; vect v ,a ,b  ; sett s ; set_it ; mapp m,mm ;  map_it ; pairr p ;
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0&&i<10&&(n/i)<10)
            temp=1;
    }
    if(temp&1)
        yes;
    else
        no;

}

main()
{
    int t;
  //  cin>>t;
  //  while(t--)
        solve();
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

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

struct edge { int to; double cost; };

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

	int n, m, p, a, b;
	while (cin >> n >> m >> p >> a >> b, n) {
		a--; b--;
		vector<double> t(n);
		rep(i, n) cin >> t[i];
		vector<vector<edge>> G(m);
		rep(i, p) {
			int x, y;
			double z;
			cin >> x >> y >> z;
			x--; y--;
			G[x].emplace_back((edge){y, z});
			G[y].emplace_back((edge){x, z});
		}

		const double inf = 1e15;
		vector<vector<double>> d(m, vector<double>(1 << n, inf));
		d[a][0] = 0;
		queue<P> que;
	    que.push(P(a, 0));

	    while (!que.empty()) {
			int v, f;
			tie(v, f) = que.front(); que.pop();
	        for (auto e: G[v]) {
				int nv = e.to;
				double cost = e.cost;
				rep(i, n) {
					if (((f >> i) & 1) == 0) {
						int nf = f | (1 << i);
						if (d[nv][nf] > d[v][f] + cost / t[i]) {
							d[nv][nf] = d[v][f] + cost / t[i];
							que.push(P(nv, nf));
						}
					}
				}
	        }
	    }

		double ans = *min_element(all(d[b]));
		if (ans == inf) {
			printf("Impossible\n");
		} else {
			printf("%.3f\n", ans);
		}
	}
}

Measured memory_bytes: 3428