akhauriyash/Code-Regression huggingface dataset:
#define rep(i, n) for(ll i = 0; i < n; i++)
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;

bool is_prime(ll n) {
	if (n==1) return false;
	else if (n==2) return true;
	else {
		ll p=2;
		while(p*p<=n) {
			if (n%p==0) return false;
			p++;
		}
		return true;
	}
}

int main() {
	ll q;
	cin >> q;
	vector<ll> p(100001,0);
	for(ll n=1;n<=100000;n++) {
		if (n%2 && is_prime(n) && is_prime((n+1)/2)) p[n]=1;
		else p[n] = 0;
	}
	vector<ll> num_p(100001,0);
	for(ll n=1;n<=100000;n++) {
		num_p[n] = num_p[n-1] + p[n];
	}
	rep(i,q) {
		ll l,r;
		cin >> l >> r;
		cout << num_p[r] - num_p[l-1] << endl;
	}
	return 0;
}


Measured memory_bytes: 2176
n=gets.to_i
a,b,array=[],[],[]
n.times do
c=gets.chomp
array<<c
a<<c.split('')[0]
b<<c.split('')[-1]
end
a.shift
b.pop
if a==b && array==array.uniq
puts 'Yes'
else
puts 'No'
end

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,d=0,m=0;
  string s,h,t;
  cin>>n>>s;
  for(auto c:s){
    d+=(c=='('?1:-1);
    m=min(m,d);
  }
  h=string(-m,'(');
  t=string(d-m,')');
  cout<<h+s+t;
}

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

long int totalAttack = 0;


void attackLoop(long int currentHP,long int loopCnt);

void attackLoop(long int currentHP,long int monstor){

    if(currentHP == 1){
       totalAttack += monstor;
       return; 
    }

    if(monstor > 0){
        totalAttack += monstor;
        attackLoop(currentHP/2 , monstor*2);
    }

}

int main() {
  long int HP,N;

  cin >> HP;

  attackLoop(HP,1);

  cout << totalAttack << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
x = []
y = []

for i in range(n):
    a = sorted(a,reverse = True)
    x.append(a[0])
    y.append(a[1])
    a[0],a[1] = 0,0

print(sum(x)-sum(y))

Measured memory_bytes: 3060
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


void solve(long long N, std::vector<long long> X){
    LL ans = 10e9;
    for(int p=1; p<=100; p++){
        LL cost=0;
        REP(i, N){
            cost+=(X[i]-p)*(X[i]-p);
        }
        ans=min(ans, cost);
        }
        cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> X(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
    }
    solve(N, std::move(X));
    return 0;
}


Measured memory_bytes: 256
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn bsearch(l: usize, r: usize, v: &Vec<u32>, a: u32) -> usize {
    if v[l] > a {
        return 0;
    }

    let ret: usize;
    if l + 1 >= r {
        ret = r;
    } else {
        let m = (l + r) / 2;
        if v[m] <= a {
            ret = bsearch(m, r, v, a);
        } else {
            ret = bsearch(l, m, v, a);
        }
    }
    ret
}

fn main() {
    let n: usize = read();
    let a: Vec<u32> = read_col(n);

    let mut v: Vec<u32> = vec![a[n - 1]];

    for i in (0..n - 1).rev() {
        let id = bsearch(0, v.len(), &v, a[i]);
        if id == v.len() {
            v.push(a[i]);
        } else {
            v[id] = a[i];
        }
    }

    println!("{}", v.len());
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;

int gcd(int n,int m)
{
  int r;
  if(n>m) swap(n,m);
  while((r=m%n)!=0)
  {
    m=n;
    n=r;
  }
  return n;
}

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

  int gcdl[n],gcdr[n];
  gcdl[0]=a[0],gcdr[n-1]=a[n-1];
  rep(i,n-1)
  {
    gcdl[i+1]=gcd(gcdl[i],a[i+1]);
  }
  rep(i,n-1)
  {
    gcdr[n-2-i]=gcd(gcdr[n-1-i],a[n-2-i]);
  }

  int maxi=0,cnt;
  rep(i,n)
  {
    //一つずつ変えてみる
    if(i==0)
    {
      cnt=gcdr[1];

      maxi=max(cnt,maxi);
    }
    else if(i==n-1)
    {
      cnt=gcdl[n-2];

      maxi=max(cnt,maxi);
    }
    else
    {
      cnt=gcd(gcdl[i-1],gcdr[i+1]);

      maxi=max(cnt,maxi);
    }
  }

  cout<<maxi<<endl;


}

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

int main() {
    int n;
    cin>>n;
    vector<long> a(n);
    long wa=0;
    long long ans=0;
    rep(i,n){
        cin>>a[i];
        ans=ans+a[i]*wa;
        wa+=a[i];
        ans%=1000000007L;
        wa%=1000000007L;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4748
import java.util.Scanner;

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

        int n = stdIn.nextInt();
        int[] a = new int[n];
        for(int i=1; i<n; i++){
            a[stdIn.nextInt() - 1]++;
        }

        for(int i=0; i<n; i++){
            System.out.println(a[i]);
        }
    }
}

Measured memory_bytes: 61996
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n, t) = get!(usize, usize);
    let ct = get!(usize, usize; n);
    let mut min = std::usize::MAX;
    for e in ct {
        if e.1 > t {
            continue;
        }
        if e.0 < min {
            min = e.0
        }
    }

    if min == std::usize::MAX {
        println!("TLE");
        return;
    }

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


Measured memory_bytes: 8572
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  ll x, a, b;
  cin >> x >> a >> b;
  a = -a;
  a += b;
  if(a <= 0) cout << "delicious";
  else if(a <= x) cout << "safe";
  else cout << "dangerous";
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    string a, b, c;
    cin >> a >> b >> c;
    cout << a.substr(0, 1) + b.substr(0, 1) + c.substr(0, 1) << endl;
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
card = {}
for i in range(N):
    s = input()
    if s in card:
        card[s] += 1
    else:
        card[s] = 1
M = int(input())
for i in range(M):
    t = input()
    if t in card:
        card[t] -= 1
ans = 0
for i in card:
    ans = max(ans, card[i])
print(ans)

Measured memory_bytes: 3064
def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

mod = 1000000007
H, W, K = map(int, input().split())
gh = gcd(H, K); rh = H // gh
gw = gcd(W, K); rw = W // gw
sub = pow(2, rh, mod) + pow(2, rw, mod) + pow(2, gcd(rh, rw), mod) - 3
ans = pow(sub, gh * gw, mod)
print(ans)

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int, int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n%2==1){
        cout << "No";
        return 0;
    }
    string t = "";
    for(int i = 0; i < s.length()/2; i++){
        t+=s[i];
    }
    string t1 = s.substr(s.size()/2, s.size()/2);
    if(t == t1){
        cout << "Yes";
        return 0;
    }
    else cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main()
{
  int a,b,c,d,e,x,z;
  cin>>a>>b>>c>>d>>e;
  z=a*e;
  if(e<=20){
    x=100;
  }
  else{
    if(c>e){
      x=b;
    }
    else{
      x=(e-c)*d+b;
    }
  }
  if(z<x){
    cout<<z<<"\n";
  }
  else{
    cout<<x<<"\n";
  }
  return(0);
}



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

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

    int n, r;
    cin >> n >> r;

    int ans = 0;
    if(n >= 10){
        ans = r;
    }else{
        ans = r + 100 * (10 - n);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// * refernce
//   * https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

use std::io;
use std::str;

fn main () {

    // STEP.01
    // create a new `String` instance to store the test data from standard input
    let mut buffer_stdin = String::new();

    // STEP.02
    // read a line from the standard input to get test data
    std::io::stdin().read_line(&mut buffer_stdin).unwrap();

    // STEP.03
    // split the stdin by spaces
    let mut test_data = buffer_stdin.split_whitespace();

    // STEP.04
    // read out the test data from the iterator
    let a: u32 = test_data.next().unwrap().parse().unwrap();
    let b: u32 = test_data.next().unwrap().parse().unwrap();

    println!( "{}", abc086_a(a, b) );

}

fn abc086_a (a: u32, b: u32) -> String {

    if is_even(a * b) { String::from("Even") }
    else              { String::from("Odd")  }

}

fn is_even (target: u32) -> bool {

    (target % 2) == 0

}

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

int main() {
    int S, M, s, m, h;
    cin >> S;
    s = S % 60;
    M = (S - s) / 60;
    m = M % 60;
    h = (M - m) / 60;
    cout << h << ':' << m << ':' << s << endl;
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;


int p, q, a, n;

int dfs(int p, int q, int x, int a_, int n_){
    if(ll(a_) * q > a) return 0;
    int ret = 0;
    if(p == 1 && q >= x) ret++;
    // cout << p << " " << q << " " << a << " " << a_ << endl;
    if(n_ >= n) return ret;
    if((n - n_ + 1) * q < p * x) return 0;
    for(ll i=x;i*a_<=a;i++){
        if(i*p > q){
            int np = i * p - q, nq = i * q;
            int div = __gcd(np, nq);
            np /= div;
            nq /= div;
            if(i*a_*nq <= a){
                ret += dfs(np, nq, i, i*a_, n_ + 1);
            }
        }
    }
    return ret;
}

int main(){
    while(true){
        cin >> p >> q >> a >> n;
        if(q == 0) break;
        int div = __gcd(p, q);
        cout << dfs(p / div, q / div, 1, 1, 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 3040
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

red = {}
for i in T:
    if i not in red:
        red[i] = 1
    else:
        red[i] += 1

blue = {}
for i in S:
    if i not in blue:
        blue[i] = 1
    else:
        blue[i] += 1

res = 0
for i in set(S):
    if i not in red:
        tmp = blue[i]
    else:
        tmp = blue[i] - red[i]

    if res < tmp:
        res = tmp

print(res)


Measured memory_bytes: 3064
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#define all(x) (x).begin(),(x).end()

void solve(){

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

    s[0] = '2';
    s[1] = '0';
    s[2] = '1';
    s[3] = '8';

    cout << s << endl;

}


Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/




int main() {
int N,Q;
cin>>N>>Q;
Graph G(N+1);
rep3(i,N-1){
  int a,b;
  cin>>a>>b;
  G[a].push_back(b);
  G[b].push_back(a);

}
ll counter[N+1];
rep3(i,N)counter[i]=0;
rep(i,Q){
  int p,x;
  cin>>p>>x;
  counter[p]+=x;

}

vector<int> seen(N+1, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    seen[1] = 0;
    que.push(1); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (seen[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            seen[nv] = 0;
            counter[nv]=counter[v]+counter[nv];
            que.push(nv);
        }
    }
    rep3(i,N){
      cout<<counter[i]<<endl;
      
    }

return 0;
}

Measured memory_bytes: 18136
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;


int main() 
{
    string s;
    cin >> s;
    int a[27] = {0};
    int cnt = 0;
    for(int i = 0; i< s.size(); i++){
        a[s[i]-'A']++;
    }
    for(int i = 0; i < 27; i++){
        if(a[i] == 2) cnt++;
    }
    if(cnt == 2){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
def main():
  import sys
  n = int(input())
  a = list(map(int,sys.stdin.readline().split()))
  b = list(map(int,sys.stdin.readline().split()))
  
  count=0
  
  for i in range(n):
    c1 = a[i] 
    c2 = a[i+1]
    h = b[i]
    count+=min(c1,h)  
    if h>c1:
        count+=min(h-c1,c2)
        a[i+1]=max(0,c2-(h-c1))
 
  print(count)
  
if __name__=="__main__":
  main()

Measured memory_bytes: 19228
#include<iostream>
using namespace std;
int n,m;
int d[1000];
main()
{
	while(cin>>n>>m,n)
	{
		for(int i=0;i<n;i++)d[i]=0;
		int cnt=0,pos=0;
		while(cnt<n)
		{
			int now=0;
			while(now<m)
			{
				if(!d[pos%n])now++;
				pos++;
			}
			d[(pos-1)%n]=1;
			cnt++;
		}
		cout<<(pos-1)%n+1<<endl;
	}
}



Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define INF 1000000000000000000
#define all(x) x.begin(), x.end()
#define PI 3.141592653589793

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> h(N);
    rep(i, N) { cin >> h[i]; }

    vector<ll> dp(N, INF);
    dp[0] = 0;
    rep(i, N) {
        for (int j = 1; j <= K && i + j < N; j++) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }

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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 200005

struct Info{
	int left,right;
};

int N;
int table[NUM];
map<int,int> MAP;
vector<int> V;
Info info[100005];

int main(){

	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		scanf("%d %d",&info[i].left,&info[i].right);
		V.push_back(info[i].left);
		V.push_back(info[i].right);
	}

	//座標圧縮
	sort(V.begin(),V.end());
	V.erase(unique(V.begin(),V.end()),V.end());

	for(int i = 0; i < V.size(); i++){

		MAP[V[i]] = i;
	}

	for(int i = 0; i < NUM; i++){

		table[i] = 0;
	}

	for(int i = 0; i < N; i++){

		table[MAP[info[i].left]]++;
		table[MAP[info[i].right]+1]--;
	}

	int ans = table[0];

	for(int i = 1; i < NUM; i++){

		table[i] += table[i-1];
		ans = max(ans,table[i]);
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 14752
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long int
#define ld long double
#define FOR(i,a,b) for (auto i = (a); i != (b); i = (a)<(b)? i+1 : i-1)
#define pb push_back
#define mod 1000000007
long long binpow(long long a, long long b, long long m=mod) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll dp[k+1]={0};
    ll ans=0;
    for(ll x=k;x>=1;x--)
    {   dp[x]=binpow((k/x),n);
        for(ll y=2*x;y<=k;y+=x)
        {
           dp[x]=(mod+dp[x]-dp[y])%mod;
        }
        ans+=dp[x]*x;
        ans%=mod;
    }
    cout<<ans;
}


Measured memory_bytes: 4428
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-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;}
 
vector<bool> seen;
vector<ll> ans ;
void dfs(const Graph &G, int v,vector<ll> &ans) {
    seen[v] = true; // v を訪問済にする
    
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        ans[next_v]= ans[v]+1 ;
        dfs(G, next_v,ans); // 再帰的に探索
    }
}

 int main(){
 ll n ; cin>> n ;
 Graph g(n) ;
 rep(i,n-1){
   ll a,b ;
   cin>>a>>b ;
   a--;b-- ;
  g[a].pb(b) ;
  g[b].pb(a) ;
 }

 vector<ll> x(n),y(n) ;
 seen.assign(n,false) ;
 dfs(g,0,x) ;
 seen.assign(n,false) ;
 dfs(g,n-1,y) ;
 ll cnt=0 ;
 rep(i,n){
   if(x[i]<=y[i]) cnt++ ;
   //cout<<x[i]<<" "<<y[i]<<endl ;
 }
 
 if(cnt>n-cnt) cout<<"Fennec"<<endl ;
 else cout<<"Snuke"<<endl ;
   return 0 ;
 }



Measured memory_bytes: 16452
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  string s;
  cin >> s;
  if(*s.rbegin() != 's') cout << s + "s" << endl;
  else cout << s + "es" << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll m,a;
  cin >> m;
  rep(p,m){
    vector<vector<ll>> v(5,vector<ll>(5));
    auto v2 = v;
    rep(i,5){
      rep(j,5){
        cin >> v[i][j];
      }
    }
    ll ans = 0;
    {
      stack<pll> st;
      rep(i,5){
        v2[0][i] = v[0][i];
        if(st.empty()){
          st.push(mp(v2[0][i],i));
        }
        else if(st.top().fi < v2[0][i]){
          st.push(mp(v2[0][i],i));
        }
        else if(st.top().fi > v2[0][i]){
          ll pos = i;
          while(!st.empty()){
            if(st.top().fi >= v2[0][i]){
              auto t = st.top();st.pop();
              ans = max(ans,t.fi * (i - t.se));
              pos = t.se;
            }
            else break;
          }
          st.push(mp(v2[0][i],pos));
        }
      }
      ans = max(ans,st.top().fi * (5 - st.top().se));
    }
    REP(j,1,5){
      stack<pll> st;
      rep(i,5){
        if(v[j][i]){
          v2[j][i] += v2[j-1][i] + 1;
        }
        if(st.empty()){
          st.push(mp(v2[j][i],i));
        }
        else if(st.top().fi < v2[j][i]){
          st.push(mp(v2[j][i],i));
        }
        else if(st.top().fi > v2[j][i]){
          ll pos = i;
          while(!st.empty()){
            if(st.top().fi >= v2[j][i]){
              auto t = st.top();st.pop();
              ans = max(ans,t.fi * (i - t.se));
              pos = t.se;
            }
            else break;
          }
          st.push(mp(v2[j][i],pos));
        }
      }
      while(!st.empty()){
        auto t = st.top();st.pop();
        ans = max(ans,t.fi * (5 - t.se));
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
struct UF {
  vector<long> pare, rank, mass;
  UF(long n) : pare(n), rank(n), mass(n){
    for(long i=0; i<n; i++){ pare[i]=i; rank[i]=0; mass[i]=1; }
  }
  long root(long x){ return (pare[x]==x)?x:pare[x]=root(pare[x]); }
  bool same(long x, long y){ return root(x)==root(y); }
  void marg(long x, long y){
    x=root(x); y=root(y); if(x==y) return;
    if(rank[x]<rank[y]){ pare[x]=y; }
    else{ pare[y]=x; if(rank[x]==rank[y]){rank[x]++;} }
    mass[x]=mass[y]=mass[x]+mass[y];
  }
  long weit(long x){ return mass[root(x)]; }
};

int main(){
long N, M, i; cin >> N >> M;
long A[M], B[M], ans[M]; ans[M-1]=N*(N-1)/2; 
for(i=0; i<M; i++){ cin >> A[i] >> B[i]; A[i]--; B[i]--; }
UF G(N);
for(i=M-1; i>0; i--){ 
  if(G.same(A[i], B[i])){ ans[i-1]=ans[i]; }
  else{ ans[i-1]=ans[i]-G.weit(A[i])*G.weit(B[i]); }
  G.marg(A[i], B[i]);
}
for(i=0; i<M; i++){ cout << ans[i] << " "; }
cout << "\n"; return 0;
}

Measured memory_bytes: 6016
// ref: https://qiita.com/drken/items/ace3142967c4f01d42e9, 1-3: DP

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N; cin >> N;
    vector<int> dp(N+1, INT_MAX); dp[0]=0;
    
    for(int n=0; n<=N; ++n){
        for(int pow6=1; n+pow6<=N; pow6*=6){ dp[n+pow6]=min(dp[n+pow6], dp[n]+1); }
        for(int pow9=1; n+pow9<=N; pow9*=9){ dp[n+pow9]=min(dp[n+pow9], dp[n]+1); }
    }
    
    cout << dp[N] << endl;
    
    return 0;
}

Measured memory_bytes: 640
import std.stdio,
       std.string,
       std.conv,
       std.algorithm,
       std.typecons,
       std.container;

void main() {
  int N = readln.chomp.to!int;
  Tuple!(int, int, bool)[] L;
  for (int i = 0; i < N; i++) {
    auto a = readln.chomp.split.to!(int[]);
    L ~= tuple(a[0], a[1], false);
  }
  for (int i = 0; i < N; i++) {
    auto a = readln.chomp.split.to!(int[]);
    L ~= tuple(a[0], a[1], true);
  }

  sort(L);

  auto s = new RedBlackTree!(Tuple!(int, int, bool));
  int ans;
  for (int i = 0; i < N * 2; i++) {
    if (L[i][2]) {
      Tuple!(int, int, bool) ma = tuple(int.min, int.min, false);
      bool f = false;
      foreach (Tuple!(int, int, bool) e; s) {
        if (L[i][0] > e[0] && L[i][1] > e[1]) {
          if (ma[1] < e[1]) {
            ma = tuple(e[0], e[1], false);
            f = true;
          }
        }
      }
      if (f) {
        s.removeKey(ma);
        ans++;
      }
    }
    else {
      s.insert(L[i]);
    }
  }

  writeln(ans);
}


Measured memory_bytes: 380
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException, NumberFormatException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		if( line != null ){
			int i = Integer.parseInt(line);
			System.out.println((int)Math.pow(i, 3));
		}
	}
}

Measured memory_bytes: 24216
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll N;
ll A[100000], B[100000];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    rep(i,0,N){
        cin>>A[i];
        B[i]=A[i];
    }
    sort(B,B+N);
    vector<ll> a,b;
    rep(i,0,N){
        if(i%2==1){
            a.pb(A[i]);
            b.pb(B[i]);
        }
    }
    map<ll,ll> x,y;
    for(ll c:a){
        x[c]++;
    }
    for(ll c:b){
        y[c]++;
    }
    ll ans=0;
    for(ll c :a){
        ans+=min(x[c], y[c]);
    }
    cout <<N/2-ans<<"\n";
}

Measured memory_bytes: 12020
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static System.Console;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		//int a = int.Parse(Console.ReadLine());
		// スペース区切りの整数の入力
		//string[] NMK = Console.ReadLine().Split(' ');
		//long N = long.Parse(NMK[0]);
		//long K = long.Parse(NMK[1]);
		string s = Console.ReadLine();

		if(s.Substring(2,1) == s.Substring(3,1) && s.Substring(4,1) == s.Substring(5,1))
			Console.WriteLine("Yes");
		else
			Console.WriteLine("No");

		// 文字列の入力
		//string s = Console.ReadLine();
		//出力
		//Console.WriteLine((a+b+c) + " " + s);
	}
}


Measured memory_bytes: 13140
n = int(input())
a = []
b = []
for _ in range(n):
    ae, be = map(int,input().split())
    a.append(ae)
    b.append(be)
a.sort()
b.sort()

center = n // 2
if n % 2 == 0:
    st = a[center] + a[center-1]
    en = b[center] + b[center-1]
    print(en-st+1)
else:
    print(b[center]-a[center]+1)


Measured memory_bytes: 25304
import java.util.Scanner;

public class Main {

	static int bmp(int x,int y){
		while(y > 0){
			int r = x % y;
			x = y;
			y = r;
		}
		return x;
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] gcd = in.nextLine().split(" ");
		int x = Integer.parseInt(gcd[0]);
		int y = Integer.parseInt(gcd[1]);
			if(x<y){
				int big = y;
				int small = x;
				System.out.println(bmp(big,small));
			}
			else{
				int big = x;
				int small = y;
				System.out.println(bmp(big,small));
			}
		}
}

Measured memory_bytes: 26156
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,K;
	ll V[101];
	ll Vr[101]={};
	vll Vsort;
	scan(N>>K);
	rep(i,N){
		scan(V[i]);
		Vr[i+1]=Vr[i]+V[i];
		Vsort.push_back(V[i]);
	}
	sort(Vsort.begin(),Vsort.end());
	ll ans=0;
	for(int tori=1;tori<=min(N,K);tori++){
		int modosu=K-tori;
		if(modosu<0) continue;
		for(int lt=0;lt<=tori;lt++){
			int rt=tori-lt;
			ll morau=Vr[lt]-Vr[0]+Vr[N]-Vr[N-rt];
			priority_queue<ll> Q;
			rep(i,N){
				if(i<lt||i>=N-rt){
					Q.push(-V[i]);
				}
			}
			ll kaesu=0;
			ll kaesumax=0;
			for(int i=0;i<modosu&&Q.size();i++){
				kaesu+=Q.top();
				Q.pop();
				kaesumax=max(kaesu,kaesumax);
			}
			ll kati;
			if(modosu>0) kati=morau+kaesumax;
			else kati=morau;
			ans=max(ans,kati);
			//printf("tori:%d modosu:%d lt:%d rt:%d morau:%lld kaesumax:%lld kati:%lld\n",tori,modosu,lt,rt,morau,kaesumax,kati);
		}
	}
	prin(ans);
	return 0;
}


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

// Loops
#define _overload3(_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 _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!

//

void solve(long long K, long long N, std::vector<long long> A) {
  ll ret = K-A[A.size()-1] + A[0];
  rep(i,1,N){
    ret = max(ret, A[i]-A[i-1]);
  }
  cout << K - ret << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  long long K;
  std::cin >> K;
  long long N;
  std::cin >> N;
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  solve(K, N, std::move(A));
  return 0;
}


Measured memory_bytes: 4752
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N = 3e5 + 7;

int32_t main(){
    IOS;
    int n;
     cin >> n;
    int max = 0;
    cin >> max;
    n--;
    int ans = 0;
    while(n--){
        int p;
        cin >> p;
        if(p < max) ans += (max-p);
        else max = p;
    }
    cout << ans << endl;
    return 0;
}



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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long N;
    cin >> N;
    vector<long long> A(N+4,0);
    vector<long long> DP(N+4);
    for (long long i = 0; i<N; ++i) cin >> A[i];
    DP[0] = 0;
    DP[1] = abs(A[0]-A[1]);
    if (N==2) cout << DP[1];
    else {
        DP[2] = min(  abs(A[0]-A[1])  ,  min(  abs(A[0]-A[2]) , abs(A[0]-A[1])+abs(A[1]-A[2]) ) );
        for (long long i = 2,total=0; i<N; ++i) {
            DP[i] = min(abs(A[i]-A[i-1])+DP[i-1],abs(A[i]-A[i-2])+DP[i-2]);
        }
        cout << DP[N-1];
    }
    
}

Measured memory_bytes: 4784
#include<iostream>
using namespace std;
 
struct pro{
  string str;
  int time;
};
 
  pro que[100000];
int head,tail,leng=100000;
 
int isEmpty(){
  return head==tail;
}
 
void enqueue(pro x){
  que[tail]=x;
  if(tail+1==leng) tail=0;
  else tail++;
}
 
pro dequeue(){
  pro x;
  x=que[head];
  if(head+1==leng) head=0;
  else head++;
  return x;
}
 
int main(){
  pro x;
  int n,q,cnt=0;
  cin>>n>>q;
  pro scn;
  for(int i=0;i<n;i++){
 cin>>scn.str>>scn.time;
 enqueue(scn);
  }
  while(!isEmpty()){
    x=dequeue();
    if(x.time>q)cnt+=q,x.time-=q,enqueue(x);
       else{
 cnt+=x.time;
 cout<<x.str<<" "<<cnt<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 7072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
// verified  http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4248412#1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <typename Monoid>
struct SegmentTree
{
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1)
    {
        sz = 1;
        while (sz < n)
            sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x)
    {
        seg[k + sz] = x;
    }

    void build()
    {
        for (int k = sz - 1; k > 0; k--)
        {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    void update(int k, const Monoid &x)
    {
        k += sz;
        seg[k] = x;
        while (k >>= 1)
        {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    Monoid query(int a, int b)
    {
        Monoid L = M1, R = M1;
        for (a += sz, b += sz; a < b; a >>= 1, b >>= 1)
        {
            if (a & 1)
                L = f(L, seg[a++]);
            if (b & 1)
                R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const
    {
        return seg[k + sz];
    }
};
//　ここに関数を書く
ll f(ll a, ll b)
{
    return a+b;
}
SegmentTree<ll> seg(500, f, 0);
ll dp[500][500];
ll rec(int l,int r){
    ll s = seg.query(l, r);
    if(dp[l][r]>=0){
        return dp[l][r];
    }
    if(r-l<=2){
        return dp[l][r] = s;
    }
    else{
        ll mn = 1e18;
        for(int i = l+1;i<r;i++){
            mn = min(mn,rec(l,i)+rec(i,r));
        }
        return dp[l][r] = mn+s;
    }
}
int main()
{
    rep(i,500){
        rep(j,500){
            dp[i][j] = -1;
        }
    }
    ll n;
    cin >> n;
    // 初期化　　　　　ノード数　関数　初期値
    rep(i,n){
        int x;
        cin >>x;
        seg.set(i,x);
        dp[i][i+1] = 0; 
    }
    seg.build();
    cout << rec(0,n)<< endl;
    return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int N;
	cin>>N;
	
	for(int i=0;i<N;i++){
		char c;
		cin>>c;
		if(c=='Y'){
			cout<<"Four"<<endl;
			return 0;
		}
	}
	
	cout<<"Three"<<endl;
	
		
    return 0;
}


Measured memory_bytes: 256
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

A, B = map(int, input().split())
n = 0
i = A
while i <= B:
    L = list(str(i))
    if L[0] == L[4] and L[1] == L[3]:
        n += 1
    i += 1
print(n)


Measured memory_bytes: 9172
k=int(input())
a=(1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51)
print(a[k-1])

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr front()
#define tp top()
typedef long long int ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <pii, int> ppi;
typedef pair <int, pii> pip;
#define iofast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define iofile freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
const ll LLINF = 9e18;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1);
const int SIZE = 100005;

int N, W;
pii A[111];
ll dp[SIZE];

int main (){
	
	for(int i=0;i<SIZE;i++){
		dp[i]=-1;
	}
	dp[0]=0;
	
	scanf("%d %d", &N, &W);
	for(int i=0;i<N;i++){
		scanf("%d %d", &A[i].fi, &A[i].se);
		for(int j=W;j>=A[i].fi;j--){
			dp[j]=max(dp[j],dp[j-A[i].fi]+A[i].se);
		}
	}
	ll ans=0;
	for(int i=0;i<=W;i++){
		ans=max(ans,dp[i]);
	}
	printf("%lld\n", ans);
	
	return 0;
}

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

int main() {
    int A[3];
    cin >> A[0] >> A[1] >> A[2];
    sort(A, A+3);
    if(A[0] == A[1] && A[0] != A[2] || A[1] == A[2] && A[0] != A[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int A,B,C;
	
	scanf("%d %d %d",&A,&B,&C);
	
	if(A<C && C<B ){
		printf("Yes");
	}else if(B<C && C<A ){
		printf("Yes");
	}else{
		printf("No");
	}
	
	return 0;
}







Measured memory_bytes: 128
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

int n,m;
vector<int> edge[1000000];
int color[1000000];


void dfs(int s){
  color[s] = 1;
  for(int i=0;i<edge[s].size();i++){
    int t = edge[s][i];
    if(color[t] == 0){
      color[t] = 1;
      dfs(t);
    }
  }
  return;
}

int main(){
  cin >> n >> m;
  int x,y,z;
  for(int i=0;i<m;i++){
    cin >> x >> y >> z;
    edge[x-1].push_back(y-1);
    edge[y-1].push_back(x-1);
  }
  int ans = 0;
  for(int i=0;i<n;i++){
    if(color[i] == 0){
      dfs(i);
      ans += 1;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 32256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define frfr  freopen("input.text","r",stdin); freopen("output.text","w",stdout)
#define ll long long int
#define wh int T;cin >> T;while(T--)
#define pb push_back
#define loop(i,a,b) for (int i = a; i < n; i++)
int main(){
  //frfr;
  int t ;
  cin >> t;
  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re= 0;
    string str[t];
    for(int i=0;i<t;i++){
      cin >> str[i] ;
      if(str[i][0] == 'A' && str[i][1] == 'C'  ){
        ac++;
      }else if(str[i][0] == 'W' && str[i][1] == 'A'  ){
        wa++;
      }else if(str[i][0] == 'R' && str[i][1] == 'E'  ){
        re++;
      }else if(str[i][0] == 'T' && str[i][1] == 'L'  && str[i][2] == 'E'){
        tle++;
      }
    }
  
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  return 0;
}


Measured memory_bytes: 6756
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        String T = sc.next();
        StringBuilder bld = new StringBuilder();
        for(int i=0;i<N*2;i++){
            if(i % 2 == 0){
                bld.append(S.charAt(i/2));
            }else{
                bld.append(T.charAt(i/2));
            }
        }
        System.out.println(bld.toString());
    }
}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int ans = 0, b = 0, ab = 0, a = 0;
    int n;
    cin >> n;
    for (int _ = 0; _ < n; _++) {
        string s;
        cin >> s;
        if (s[0] == 'B' && s.back() == 'A') {
            ab++;
        } else if (s[0] == 'B') {
            b++;
        } else if (s.back() == 'A'){
            a++;
        }
        for (int i = 0; i < sz(s) - 1; i++) {
            if (s[i] == 'A' && s[i + 1] == 'B') {
                ans++;
            }
        }
    }
    if (ab > 0) {
        ans += ab - 1;
        if (b > 0) {
            ans++;
            b--;
        }
        if (a > 0) {
            ans++;
            a--;
        }
    }
    ans += min(a, b);
    cout << ans << "\n";
}
    

Measured memory_bytes: 256