akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

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

int main(void) {
    long long int h,count=0;
    long long int now=1;

    cin>>h;

    while(1){
        count+=now;
        if(h==1){
            break;
        }
        now*=2;
        h/=2;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 256
/*  ex6_2
    person_A  */
#include<stdio.h>
#include<math.h>
#include<string.h>
#define SIZE 101

int main(void){
    //変数の宣言
    int length;
    char word[SIZE];

    //単語の入力
    scanf("%s",word);
    //単語の文字数を取得
    length=strlen(word);
    //単語の最初の一文字、単語から両端の一文字を除いた文字数、単語の最後の文字、を続けて出力
    printf("%c%d%c\n",word[0],length-2,word[length-1]);
    return 0;
}

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

int main() {
  int N, K;
  int sum = 1;
  cin >> N ;
  cin >> K ;
  
  for(int i=0;i<N;i++){
	if(sum > K){
    	sum+=K;
    }
    else{
    	sum *= 2;
    }
  }
  cout << sum;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [0 for i in range(n+1)]
b.append(0)
for i in range(k):
    for j in range(n):
        if a[j] > j and a[j] + j + 1 > n:
            b[0] += 1
            b[-1] -= 1
        if a[j] > j and a[j] + j + 1 <= n:
            b[0] += 1
            b[j+a[j]+1] -= 1
        if a[j] <= j and a[j] + j + 1 > n:
            b[j-a[j]] += 1
            b[-1] -= 1
        if a[j] <= j and a[j] + j + 1 <= n:
            b[j-a[j]] += 1
            b[j+a[j]+1] -= 1
    for j in range(1,n):
        b[j] += b[j-1]
    for j in range(n):
        a[j] = b[j]
    if b.count(n) == n:
        break
    for j in range(n):
        a[j] = b[j]
    b = [0 for i in range(n+1)]
print(*a)

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

int main(){
  int n, d;
  cin >> n >> d;
  int x[n][d];
  rep(i,n) rep(j,d) cin >> x[i][j];
  
  int cnt = 0;
  
  for(int i = 1; i < n; i++){
    for ( int j = 0; j < i; j++) {
      int dist = 0;
      rep(k, d){
        dist += pow((x[i][k] - x[j][k]), 2);
      }
      if(pow((int)sqrt(dist), 2) == dist) {
        cnt++;
      }
    }
  }
  
  cout << cnt << endl;

  return 0;
}

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

int n;
int t[110];
int m;
int p[110];
int x[110];
int ans;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> t[i];
		ans += t[i];
	}
	cin >> m;
	for (int i = 1; i <= m; i++) {
		cin >> p[i] >> x[i];
		cout << ans - t[p[i]] + x[i] << endl;
	}
	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);
        String str = sc.next();

        if (Character.isUpperCase(str.charAt(0))) {
            System.out.println("A");
        } else {
            System.out.println("a");
        }
        sc.close();
    }
}

Measured memory_bytes: 35696
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
   int N,A,B; cin >> N >> A >> B;
   string S; cin >> S;
   int ok = 0;
   int fore = 1;
   rep(i,S.size()){
      if(S[i] == 'a' && ok < A+B){
         ok++;
         cout <<"Yes" << endl;
      }
      else if(S[i] == 'b' && ok < A+B && fore <= B){
         ok++;
         fore++;
         cout << "Yes" << endl;
      }
      else cout << "No" << endl;
   }

}



Measured memory_bytes: 896
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <vector>

#define rep(i,a,b) for(long long i=a;i<b;i++)

using namespace std;


int main(void) {

	long long N = 0, K = 0, A = 0, B = 0, C = 0;
	long long a[300] = {0};
	long long b[300] = { 0 };
	long long c[300] = { 0 };
	long long d[300] = { 0 };
	//long long y[20] = {};
	string s;
	
	long long min = 0, min2 = 0;
	long long dif = 0;
	long long hoge = 0;
	long long sum = 0;

	cin >> N;
	


	/*rep(i, 0, N) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}*/

	for (int j = 0; j < 101; j += 7) {
		for (int i = 0; i < 101; i += 4) {

			if (N == i + j) {
				hoge = 1;
			}
			//cout << i + j << endl;
		}
	}


	if(hoge == 1)
			cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
	int n,k;
	ll a[15];
	ll ans = 1000000000000;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++) scanf("%lld",a+i);
	for(int S=0;S<(1<<n);S++){
		int cnt = 0;
		for(int j=0;j<n;j++) if((S>>j)&1) cnt++;
		if(cnt!=k) continue;
		ll h = 0;
		ll res = 0;
		for(int j=0;j<n;j++){
			if((S>>j)&1){
				if(h<a[j]) h = a[j];
				else{
					res += h - a[j] + 1;
					h++;
				}
			}else{
				h = max(h,a[j]);
			}
		}
		ans = min(ans,res);
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 128
import sys

def main():
    input_list = input().split(" ")
    a1, a2, a3 = int(input_list[0]), int(input_list[1]), int(input_list[2])
    if a1 + a2 + a3 >= 22:
        print('bust')
    else:
        print('win')

if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
bool isPrime(ll n) 
{ 
    
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
   
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
int minthis(int a, int b){
if(a < b){
return a;
}
return b;
}
int maxthis(int a, int b){
if(a > b){
return a;
}
return b;
}
int gcd(int a, int b){
    if( a<0 ) a = -a;
    if( b<0 ) b = -b;
    while( b!=0 ){
        a %= b;
        if( a==0 ) return b;
        b %= a;
    }
    return a;
}
 
int findLargestDivisor(int n) 
{ 
	int max = 1;
    for (int i = 2; i < n; i++) {        
        if(n %(i) == 0) { 
            max = i;
        } 
    }
    return max;     
} 
 
 
ll power(ll x, ll y)  
{  
    ll temp;  
    if(y == 0)  
        return 1;  
    temp = power(x, y / 2);  
    if (y % 2 == 0)  
        return temp * temp;  
    else
    {  
        if(y > 0)  
            return x * temp * temp;  
        else
            return (temp * temp) / x;  
    }  
}  


void solve(){	
	ll N;
    cin>>N;
    ll tmp = N;
    string ans = "";
    while(tmp>0){
        tmp--;
        ans += char(tmp%26+'a');
        tmp/=26;
    }
    reverse(ans.begin() , ans.end());
    cout<<ans<<endl;
}
  
int main(){ 
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;    
    //cin >> t;
    while(t--){
		solve();
	}
    return 0; 
}


Measured memory_bytes: 3664
fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map(String::toInt)
    val P = readLine()!!.split(" ").map { (it.toDouble() + 1.0) / 2.0 }
    var sum = P.take(K).sum()
    var max = sum
    (0 until P.size - K).forEach { i ->
        sum += P[K+i] - P[i]
        if (max < sum) max = sum
    }
    println(max)
}

Measured memory_bytes: 79364
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  ll N;cin>>N;
  vector<ll> a(N);
  ll i,j,k;
  rep(i,N) cin>>a[i];
  sort(a.begin(),a.end());
  ll ans=0;
  ans = a[N/2] - a[N/2 -1];
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
package main

import (
  "fmt"
  "sort"
)

func main() {
  var n int
  fmt.Scan(&n)
  
  nums := make([]int, n)
  for i := 0; i < n; i ++ {
    fmt.Scan(&nums[i])
  }
  
  sort.Sort(sort.Reverse(sort.IntSlice(nums)))
  
  nums[0] /= 2
  
  sum := 0
  for i := 0; i < n; i ++ {
    sum += nums[i]
  }
  
  fmt.Println(sum)
}

Measured memory_bytes: 512
#include <cstdio>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;
typedef pair<int, int> P;
P po[100], res[100];
int main() {
    int n; scanf("%d",&n);
    for (int i=0; i<n; i++) {
        po[i].second=i;
        po[i].first=0;
    }
    for (int i=0; i<n*(n-1)/2; i++) {
        int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d);
        if (c>d) {
            po[a-1].first+=3;
        } else if (c<d) {
            po[b-1].first+=3;
        } else {
            po[a-1].first++;
            po[b-1].first++;
        }
    }
    sort(po, po+n);
    int pos=1, cnt=0, bef=0;
    for (int i=n-1; i>=0; i--) {
        if (bef!=po[i].first) {
            pos+=cnt;
            res[i].first=po[i].second;
            res[i].second=pos;
            cnt=1; bef=po[i].first;
        } else {
            res[i].first=po[i].second;
            res[i].second=pos;
            cnt++;
        }
    }
    sort(res,res+n);
    for (int i=0; i<n; i++) printf("%d\n",res[i].second);
}

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

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

  // ここにプログラムを追記
  for (int i = 0; i < N; i++) {
  string S;
  cin >> S;
  
   if(S =="Y"){
   cout<< "Four";
   break;
  }
 else if (i == N-1){
   cout<< "Three";
  
  }  
  }
  }

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

int main(){
    long long int n;
    cin >> n;

    string ans;
    while(n){
        n--;
        ans += n%26 + 'a';
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 3608
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let cs: Vec<char> = sc.chars();
    let xs: Vec<usize> = cs.iter().map(|&c| ((c as u8) - ('0' as u8)) as usize).collect();
    let mut memo = vec![vec![vec![0; 10]; n]; 3];

    for i in 0..n {
        memo[0][i][xs[i]] = 1;
    }
    for i in 1..n {
        for c in 0..10 {
            memo[0][i][c] = max!(memo[0][i][c], memo[0][i-1][c]);
        }
    }
    for i in 1..n {
        for c in 0..10 {
            memo[1][i][xs[i]] += memo[0][i-1][c];
        }
    }
    for i in 1..n {
        for c in 0..10 {
            memo[1][i][c] = max!(memo[1][i][c], memo[1][i-1][c]);
        }
    }
    for i in 2..n {
        for c in 0..10 {
            memo[2][i][xs[i]] += memo[1][i-1][c];
        }
    }
    for i in 1..n {
        for c in 0..10 {
            memo[2][i][c] = max!(memo[2][i][c], memo[2][i-1][c]);
        }
    }

    put!(memo[2][n-1].iter().sum::<usize>());
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 12540
// ????????????????????????
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
using namespace std;
int T, N, K, X[100000+10], A[100000+10]; 
int main() {
  cin >> T; // ???????????????????????°???????????????
  for (int t=0; t<T; ++t) {
    cin >> N;
    cin >> K;
    for (int i=0; i<N; ++i) cin >> X[i]; // ??¶??????????????\???
    for (int i=0; i+1<N; ++i) A[i] = X[i+1]-X[i]; // ??¶??¨??¶??????
    sort(A,A+N-1);
    int m = max(0,N-1-(K-1));
    int sum = 0;
    for (int i=0; i<m ; ++i)
      sum += A[i];
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1956
N = int(input())
H = [int(i) for i in input().split()]

ans = 0
counter = 0
for i in range(N - 1):
    h = H[i]
    h1 = H[i + 1]
    if h >= h1:
        counter += 1
        if ans < counter :
            ans = counter
    else:
        counter = 0
print(ans)

Measured memory_bytes: 14224
#include <iostream>

int main() {
  // N is an integer between 1 and 200 (inclusive)
  // The test number n is in range(1, 200) (inclusive)
  // n is odd number
  int N;
  std::cin >> N;

  int divisors_counter{}, divisors8_counter{};
  for (int n = 1; n <= N; n += 2) {
    for (int i = 1; i <= n; i++)
      if (n % i == 0) divisors_counter++;

    if (divisors_counter == 8) divisors8_counter++;

    divisors_counter = 0;
  }

  std::cout << divisors8_counter << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		List<Map<Integer, Integer>> list = new ArrayList<>();
		Map<Integer, Integer> map = new LinkedHashMap<>();
		while(true) {
			if ((map = checkZero(input.readLine())) == null) {
			  break;
			} else {
			  list.add(map);
			}
		}
		for (Map<Integer, Integer> resultMap : list) {
			for (Map.Entry<Integer, Integer> entry: resultMap.entrySet()) {
				System.out.println(entry.getKey() + " " + entry.getValue());
			}
		}

	}

	public static Map<Integer, Integer> checkZero(String readLine) {
		Map<Integer, Integer> checkZeroResult = new LinkedHashMap<>();

		String[] inputStr = readLine.split(" ");
		int[] inputInt = new int[inputStr.length];
		for (int i = 0; i < inputInt.length; i++) {
			inputInt[i] = Integer.parseInt(inputStr[i]);
		}
		// input number is both zero
		if (inputInt[0] == 0 && inputInt[1] == 0 ) {
			checkZeroResult = null;
		// other
		} else {
			// compare input number
			if (inputInt[0] > inputInt[1]) {
			  checkZeroResult.put(inputInt[1], inputInt[0]);
			} else {
			  checkZeroResult.put(inputInt[0], inputInt[1]);
			}
		}
		return checkZeroResult;
	}

}



Measured memory_bytes: 27692
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int a,b,k;
    cin >> a >> b >> k;
    vector<int> g;
    rep(i, min(a,b)) {
        if (a % (i + 1) == 0 && b % (i + 1) == 0) {
            g.push_back(i + 1);
        }
    }
    cout << g[g.size() - k];
}



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

using namespace std;

int main() {
	long long int N;
	cin >> N;
	vector<long long int>L( 2 * N );
	for( size_t i = 0; i < 2 * N; i++ ) {
		cin >> L[i];
	}
	sort( L.begin(), L.end() );
	long long int ans = 0;
	for( size_t i = 0; i < N; i ++ ) {
		ans += L[i * 2];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

// fmt.Scan is high cost
func main() {
	var sc = bufio.NewScanner(os.Stdin)
	buf := make([]byte, 1024)
	sc.Buffer(buf, 400000)
	var s string
	sc.Scan()
	s = sc.Text()
	a, z := -1, -1
	for i := 0; i < len(s); i++ {
		if a == -1 && s[i] == 'A' {
			a = i
		}
		if s[i] == 'Z' {
			z = i
		}
	}
	fmt.Println(z - a + 1)
}


Measured memory_bytes: 1280
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    
    int n ;
    cin >> n;
    cout << (n-30)/2 << endl;
    
    return 0;
}


Measured memory_bytes: 3108
#include <iostream>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  cout << ((n >= 15) ? (n * 800 - 200 * (n / 15)) : (800 * n)) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	
	int n; 
	cin>>n;
	if(n<1200)
		cout<<"ABC";
	if(n>=1200&&n<2800)	
		cout<<"ARC";
	if(n>=2800)	
		cout<<"AGC";	
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import itertools

N = int(input())
permutations = list(itertools.permutations(list(range(1, N+1))))
p = tuple(map(int, input().split(' ')))
q = tuple(map(int, input().split(' ')))
order = [-1] * 2
for i in range(len(permutations)):
    if p == permutations[i]:
        order[0] = i
    if q == permutations[i]:
        order[1] = i
ans = abs(order[1] - order[0])
print(ans)

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a[1000005];
int main(){

    int n, t;
    cin>>n>>t;
    for(int i=1; i<=n; i++) cin>>a[i];
    ll ans=0;
    for(int i=2; i<=n; i++){
        if(a[i]>=a[i-1]+t){
            ans+=t;
        }
        else{
            ans+=a[i]-a[i-1];
        }
    }
    cout<<ans+t;
    return 0;

}


Measured memory_bytes: 1792
package main

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

const size = 1000000
var reader = bufio.NewReaderSize(os.Stdin,size)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInts() (int,int) {
  var n,k int
  var s []string = strings.Split(NextLine()," ")
  n,_ = strconv.Atoi(s[0])
  k,_ = strconv.Atoi(s[1])
  return n,k
}
func NextIntArray() []int {
  var s []string = strings.Split(NextLine()," ")
  var n int = len(s)
  var a []int = make([]int,n)
  for i:=0;i<n;i++ {
    a[i],_ = strconv.Atoi(s[i])
  }
  return a
}

func main() {
  var n,k int = NextInts()
  var h []int = NextIntArray()
  var c []int = make([]int,n)
  var m int
  c[0] = 0
  for i:=1;i<n;i++ {
    m = 2000000000
    for j:=max(i-k,0);j<i;j++ {
      m = min(m,c[j]+abs(h[i]-h[j]))
    }
    c[i] = m
  }
  fmt.Println(c[n-1])
}
func abs(n int) int {
  if n < 0 { return -n }
  return n
}
func min(n int,m int) int {
  if n < m { return n }
  return m
}
func max(n int,m int) int {
  if n > m { return n }
  return m
}

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

int n;
string str;

int main(){
    cin>>n;
    cin>>str;
    if(n%2==1){
        cout<<"No"<<endl;
        return 0;
    }
    else{
        for(int i=0;i<n/2;i++){
            if(str[i]!=str[i+n/2]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// ABCテンプレート

#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;

int main() {
  ll N;
  cin >> N;
  ll a=sqrt(N);
  int nijou=0, ans=0;
  for(ll i=1; i<=a; i++){
    if(i*i<=N-1) nijou++;
  }
  for(ll i=1; i<=N-1; i++){
    ans += (N-1)/i;
  }
  cout << ans;
}


Measured memory_bytes: 3532
#include <iostream>
#include <vector>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "YES" << endl; exit(0); }
void no() { cout << "NO" << endl; exit(0); }

int main() {
    int n, k; cin >> n >> k;
    if(n >= 2 * k - 1) yes();
    no();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    string S;
    cin >> S;
    
    size_t size = S.size();
    int ox[10] = {};
    
    for(int i=0;i<size;i++){
        if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T'){
            ox[i] = 1;
        }else{
            ox[i] = 0;
        }
    }
    
    int count = 0;
    int maxcount = count;
    for(int i=1;i<=10;++i){
        if(ox[i] == ox[i-1] && ox[i] == 1){
            count++;
        }else{
            count = 0;
        }
        maxcount = max(count,maxcount);
    }
    int s = 0;
    for(int i=0;i<size;i++){
        s += ox[i];
    }
    if(s==0){
        cout << 0 << endl;
    }else{
        cout << maxcount+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, x, n) for(int i = x; i < (int)(n); i++)
#define ALL(n) begin(n), end(n)
//struct cww{cww(){ios::sync_with_stdio(false);cin.tie(nullptr);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;

int main() {
  int n;
  scanf("%d", &n);
  // n = 200000;

  vector<int> a(n + 1);
  vector<ll> b(n + 2);
  vector<ll> c(n + 2);
  vector<ll> d(n + 2);
  REP(i, n) {
    scanf("%d", &a[i]);
    // a[i] = n;
    b[a[i]]++;
    c[a[i]]++;
  }

  ll sum = 0;
  REP(i, n + 1) {
    if (b[i] >= 2) {
      b[i] = b[i] * (b[i] - 1) / 2;
    } else {
      b[i] = 0;
    }

    sum += b[i];

    if (c[i] >= 3) {
      c[i] = (c[i] - 1) * (c[i] - 2) / 2;
    } else {
      c[i] = 0;
    }
  }

  REP(i, n + 1) {
    d[i] = sum - b[i] + c[i];
  }

  REP(i, n) {
    printf("%lld\n", d[a[i]]);
  }

  return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

template <class T>
inline void read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

typedef long long LL;

LL x, ans, now = 100;

int main() {
    read(x);
    while (now < x) {
        now = now + now / 100;
        ++ans;
    }
    printf("%lld\n", ans);
    return 0;
}

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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

bool ok(int w,int n,const int* sum,int sp)
{
	//int n=sum.size()-1;
	
	//vi dp(n+1); dp[0]=1;
	static int dp[50001];
	dp[0]=1;
	
	int l=0,r=0,cnt=0;
	rep(i,n){
		for(;l<i;cnt-=!!dp[l++]) if(sum[i+1]-sum[l]+(i-l)<=w) break;
		for(;r<i;cnt+=!!dp[r++]) if(sum[i+1]-sum[r]+(i-r)*sp<w) break;
		dp[i+1]=!!cnt;
	}
	
	int res=dp[n];
	for(int i=n;i--;){
		if(sum[n]-sum[i]+(n-i-1)>w) break;
		res|=dp[i];
	}
	
	return res;
}

int main()
{
	for(int w,n;~scanf("%d%d",&w,&n) && w|n;){
		vi xs(n);
		rep(i,n) scanf("%d",&xs[i]);
		
		vi sum(n+1);
		rep(i,n) sum[i+1]=sum[i]+xs[i];
		
		int lo=1,hi=w;
		while(lo<hi){
			int mi=(lo+hi)/2;
			if(ok(w,n,sum.data(),mi))
				hi=mi;
			else
				lo=mi+1;
		}
		printf("%d\n",lo);
	}
}

Measured memory_bytes: 1612
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>

using namespace std;

int main(){
    int alice;
    int bob;
    cin>>alice;
    if(alice==1) alice=14;
    cin>>bob;
    if(bob==1) bob=14;
    if(alice>bob) cout<<"Alice"<<endl;
    else if(alice==bob) cout<<"Draw"<<endl;
    else cout<<"Bob"<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}


// end of Template
set <ll> s;
int n;
int main(){

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;
    for(int i=1;i<=n;i++){
        ll temp; cin>>temp;
        if(s.count(temp)){s.erase(temp);}
        else{s.insert(temp);}
    }
    cout<<s.size()<<newl;
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};

class UnionFind{
  public:
  vector<int> par;
  UnionFind(int size) : par(size,-1) {}
  bool unite(int x,int y){
    x = root(x),y = root(y);
    if(x == y)return false;
    if(par[y] < par[x])swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  bool find(int x,int y){
    return root(x) == root(y);
  }
  ll root(int x){
    return par[x] < 0 ? x : par[x] = root(par[x]);
  }
  ll size(int x){
    return -par[root(x)];
  }
};

int main(){

  ll n,m;
  cin >> n >> m;
  vector<P> v;
  REP(i,m){
    ll x,y;cin >> x >> y;
    x--,y--;
    v.push_back(make_pair(x,y));
  }
  reverse(ALL(v));
  UnionFind uf(n);
  vector<ll> res;
  const ll max = n*(n-1)/2;
  ll pre = 0;
  res.push_back(max);

  REP(i,m-1){
    ll fs = uf.size(v[i].first),ss = uf.size(v[i].second);
    bool flag = uf.find(v[i].first,v[i].second);
    uf.unite(v[i].first,v[i].second);
    if(fs == 1 && ss == 1){
      pre++;
      res.push_back(max-pre);
    }else if(fs > 1 && ss == 1){
      pre += fs;
      res.push_back(max-pre);
      
    }else if(fs == 1 && ss > 1){
      pre += ss;
      res.push_back(max-pre);
      
    }else{
      if(flag){
        res.push_back(max-pre);

      }else{
        pre = pre-1ll*fs*(fs-1)/2-1ll*ss*(ss-1)/2+1ll*(fs+ss)*(fs+ss-1)/2;
        res.push_back(max-pre);
        
      }
    }
    
  }
  reverse(ALL(res));
  REP(i,m){
    cout << res[i] << endl;
  }





  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    int n, l;
    cin >> n >> l;

    ll sum = 0;
    for (int i = 1; i <= n; ++i) {
        sum += l + i - 1;
    }

    ll max_v = INT_MAX;
    for (int i = 1; i <= n; ++i) {
        ll tmp = 0;
        for (int j = 1; j <= n; ++j) {
            if (i == j) continue;
            tmp += l + j - 1;
        }
        if (abs(sum - tmp) < abs(sum - max_v))
            max_v = tmp;
    }

    cout << max_v << endl;


    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.util.OptionalInt;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();

            int[] p = in.nextIntArray(n);
            int[] cnt = new int[3];
            for (int i = 0; i < n; i++) {
                if (p[i] <= a) {
                    cnt[0]++;
                } else if (p[i] <= b) {
                    cnt[1]++;
                } else {
                    cnt[2]++;
                }
            }

            out.println(IntStream.of(cnt).min().getAsInt());
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

    }
}



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

const ll int INF = 1e18 + 5;
const int maxint = 301;
double dp[maxint+1][maxint+1][maxint+1];

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[3] = {0};
    for(int i=0;i<n;i++){
    	int x;
    	cin>>x;
    	a[x-1]+=1;
    }
    // cout<<dp[0][0][0];
    double ans = 0;
	dp[a[0]][a[1]][a[2]] = 1;
	for(int k=n;k>=0;k--){
		for(int j=n;j>=0;j--){
			for(int i=n;i>=0;i--){
				int tot = i+j+k;
				if(tot == 0 || tot > n)
					continue;
				double mul = dp[i][j][k];
				double waste= (double)(((double)1-((double)tot)/((double)n)));
				ans += mul*waste/(1-waste);
				if(i>=1)
				dp[i-1][j][k] += ((double)i)/((double)tot)*mul;
				if(j>=1)
				dp[i+1][j-1][k] += ((double)j)/((double)tot)*mul;
				if(k>=1)
				dp[i][j+1][k-1] += ((double)k)/((double)tot)*mul;
			}
		}
	}
	// cout<<ans + a[0] + 2*a[1] + 3*a[2];
	printf("%.15lf\n", ans + a[0] + 2*a[1] + 3*a[2]);
	return 0;
}

Measured memory_bytes: 215424
#!/usr/bin/env python3


def solve(N, A, B, C):
    last = -1
    ans = 0
    for a in A:
        ans += B[a-1]
        if a == last+1:
            ans += C[last-1]
        last = a
    return ans


if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    ans = solve(N, A, B, C)

    print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>
#include <string.h>
#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}



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



long long mod = 1000000007;

typedef __int128 int128_t;

long long cnt[1000005];
int main(){
	//freopen("i.txt","r",stdin);
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	
	long long t1, t2, a1, a2, b1, b2;
	
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
	
	long long distA = t1 * a1 + t2 * a2;
	long long distB = t1 * b1 + t2 * b2;
	
	if(distA == distB){
		cout << "infinity";
		return 0;
	}
	if(distA > distB){
		swap(distA,distB);
		swap(a1,b1);
		swap(a2,b2);
	}
	
	long long gap = distB - distA;
	//cout << gap;
	if(a1 == b1){
		cout << "infinity";
		return 0;
	}
	if(a1 < b1){
		cout << 0;
		return 0;
	}
	long long low = 0;
	long long high = 102345678901234567;
	long long ans = 0;
	while(true){
		if(low == high - 1) break;
		
		int128_t s = (low + high) / 2;

		
		int128_t startA = 0;
		int128_t startB = s * gap;
		
		int128_t midA = t1 * a1;
		int128_t midB = (int128_t) t1 *  (int128_t) b1 + startB;
		
		//int128_t endA = t2 * a2;
		//int128_t endB = t2 * b2;
		//cout << (int)midA << " " << (int)midB;
		//cout << s << " " <<  midA << " " << midB << "\n";
		if(midA >= midB){
			low = s;
			//cout << "yes";
			if(midA == midB) ans--;
		}
		else{
			high = s;
		}
		//break;
	}
	
	ans += 2 * low + 1;
	
	
	cout << ans;
	
}


Measured memory_bytes: 256
<?php
class MatrixMultiplication
{
    public function __construct()
    {

    }

    public function get_input_matrix($row)
    {
        $matrix = [];
        for ($i = 0; $i < $row; $i++) {
            $matrix[] = explode(" ", trim(fgets(STDIN)));
        }
        return $matrix;
    }


    public function multiplication_matrixa_matrixb()
    {
        list($n,$m,$l) = explode(" ", trim(fgets(STDIN)));
        $matrix_a = $this->get_input_matrix($n);
        $matrix_b = $this->get_input_matrix($m);

        for ($i = 0; $i < $n; $i++) {
            for ($j = 0; $j < $l; $j++) {
                $matrix_ab[$i][$j] = 0;
                for ($k = 0; $k < $m; $k++) {
                    $matrix_ab[$i][$j] += $matrix_a[$i][$k] * $matrix_b[$k][$j];
                }
            }
        }

        foreach ($matrix_ab as $result) {
            echo implode(" ", $result) . PHP_EOL;
        }
    }
}

$calculator = new MatrixMultiplication();
$calculator->multiplication_matrixa_matrixb();



Measured memory_bytes: 14440
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-03 00:50:37
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int q; cin >> q;

  while (q--) {
    string s, t; cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (s[i] == t[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
        } else {
          dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
        }
      }
    }
    cout << dp[n][m] << '\n';
  };

  return 0;
}


Measured memory_bytes: 6912
#include <stdio.h>


int main()
{
	int H, W;
	int h, w;

	while (1) {
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0) break;
		for (h = 0; h < H; h++) {
			for (w = 0; w < W; w++) putchar('#');
			putchar('\n');
		}
		putchar('\n');
	}
	return 0;
}



Measured memory_bytes: 2108
//#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

ll gcd(ll a, ll b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}//GCD

ll lcm(ll a,ll b){
    if(a==0||b==0){
        return 0;
    }
    return a*b/gcd(a,b);
}

int main(){
    ll n;
    cin >> n;
    ll p=1,q=1;
    //cerr<<endl;
    //cerr<<endl;
    rep(i,n){
        ll t, a;
        cin >> t>>a;
        
        ll m=max((p-1)/t+1,(q-1)/a+1);
        p=t*m;q=a*m;
        
        //cerr<<p<<' '<<q<<endl;
    }
    cout<<p+q<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    int suma = 0, sumb = 0;
    rep(i, n) suma += a[i];
    rep(i, n) sumb += b[i];

    int sumA = 0;
    int ans = 0;
    rep(i, n)
    {
        ans = max(ans, a[i] + sumA + sumb);
        sumA += a[i];
        sumb -= b[i];
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
n = int(input())
d = list(map(int, input().split())) 
ans = int(0)
s = int(0)
for k in range(n):
    if k < n:
        for i in range(n-1):
            if k < i + 1:
                s=d[k]*d[i+1]
                ans += s
        k += 1
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#define min(a, b) ((a)<(b) ? (a) : (b))

int main(){
  int n, k;  scanf("%d %d", &n, &k);
  int sum = 0;
  for(int i=0; i<n; i++){
    int t;  scanf("%d", &t);
    sum = sum + min(t, k-t)*2;
  }
  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

template <typename T> inline void voutput(T &v){
    rep(i, v.size()){
        if (i) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    ll D;
    cin >> D;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    int Q;
    cin >> Q;
    vector<int> B(Q);
    rep(i, Q) cin >> B[i], B[i]--;
    
    vector<ll> P(N + 1);
    P[0] = D;
    rep(i, N){
        P[i + 1] = min(P[i], abs(P[i] - A[i]));
    }
    
//    voutput(P);
    
    vector<ll> pos(N + 1, 0);
    pos[N] = 0;
    
    ll p = 0;
    for(int i = N - 1; i >= 0; i--){
        if(p * 2 + 1 >= A[i]){
            p += A[i];
            pos[i] = p;
        }
        else{
            pos[i] = p;
        }
    }
    
//    voutput(pos);
    
    rep(i, Q){
        int ind = B[i];
        ll a = 0;
        if(ind > 0) a = P[ind - 1];
        ll dist = abs(D - a);
//        cout << "pos:" << abs(D - pos[ind + 1]) << endl;
        if(pos[ind + 1] >= P[ind]){
            output("NO");
        }
        else{
            output("YES");
        }
    }
    
    
    
    return 0;
}


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

int main(){
    int V, E;
    cin >> V >> E;
    vector<pair<int, int> > edge(E);
    for (int i = 0; i < E; i++) {
        cin >> edge[i].first >> edge[i].second;
    }
    vector<int> ans;
    vector<int> state(V, 1);
//0: edge[i].secondに載っているため設定できない
//1: 設定できる状態
//2: すでに設定済みなので除外

    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            if (state[i] != 2) state[i] = 1;
        }
        for (int i = 0; i < edge.size(); i++) {
            state[edge[i].second] = 0;
        }
        for (int i = 0; i < V; i++) {
            if (state[i] == 1) {
                ans.push_back(i);
                state[i] = 2;
                for (int j = 0; j < edge.size(); j++) {
                    if (edge[j].first == i) {
                        edge[j] = edge.back();
                        edge.pop_back();
                        j--;
                    }
                }
                break;
            }
        }
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 3376