akhauriyash/Code-Regression huggingface dataset:
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : a : b : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    a' = min a b
    b' = max a b
    d = b' - a'
    (q, r) = d `divMod` 2
  print $ if r == 0 then q else if a' - 1 <= n - b' then a' + (d `div` 2) else (n - b' + 1) + (d `div` 2)

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main ()
{
	long long a,b,c;
	cin>>a>>b;
	c=b-a+1;
	if(a<b)
	{
			if(a>0&&b>0)
	{
		cout<<"Positive"<<endl;
	}
	else if(a<=0&&b>0)
	{
		cout<<"Zero"<<endl;
	}
	else if(a<0&&b<=0)
	{
		if(b==0)
		{
			cout<<"Zero"<<endl;
		}
		else
		{
			if(c%2==0)
			{
				cout<<"Positive"<<endl;
			}
			else
			{
				cout<<"Negative"<<endl;
			}
		}
	}
	}
	else
	{
		return 0;
	}

	return 0;
} 

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

using namespace std;

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

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

    if (n < m) {
        cout << "NO" << endl;
        return 0;
    }
    sort(d.begin(), d.end());
    sort(t.begin(), t.end());

    int a = 0, b = 0;
    while (a < n || b <= m) {
        if (b == m) {
            cout << "YES" << endl;
            return 0;
        }

        if (d[a] == t[b]) {
            a++; b++;
        } else if (d[a] > t[b]) {
            cout << "NO" << endl;
            return 0;
        } else {
            a++;
        }
    }

    cout << "NO" << endl;

    return 0;
}


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

int main(){
    int N, K, S;
    cin >> N >> K >> S;
    vector<int> ans(N);
    
    for(int i=0; i<N; i++){
	if(i<K)
	    ans[i] = S;
	else
	    ans[i] = S!=1e9? 1e9: 1e9-1;
    }

    for(int i=0; i<N; i++){
	cout << ans[i] << " ";
    }
    cout << endl;
	
}



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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, t;
  cin >> n >> t;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(t + 1, vector<int>(2)));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < t; j++) {
      dp[i][j][1] = max(dp[i][j][1], dp[i][j][0]);
      dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][0] + b[i]);
      int eaten = j + a[i];
      if (eaten < t)
        dp[i + 1][eaten][1] = max(dp[i + 1][eaten][1], dp[i][j][1] + b[i]);
      if (eaten <= t)
        dp[i + 1][eaten][0] = max(dp[i + 1][eaten][0], dp[i][j][0] + b[i]);
      for (int k = 0; k < 2; k++) {
        dp[i + 1][j][k] = max(dp[i][j][k], dp[i + 1][j][k]);
        dp[i][j + 1][k] = max(dp[i][j][k], dp[i][j + 1][k]);
      }
    }
  }
  int ans = 0;
  for (auto& r : dp)
    for (auto& k : r)
      ans = max({k[0], k[1], ans});
  cout << ans << endl;
}


Measured memory_bytes: 493056
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n,a[1001],i,min=1001,max=0;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
		if(a[i]<min)
			min=a[i];
		
		if(a[i]>max)
			max=a[i];
	}
	cout << max-min << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a, b;
	cin>>a>>b;
	long int sum = a+b;
	long int diff = a-b;
	long int mul = a*b;
	long int ans = max(mul, max(sum, diff));
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
    }

    let result = match n % 10 {
        2 | 4 | 5 | 7 | 9 => "hon",
        0 | 1 | 6 | 8 => "pon",
        3 => "bon",
        _ => ""
    };
    println!("{}", result);
}


Measured memory_bytes: 2180
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1000000007;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, size_t second_itr) {
	std::string tmp;
	for (size_t i = first_itr; i < second_itr + 1; i++) {
		tmp.push_back(str.at(i));
	}
	return tmp;
}
ll max(ll a, ll b) {
	return a > b ? a : b;
}
ll min(ll a, ll b) {
	return a < b ? a : b;
}


int main() {
	int n; cin >> n;
	vector<ll> a(n+1), b(n);
	rep(i, n + 1) {
		cin >> a[i];
	}
	rep(i, n) {
		cin >> b[i];
	}
	ll ans = 0;
	rep(i, n) {
		ll tmp = 0;
		if (a[i] < b[i]) {
			tmp += a[i];
			ll diff = b[i] - a[i];
			if (a[i + 1] < diff) {
				tmp += a[i+1];
				a[i + 1] = 0;
			}
			else {
				tmp += diff;
				a[i + 1] -= diff;
			}
		}
		else {
			tmp += b[i];
		}
		ans += tmp;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1920
# include <iostream>
# include <vector>


using namespace std;


int main() {
    int n; cin >> n;
    vector<pair<int, int>> a(n);

    int ai;
    for (int i=0; i<n; i++) {
        cin >> ai;
        a[i] = make_pair(ai, i);
    }

    sort(a.begin(), a.end());
    for (auto e: a) cout << e.second+1 << ' '; cout << endl;

    return 0;
}



Measured memory_bytes: 1664
#include<stdio.h>
#include<string>

typedef struct fox{ int val; fox *left, *right; } fox_n;

fox_n* init()
{
    fox_n* root = new fox_n;
    root->val = -1;
    root->left = NULL;
    root->right = NULL;
    return root;
}

void insert(fox_n* root, int key)
{
    static bool first = true;
    static bool add_leaf = true;  // true:left, false:right.
    if(first){ first = false; root->val = key; return; }  // initialize.
    fox_n* canis;
    fox_n* water = root;  // water from root to leaf.
    do{
        canis = water;
        if(key < canis->val){  // canis chases water.
            water = canis->left;
            add_leaf = true;
        }else{
            water = canis->right;
            add_leaf = false;
        }
    }while(water != NULL);

    fox_n* leaf = new fox_n;  // add new leaf.
    leaf->val = key;
    leaf->left = NULL;
    leaf->right = NULL;
    if(add_leaf){ canis->left = leaf; }else{ canis->right = leaf; }
    return;
}

void inorder(fox_n* root)
{
    if(!root) return;
    inorder(root->left);
    printf(" %d", root->val);
    inorder(root->right);
    return;
}

void preorder(fox_n* root)
{
    if(!root) return;
    printf(" %d", root->val);
    preorder(root->left);
    preorder(root->right);
    return;
}

int main()
{
    fox_n* root = init();
    int i, n, key; char cmd[6];
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%s", cmd);
        if(cmd[0] == 'i'){ scanf("%d", &key); insert(root, key); }
        else{ inorder(root); printf("\n"); preorder(root); printf("\n"); }
    }
    return 0;
}

Measured memory_bytes: 16656
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=2e5+10;
int n;
char s[MAXN];
int md[2020];
void solve()
{
    scanf("%s",s);
    n=strlen(s);
    ll ans=0;
    int m=0,b=1;
    md[0]++;
    for(int u=n-1;u>=0;u--){
        m=(m+(s[u]-'0')*b)%2019;
        b=(b*10)%2019;
        ans+=md[m];
        md[m]++;
    }
    cout<<ans;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int N, C, K;
  cin >> N >> C >> K;
  vector<int> T(N);
  for (int i = 0; i < N; i++)
  {
    cin >> T.at(i);
  }
  
  sort(T.begin(), T.end());
  
  int ans = 0;
  for (int i = 0; i < N; )
  {
    int t = T.at(i) + K;
    for (int j = 0; j < C; j++)
    {
      i++;
      if (i >= N) break;
      if (T.at(i) > t) break; 
    }
    
    ans++;
    //cerr << i << endl;
  }

  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=0;i<=(n);i++)

int main(){
	int n, k, x, y, ans=0;
	cin >> n >> k >> x >> y;
	
	rep(i, n){
		if(i < k){
			ans += x;
		}else{
			ans += y;
		}
	}
	
	cout << ans << endl;

	return 0;
}


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

class BIT {
public:
	int size_ = 1;
	vector<int> bit;

	void init(int sz) {
		size_ = sz + 2;
		bit.resize(size_ + 2, 0);
	}
	void add(int pos, int x) {
		pos++;
		while (pos <= size_) {
			bit[pos] += x;
			pos += (pos & -pos);
		}
	}
	int sum(int pos) {
		int s = 0; pos++;
		while (pos >= 1) {
			s += bit[pos];
			pos -= (pos & -pos);
		}
		return s;
	}
};

int N; char c[1 << 19];
int Q, T[1 << 19], A[1 << 19], B[1 << 19]; char C[1 << 19];

BIT V[27];

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> c[i];
	cin >> Q;
	for (int i = 1; i <= Q; i++) {
		cin >> T[i];
		if (T[i] == 1) cin >> A[i] >> C[i];
		if (T[i] == 2) cin >> A[i] >> B[i];
	}
	for (int i = 0; i < 26; i++) V[i].init(N + 2);
	for (int i = 1; i <= N; i++) V[c[i] - 'a'].add(i, 1);

	for (int i = 1; i <= Q; i++) {
		if (T[i] == 1) {
			V[c[A[i]] - 'a'].add(A[i], -1);
			c[A[i]] = C[i];
			V[c[A[i]] - 'a'].add(A[i], 1);
		}
		if (T[i] == 2) {
			int cnt = 0;
			for (int j = 0; j < 26; j++) {
				if (V[j].sum(B[i]) - V[j].sum(A[i] - 1) != 0) cnt++;
			}
			cout << cnt << endl;
		}
	}
	return 0;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
const int inf = 100100100100100009;
const int mod = 1000000007;


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

    int n, ma, mb; cin >> n >> ma >> mb;

    vector<vector<int> > arrf;
    vector<vector<int> > arrs;
    rep(i,0,n/2){
        int a, b, cost;
        cin >> a >> b >> cost;
        vector<int> tmp = {a, b, cost};
        arrf.push_back(tmp); 
    }

    rep(i,n/2,n){
        int a, b, cost;
        cin >> a >> b >> cost;
        vector<int> tmp = {a, b, cost};
        arrs.push_back(tmp); 
    }

    vector< vector<int> > fir;
    rep(i,0,pow(2,arrf.size())){
        int asum = 0, bsum = 0, csum = 0;
        rep(j,0,arrf.size()){
            if(i & (1 << j)){
                asum += arrf[j][0]; bsum += arrf[j][1]; csum += arrf[j][2];
            }
        }
        vector<int> tmp = {asum, bsum, csum}; fir.push_back(tmp);
    }

    map<pair<int, int> , int> mp;
    rep(i,0,pow(2,arrs.size())){
        int asum = 0, bsum = 0, csum = 0;
        rep(j,0,arrs.size()){
            if(i & (1 << j)){
                asum += arrs[j][0]; bsum += arrs[j][1]; csum += arrs[j][2];
            }
        }
        pair<int, int> key = make_pair(asum, bsum); 
        
        if(mp.find(key) == mp.end()){ //not found
            mp[key] = csum;
        }else{
            mp[key] = min(mp[key], csum);
        }
    }

    int ans = inf;
    rep(i,0, fir.size()){
        rep(j,1,15){
            pair<int, int> key = make_pair(ma * j - fir[i][0], mb * j - fir[i][1]);
            if(mp.find(key) == mp.end()){
                continue;
            }else{
                ans = min(ans, fir[i][2] + mp[key]);
            }
        }
    }

    if(ans == inf){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;






}

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

int main(){
  double n;
  cin >> n;
  double ans;
  int cnt = 0;
  for (int i = 1;i <= n;i++){
    if (i % 2 != 0) cnt++;
  }
  ans = cnt / n;
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int ans=0;
		while(cin.hasNext()){
			String str = cin.next();
			char[] s = (str+"       ").toCharArray();
			ans += secret(s);
		}
		System.out.println(ans);
	}
	static int secret(char[] s){
		int re = 0;
		for(int i = 0;i<s.length;i++){
			if(Character.isDigit(s[i])){
				String str = ""+s[i];
				for(int j =i+1;j<s.length;j++){
					if(Character.isDigit(s[j])){
						str = str + s[j];
					}
					else{
						i=j;
						break;
					}
				}
				re += Integer.parseInt(str);
			}
		}
		
		return re;
	}
}

Measured memory_bytes: 11000
#include <stdio.h>
#include <string.h>

//the, this, thatが含まれているかどうかを確認する
int checkSolve(char str[]){
	if(strstr(str, "the") != NULL ||
	   strstr(str, "this") != NULL ||
	   strstr(str, "that") != NULL){
			printf("%s",str);
			return 1;
	}
	return 0;
}

int main(){
	int i;
	char str[81];
	char str_init;

	//空白を含めて1行を80字まで読み込む
	while(fgets(str,80,stdin) != NULL){
		//正常に暗号化されていない文字検出用
		str_init = str[0];
		//the, this, thatが見つからない限り繰り返し
		while(checkSolve(str)==0){
			//アルファベット小文字のみ1字ずらす
			for(i=0; i < strlen(str); i++){
				if(str[i]>='a' && str[i]<='z'){
					//文字が"a"の場合は"z"にする（アルファベット一回転）
					str[i] = (str[i]=='a') ? 'z' : str[i] -1;
				}
			}
			//正常に暗号化されていない場合（繰り返して最初の文字列に戻ったことを検出した場合）
			if(str_init == str[0]){
				printf("error\n");
				break;
			}
		}
	}
	return 0;
};

Measured memory_bytes: 524
#include <iostream>
#include <vector>

using namespace std;

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

#define F first;
#define S second;
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i = a; i <= b; i++)
#define SQ(a) (a)*(a);

const int INF = 1e9 + 5;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n ,k;
    scanf("%d %d",&n,&k);
    vector<int> h(n);

    for(int&x : h){
        scanf("%d",&x);
    }

    vector<int> dp(n,INF);
    dp[0] = 0;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j <= i+k ; j++) {
            dp[j] = min(dp[j],dp[i] + abs(h[i] - h[j]));
        }
    }

    printf("%d",dp[n - 1]);

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int MAX_V = 10000;
int prime[10001];
int main() {
  int i, k, l;
  int m = 0;
  int n[10000] = {1};
  int p1[10000];
  int q1[10000];
  while (1) {
    scanf("%d", &n[m]);
    if (n[m] == 0) {
      break;
    }
    m++;
  }
  for (i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for (i = 2; i * i <= MAX_V; i++) {
    if (prime[i]) {
      for (k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  for (l = 0; l < m; l++) {
    while (1) {
      if (prime[n[l]] == 1 && prime[n[l] - 2] == 1) {
        p1[l] = n[l] - 2;
        q1[l] = n[l];
        printf("%d %d\n", p1[l], q1[l]);
        break;
	  }
      n[l]--;
    }
  }
  return 0;
}

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

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

 int main() {
   int n, k;
   cin >> n >> k;
   int h[n];
   rep(i, n) cin >> h[i];

   int dp[n];

   dp[0] = 0;

   for (int i = 1; i < n; i++) {
       int l = max(i-k, 0);
       dp[i] = dp[l] + abs(h[i] - h[l]);
       for (int j = l + 1; j < i; j++) {
           dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
       }
   }

   cout << dp[n-1] << endl;

   return 0;
     
 }


Measured memory_bytes: 3912
using System;
class Program
{
	static void Main()
	{
	string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
	int n = int.Parse(input[0]);
	int k = int.Parse(input[1]);
	int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
    int[] howmany = new int[200001];//各数字はいくつか
    int answer = 0;
      
      for(int i = 0; i < nums.Length; i++)
      {
        howmany[nums[i]]++;//数える
      }
      
      Array.Sort(howmany);
      
      for(int i = 200000 - k; i >= 0; i--)
      {
        answer += howmany[i];
      }

	Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
}

Measured memory_bytes: 35420
# ABC151 C

N, M = map(int, input().split())

AC = [0] * N
WA = [0] * N
WA_count = 0

for i in range(M):
    p, S = input().split()
    p = int(p) - 1
    
    if S == "WA" and AC[p] == 0:
        WA[p] += 1
    elif S == "AC" and AC[p] == 0:
        AC[p] += 1
        WA_count += WA[p]
    else:
        continue

print(sum(AC), WA_count)

Measured memory_bytes: 4596
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
V<string> s;
int h,w;
V<int> dx={-1,0,1,0},dy={0,-1,0,1};
int main(){
  cin>>h>>w;  
  s.resize(h);
  for(int i=0;i<h;i++)cin>>s[i];
  int ans=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
        if(s[i][j]=='#')continue;
        for(int k=0;k<h;k++){
            for(int d=0;d<w;d++){
                if(s[k][d]=='#')continue;
                if(i==k&&j==d)continue;
                queue<P> q;
                q.push(P(i,j));
                V<V<int>> used(h,V<int>(w,0));
                while(!q.empty()){
                    P now=q.front();
                    q.pop();
                    for(int r=0;r<4;r++){
                        int nx=now.fi+dx[r],ny=now.se+dy[r];
                        if(nx<0||nx>=h||ny<0||ny>=w)continue;
                        if(s[nx][ny]=='#')continue;
                        if(used[nx][ny])continue;
                        used[nx][ny]+=used[now.fi][now.se]+1;
                        q.push(P(nx,ny));
                    }
                }
                chmax(ans,used[k][d]);
            }
        }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a, b, c, i, temp = 0;
	scanf("%d %d %d", &a, &b, &c);
	for(i = a; i<=b; i++){
		if(c%i==0){
			temp++;
			//printf("%d %d %d\n", c, i, temp);
		}
	}
	printf("%d\n", temp);
	return 0;
}



Measured memory_bytes: 2112
from collections import defaultdict

N, M = map(int, input().split())
E = defaultdict(list)
for _ in range(M):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)
for i in range(1, N+1):
    if 1 in E[i] and N in E[i]:
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 54024
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
      int n , m;
      cin >> n >> m;
      int lmax , rmin , l , r;
      cin >> lmax >> rmin;
      for(int i = 1 ; i < m ; i++){
          cin >> l >> r;
          lmax = max(lmax , l);
          rmin = min(rmin , r);
      }
      if(lmax > rmin){
          cout << 0 << endl;
      }else{
         cout << (rmin - lmax + 1)  << endl;
      }
      
      return 0;
    }

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

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

		int a[] = new int[5];

		for (int i = 0; i < 5; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}
		int k = Integer.parseInt(br.readLine());

		if (a[4] - a[0] > k) {
			System.out.println(":(");
			return;
		}

		System.out.println("Yay!");
	}
}


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

using namespace std;

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

    int net[N];

    for(int i = 0; i < N; i++)
    {
        cin >> net[i];
    }
    
    int input;
    for (int i = 0; i < N; i++)
    {
        cin >> input;
        net[i] -= input;
    }

    int max = 0;
    for (int i = 0; i < N; i++)
    {
        if (net[i] > 0)
        {
            max += net[i];
        }
    }

    cout << max;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <cstring>
#include <iomanip>
using namespace std;
typedef long long ll;



int main() {
    string S; cin >> S;
    int K; cin >> K;
    
    vector<string> V;
    
    for(int i=1; i<=min(K, (int)S.size()); i++){
        for(int j=0; j<S.size()-i+1; j++){
            string t = "";
            for(int p=j; p<j+i; p++) t += S[p];
            V.push_back(t);
        }
    }
    
    sort(V.begin(), V.end());
    unique(V.begin(), V.end());
    cout << V[K-1] << endl;
    
    return 0;
}


Measured memory_bytes: 1660
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

typedef long long LL;
const int MaxN = 2e5;
using namespace std;


int a[MaxN + 5];

int main() 
{
	int n; while(~scanf("%d", &n)) {
		for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
		bool ok = 1;
		for (int i = 2; i <= n; i++) if(a[i] > a[i - 1] + 1) ok = 0;
		if(a[1] || !ok) printf("-1\n");
		else {
			LL res = 0;
			for (int i = 2; i <= n; i++) {
				if(a[i - 1] < a[i]) res++;
				else res += a[i];
			}
			printf("%lld\n", res);
		}
	}
	return 0;
}


Measured memory_bytes: 896
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define P pair<ll,ll>
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int n; cin >> n;
	string s,t; cin >> s >> t;
	rep(i,n){
		cout << s[i] << t[i];
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        if(s[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<set>
#include<vector>
#include<map>
#include<queue>

#define N 300005
#define M 8000005

#define ls (t<<1)
#define rs ((t<<1)|1)
#define mid ((l+r)>>1)

#define mk make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

int i,j,m,n,p,k,a[N],ans[N];

struct Tre{
	int Min[N*4],pos[N*4],x;
	void build_tree(int l,int r,int t)
	{
		//	fprintf(stderr,"%d\n",t);
			if (l==r)
			{
					if ((l&1)==x) Min[t]=a[l]; else Min[t]=(int)1e9; 
					if ((l&1)==x) pos[t]=l; else pos[t]=n+1;
			}
			else 
			{
					build_tree(l,mid,ls); build_tree(mid+1,r,rs);
					if (Min[ls]<Min[rs]) Min[t]=Min[ls],pos[t]=pos[ls];
					else Min[t]=Min[rs],pos[t]=pos[rs];
			}
	}
	int ask(int ll,int rr,int l,int r,int t)
	{
			if (ll<=l&&r<=rr) return pos[t];
			else 
			{
					int now=n+1;
					if (ll<=mid)
					{
							int p=ask(ll,rr,l,mid,ls);
							if (a[now]>a[p]) now=p;
					}
					if (rr>mid)
					{
							int p=ask(ll,rr,mid+1,r,rs);
							if (a[now]>a[p]) now=p;
					}
					return now;
			}
	}
}t[2];

int Cas=0;

struct Node{
		int l,r,ansx,ansy;
		void work()
		{
				ansx=t[l&1].ask(l,r,1,n,1);
				ansy=t[(l&1)^1].ask(ansx+1,r,1,n,1);
		}
};

inline bool operator <(Node A,Node B)
{
		return a[A.ansx]<a[B.ansx];
}

int main()
{
		scanf("%d",&n);
		for (i=1;i<=n;++i) scanf("%d",&a[i]);
		t[0].x=0; t[1].x=1;
		t[0].build_tree(1,n,1);
		t[1].build_tree(1,n,1); 
		a[n+1]=n+1;
		Node x; x.l=1; x.r=n; x.work();
		set<Node>st; st.clear(); st.insert(x); int Cas=0;
		for (;st.size();)
		{
			   Node x=*st.begin(); st.erase(st.begin());
			   ans[++ans[0]]=a[x.ansx]; ans[++ans[0]]=a[x.ansy];
			   Node y;
			   if (x.l<=x.ansx-1)
			   {
			   		y.l=x.l; y.r=x.ansx-1; y.work();
			   		st.insert(y);
			   }
			   if (x.ansx+1<=x.ansy-1)
			   {
			   		y.l=x.ansx+1; y.r=x.ansy-1; y.work();
			   		st.insert(y);
			   }
			   if (x.ansy+1<=x.r)
			   {
			   		y.l=x.ansy+1; y.r=x.r; y.work();
			   		st.insert(y);
			   }
		}
		for (i=1;i<=n;++i) printf("%d ",ans[i]);
}


Measured memory_bytes: 22656
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#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++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
ll exp(ll x,ll y){
    if(y==0)return 1;
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    ll t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

int main(){
  ll x;cin >> x;
  //100*(101)^n
  ll money=100;
  rep(i,3760){
    money+=money/100;
    if(money>=x){cout << i+1<< endl;return 0;}
  }
}

Measured memory_bytes: 3636
fun main(args: Array<String>) {
    abc141c()
}

/*
    K - Q + 自身の正解数が0以下であれば敗退者
 */
fun abc141c() {
    val (n, k, q) = readLine()!!.split(" ").map { it.toInt() }
    val aList = (1..q).map { readLine()!!.toInt() - 1 }.toIntArray()

    val points = (1..n).map { i ->
        k - q
    }.toMutableList()

    aList.forEach { points[it]++ }

    val answer = points.map { if (it > 0) "Yes" else "No" }

    println(answer.joinToString(separator = System.lineSeparator()))
}


Measured memory_bytes: 45972
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	ll A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;

	ll mi = min(X, Y);
	ll ans = 0;
	if (A + B < 2 * C) {
		ans += (A * X + B * Y);
	}
	else {
		if (X < Y) {
			int ans1 = 2 * Y * C;
			int ans2 = 2 * C * X + B * (Y - X);
			ans = min(ans1, ans2);
		}
		else {
			int ans3 = 2 * C * X;
			int ans4 = 2 * C * Y + A * (X - Y);
			ans = min(ans3, ans4);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int, (input().split())))

distance = lambda Xi, P: (Xi - P) ** 2

X_max = max(X)

answer = 99999999999
for P in range(1, X_max + 1):
    total = 0
    for Xi in X:
        total += distance(Xi, P)
    answer = min(total, answer)

print(answer)


Measured memory_bytes: 3060
N=int(input())
Atamasiri = [[0 for i in range(10)] for j in range(10)]#Atamasiri[atama][siri]
cursaijou = 1
for n in range(1,N+1):
    if n>=cursaijou*10:
        cursaijou *= 10
    atama = n//cursaijou
    siri = n%10
    Atamasiri[atama][siri] += 1
ans = 0
for head in range(10):
    for ketsu in range(10):
        ans += Atamasiri[head][ketsu]*Atamasiri[ketsu][head]
print(ans)


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

int main() {
	int e;
	while(cin >> e && e > 0) {
		int x, y, z;
		int maxz, maxy;
		int min = 1000000;
		//maxz = int(pow(e, 1.0/3.0));
		//maxy = int(pow(e, 1.0/2.0));
		//cout << "maxz:" << maxz << endl;
		//cout << "maxy:" << maxy << endl;
		for(int z = 0; z*z*z <= e; z++) {
			for(int y = 0; y*y <= e; y++) {
				x = e - y*y - z*z*z;
				if(x >= 0 && x+y+z < min) min = x+y+z;
			}
		}
		cout << min << endl;
	}
}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n,k;
	cin >> n >> k;
	vector<ll> left;
	vector<ll> right;
	FOR(i,0,n){
		ll x;
		cin >> x;
		if(x < 0){
			left.pb(-x);
		}else if(x > 0){
			right.pb(x);
		}else{
			k--;
		}
	}
	reverse(ALL(left));
	ll ans = LLINF;
	if(k == 0)
		ans = 0;
	int a = max(0, k - (int)right.size());
	int b = min((int)left.size(), k);
	for(int i = a; i <= b; i++){	//i=左から取る個数
		ans = min(ans, ((i > 0)?left[i-1]:0) * 2 + ((k-i>0)?right[k-i-1]:0));
		ans = min(ans, ((i > 0)?left[i-1]:0) + ((k-i>0)?right[k-i-1]:0) * 2);
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 1656
// GOOD BUT SLIGHTLY CONFUSING

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;

ll qpow(ll x,ll n,int mod)
{
    ll sum=1;
    while(n){
        if(n&1) sum=sum*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return sum;
}
int ans(int x)
{
    if(x==0) return 0;
    int kk=__builtin_popcount(x);
    return 1+ans(x%kk);
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    string s;cin>>s;
    int one=0;
    for(int i=0;i<n;i++){
        if(s[i]=='1') one++;
    }
    int p1=0,p2=0;
    for(int i=0;i<n;i++){
        if(one!=1){
            p1=(p1*2+s[i]-'0')%(one-1);
        }
        p2=(p2*2+s[i]-'0')%(one+1);
    }
    for(int i=0;i<n;i++){
        if((s[i]=='1'&&one==1)){
            cout<<0<<endl;
        }
        else if(s[i]=='1'){
            cout<<1+ans((p1-qpow(2,n-i-1,one-1)+(one-1))%(one-1))<<endl;
        }
        else if(s[i]=='0'){
            cout<<1+ans((p2+qpow(2,n-i-1,one+1)+(one+1))%(one+1))<<endl;
        }
    }
    return 0;
}


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

//#define cin fin
//#define cout fout
#define ld long double 
#define pb push_back
#define F first
#define S second 
#define ll long long

using namespace std;

const int N = 2022 ; 

int dp[N][2] ; 

int a[N] , x , y , n ; 

bool check(int mid)
{
//	if(abs(y-a[n-1])>mid) return 1 ; 
	for(int i = n - 2 ; i > -1 ; i -- ) 
	{
		dp[i][0] = 0 ; 
		for(int j = i + 1 ; j < n - 1 ; j ++ ) 
			if(!dp[j][1])
				dp[i][1] = 1 ; 
		if(abs(a[i]-a[n-1])>mid) dp[i][0] = 1 ; 
		
		dp[i][1] = 0 ; 
		for(int j = i + 1 ; j < n - 1 ; j ++ ) 
			if(!dp[j][0])
				dp[i][1] = 1 ; 
		if(abs(a[i]-a[n-1])<=mid) dp[i][1] = 1 ; 
	}
	return dp[0][0] ;
}

int32_t main()
{
	ios::sync_with_stdio(0) ; cin.tie(0) ; 
	int n , x , y ;
	cin >> n >> x >> y ;
	a[0] = y ; 
	n ++ ; 
	for(int i = 1 ; i < n ; i ++ ) cin >> a[i] ; 
	
	for(int i = n - 2 ; i > -1 ; i -- ) 
	{
		dp[i][0] = 0 ; 
		for(int j = i + 1 ; j < n - 1 ; j ++ ) 
			dp[i][0] = max(dp[i][0],dp[j][1]) ; 
		dp[i][0] = max(dp[i][0],abs(a[i]-a[n-1])) ;
	
		dp[i][1] = 2e9 ; 
		for(int j = i + 1 ; j < n - 1 ; j ++ ) 
			dp[i][1] = min(dp[i][1],dp[j][0]) ; 		
		dp[i][1] = min(dp[i][1],abs(a[i]-a[n-1])) ; 
	}
	cout << dp[0][0] << endl ; 
	return 0 ; 
	int l = -1 , r = 1e9 ; 
	cout << check(0) << endl  ; 
	//return 0 ; 
	while(r-l>1)
	{
		int mid = (l+r) / 2 ; 
		if(check(mid))
			l = mid ; 
		else 
			r = mid ; 
		cout << l << ' ' << r << ' '<< mid << endl ; 
	
	}
	cout << r << endl ; 
}



Measured memory_bytes: 256
answer_set = []

while True:
    deck = input()
    if deck == "-":
        break
    m = int(input())
    h = []

    for i in range(m):
        h.append(int(input()))

    length_deck = len(deck)
    total_h = sum(h) % length_deck
    deck += deck

    answer_set.append(deck[total_h:total_h+length_deck])

for i in range(len(answer_set)):
  print(answer_set[i])



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

using namespace std;

const unsigned long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % MOD;
       base = base * base % MOD;
    }
    return tot;
}

int arr[12], bon[12];
long long dp[12][1001];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, a; cin >> n;

    // greedy, add to pile with highest number that is smaller?

    multiset<int> stacks;

    for(int i = 0; i < n; ++i){
        cin >> a;
        auto it = stacks.lower_bound(a);
        if(it != stacks.begin()){
            --it;
            stacks.erase(it);
        }
        stacks.insert(a);
    }

    cout << stacks.size() << "\n";

    return 0;

}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
using  P=pair<int,int>;
int main(){
  ll N,T;
  cin>>N>>T;
  vector<P> vec(0);
  for(ll i=0;i<N;i++){
    ll a,b;
    cin>>a>>b;
    vec.push_back(make_pair(a,b));//所要時間,価値
  }
  sort(vec.begin(),vec.end());
  //(1+(10^価値)*x^(所要時間))の累積の考えて指数について制限をかけて考える
  ll dp[3020][6020];
  ll maxvalue=0;
  for(ll h=0;h<N;h++){
    dp[h][0]=1;
    for(ll i=1;i<=T;i++){
      dp[h][i]=0;
    }
  }
  for(ll i=1;i<=N;i++){
    for(ll j=0;j<T;j++){
      if(dp[i-1][j]!=0){
        dp[i][j+vec.at(i-1).first]+=dp[i-1][j]+vec.at(i-1).second;
        dp[i][j+vec.at(i-1).first]=max(dp[i][j+vec.at(i-1).first],dp[i-1][j+vec.at(i-1).first]);
        if(j==0){dp[i][j+vec.at(i-1).first]--;}
        dp[i][j]=max(dp[i][j],dp[i-1][j]);
      }
    }
    for(ll j=0;j<=6010;j++){
      maxvalue=max(maxvalue,dp[i][j]);
    }
  }
  cout<<maxvalue<<endl;
}

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

using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 100;

int dp[N];

int mul(int a , int b){
  return a*1ll*b%mod;
}
int sub(int a , int b){
  a -= b;
  if(a < 0) a += mod;
  return a;
}
int add(int a , int b){
  a += b;
  if(a >= mod) a -= mod;
  return a;
}
int power(int x , int y){
  int res = 1;
  while(y){
    if(y&1)
      res = mul(res , x);
    x = mul(x , x);
    y >>= 1;
  }
  return res;
}

int main(){
  int n , k; cin >> k;
  n = 3;
  for(int i = k ;i >= 1 ; --i){
    int no = k/i; 
    dp[i] = power(no , n);
    for(int j = 2*i; j <= k ; j += i)
      dp[i] = sub(dp[i] , dp[j]);
  }
  int ans = 0;
  for(int i = 1;i <=k ; ++i)
    ans = add(ans , mul(i, dp[i]));
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  int b[105] = {};
  int a[105] = {};
  int ans = 0;

  cin >> n;
  for(int i=0; i<n-1; i++) cin >> b[i];

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

  for(int i=0; i<n; i++) ans += a[i];

  cout << ans << endl;

  return 0;
}


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

int main() {
  LL N, A, B;
  cin >> N >> A >> B;

  if (N < A + B - 1 || N > A * B) {
    cout << -1 << endl;
    return 0;
  }

  bool maked = false;
  for (int i = 1; i <= B; i++) {
    int remain = N - A * i;
    if (remain < 0) continue;
    int lengthA;
    vector<int> lengths;
    if (i < B) {
      lengthA = remain / (B - i);
      if (lengthA == 0) continue;
      if (remain > (B - i) * A) continue;
      for (int j = 0; j < B - i; j++) lengths.push_back(lengthA);
      for (int j = 0; j < remain % (B - i); j++) lengths[j]++;
      if (remain % (B - i) != 0) lengthA++;
    }
    if (i == B) {
      lengthA = 0;
    }
    vector<LL> output;
    LL offset = N - i * A;
    for (int j = 0; j < A; j++) {
      for (int k = 0; k < i; k++) {
        output.push_back(offset + j * i + i - k);
        //        cout << offset + j * i + i - k << endl;
      }
    }

    for (int j = 0; j < B - i; j++) {
      offset -= lengths[j];
      for (int k = 0; k < lengths[j]; k++) {
        int cand = offset + k + 1;
        if (cand <= 0) continue;
        // cout << cand << endl;
        output.push_back(cand);
      }
    }
    for (int i = 0; i < output.size(); i++) {
      cout << output[i];
      if (i == output.size() - 1)
        cout << endl;
      else
        cout << " ";
    }
    return 0;
  }

  if (!maked) {
    cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 6640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std; 
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define endl "\n"
#define F first
#define S second
//typedef 1000000007 mod

#define mp map<ll,ll>
#define vc vector<ll>
#define MAX  *max_element
#define MIN  *min_element
#define lcm(a,b) (a*b)/__gcd(a,b)
#define des_sort(v) sort(v.begin(),v.end(),greater<int>())
//max xor btw range of two numbers..

#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define c_ones(number) __builtin_popcountll(number)
#define flip_bits(number) static_cast<unsigned>(~number)

#define all(X) X.begin(),X.end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(itr,n) for(itr=n.begin();itr!=n.end();itr++)

#define FLUSH fflush(stdout)
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb_ds tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define mod 1000000007

bool compare(pair<int,int>a , pair<int,int>b){
	return a.first==b.first ? a.second<b.second : a.first < b.first;
}
ll n;
vector<ll> dp;
ll find_(ll n,vector<ll> &a){
	if(n==0)return 0;
	if(dp[n]!=-1)return dp[n];
	ll x = abs(a[n]-a[n-1]) + find_(n-1,a);
	ll y = abs(a[n]-a[n-2])+find_(n-2,a);
	return dp[n] = min(x,y);
}

int main(){ 
	cin>>n;
	dp.resize(n,-1);
	vector<ll> a(n);
	rep(i,n)cin>>a[i];
	cout<<find_(n-1,a)<<endl;;
}

Measured memory_bytes: 6528
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: isize = iterator.next().unwrap().parse().unwrap();
    let k: isize = iterator.next().unwrap().parse().unwrap();

    let a = n % k;
    let ans = min(a, k - a);

    return ans.to_string();
}


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

int main(){
	int n;
	cin >> n;
	char s[n];
	REP(i,n) cin >> s[i];
	REP(i,n){
		if(s[i] == 'Y'){
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] t = new int[n + 1];
        int[] x = new int[n + 1];
        int[] y = new int[n + 1];
        for (int i = 1; i < n + 1; i++) {
            t[i] = sc.nextInt();
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        String res = "Yes";
        for (int i =1; i < n + 1; i++) {
            int dx = Math.abs(x[i - 1] - x[i]);
            int dy = Math.abs(y[i - 1] - y[i]);
            int d = dx + dy;
            int s = (t[i] - t[i - 1]);
            if (s < d || s % 2 != d % 2) {
                res = "No";
                break;
            }
        }
        System.out.println(res);
    }

}


Measured memory_bytes: 91240
def main():
	n, q = map(int, input().split())
	s = input()
	acs = [0]*(n)
	for i in range(1, n):
		if s[i-1] == "A" and s[i] == "C":
			acs[i] = acs[i-1] + 1
		else:
			acs[i] = acs[i-1]
	results = [0]*q
	for i in range(q):
		l, r = map(int, input().split())
		results[i] = acs[r-1] - acs[l-1]
	for result in results:
		print(result)

if __name__ == '__main__':
    main()

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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int t=1;
	//cin>>t;
	//SieveOfEratosthenes(1000000);
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];
        ll dp[n][n];
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                dp[i][j]=0;
        for(int j=0;j<n;j++){
            dp[j][j]=a[j];
            for(int i=j-1;i>=0;i--){
                dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
            }
        }
        
        cout<<dp[0][n-1];
    }
}

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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

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

#define all(c) begin(c),end(c)

#define D(x) do { std::cerr << x << " "; } while (0)
#define D2(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)


template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


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

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


bool solve() {
    int N, K;
    cin >> N >> K;

    vi a(N);
    for (auto &&e: a) cin >> e;

    auto dp = vector<vector<bool>>(K+1, vector<bool>(2, false));
    REP(i,K+1) {
        REP(j,2) {
            bool can = false;
            REP(k,N) {
                if(i-a[k] < 0) continue;
                if(!dp[i-a[k]][!j]) can = true;
            }
            dp[i][j] = can;
        }
    }

    return dp[K][0];
}


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

    cout << (solve() ? "First" : "Second") << endl;
//    cout << (solve() ? "YES" : "NO") << endl;
//    cout << solve() << endl;
//    solve();

    return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>

using ll = long long;
int main() {
    int K;
    std::string S;
    std::cin >> S;

    int sum = 0;
    K = S.length();
    for (int i = 0; i < K; i++) {
        if (S[i] == 'o') {
            sum++;
        }
    }

    if (sum + 15 - K >= 8) {
        std::cout << "YES" << std::endl;
    }
    else {
        std::cout << "NO" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#AGC019A

q,h,s,d=map(int,raw_input().split())
n=int(raw_input())
res=0
if n%2:
 res=min(q*8,h*4,s*2,d)*(n-1)/2+min(q*4,h*2,s)
else:
 res=min(q*8,h*4,s*2,d)*n/2
print res


Measured memory_bytes: 2568