akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std ;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll ;
typedef vector<int> vint;
typedef vector<double> vdbl ;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int,int>> vpii ;
typedef vector<pair<ll,ll>> vpll ;
typedef priority_queue<int, vector<int>, greater<int>> spqint ; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll ; //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint ; //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll ; //大きい順に取り出し


#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define IREP(i,v) for(auto i=v.begin(); i !=v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(),(v).end()
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

void yes(){
  cout <<"unsafe"<<endl ;
}
void no(){
  cout <<"safe"<<endl ;
}
//-----------------------------------------




















//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int s, w ;
  cin >> s >> w ;
  if(s<=w){
    yes() ;
  }
  else{
    no() ;
  }
  
  
  
  return 0 ;
}



Measured memory_bytes: 3616
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,M = map(int,readline().split())
A = np.array(read().split(),np.int64)

f = np.bincount(A)

fft_len = 1<<18
fft = np.fft.rfft; ifft = np.fft.irfft
Ff = fft(f,fft_len)
G = np.rint(ifft(Ff * Ff,fft_len)).astype(np.int64) # 和 -> 何通りか

Gcum = G.cumsum()
remove_cnt = N * N - M
i = np.searchsorted(Gcum,remove_cnt)

# i未満は全部除外。ちょうどiのものもいくつか除外
x = remove_cnt - Gcum[i-1]
remove_sum = (G[:i] * np.arange(i,dtype=np.int64)).sum() + i * x

answer = A.sum() * 2 * N - remove_sum
print(answer)

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

#define INF 1000000007
#define min(a,b) (a>b?b:a)

int lst[6][2] = {
	{ 2, 380},
	{ 3, 550},
	{ 5, 850},
	{10, 1520},
	{12, 1870},
	{15, 2244}
};
#define M 50
int dp[M+1];

int main() {
	int n;
	for(int i=0; i<=M; ++i) dp[i] = INF;
	dp[0] = 0;
	for(int i=1; i<=M; ++i) {
		for(int j=0; j<6; ++j) {
			if(i>=lst[j][0]) dp[i] = min(dp[i], dp[i-lst[j][0]]+lst[j][1]);
		}
		//cout << dp[i] << endl;
	}
	while(cin >> n && n) cout << dp[n/100] << endl;
	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int students = sc.nextInt();
		int studentNum[] = new int[students];

		//登校順(入力する値の大きさ順)の要素番号に、生徒番号(= i)を入力する
		for(int i=1 ; i<=students ; i++) {
			int a = sc.nextInt();
			studentNum[a-1] = i;
		}

		//0から順に表示
		for(int i=0 ; i<students ; i++) {
			System.out.print(studentNum[i] + " ");
		}
		sc.close();
	}
}

Measured memory_bytes: 50424
#include <iostream>

using namespace std;
int main(void){

  int x, k;
  cin >> x >> k;
  
  int max = (k+x-1 < 1000000) ? k+x-1 : 1000000;
  int min = (k-x+1 > -1000000) ? k-x+1 : -1000000;
  
  for(int i = min; i <= max; i++){
  cout << i << " ";
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long
using namespace std;

ll Ha, Hb, Hc, Hx, Hy, Hz, Hmax, Hmin;
ll ans;
ll a,b;

ll temp;
string s, t;

int main() {
	cin >> s>>t;

	cout << t << s << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iterator>
#include <random>
#include <cmath>
#include <functional>


using namespace std;
using lint = long long int;



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

	if (s[0] == s[1] && s[0] == s[2]) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}
}



Measured memory_bytes: 256
N,Y=map(int,input().split())
flag=False
for i in range(N+1):
    for j in range(N-i+1):
        if i*10000+j*5000+(N-i-j)*1000==Y:
            flag=True
            a=i
            b=j
            c=N-i-j
if flag==True:
    print(a,b,c)
else:
    print('-1 -1 -1')

Measured memory_bytes: 42352
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string n;
int nlen, ans = 0;
void gen(string cur, int len, int am7, int am5, int am3) {
  if(len > nlen) return;
  if(len && am3 && am5 && am7) ans += (stoi(cur) <= stoi(n));
  gen(cur + '3', len + 1, am7, am5, am3 + 1);
  gen(cur + '5', len + 1, am7, am5 + 1, am3);
  gen(cur + '7', len + 1, am7 + 1, am5, am3);
}
int main() {

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

  cin >> n;

  nlen = n.size();

  gen("", 0, 0, 0, 0);

  cout << ans;

  return 0;
}
/*

*/


Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) {
    	Main executer = new Main();
		executer.execute();
    }
    
    public void execute() {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] args = br.readLine().split(" ");
			
			Integer keta100 = Integer.parseInt(args[0]);
			Integer keta10 = Integer.parseInt(args[1]);
			Integer keta1 = Integer.parseInt(args[2]);
			
			Integer num = keta100 * 100 + keta10 * 10 + keta1;
			
			String ret = (num % 4 == 0) ? "YES" : "NO";
			
			System.out.println(ret);
		} catch (Exception ex) {
			ex.printStackTrace();
			System.err.println(ex.getMessage());
		}
	}
}

Measured memory_bytes: 21332
import sys
from math import factorial
from collections import Counter
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    c = Counter(A)

    data = [0] * (N+1)
    sum_count = 0
    for i, v in c.items():
        if v < 2:
            continue
        value = factorial(v) // 2 // factorial(v - 2)
        data[i] = value - value * (v - 2) // v
        sum_count += value

    print('\n'.join([str(sum_count - data[a]) for a in A]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 32940
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};


int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll n, k;
    cin >> n >> k;
    n = n % k;
    while(n > abs(n-k)) {
        if(n > k) {
            n = n - k;
        } else {
            n = k - n;
        }
    }
    cout << n << endl;
}


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

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

        int n=scan.nextInt();
        int s[]=new int[n];
        int sum=0;
        int cur[]=new int[n];
        boolean jdg=false;
        for(int i=0;i<n;i++){
            s[i]=scan.nextInt();
            sum+=s[i];
            if(s[i]%10!=0){
                cur[i]=s[i];
                jdg=true;
            }
        }

        Arrays.sort(s);
        Arrays.sort(cur);

        if(sum%10!=0)
            jdg=false;
        if(jdg){
            for(int i=0;i<n;i++){
                sum-=cur[i];
                if(sum%10!=0)
                    break;
            }
        }else{
            if(sum%10==0)
            sum=0;
        }


        System.out.println(sum);
    }
}


Measured memory_bytes: 21844
h, w, d = map(int, input().split())
board = [list(map(int, input().split())) for _ in range(h)]
q = int(input())
quest = [tuple(map(int, input().split())) for _ in range(q)]
enumboard = []
for i in range(h):
    for j in range(w):
        enumboard.append((board[i][j], i, j))
enumboard.sort(key = lambda x: x[0])
cumboard = [0 for _ in range(h*w)]
for i in range(d, h*w):
    cumboard[i] = cumboard[i-d] + abs(enumboard[i][1] - enumboard[i-d][1]) + abs(enumboard[i][2] - enumboard[i-d][2])
for l, r in quest:
    print(cumboard[r-1] - cumboard[l-1])

Measured memory_bytes: 32128
program abc45
 implicit none
 character(len=200000)::N
 integer,allocatable::a(:)
 integer::len,ia,s
 read(*,*)N
 len=len_trim(N)
 allocate(a(len))
 do ia=1,len
  read(N(ia:ia),*)a(ia)
 end do
 s=sum(a)
 if(mod(s,9)==0)then
  print'(a)',"Yes"
 else
  print'(a)',"No"
 end if
end program abc45

Measured memory_bytes: 3928
import java.util.Scanner;

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

		int N = sc.nextInt();

		double s = 0;
		for(int i = 0;i < N;i++) {
			int a = sc.nextInt();
			s += 1.0/a;
		}

		sc.close();


		System.out.println(1/s);

	}
}


Measured memory_bytes: 21716
from collections import Counter

n = int(input())
c = Counter()
for i in range(n):
  s = input()
  c[s] += 1

_, maxi = c.most_common()[0]
ans = []
for s, i in c.most_common():
  if i != maxi:
    break
  ans.append(s)
  
for s in sorted(ans):
  print(s)

Measured memory_bytes: 43552
a, b, c, x, y = STDIN.gets.split.map(&:to_i)

a1 = a * x + b * y

a2 = if x > y
  y * 2 * c + (x - y) * a
elsif y > x
  x * 2 * c + (y - x) * b
else
  x * 2 * c
end

a3 = [x, y].max * 2 * c

puts [a1, a2, a3].min

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

num = 0
while True:
    if X+num in p_n:
        pass
    else:
        print(X +num)
        break
    num += 1
    if X - num in p_n:
        pass
    else:
        print(X - num)
        break

Measured memory_bytes: 9200
import math
X=int(input())

def is_prime(x):
    n = math.floor(math.sqrt(x))
    for i in range(2, n+1):
        if x % i == 0:
            return False
    return True

i = X
while True:
    if is_prime(i):
        print(i)
        break
    i += 1

Measured memory_bytes: 62728
S = input()

first = S[0]
fnum = 1
snum = 0
for i in range(1, 4):
	if S[i] == first:
		fnum += 1
	elif snum == 0:
		sec = S[i]
		snum += 1
	elif S[i] == sec:
		snum += 1

if fnum == 2 and snum == 2:
	print("Yes")
else:
	print("No")



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e11+7;
long long dp[103][100004];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,w;
    cin>>n>>w;
    int a[103],b[103];
    for(int i=0;i<n;i++)cin>>a[i]>>b[i];
    for(int i=0;i<n+1;i++)for(int j=0;j<100004;j++)dp[i][j]=mod;
    dp[0][0]=0;
    for(int i=0;i<n;i++)for(int j=0;j<100004;j++){
        if(j>=b[i])dp[i+1][j]=min(dp[i][j],dp[i][j-b[i]]+a[i]);
        else dp[i+1][j]=dp[i][j];
    }
    
    long long res=0;
    for(int j=0;j<100004;j++)if(dp[n][j]<=w)res=j;
    cout<<res<<endl;
    
    return 0;
}


Measured memory_bytes: 80128
#!/usr/bin/env python3
import sys
import math

def solve(X: int):
    ans = 100
    cnt = 0
    while True:
        ans = int(ans * 1.01)
        cnt += 1

        if ans>=X:
            print(cnt)
            return
    
    return 


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll=long long;

ll gcd(ll a, ll b){
    if(a<b) return gcd(b,a);
    ll r;
    while((r=a%b)){
        a=b;
        b=r;
    }
    return b;
}

int main(){
    ll n,i;
    cin>>n;
    vector<ll> a(n);
    for(i=0;i<n;i++) cin>>a[i];
    ll a_gcd=gcd(a[0],a[1]);
    for(i=2;i<n;i++) a_gcd=gcd(a_gcd,a[i]);
    cout<<a_gcd;

    return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	ll ans = INF;
	for (int i = 0; i <= 100000; i++) {
		ll cost = max(0, x - i) * a + max(0, y - i) * b + i * 2 * c;
		ans = min(ans, cost);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long div = n / (a + b);
		long mod = n % (a + b);
		long ans = div * a + ((mod < a) ? mod : a);
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
#![allow(unused_imports)]
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]

use std::{cmp, fmt};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Write};
use std::ops::{Add, Div, Mul, Sub};
use std::str::{self, FromStr};

fn main() {
    let (a, b, x): (u32, u32, u32) = {
        let mut sc = InputScanOnce::new(io::stdin(), 1024);
        (sc.next(), sc.next(), sc.next())
    };
    if a <= x && x <= a + b {
        println!("YES");
    } else {
        println!("NO");
    }
}

struct InputScanOnce {
    buf: Vec<u8>,
    pos: usize,
}

#[allow(dead_code)]
impl InputScanOnce {
    fn new<R: Read>(mut reader: R, estimated: usize) -> Self {
        let mut buf = Vec::with_capacity(estimated);
        let _ = io::copy(&mut reader, &mut buf).unwrap();
        InputScanOnce { buf: buf, pos: 0 }
    }

    #[inline]
    fn next<T: FromStr>(&mut self) -> T
    where
        T::Err: fmt::Debug,
    {
        let mut start = None;
        loop {
            match (self.buf[self.pos], start.is_some()) {
                (b' ', true) | (b'\n', true) => break,
                (_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
                (_, false) => start = Some(self.pos),
            }
        }
        let target = &self.buf[start.unwrap()..self.pos];
        unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        T::Err: fmt::Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<T1: FromStr, T2: FromStr>(&mut self, n: usize) -> Vec<(T1, T2)>
    where
        T1::Err: fmt::Debug,
        T2::Err: fmt::Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<T1: FromStr, T2: FromStr, T3: FromStr>(&mut self, n: usize) -> Vec<(T1, T2, T3)>
    where
        T1::Err: fmt::Debug,
        T2::Err: fmt::Debug,
        T3::Err: fmt::Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        T::Err: fmt::Debug,
    {
        (0..m).map(|_| self.vec(n)).collect()
    }

    fn strings_as_mat<T, F: FnMut(u8) -> T>(&mut self, h: usize, mut f: F) -> Vec<Vec<T>> {
        (0..h)
            .map(|_| {
                let l = self.next::<String>();
                l.as_bytes().iter().cloned().map(&mut f).collect()
            })
            .collect()
    }
}


Measured memory_bytes: 4352
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    int X, Y, Z;
    cin >> X >> Y >> Z;
    swap(X, Y);
    swap(X, Z);
    cout << X << " " << Y << " " << Z << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
  ll n,x,y;cin >> n >> x >> y;
  vl v(n);rep(i,n)cin >> v[i];
  vvl dp(n,vl(2));
  rep(i,n)dp[i][0]=0;
  rep(i,n)dp[i][1]=inf;
  per(i,n){
    ll Y = (i ? v[i-1] : y);
    chmax(dp[i][0],abs(v[n-1]-Y));
    repl(j,i+1,n){
      chmax(dp[i][0],dp[j][1]);
    }
    ll X = (i ? v[i-1] : x);
    chmin(dp[i][1],abs(v[n-1]-X));
    repl(j,i+1,n){
      chmin(dp[i][1],dp[j][0]);
    }
  }
  cout << dp[0][0] <<endl;
}

Measured memory_bytes: 384
N=int(input())
#含んではいけない
#AGC
#GAC
#ACG
#ACGC
#AGGC
#ATGC
#AGAC
#AGTC

# AAA,AAC,AAG...という3文字セットの組み合わせ64通り
from collections import deque
stack=deque([""])
buf=[]
while stack:
  s=stack.popleft()
  if len(s)==3:
    buf.append(s)
    continue
  for c in ("ACGT"):
    stack.append(s+c)

# dp["XXX"] : 直近3文字がXXXになっている場合の数のDP
dp={}
for b in buf:
  dp[b]=[0 for i in range(N+1)]
  if b not in ("AGC","ACG","GAC"):
    dp[b][3]=1

# ある3文字に対して次に来てはいけない文字
NG={
  "ACG":"C",
  "AGG":"C",
  "ATG":"C",
  "AGA":"C",
  "AGT":"C"
}
DIV=10**9+7

for i in range(3,N):
  for item in dp.items():
    key=item[0]
    value=item[1]
    ngnex=""
    if key in NG:
      ngnex=NG[key]
    las2=key[1:]
    for c in ("ACGT"):
      if las2+c in ("AGC","ACG","GAC"):
        continue
      if c!=ngnex:
        dp[las2+c][i+1]+=dp[key][i]
        dp[las2+c][i+1]%=DIV

ans=0
for v in dp.values():
  ans+=v[-1]
print(ans%DIV)

Measured memory_bytes: 3564
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

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

void fastIO() {std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) {if(y < x) x = y;}
template<typename T, typename U> inline void mxze(T &x, U y) {if(x < y) x = y;}

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h)
	{ cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++;
	cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

const int INF = 0x3f3f3f3f;
const int MAXN = 5e5+5;

int a[MAXN], N;
char s[MAXN];

int main(){
	scan(s);
	N = strlen(s)+1;
	ms(a, INF);
	if(s[0] == '<') a[0] = 0;
	if(s[N-2] == '>') a[N-1] = 0;
	for(int i=0; i<(int)N-2; i++){
		if(s[i] == '>' && s[i+1] == '<') a[i+1] = 0;
	}
	for(int i=0; i<(int)N-1; i++){
		if(s[i] == '<') a[i+1] = a[i] + 1;
	}
	for(int i=N-2; i>-1; i--){
		if(s[i] == '>'){
			if(a[i] == INF) a[i] = a[i+1] + 1;
			else mxze(a[i], a[i+1] + 1);
		}
	}
	ll ans = 0;
	for(int i=0; i<(int)N; i++) ans += a[i];
	printf("%lld\n",ans);
}


Measured memory_bytes: 2688
#include <iostream>

using namespace std;

long div(long a, long b, long q)
{
  long l = b - a + 1;
  long x = a % q;
  if (x == 0) x = q;
  l = l - q + x;
  if (l < 1) return 0;
  return (l - 1)/q + 1;
}

int euclid(int c, int d)
{
  if (c == 0) return d;
  else if (c == 1) return 1;
  else euclid(d % c, c);
}

int main(){
  long a, b;
  long c, d;
  cin >> a >> b >> c >> d;
  long ans = (b - a + 1) - (div(a, b, c) + div(a, b, d) - div(a, b, c*d/euclid(c, d)) );
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	int ans=0;
	int a;
	a = n / 1000;
	if (a == 0)ans = 1000 - n;
	else {
		if (n % 1000 == 0) ans = 0;
		else ans = 1000 * (a + 1) - n;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int n, m, q, ans = INT_MIN;
vector<int> a, b, c, d;
void check(int i, int num, vector<int> &arr)
{
    if (i == n)
    {
        int sum = 0;
        for (int p = 0; p < q; p++)
        {
            if (arr[b[p]] - arr[a[p]] == c[p])
                sum += d[p];
        }
        ans = max(ans, sum);
        return;
    }
    for (int p = num; p <= m; p++)
    {
        arr[i] = p;
        check(i + 1, p, arr);
    }
}
int main()
{
    cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    for (int i = 0; i < q; i++)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    vector<int> arr(n, 0);
    check(0, 1, arr);
    cout << ans;
    return 0;
}

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

int main() {
  ll n, h, w;
  cin >> n >> h >> w;
  cout << (n-h+1) * (n-w+1) << endl; 
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}

int main() {
  string s, t;
  cin >> s >> t;
  int S = s.size();
  bool f = 1;
  for (int i = 0; i < S; i++) {
    if (s[i] != t[i]) f=0;
  }
  if (f) cout <<"Yes"<<endl;
  else cout << "No"<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
#include <complex>
#include <cstdio>
using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef complex<double> vec;

int main(){
    double dir = acos(-1)/2;
    vec v(0,0);
    int r,t;
    while(scanf("%d,%d",&r,&t)!=EOF && r|t){
        v += polar<double>(r,dir);
        dir+=1.0 * t / 180 * acos(-1);
    }
    cout << int(-v.real()) << endl << int(v.imag()) << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, K;
    cin >> N >> K;

    if(K == 1) cout << 0 << endl;
    else cout << (N>=K ? N-K : 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, n) for (int i = 0; i <= (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, n) for (int i = (n)-1; i > 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

const int dr[] = {0, 1, 0, -1};
const int dc[] = {1, 0, -1, 0};

template <typename T, typename U>
constexpr void amin(T &a, const U &b) {
  if (b < a) a = b;
}

template <typename T, typename U>
constexpr void amax(T &a, const U &b) {
  if (b > a) a = b;
}

const int mxN = 3010;
LL dp[mxN][mxN][4], grid[mxN][mxN];

void solve() {
  int r, c, k;
  cin >> r >> c >> k;
  rep(i, r) rep(j, c) {
    grid[i][j] = 0;
    rep(k, 4) dp[i][j][k] = -1e9;
  }
  rep(i, k) {
    int a, b, d;
    cin >> a >> b >> d;
    grid[a - 1][b - 1] = d;
  }
  dp[0][0][0] = 0;
  rep(i, r) {
    rep(j, c) {
      rrep(k, 3) {
        if (dp[i][j][k] >= 0) amax(dp[i][j][k + 1], dp[i][j][k] + grid[i][j]);
      }
      rep(k, 4) {
        if (dp[i][j][k] >= 0) {
          if (i < r - 1) amax(dp[i + 1][j][0], dp[i][j][k]);
          if (j < c - 1) amax(dp[i][j + 1][k], dp[i][j][k]);
        }
      }
    }
  }
  cout << max({dp[r - 1][c - 1][0], dp[r - 1][c - 1][1], dp[r - 1][c - 1][2],
               dp[r - 1][c - 1][3]});
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}


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

int main(){
	int N, M;
	int a[101];
	cin >> N >> M;
	for(int i = 1; i <= N; i++) cin >> a[i];
	for(int i = 1; i <= M; i++){
		for(int j = 1; j < N; j++){
			if(a[j + 1] % i < a[j] % i){
				swap(a[j], a[j + 1]);
			}
		}
	}
	for(int i = 1; i <= N; i++){
		cout << a[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int N;
vector<long long> a;

void solve() {
    map<long long, long long> ma;
    for (int i = 0; i < N; ++i) ma[a[i]]++;

    long long res = 0;
    for (auto it : ma) res += it.second * (it.second - 1) / 2;
    for (int i = 0; i < N; ++i) {
        long long val = ma[a[i]];
        long long before = val * (val - 1) / 2;
        long long after = (val - 1) * (val - 2) / 2;
        cout << res + after - before << endl;
    }
}

int main() {
    while (cin >> N) {
        a.resize(N);
        for (int i = 0; i < N; ++i) cin >> a[i];
        solve();
    }
}


Measured memory_bytes: 11904
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        String[] a = new String[n];
        Arrays.setAll(a, i -> scanner.next());
        String[] b = new String[m];
        Arrays.setAll(b, i -> scanner.next());
        for (int i = 0; i <= n - m; i++) {
            for (int j = 0; j <= n - m; j++) {
                boolean f = true;
                for (int k = 0; k < m; k++) {
                    f &= a[i + k].substring(j, j + m).equals(b[k]);
                }
                if (f) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 26580
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.SQLOutput;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    static void bin(int n) {
        if (n > 1)
            bin(n/2);

        System.out.print(n % 2);
    }
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }
    static class Pair<a , b>{
        a v1;
        b v2;
        Pair(a v1 , b v2){
            this.v1 = v1;
            this.v2 = v2;
        }
    }
    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out){
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i <n ; i++) {
                arr[i]= in.nextInt();
            }
            int small=arr[0];
            int ans = 0;
            for (int i = 0; i <n ; i++) {
                if (arr[i] <= small) {
                    ans++;
                    small = arr[i];
                }
            }
            System.out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt(){return  Integer.parseInt(next());}
        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 47640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int N = 2e5 + 7;

int a[N];
int mn[N << 2], mx[N << 2];
void build(int v, int tl, int tr) {
    if (tl == tr) {
        mn[v] = mx[v] = a[tl];
        return;
    }   
    int tm = (tl + tr) >> 1;
    build(v * 2 + 1, tl, tm);
    build(v * 2 + 2, tm + 1, tr);
    mn[v] = min(mn[v * 2 + 1], mn[v * 2 + 2]);
    mx[v] = max(mx[v * 2 + 1], mx[v * 2 + 2]);
}   
int getmin(int v, int tl, int tr, int l, int r) {
    if (tr < l || r < tl)
        return N;
    if (l <= tl && tr <= r)
        return mn[v];
    int tm = (tl + tr) >> 1;
    return min(getmin(v * 2 + 1, tl, tm, l, r), getmin(v * 2 + 2, tm + 1, tr, l, r));            
}   
int getmax(int v, int tl, int tr, int l, int r) {
    if (tr < l || r < tl)
        return -1;
    if (l <= tl && tr <= r)
        return mx[v];
    int tm = (tl + tr) >> 1;
    return max(getmax(v * 2 + 1, tl, tm, l, r), getmax(v * 2 + 2, tm + 1, tr, l, r));            
}   
int getmin(int l, int r) { 
    return getmin(0, 0, N - 1, l, r);
}   
int getmax(int l, int r) {
    return getmax(0, 0, N - 1, l, r);
}   

int pref[N];
bool sorted(int l, int r) {
    return pref[r] - pref[l] == r - l;
}   
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n - 1; ++i) {
        pref[i + 1] = pref[i] + (a[i] < a[i + 1]);
    }   

    build(0, 0, N - 1);
    int ans = 1;
    for (int i = 1; i + k - 1 < n; ++i) {
        if (!(getmin(i - 1, i - 1 + k - 1) == a[i - 1] && getmax(i, i + k - 1) == a[i + k - 1]))
            ++ans;
    }   

    int cnt = 0;
    for (int i = 0; i + k - 1 < n; ++i) {
        cnt += sorted(i, i + k - 1);
    }   

    for (int i = 0; i + k < n; ++i) {
        if (sorted(i, i + k - 1) && sorted(i + 1, i + k))
            ++ans;
    }   

    if (cnt) {
        ans -= cnt - 1;
    }
    
    /*
    set <vector <int> > ms;
    for (int i = 0; i + k - 1 < n; ++i) {
        cout << i << " : ";
        vector <int> t;
        for (int j = 0; j < n; ++j)
            t.app(a[j]);
        sort(t.begin() + i, t.begin() + i + k);
        for (int e : t)
            cout << e << ' ';
        cout << endl;
        ms.insert(t);
    }   
    cout << ms.size() << endl;
    */

    cout << ans << endl;
}

Measured memory_bytes: 15872
package main

import "fmt"

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

func main() {
	var A, B int
	fmt.Scan(&A, &B)
	v1 := A + B
	v2 := A - B
	v3 := A * B
	fmt.Println(max(max(v1, v2), v3))
}


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

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  int current = 1;
  int res = 0;
  while (current < B) {
    current += (A - 1);
    res++;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
     
    using namespace std;
     
    const int NMAX=2e5+1;
     
    char s[NMAX],t[NMAX];
     
    int main()
    {
    	scanf("%s%s",s,t);
        int n=strlen(s);
        int cnt=0;
        for(int i=0;i<n;i++)
        {
        	if(s[i]!=t[i])
            	cnt++;
        }
        printf("%d\n",cnt);
    }

Measured memory_bytes: 4140
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod=1e9+7;
const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=2e5+10;
const ll inf=0x3f3f3f3f;
const int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}};

int l[maxn],r[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n,k,c;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    int cnt=k-1,mx=n;
    for(int i=s.length()-1;i>=0;i--)
        if(s[i]=='o'&&i<mx&&cnt>=0)r[cnt]=i,mx=i-c,cnt--;
    cnt=0,mx=-1;
    for(int i=0;i<s.length();i++)
        if(s[i]=='o'&&i>mx)l[cnt]=i,mx=i+c,cnt++;
    for(int i=0;i<k;i++)
        if(l[i]==r[i])cout<<l[i]+1<<endl;
    return 0;
}


Measured memory_bytes: 3348
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  //周上あるいは対角線上か調べる
  int64_t W,H,x,y;
  cin >> W >> H >> x >> y;
  int ans = 0;
  
  if(x == W || y == H || x == W/2.0 || y == H/2.0 || x == 0 || y == 0)//周上
    ans = 0;
  
  if(y == x || y == H - x)
    ans = 0;
  
  if(x == W/2.0 && y == H/2.0)
    ans = 1;
  
  
  cout << W*H/2.0 << " " <<   ans <<endl;
  
 
}

Measured memory_bytes: 3736
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int A = 0;
		int Z = 0;
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == 'A') {
				A = i;
				break;
			}
		}
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(s.length() - 1 - i) == 'Z') {
				Z = s.length() - i;
				break;
			}
		}
		System.out.println(Z - A);
	}
}


Measured memory_bytes: 26304
#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for(int i=1; i<=n; i++)

int main() {
	int N;
	cin >> N;
	vector<int> v(10001);
	rep1(x, 100) {
		rep1(y, 100) {
			rep1(z, 100) {
				int f = x*(x+y+z) + y*(y+z) + z*z;
				if (f > 10000) break;
				else v.at(f)++;
			}
		}
	}
	rep1(i, N) {
		std::cout << v.at(i) << '\n';
	}
}


Measured memory_bytes: 3660
n = input().split()
D = int(n[0])
N = int(n[1])

if D == 0:
    if N == 100:
        print('101')
    else:
        print(str(N))
elif D == 1:
    if N == 100:
        print('10100')
    else:
        print(str(N * 100))
else:
    if N == 100:
        print('1010000')
    else:
        print(str(N * 10000))

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while(true){
        cin >> H >> W;
        if (H != 0 || W != 0){
            for(int i = 1; i <= H; i++){
                if(i == 1 || i == H){
                    for(int j = 1; j <= W; j++){
                        cout << '#';
                    }
                } else {
                    for(int j = 1; j <= W; j++){
                        if(j == 1 || j == W){
                            cout << '#';
                        } else {
                            cout << '.';
                        }
                    }
                }
                cout << endl;        
            }
            cout << endl;
        } else {
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define il inline
#define ll long long
const int N=1e5+5;
 
int n,s,x[N]; ll p[N];
 
il ll cal(int l,int r,int t)
{
	if (s<x[l]) return x[r]-s; if (x[r]<s) return s-x[l];
	if (p[l]>=p[r]) return p[l]+=p[r],cal(l, r - 1, l)+(t==r)*(x[r]-x[l]);
	return p[r]+=p[l],cal(l+1,r,r)+(t==l)*(x[r]-x[l]);
}
 
int main()
{
	scanf("%d%d",&n,&s); int i;
    for (i=1; i<=n; i++) scanf("%d%lld",x+i,p+i);
	
	printf("%lld", cal(1,n,p[1]<p[n]?1:n));

	return 0;
}

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

#define int long long

signed main() {
        int n, m;
        cin >> n >> m;
        vector<int> s(m), c(m);
        for(int i = 0; i < m; i++) {
                cin >> s[i] >> c[i];
        }

        for(int i = 0; i <= 999; i++) {
                string st = to_string(i);
                if(st.size() == n) {
                        bool flag = true;
                        for(int j = 0; j < m; j++) { 
                                if(st[s[j] - 1] - '0' != (char)(c[j])) {
                                        flag = false;
                                }
                        }
                        if(flag) {
                                cout << stoi(st) << endl;
                                return 0;
                        }
                }
        }

        cout << -1 << endl;
        return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
h = [int(x) for x in input().split()]

Cost = [0] * N
Cost[0] = 0

for i in range(1, N):
    tmp = [Cost[k] + abs(h[i] - h[k]) for k in range(max(0, i - K),i)]
    Cost[i] = min(tmp)

print(Cost[-1])

Measured memory_bytes: 20452
#include<cstdio>
int pow(int a,int b){
    if(b==0)return 1;
    else{
        int c=pow(a,b/2);
        return c*c*((b%2==0)?1:a);
    }
}
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    printf("%d",k*pow(k-1,n-1));
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


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

    int t=1,te=0;
    // cin>>t;
    while(t--){
        int n,r;
        cin>>n>>r;

        if(n>=10){
            printf("%d\n", r);
        }
        else{
            printf("%d\n", r + (100*(10-n)));
        }


        //printf("Case %d: ",++te);
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

vector<int> pp;
void preparePrime( int maxp )
{
    int i;
    vector<int> a(maxp+1);
    for(i=2; i<=maxp; i++) {
        int k=i+i;
        while(k<=maxp) {
            a[k]=1;
            k+=i;
        }
    }
    for(i=2; i<=maxp; i++) {
        if(a[i]==0) pp.push_back( i );
    }
    return;
}

int main(int argc, char* argv[])
{
    preparePrime(2200);       // (10^10)^(1/3) 以下の数について素数を列挙
    const int num3=(int)pp.size();
    vector<ll> a2(num3);    // 2乗した数を列挙  a2[i]=i^2
    vector<ll> a3(num3);    // 3乗した数を列挙  a3[i]=i^3

    int i,j;
    for(i=0; i<num3; i++) {
        a2[i]=(ll)pp[i]*pp[i];
        a3[i]=a2[i]*pp[i];
    }

    int n;
    scanf("%d", &n);

    map<ll,int> cnt;
    for(i=0; i<n; i++) {
        ll s;
        scanf("%lld", &s);
        for(j=0; j<num3; j++) {      // 立方数で割っておく
            if(s<a3[j]) break;
            while(s%a3[j]==0) {
                s/=a3[j];
            }
        }
        cnt[s]++;
    }

    int ans=0;
    if(cnt.find(1)!=cnt.end()) {    // 1（つまり元々立方数だったもの）を答えに反映させて、mapから削除
        ans++;
        cnt.erase(1);
    }

    queue<ll> que;
    {
        auto it=cnt.begin();
        for(; it!=cnt.end(); ++it) {
            que.push(it->first);
        }
    }

    while(!que.empty()) {
        ll tt=que.front();
        que.pop();

        auto it=cnt.find(tt);
        if(it==cnt.end()) continue;

        ll curr=it->first;
        ll sub=1;
        for(j=0; j<num3; j++) {        // currを平方数と無平方数の積にする。ただし平方数はa2に列挙したもののみ考えればよい
            if(curr<a2[j]) break;
            while(curr%a2[j]==0) {
                curr/=a2[j];
                sub*=pp[j];
            }
            if(sub>num3 || curr<sub) break;
        }
        if(sub>num3 || curr<sub) continue;
        double chk=(double)curr*curr*sub;
        if(chk>1e12) continue;
        ll tmp=curr*curr*sub;         // currとペアになる数（積が立方数になるもの）を見つける
        auto it2=cnt.find(tmp);
        if(it2!=cnt.end()) {          // ペアが見つかったら答に追加して、currおよびペアをmapから削除
            ans += MAX(it->second, it2->second);
            ll tmp0=it->first;
            ll tmp1=it2->first;
            cnt.erase(tmp0);
            cnt.erase(tmp1);
        }
    }

    auto it=cnt.begin();
    for(; it!=cnt.end(); ++it) {    // ペアにならなかった分を答に反映
        ans+=it->second;
    }
    printf("%d\n", ans);

    return 0;
}


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

int main() {

	string s;
	cin >> s;

	int a, z;
	a=z=-1;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A' && a==-1) {
			a = i;
		}
		if (s[i] == 'Z') {
			z = i;
		}
	}

	int ans = z-a+1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
 const int MAX_SIZE = 1e6; 
  
bool prime[MAX_SIZE + 1]; 
  
void sieve() 
{ 
  
    memset(prime, true, sizeof(prime)); 
  
    for (int p = 2; p * p <= MAX_SIZE; p++) { 
  
        if (prime[p] == true) { 
  
            for (int i = p * p; i <= MAX_SIZE; i += p) 
                prime[i] = false; 
        } 
    } 
} 
int PrimeGreaterThanN(int n) 
{ 
  
     
    for (int i = n; i < MAX_SIZE; i++) { 
  
        if (prime[i] == true) 
        
  
    return i; 
}
} 
int main()
{
	//int t;
	//cin >> t;
	//while(t--)
	//{
		int n ,k;
		cin >> n >>k;
		int r,s,p;
		cin >> r >> s  >> p;
		string str;
		cin >> str;
		string ans=str;
		for(int i =0;i<k;i++)
		{
			if(str[i]=='r')
				ans[i]='p';
			if(str[i]=='p')
				ans[i]='s';
			if(str[i]=='s')
				ans[i]='r';
		}
		for(int i =k;i<n;i++)
		{
			if(str[i]=='r')
				{
					if(ans[i-k]!='p')
					ans[i]='p';
					else
						ans[i]='?';
				}
				if(str[i]=='p')
				{
					if(ans[i-k]!='s')
					ans[i]='s';
					else
						ans[i]='?';
				}
				if(str[i]=='s')
				{
					if(ans[i-k]!='r')
					ans[i]='r';
					else
						ans[i]='?';
				}
		}
		long long ansc = 0;
		for(int i =0;i<ans.length();i++)
		{
			if(ans[i]=='p')
				ansc+=p;
			if(ans[i]=='r')
				ansc+=r;
			if(ans[i]=='s')
				ansc+=s;
		}
		cout <<  ansc<<endl;
	//}
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    int N;cin>>N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    vector<ll> S(N+1,0),M(N+1,0);
    REP(i,N){
        S[i+1]=S[i]+A[i];
    }
    ll ans=LLONG_MAX;
    REP(i,N+1) {
        ans=min(ans,llabs(S[i]-(S[N]-S[i])));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5504