akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cmath>

using namespace std;

#define in(x) cin >> x
#define out(x) cout << x << endl

#define PI acos(-1)
#define pp push_back

#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl

#define vec2(type) vector<vector<type>>
#define vec3(type) vector<vector<vector<type>>>

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

template<typename T> void sort(vector<T> &ary){
	sort(ary.begin(), ary.end());
}

template<typename T> void rsort(vector<T> &ary){
	sort(ary.rbegin(), ary.rend());
}

void rstring(string &str){
	string temp = str;

	For(i, (int)str.size()){
		str[i] = temp[(str.size() - 1) - i];
	}
}

int main(){

	int n, t, a, h, plc = 0;
	int x = 1000000;

	in(n), in(t), in(a);

	For(i, n){
		in(h);
		if(abs(t - h * 0.006 - a) < abs(t - x * 0.006 - a)){
			x = h;
			plc = i + 1;
		}
	}

	out(plc);

	return 0;
}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n=int(input())
sum=0
for i in range(n+1):
    if i%2!=0:
        if len(make_divisors(i))==8:
            sum+=1
print(sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<string> S(n); rep(i, n) cin >> S[i];
  vector<pair<int, int>> p1, p2, p3, p4;
  rep(i, n) {
    int mn = 0;
    int sum = 0;
    for(char c: S[i]) {
      sum += (c=='(' ? 1 : -1);
      chmin(mn, sum);
    }
    if(mn >= 0 && sum >= 0) p1.push_back({mn, sum});
    else if(mn < 0 && sum >= 0) p2.push_back({mn, sum});
    else if(mn == sum) p3.push_back({0, -sum});
    else p4.push_back({mn-sum, -sum});
  }
  ll tmp1 = 0;
  for(auto p: p1) tmp1 += p.second;
  sort(all(p2), greater<pair<int, int>>());
  for(auto p: p2) {
    if(tmp1+p.first < 0) {
      cout << "No" << endk;
      return 0;
    }
    tmp1 += p.second;
  }
  ll tmp2 = 0;
  for(auto p: p3) tmp2 += p.second;
  sort(all(p4), greater<pair<int, int>>());
  for(auto p: p4) {
    if(tmp2+p.first < 0) {
      cout << "No" << endk;
      return 0;
    }
    tmp2 += p.second;
  }
  cout << (tmp1 == tmp2 ? "Yes" : "No") << endk;
  return 0;
}


Measured memory_bytes: 42452
// 選択ソート

#include <iostream>
using namespace std;

int selectionSort(int A[], int N);

int main()
{
    int N, A[100], sw;

    cin >> N;
    for (int i=0; i<N; i++) cin >> A[i];

    sw = selectionSort(A, N);

    for (int i=0; i<N; i++) {
        if (i) cout << ' ';
        cout << A[i];
    }
    cout << '\n' << sw << '\n';
    return 0;
}

int selectionSort(int A[], int N)
{
    int sw = 0;
    for (int i=0; i<N; i++) {
        int minj = i;  // i番目に小さい数のインデックス？
        for (int j=i; j<N; j++) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }
        swap(A[i], A[minj]);
        if (i!=minj) sw++;
    }
    return sw;
}


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

using namespace std;

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

#define TT template<typename T>
TT T    sq(T x){ return x*x; }
TT int  ubnd(vector<T>& v,T x){ return upper_bound(v.begin(), v.end(), x) - v.begin(); }
TT int  lbnd(vector<T>& v,T x){ return lower_bound(v.begin(), v.end(), x) - v.begin(); }
TT void sort(T& v){ sort(v.begin(), v.end()); }
TT void revs(T& v){ reverse(v.begin(), v.end()); }
TT void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TT void show(T& v,char d=' ',char e='\n'){for(int i=0;i<v.size();++i)cout<<v[i]<<((i==v.size()-1)?e:d);}
TT void inpt(vector<T>& v,int n){ v.reserve(n);for(int i=0;i<n;++i){T x; cin>>x; v.push_back(x);} }
TT T In(){ T x; cin >> x; return x; }

static inline void fast_io(){ ios::sync_with_stdio(0); cin.tie(0); }
static inline int in(){ int x; scanf("%d", &x); return x; }
static inline string instr(){ string x; cin >> x; return x; }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};

int main()
{
  string s;
  cin >> s;
  int bucket[256] = {};
  for (int i = 0; i < s.size(); i++) bucket[s[i]]++;
  printf("%d\n", min(bucket['K'], min(bucket['U'], min(bucket['P'], bucket['C']))));

  return (0);
}

Measured memory_bytes: 1184
x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
if x in a and y in a:
	print("Yes")
elif x in b and y in b:
	print("Yes")
else:
	print("No")


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

using namespace std;

int ok[10] = { 0 };

bool judge(int i)
{
	while (i != 0) {
		if (ok[i%10] == 1) {
			return false;
		}
		i /= 10;
	}
	return true;
}

int main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		int in;
		cin >> in;
		ok[in] = 1;
	}
	for (int i = n; i < 99999; i++) {
		if (judge(i)) {
			cout << i << endl;
			return 0;
		}
	}

}

Measured memory_bytes: 256
from functools import lru_cache
T = int(input())
for _ in range(T):
    @lru_cache(maxsize=None)
    def f(n):
        if n == 0:
            return 0
        if n == 1:
            return D
        if n == 2:
            return min(2*D, A+D)
        temp = [D * n]
        d = n % 2
        temp.append(f(n // 2) + A + D * d)
        temp.append(f(n // 2 + 1) + A + D * (2-d))
        d = n % 3
        temp.append(f(n // 3) + B + D * d)
        temp.append(f(n // 3 + 1) + B + D * (3-d))
        d = n % 5
        temp.append(f(n // 5) + C + D * d)
        temp.append(f(n // 5 + 1) + C + D * (5-d))
        return min(temp)
    N, A, B, C, D = map(int, input().split())
    print(f(N))


Measured memory_bytes: 11636
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>
#include <queue>
#include <bitset>
#include <sstream>
using namespace std;
typedef long long ll;

bool Check(string &L, int s, int g){
        s--;
        g--;
        bool ans=true;
        for(int i=s+1; i < g-1; i++){
                if(L[i] == '#' && L[i-1] == '#') ans = false;
        }
        return ans;
}


bool Check2(string &L, int s, int g){
        s--;
        g--;
        bool ans=false;
        for(int i=s+1; i < g+2; i++){
                if(L[i] == '.' && L[i-1] == '.' && L[i-2] == '.') ans = true;
        }
        return ans;
}

int main(){
        int N,a, b, c, d, a1;
        cin >> N >> a >> b >> c >> d;
        string S;
        cin >> S;
        if(a > b){
                a1 = a;
                a = b;
                b = a1;
                a1 = c;
                c = d;
                d = a1;
        }

        if(b < c && c < d){
                if(Check(S, a, d)) cout << "Yes";
                else cout << "No";
        }
        else if(d < c){
                if(Check(S, a, c) && Check2(S, b, d)) cout << "Yes";
                else cout << "No";
        }
        else{
                if(Check(S, a, c) && Check(S, b, d)) cout << "Yes";
                else cout << "No";
        }


}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
class Item {
public:
	int w, v;
	bool operator<(const Item &other) {
		return w > other.w;
	}
};
signed main() {
	int N, W; cin >> N >> W;
	vector<int>v(N + 1), w(N + 1);
	rep(i, 1, N + 1)cin >> v[i] >> w[i];
	vector<int>dp(W + 1, 0);
	rep(i, 1, N + 1)rep(j, w[i], W + 1) {
		dp[j] = max(dp[j - w[i]] + v[i], dp[j]);
	}
	cout << dp[W] << endl;
	return 0;
}

Measured memory_bytes: 3136
import java.util.Scanner;

class Main{
	public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			
				if(a < b && b < c){ System.out.println("Yes");
				}
				
				else{ System.out.println("No");
				}
	}
}


Measured memory_bytes: 26268
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
  int d,i,j,k;
  cin >> d;
  double a[1000]={},b[1000]={};
  for(i=0;i<d;i++) cin >> a[i];
  for(i=0;i<d;i++) cin >> b[i];
  double o1=0,o2=0,o3=0,oe=0;
  for(i=0;i<d;i++){
    o1+=fabs(a[i]-b[i]);
    o2+=fabs(a[i]-b[i])*fabs(a[i]-b[i]);
    o3+=fabs(a[i]-b[i])*fabs(a[i]-b[i])*fabs(a[i]-b[i]);
    oe=max(oe,fabs(a[i]-b[i]));
  }
  printf("%.6f\n",o1);
  printf("%.6f\n",sqrt(o2));
  printf("%.6f\n",pow(o3,1.0/3.0));
  printf("%.6f\n",oe);
  return 0;
}

Measured memory_bytes: 1300
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: i64 = 1_000_000_007;

pub fn pow(x: i64, n: i64) -> i64 {
    let (mut x, mut y, mut n) = (x % P, 1_i64, n);
    while n > 0 {
        if n % 2 != 0 {
            y = (y * x) % P;
            n -= 1;
        }

        x = (x * x) % P;
        n /= 2;
    }
    y
}

fn main() {
    let (n, k) = read!(usize, usize);
    let M = n * 2;

    let mut fact = vec![0; M];
    fact[0] = 1_i64;
    fact[1] = 1;
    for i in 2..M {
        fact[i] = (i as i64) * fact[i - 1] % P;
    }

    let mut fact_inv = vec![0; M];
    fact_inv[M - 1] = pow(fact[M - 1], P - 2);

    for i in (1..M).rev() {
        fact_inv[i - 1] = (i as i64) * fact_inv[i] % P;
    }

    let mut s = 0;

    for z in 0..min(n, k + 1) {
        // C(n, z) * (z + (n - z - 1))! / z! * (n - z - 1)!)
        let mut c = fact[n];
        c *= fact_inv[z];
        c %= P;
        c *= fact_inv[n - z];
        c %= P;

        let mut t = c;
        t *= fact[z + (n - z - 1)];
        t %= P;
        t *= fact_inv[z];
        t %= P;
        t *= fact_inv[n - z - 1];
        t %= P;

        s += t;
        s %= P;
    }

    println!("{}", s)
}


Measured memory_bytes: 12540
n=int(input())
a=list(map(int,input().split()))
if n==0 and a[0]==1:
	print(1)
elif n==0:
	print(-1)
elif a[0]!=0:
	print(-1)
else:
	ruisekiwa = [0 for _ in range(n+1)]
	ruisekiwa[n] = a[n]
	for i in range(n)[::-1]:
		ruisekiwa[i] = a[i] + ruisekiwa[i+1]
	cnt=1
	ans=1
	for i in range(1,n+1):
		target = a[i]
		if cnt*2 - target <= 0 and i != n:
			print(-1)
			exit()
		elif i == n:
			if cnt * 2 - target < 0:
				print(-1)
				exit()
			else:
				ans += target
		else:
			if cnt*2 < ruisekiwa[i]:
				ans += cnt*2
				cnt = cnt*2-a[i]
			else:
				ans += ruisekiwa[i]
				cnt = ruisekiwa[i]
	print(ans)

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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

void megaRandom() {
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  srand(FOR);
}

string s;

int main() {
	megaRandom();
	cin >> s;
	int res = inf;
	for(int i = 'a'; i <= 'z'; i ++) {
		int prv = -1, mx = 0;
		for(int j = 0; j < sz(s); j ++) {
			if(s[j] == i) {
				mx = max(mx, j - prv - 1);
				prv = j;
			}
		}
		mx = max(mx, sz(s) - 1 - prv);
		//cout << "i: " << (char)i << " mx: " << mx << "\n";
		res = min(res, mx);
	}
	cout << res;
	return 0;         
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dx[4] = {0,-1,0,1};
int dy[4] = {-1,0,1,0};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, n;
    set<int> p_set;
    cin >> x >> n;
    rep(i, n) {
      int p;
      cin >> p;
      p_set.insert(p);
    }
    rep(i, 101) {
      if (p_set.find(x - i) == p_set.end()) {
        cout << x - i << endl;
        break;
      }
      if (p_set.find(x + i) == p_set.end()) {
        cout << x + i << endl;
        break;
      }
    }

}

Measured memory_bytes: 3644
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	if b/a >= c {
		fmt.Println(c)
	} else if b/a < c {
		fmt.Println(int(b / a))
	} else if a > b {
		fmt.Println(0)
	}
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

const int MAX_H = 105;
const int MAX_W = 105;
char D[MAX_H][MAX_W];

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

void dfs(char c, int y, int x, int w, int h) {
  for (int k = 0; k < 4; k++) {
    int x2 = x + dx[k];
    int y2 = y + dy[k];
    if (0 <= x2 && x2 < w && 0 <= y2 && y2 < h && c == D[y2][x2]) {
      D[y2][x2] = '.';
      dfs(c, y2, x2, w, h);
    }
  }
}

int main() {
  int H, W;

  while (true) {
    cin >> H >> W;
    if (H == 0 && W == 0) break;

    for (int i = 0; i < H; i++) {
      string s;
      cin >> s;
      for (int j = 0; j < W; j++) {
        D[i][j] = s[j];
      }
    }

    int res = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        char c = D[i][j];
        if (c != '.') {
          dfs(c, i, j, W, H);
          res++;
        }
      }
    }

    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 3968
#include <cstring>
#include <cstdio>
int arr[200005]; 
bool val[200005]; 
int main()
{
	// freopen("AGC006-D.in", "r", stdin); 
	int n; 
	scanf("%d", &n); 
	int len = (n << 1) - 1; 
	for (int i = 0; i < len; i++)
		scanf("%d", arr + i); 
	int l = 1, r = 2e5, ans = -1; 
	while (l <= r)
	{
		int m = l + r >> 1, res = -1; 
		memset(val, 0, sizeof(val)); 
		for (int i = 1; i < len; i++)
		{
			if ((arr[i] < m) == (arr[i - 1] < m))
				val[i - 1] = val[i] = true; 
		}
		for (int i = n - 1, j = n - 1; i >= 0 && -1 == res; i--, j++)
		{
			if (val[i])
				res = arr[i] >= m; 
			if (val[j])
				res = arr[j] >= m; 
		}
		if (-1 == res)
			res = arr[0] >= m; 
		if (res)
		{
			ans = m; 
			l = m + 1; 
		}
		else
			r = m - 1; 
	}
	printf("%d\n", ans);
	return 0; 
}


Measured memory_bytes: 1152
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_093_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(4).
    01 maxlen PIC 9(1)  VALUE 3.
    01 cur    PIC 9(1)  VALUE 1.

    01 len    PIC 9(1)  VALUE 1.

    01 ABC1.
        03 ABC11 OCCURS 3.
            05 ABC PIC 9(1) VALUE 0.
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    PERFORM maxlen TIMES

        IF INP(cur:len) = 'a' THEN
            MOVE 1 TO ABC(1)
        ELSE
            IF INP(cur:len) = 'b' THEN
                MOVE 1 TO ABC(2)
            ELSE
                MOVE 1 TO ABC(3)
            END-IF
        END-IF

        COMPUTE cur = cur + 1

    END-PERFORM.

    IF ABC(1) = 1 AND ABC(2) = 1 AND ABC(3) = 1 THEN
        DISPLAY "Yes"
    ELSE
        DISPLAY "No"
    END-IF.

    STOP RUN.


Measured memory_bytes: 764
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>
#include <limits.h>
#include <iomanip>
#include <stack>

using namespace std;
using namespace boost::multiprecision;
typedef pair<int, int> pii;

class segmentTreeElement {
public:
	pii ele;
	segmentTreeElement(pii a) :ele(a) {};
	segmentTreeElement() :ele(pii(INT_MAX,0)) {};
};

segmentTreeElement operator*(segmentTreeElement& a, segmentTreeElement& b) {
	if (a.ele.first < b.ele.first)return a;
	else return b;
}

class segTree {
public:
	long long N;   //中身のある要素数
	long long RN;   //2の累乗数にするために合わせた、ゴミデータ含めた要素数
	vector<segmentTreeElement>* array;
	//コンストラクタ:要素数、初期化用の数
	segTree(long long n) {
		N = n;
		RN = 1;
		while (RN < N)RN *= 2;
		array = new vector<segmentTreeElement>;
		array->resize(2 * RN - 1, segmentTreeElement());
	}
	~segTree() {
		delete array;
	}
	void set(int n, segmentTreeElement t) {   //n番目の要素にtを設定
		n = RN + n - 1;
		array->at(n) = t;
		while (n > 0) {
			n = (n - 1) / 2;
			array->at(n) = array->at(2 * n + 1)*array->at(2 * n + 2);
		}
	}
	inline segmentTreeElement& operator[](int a) {
		return array->at(RN + a - 1);
	}
	inline segmentTreeElement get(int a, int b) {
		segmentTreeElement vl = segmentTreeElement(),
			vr = segmentTreeElement();
		for (int l = a + RN, r = b + RN; l < r; l >>= 1, r >>= 1) {
			if (l & 1) vl = vl * array->at((l++) - 1);
			if (r & 1) vr = array->at((--r) - 1)*vr;
		}
		return vl * vr;
	}
};

int N;
vector<vector<int>> edges;
vector<int> C;
vector<int> ans;

void solve() {
	cin >> N;
	edges.resize(N);
	segTree seg(N);
	for (int n = 0; n < N-1; n++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	C.resize(N);
	ans.resize(N);
	for (int n = 0; n < N; n++) {
		int c;
		cin >> c;
		C[n] = c;
	}
	sort(C.begin(), C.end());
	for (int n = 0; n < N; n++) {
		seg.set(n, segmentTreeElement(pii(edges[n].size(), n)));
	}
	long long sum = 0;
	for (int n = 0; n < N; n++) {
		pii cur = seg.get(0, N).ele;   //残っているものの中で入出時数最小
		sum += C[n] * cur.first;
		ans[cur.second] = C[n];
		seg.set(cur.second, segmentTreeElement(pii(INT_MAX, cur.second)));
		for (auto itr = edges[cur.second].begin(); itr != edges[cur.second].end(); itr++) {
			if (seg[*itr].ele.first == INT_MAX)continue;   //消去済み
			segmentTreeElement next = seg[*itr];
			next.ele.first--;
			seg.set(*itr,next);
		}
	}
	cout << sum << endl;
	for (int n = 0; n < N; n++)cout << ans[n] << endl;
	return;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define log(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  string s,t;cin>>s>>t;
  if(t.substr(0,t.size()-1) == s)print("Yes");
  else print("No");
  
  return 0; 
}


Measured memory_bytes: 3652
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m = map(int,input().split())
CD = [tuple(map(int,input().split())) for i in range(n)]
AB = [tuple(map(int,input().split())) for i in range(m)]
for c,d in CD:
  print(min(range(m),key = lambda x:abs(AB[x][0]-c) + abs(AB[x][1]-d))+1)



Measured memory_bytes: 3316
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<ii, ii>> vii;

const int N = 1e5 + 5 , MOD = 1e9 + 7;
long long fact[N] , fact_inv[N];

long long mul(long long a , long long b) {
    return (a + MOD) * b % MOD;
}

long long power(long long a , long long b) {
    if (!b) return 1;
    long long r = power(a , b / 2);
    r = mul(r , r);
    if (b&1) return mul(r , a);
    return r;
}

long long mod_inv(long long x) {
    return power(x , MOD - 2);
}

long long nCr(long long n , long long r){
    if (!n) return !r;
    if(r>n) return  0;
    return mul(fact[n] , mul(fact_inv[n - r] , fact_inv[r]));
}

void pre() {
    fact[0] = fact_inv[0] = 1;
    for(int i = 1 ; i < N ;i++) {
        fact[i] = mul(fact[i - 1] , i);
        fact_inv[i] = mod_inv(fact[i]);
    }
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    pre();
    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for (int &x : arr)
        cin >> x;
    sort(arr.begin(), arr.end());

    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        if (i + 1 >= k) {
            ans += mul(arr[i], nCr(i, i + 1 - k));
            ans %= MOD;
        }
        if (n - i + 1 >= k) {
            ans += mul(-arr[i], nCr(n - i - 1, k - 1));
            ans %= MOD;
        }
    }

    cout << ans << '\n';


    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
     
int main() {
    int   A,B,C;
    cin >> A >> B >> C;

    int KAISUU = B/A;
    if (KAISUU <= C){
      cout << KAISUU << endl;
    }
    else if (C < KAISUU){
      cout << C << endl;
    }
          
}

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

int winner;
string s;
int main(){
    cin>>s;
    if(s[0]==s[s.length()-1]){
        if(s.length()%2==1)
           winner = 2;
        else
            winner = 1;
    }
    else{
        if(s.length()%2==0)
           winner = 2;
        else
            winner = 1;
    }
    if(winner==1)
        cout<<"First"<<endl;
    else
        cout<<"Second"<<endl;

}


Measured memory_bytes: 512
def main():
    num = int(input())
    str = input()

    array = []

    for i in range(len(str)):
        change_str = ord(str[i])
        over_num = change_str +  num
        if (over_num > 90):
            over_num = over_num - 90 + 64
        
        array.append(chr(over_num))
    
    str2 = ''.join(array)
    print(str2)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
from functools import reduce
import math


def gcd(*numbers):
    return reduce(math.gcd, numbers)


K = int(input())
gcdsum = K*K*K
gcd_ab = []
ab_list = []
for a in range(1, K + 1):
    for b in range(1, K + 1):
        #print(str(gcd(a, b))+', a:'+str(a)+', b:'+str(b))
        if gcd(a, b) != 1:
            ab_list.append(a)
            ab_list.append(b)
            gcd_ab.append(ab_list)
            ab_list = []
for ab in gcd_ab:
    ab = gcd(ab[0], ab[1])
    for c in range(1, K+1):
        if gcd(ab, c) != 1:
            #print(gcd(ab, c))
            gcdsum += gcd(ab, c)-1

print(gcdsum)


Measured memory_bytes: 10876
ans = 2020
L, R = map(int, input().split())
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        mod = i * j % 2019
        if mod == 0:
            print(0)
            exit(0)
        ans = min(ans, mod)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	string S; 
	cin >> S; 
    int N = S.size(); 
	string ans = "NO"; 
	for(int i = 0; i <= 7; i++){
		string a = S.substr(0, i); 
		string b = S.substr(N-7+i, 7-i); 
		if(a + b == "keyence"){
          ans = "YES";
        }
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
Z=0
flag=0
x.sort()
y.sort()
#print(N,M,X,Y,x,y)
#print(x[N-1],y[0])

if (x[N-1]>=y[0]):
    print("War")
else:
    for i in range(X+1,Y+1):
        if (x[N-1]==i):
            flag=flag+1
        if(y[0]==i):
            flag=flag+1
    if flag==2:
        print("No War")
    else:
        print("War")

Measured memory_bytes: 38256
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const long long inf = 1LL << 58;
int main() {
	int A, B, Q;
	cin >> A >> B >> Q;
	vector<long long> S(A + 2), T(B + 2);
	S[0] = -inf; S[A + 1] = inf;
	T[0] = -inf; T[B + 1] = inf;
	for (int i = 1; i <= A; ++i) cin >> S[i];
	for (int i = 1; i <= B; ++i) cin >> T[i];
	for (int i = 0; i < Q; ++i) {
		long long x;
		cin >> x;
		int ptra = lower_bound(S.begin(), S.end(), x) - S.begin();
		int ptrb = lower_bound(T.begin(), T.end(), x) - T.begin();
		long long la = S[ptra - 1], ra = S[ptra];
		long long lb = T[ptrb - 1], rb = T[ptrb];
		cout << min({ abs(x - la) + abs(la - lb), abs(x - la) + abs(la - rb), abs(x - ra) + abs(ra - lb), abs(x - ra) + abs(ra - rb), abs(x - lb) + abs(lb - la), abs(x - lb) + abs(lb - ra), abs(x - rb) + abs(rb - la), abs(x - rb) + abs(rb - ra) }) << '\n';
	}
	return 0;
}

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

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

	int r = 0;

	for( int i = 0; i < 3; ++i ) {
		if( s[i] == '1' ) {
			r += 1;
		}
	}

	cout << r << endl;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        hh: [u32;n]
    }
    let mut cnt = 0;
    for i in 0..n {
        let h = hh[i];
        let mut b = true;
        for j in 0..i {
            if hh[j] > h {
                b = false;
                break;
            }
        }
        if b {cnt += 1};
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const ll mod=998244353;
const double pi=acos(-1); 
int main()
{
	int r;
	sc(r);
	double cou=2.0*r*pi;
	pf("%0.30lf\n",cou);
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  int r, s, p;
  cin >> r >> s >> p;
  string t;
  cin >> t;
  vector<bool> chk(t.size(), false);
  int ans = 0;
  rep(i, t.size()){
    // cerr << ans << endl;
    char now = t.at(i);
    if(i - k >= 0){
      int re = i - k;
      if(chk.at(re) == false && t.at(re) == now){
        t.at(i) = true;
        continue;
      }
    }
    int add;
    if(now == 'r') add = p;
    else if(now == 's') add = r;
    else add = s;
    ans += add;
  }
  cout << ans << endl;
  return 0;
}

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

int mod = 1000000007;
int64_t large = 9223372036854775807;

int main()
{
    string S, T;
    cin >> S >> T;
    int ans = 0;
    for (int i = 0; i < 3; i++)
        if (S[i] == T[i])
            ans++;
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int> left(N), right(N);
  // S[0]~S[i]で西を向いている人数
  if (S[0]=='W') left[0] = 1;
  else left[0] = 0;
  for (int i=1; i<N; i++) {
    if (S[i]=='W') left[i] = left[i-1]+1;
    else left[i] = left[i-1];
  }
  // S[i]~S[N-1]で東を向いている人数
  if (S[N-1]=='E') right[N-1] = 1;
  else right[N-1] = 0;
  for (int i=N-1; i>=0; i--) {
    if (S[i]=='E') right[i] = right[i+1]+1;
    else right[i] = right[i+1];
  }
  int res = min(right[1], left[N-1]);
  for (int i=1; i<N-1; i++) res = min(res, left[i-1]+right[i+1]);
  cout << res << endl;
}

Measured memory_bytes: 3076
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int test1 = 0,test2 = 0,data,i;
	for(i = 0;i < 4;i++){
		scanf("%d",&data);
		test1 += data;
	}
	for(i = 0;i < 4;i++){
		scanf("%d",&data);
		test2 += data;
	}
	if(test1 >= test2){
		printf("%d\n",test1);
	}
	else{
		printf("%d\n",test2);
	}
}

Measured memory_bytes: 1188
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define ALL(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

int ctoi(const char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return -1;
	}
}
int keta(int a) {
	return to_string(a).size();
}
int a[10010];
signed main() {
	int k,t;
	cin>>k>>t;
	rep(i,t){
		cin>>a[i];
	}
	sort(a,a+t);
	cout<<max(a[t-1]-1-(k-a[t-1]),(ll)0)<<endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int main() {
  int n;
  int s;
  vector<int> v;
  cin >> n;
  while (cin >> s) v.push_back(s);
  sort(v.begin(), v.end());
  v[v.size()-1] /= 2;
  cout << accumulate(v.begin(), v.end(), 0) << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

bool pair_comp(const pair<ll, int> &a, const pair<ll, int> &b){
  if( a.first < b.first ) return true;
  else return false;
}

int main(){
  int n, m;
  std::cin >> n >> m;
  vector<pair<ll, int> > data(n);
  for(int i=0; i<n; i++){
    ll temp1, temp2;
    std::cin >> temp1 >> temp2;
    data[i] = make_pair(temp1, temp2);
  }

  sort(data.begin(), data.end(), pair_comp);

  // for(int i=0; i<data.size(); i++) std::cerr << data[i].first << ' ' << data[i].second << '\n';

  ll ans = 0;
  for(int i=0; i<n; i++){
    if( !m ) break;
    ans += data[i].first * min(m, data[i].second);
    m -= min(m, data[i].second);
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1792
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N;
    scan(N);
    auto adj = new int[][](N, 0);
    foreach (i ; 0 .. N - 1) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        adj[ai] ~= bi;
        adj[bi] ~= ai;
    }

    auto col = new int[](N);
    col[] = -1;

    auto cc = new int[](3);

    void color(int v, int p, int num) {
        col[v] = num;
        cc[num]++;
        foreach (u ; adj[v]) if (u != p && col[u] == -1) {
            int nex = num == 1 ? 2 : 1;
            color(u, v, nex);
        }
    }

    color(0, -1, 1);

    assert(cc[1] + cc[2] == N);

    int les = 1, many = 2;
    if (cc[1] > cc[2]) {
        swap(les, many);
    }

    assert(cc[les] <= cc[many]);

    auto p = new int[](N);
    p[] = -1;

    auto div = new int[][](3, 0);
    foreach (i ; 1 .. N + 1) {
        div[i % 3] ~= i;
    }

    // 少ない方に全て2が収まるとき
    if (cc[les] >= div[2].length) {
        foreach (i ; 0 .. N) {
            if (col[i] == les) {
                if (!div[2].empty) {
                    p[i] = div[2].front;
                    div[2].popFront;
                }
                else {
                    p[i] = div[0].front;
                    div[0].popFront;
                }
            }
        }
    }
    else {
        // 収まらないときは全て0で埋め尽くすことが出来る
        assert(cc[les] < div[2].length);
        assert(cc[les] <= div[0].length);

        foreach (i ; 0 .. N) {
            if (col[i] == les) {
                assert(!div[0].empty);
                p[i] = div[0].front;
                div[0].popFront;
            }
        }
    }

    // 最後に余った奴はなんでもいいので割り当てる
    foreach (i ; 0 .. N) {
        if (p[i] == -1) {
            bool ok = false;

            foreach (k ; 0 .. 3) {
                if (!div[k].empty) {
                    p[i] = div[k].front;
                    div[k].popFront();
                    ok = true;
                    break;
                }
            }

            assert(ok);
        }
    }

    writefln("%(%s %)", p);
}





void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}





Measured memory_bytes: 29308
package main

import (
	"fmt"
)

func main() {

	var N,A,B int
	fmt.Scanf("%d %d %d\n", &N, &A, &B)
	a := N / (A + B)
	m := N % (A + B)
	r := a * A
	if m > A {
		r += A
	} else {
		r += m
	}
	fmt.Println(r)
}


Measured memory_bytes: 512
import java.util.*;


import java.io.*;
import java.math.BigInteger;


public class Main 
{   
	static int dp[];
	public static void main(String[] args) throws IOException 
	{ 
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int ar[]=new int[n];
		
		for(int i=0;i<n;i++)
			ar[i]=s.nextInt();
		dp=new int[n];
		Arrays.fill(dp, -1);
		int ans=frog(ar,0,n);
		System.out.println(ans);
	}

	private static int frog(int[] ar, int i,int n) {
		// TODO Auto-generated method stub
		if(i>=n-1) {
			//System.out.println(1);
			return 0;

		}
		
		if(dp[i]!=-1)
			return dp[i];
		
		int op1=(i+1<n?Math.abs(ar[i]-ar[i+1])+frog(ar, i+1, n):Integer.MAX_VALUE);
		
		int op2=(i+2<n?Math.abs(ar[i]-ar[i+2])+frog(ar, i+2, n):Integer.MAX_VALUE);
		
		dp[i]= Math.min(op1, op2);
		
		return dp[i];
		
	}

}


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

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

    int n;
    cin>>n;
    int a[n+1];
    for (int i=1; i<=n; i++){
        cin>>a[i];
    }
    set<int> visited;
    visited.insert(1);
    int curr = 1;
    int cnt = 1;
    while(true){
        
        curr = a[curr];
        if (visited.count(curr)){
            cout<<-1;
            break;
        }
        if (curr==2){
            cout<<cnt;
            break;
        }

        visited.insert(curr);
        cnt++;
    }

}


Measured memory_bytes: 5376
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <stdio.h>
#include <math.h>
int main()
{ long long int ans;
    long long int i, n,temp,temp1;
    scanf("%lld",&n);
    for (i=1;i<=sqrt(n);i++)
    {
        if (n%i==0)
        {  temp=i;
          temp1=n/i;
            if (i==1)
            ans=temp+temp1-2;
            else if (temp+temp1-2<ans)
            ans=temp+temp1-2;
        }
    }
    
 printf ("%lld",ans);   
    
    
}



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

int main() {
  long long A, B, C;
  cin >> A >> B >> C;

  if (A + B + 1 < C) {
    cout << (A + B + 1) + B << endl;
  } else {
    cout << B + C << endl;
  }
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li cnt[111];

int main() {
    li n, m;
    cin >> n >> m;
    rin{
        li k;
        cin >> k;
        rep(j, k) {
            li x;
            cin >> x;
            cnt[x - 1]++;
        }
    }
    li res = 0;
    rep(i, m) {
        if (cnt[i] == n)res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <ios>
#include <vector>
#include <cmath>
using namespace std;
int main(void){
  long long N,M;
  cin >> N >> M;

  vector<long long>broken(M + 2,0);
  broken[0] = -1;
  for(int i=1;i<=M;i++){
    cin >> broken[i];
  }
  broken[M + 1] = N + 1;

  vector<long long>pattern(100005,0);
  pattern[0] = 1;
  pattern[1] = 1;
  for(int i=2;i<100005;i++){
    pattern[i] = (pattern[i - 2] + pattern[i - 1]) % 1000000007;
  }

  long long ans = 1;

  for(int i=0;i<=M;i++){
    if(broken[i + 1] - broken[i] - 2 < 0){
      ans = 0;
      break;
    }
    else{
      ans *= pattern[broken[i + 1] - broken[i] - 2];
      ans = ans % 1000000007;
    }
  }

  cout << ans << endl;

  return 0;
}


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

using ll = long long;
using vi = vector<int>;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)
#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

#define pb push_back

int H, W;

int a[502][502];

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

int N;
vi x, y, x_, y_;

void ps(int i, int j, int k, int l) {
  N++;
  x.pb(i);
  y.pb(j);
  x_.pb(k);
  y_.pb(l);
}

int main() {
  cin.tie(0);cout.tie(0);
  ios_base::sync_with_stdio(false);
  
  cin>>H>>W;
  for_(i, 1, H+1) for_(j, 1, W+1)cin>>a[i][j];
  
  for_(i, 1, H+1) for_(j, 1, W) {
  	if(a[i][j]%2==0)continue;
  	ps(i, j, i, j+1);
  	a[i][j]--;
  	a[i][j+1]++;
  }
  
  for_(i, 1, H) {
	if(a[i][W]%2==0)continue;
  	ps(i, W, i+1, W);
  	a[i][W]--;
  	a[i+1][W]++;
  	
  }
  
  cout<<N<<endl;
  rep(i, N)cout<<x[i]<<' '<<y[i]<<' '<<x_[i]<<' '<<y_[i]<<endl;
  
  return 0;
}


Measured memory_bytes: 5224
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 2000001
#define inf 1e15
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,
q,q1,q2,q3,q4,r,s,t,u,v,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id1,id2,id3,id4,lim;


char num[Mx];
L cnt[2020];

void solve(){
  l=strlen(num);
  L ghat=1,rem=0,ans=0;
  cnt[0]=1;
  for(L i=l-1;i>=0;i--){
    rem=(rem+(num[i]-'0')*ghat)%2019;
    ans+=cnt[rem]++;
    ghat=(ghat*10)%2019;
  }
  printf("%lld\n",ans);
}
int main()
{
    scanf("%s",num);
    solve();
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


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


int main(){
	string S;
	cin >> S;
	if(S.size()==2) {
		cout << S << endl;
	}
	else cout << S[2] << S[1] << S[0] << endl;	
}









Measured memory_bytes: 3620