akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

int main(int argc, char **argv)
{
    std::string N;
    std::cin >> N;
    for(unsigned int i = 0; i < N.size(); i++){
        if(N.at(i) == '7'){
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    cin>>n;
    ll k;
    cin>>k;
    vector<ll> v(n,0);
    for(int i = 0;i < n; i++){
        cin>>v[i];
    }
    ll now;
    ll ans=inf;
    for(int i=0;i+k-1<n;i++){
        if(v[i]*v[i+k-1]<0){
            now=min(abs(v[i]),v[i+k-1])*2+max(abs(v[i]),v[i+k-1]);
        }
        else{
            now=max(abs(v[i]),abs(v[i+k-1]));
        }
        ans=min(now,ans);
    }
    cout<<ans<<endl;    
    return 0;
}

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

int n,m,x[100010],y[100010],gg[405],ans;
bitset <405> a[405];

void work()
{
	scanf("%d %d",&n,&m);
	for (int i=1; i<=m; i++)  scanf("%d %d",&x[i],&y[i]);
	for (int i=1; i<=n; i++)
		{
			a[i][i]=1;
			for (int j=m; j; j--)
				if ((a[i][x[j]])&&(a[i][y[j]]))  gg[i]=1;
				else  if ((a[i][x[j]])||(a[i][y[j]]))  a[i][x[j]]=1,a[i][y[j]]=1;
		}
	for (int i=1; i<=n; i++)
		for (int j=1; j<i; j++)
			ans+=(!gg[i])&&(!gg[j])&&(!(a[i]&a[j]).count());
	printf("%d",ans);
}

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


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

int main() {
  int x, y, ans = 0;
  cin >> x >> y;
  if (x == 3) ans += 100000;
  if (x == 2) ans += 200000;
  if (x == 1) ans += 300000;
  if (y == 3) ans += 100000;
  if (y == 2) ans += 200000;
  if (y == 1) ans += 300000;
  if (x == 1 && y == 1) ans += 400000;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define setbits(x)          __builtin_popcountll(x)
#define lp(a,n) for(ll i=a; i<n; i++)
#define lpi(a,n) for(int i=a; i<n; i++)
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int> 
#define vll vector<ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define inf 1e9
#define LB lower_bound
#define UB upper_bound
const int mod = 1000000007;
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}

int prime[100007];
void SieveOfEratosthenes(int n) 
{ 
    memset(prime, -1, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
         
        if (prime[p] == -1) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = p; 
        } 
    } 
    
} 
int lps(string s){
    int len = 0;
    int n = s.length();
    int dp[n];
    dp[0] = 0;
    for(int i=1; i<n; i++){
        if(s[i] == s[len]){
            len++;
            dp[i] = len;
            continue;
        }
        if(len!=0){
            len = dp[len-1];
            i--;
            continue;
        }
        dp[i]=0;
    }
    return dp[n-1];
}
 
ll power(unsigned ll x,unsigned  ll y) 
{ 
    ll res = 1;     
    while (y > 0) 
    { 
        if (y & 1) 
            res = res*x; 
   
        y = y>>1;
        x = x*x;  
    } 
    return res; 
}

//to calculate p1^x  *  p2^x2  *p3^x3 ----------
//i.e. prime factorization and store pi and xi in vector 
vector<pair<ll, ll>> pFactor;

void factorize(long long n) 
{ 
    int count = 0; 
  
    // count the number of times 2 divides  
    while (!(n % 2)) { 
        n >>= 1; // equivalent to n=n/2; 
        count++; 
    } 
  
    // if 2 divides it 
    if (count) 
        pFactor.pb({2,count}); 
  
    // check for all the possible numbers that can  
    // divide it 
    for (long long i = 3; i <= sqrt(n); i += 2) { 
        count = 0; 
        while (n % i == 0) { 
            count++; 
            n = n / i; 
        } 
        if (count) 
            pFactor.pb({i,count});
    } 
  
    // if n at the end is a prime number. 
    if (n > 2) 
        pFactor.pb({n,1}); 
} 



int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
   double d,t,s;
   cin>>d>>t>>s;
   double x = d/s;
   if(x<=t){
       cout<<"Yes\n";
   }else{
       cout<<"No\n";
   }
}

Measured memory_bytes: 3796
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
int main() {
    string s, t;
    cin >> s >> t;

    int lenS = s.length();
    int lenT = t.length();
    int ans = 10005;
    for (int i = 0; i + lenT <= lenS; i++) {
        int change = 0;
        for (int j = 0; j < lenT; j++) {
            if (s[i + j] != t[j]) {
                change++;
            }
        }
        ans = min(ans, change);
    }

    cout << ans <<endl;
}


Measured memory_bytes: 3596
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	B := make([]int, N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sumA, sumB := 0, 0
	for i := 0; i < N; i++ {
		A[i] = nextInt(sc)
		sumA += A[i]
	}
	for i := 0; i < N; i++ {
		B[i] = nextInt(sc)
		sumB += B[i]
	}
	if sumB > sumA {
		fmt.Println(-1)
		return
	}
	dA := make([]int, 0)
	var dAcnt, dBcnt, dBsum int
	for i := 0; i < N; i++ {
		if A[i] >= B[i] {
			dAcnt++
			dA = append(dA, A[i]-B[i])
		} else {
			dBsum += B[i] - A[i]
			dBcnt++
		}
	}
	if dAcnt == N {
		fmt.Println(0)
		return
	}
	sort.Sort(sort.Reverse(sort.IntSlice(dA)))
	var i int
	for dBsum > 0 {
		if dBsum-dA[i] >= 0 {
			dBsum -= dA[i]
			i++
		} else {
			break
		}
	}
	fmt.Println(dBcnt+i+1)
}


Measured memory_bytes: 7296
n, k = map(int, input().split())
mod = int(1e9 +7)
c = [[0 for i in range(n+1)] for j in range(n+1)]

def pascal():
    c[0][0] = 1
    for i in range(1, n+1):
        for j in range(n+1):
            if j == 0 or j == i:
                c[i][j] = 1
                continue
            c[i][j] = c[i-1][j-1] +c[i-1][j]
def main():
    if n == k:
        print(1)
        [print(0) for i in range(k-1)]
        return 0
    for i in range(1, k+1):
        print((c[n-k+1][i] * c[k-1][i-1])%mod)
    return 0

pascal()
main()

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

const vector<int> calcV(string s) {

    int n = s.size();
    map<char, int> usedMap;
    vector<int> retV(n);
    int count = 0;

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

        if(usedMap.find(s[i]) == usedMap.end()) {
            usedMap[s[i]] = count++;
        }
        retV[i] = usedMap[s[i]];

    }

    return retV;

}

int main() {

    string s, t;

    cin >> s;
    cin >> t;


    if(calcV(s) == calcV(t))
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;

    return 0;

}

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

int main(){
    long double N;
    long double delta = 0.00001;
    cin >> N;
    long long keta = (long long)(log(N+delta)/log(10))+1;
    int topketa=(N+1)/pow(10, keta-1);
    cout << topketa - 1 + 9*(keta-1);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <set>
#include <climits>
#include <map>

using namespace std;

int a[10000];
int c[100][100];


int main(){
  int H;
  int W;
  cin >> H >> W;
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }

  int cur_color_ind = 0;
  for(int i = 0; i < H; i++){
    if(i % 2 == 0){
      for(int j = 0; j < W; j++){
        if(a[cur_color_ind] > 0){
          c[i][j] = cur_color_ind;
          a[cur_color_ind] --;
        } else {
          cur_color_ind ++;
          c[i][j] = cur_color_ind;
          a[cur_color_ind] --;
        }
      }
    } else {
      for(int j = W - 1; j >= 0; j--){
        if(a[cur_color_ind] > 0){
          c[i][j] = cur_color_ind;
          a[cur_color_ind] --;
        } else {
          cur_color_ind ++;
          c[i][j] = cur_color_ind;
          a[cur_color_ind] --;
        }
      }
    }
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(j != W - 1){
        cout << c[i][j] + 1 << " ";
      } else {
        cout << c[i][j] + 1 << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;

const int MAXN = 1e5 + 5;
const LL p = 1e9 + 7;

LL a[MAXN + 5], b[MAXN + 5];
LL A[MAXN + 5], B[MAXN + 5];

int main()
{
    LL n, m;
    scanf("%lld %lld", &n, &m);
    for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    for(int i = 1; i <= m; i++) scanf("%lld", &b[i]);
    LL la = 0, lb = 0;
    for(int i = 2; i <= n; i++) A[++la] = a[i] - a[i - 1];
    for(int i = 2; i <= m; i++) B[++lb] = b[i] - b[i - 1];
    //cout<<la<<endl<<lb<<endl;
    LL suma = 0, sumb = 0;
    for(LL i = 1; i <= la; i++) suma = (suma + A[i] * i % p * (la - i + 1) % p) % p;
    for(LL i = 1; i <= lb; i++) sumb = (sumb + B[i] * i % p * (lb - i + 1) % p) % p;
    printf("%lld\n", suma * sumb % p);
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define L "\n"
#define S " "
#define ll long long
#define pb push_back
#define mp make_pair
#define vi std::vector<int>
#define si std::set<int>
#define vl std::vector<long long>
#define qi std::queue<int>
#define de(a) cout << #a << "  ------>  " << a << "\n"
#define SIZE 100002
#define INF INT_MAX
#define FOR(i, n) for (i = 1; i <= n; i++)
#define FASTIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

using namespace std;

vi adj[SIZE];
int dp[SIZE];
bool vis[SIZE];

void dfs(int v)
{
    int res = 0;
    vis[v] = 1;
    for (int u : adj[v])
    {
        if (!vis[u])
        {
            dfs(u);
            res = max(res, dp[u] + 1);
        }
        else
        {
            res = max(res, dp[u] + 1);
        }
    }
    dp[v] = res;
}

void solve()
{
    int n, m, i, x, y, ans = 0;
    cin >> n >> m;
    FOR(i, m)
    {
        cin >> x >> y;
        adj[x].pb(y);
    }
    FOR(i, n)
    {
        if (!vis[i])
        {
            dfs(i);
        }
    }
    FOR(i, n)
    {
        ans = max(ans, dp[i]);
    }
    cout << ans << L;
}
int main()
{
    FASTIO;
    // #ifndef ONLINE_JUDGE
    //     freopen("in.txt", "r", stdin);
    // #endif
    int t;
    // cin >> t;
    // while (t--)
    solve();
    return 0;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> n >> x;
    sum = 0;
    ll mn = LONG_LONG_MAX;
    NREP() {
        cin >> m;
        sum += m;
        mn = min(mn, m);
    }
    MSG(n + (x - sum) / mn)
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b;
	scanf("%d%d",&a,&b);
	int i = a;
	int left;
	int right;
	int revleft;
	int count = 0;
	while (i <= b)
	{
		left = i / 1000;
		right = i % 100;
		revleft = (left % 10 * 10) + left / 10;
		if (revleft == right)
		{
			// printf("%d\n", i);
			count++;
		}
		i++;
	}
	printf("%d\n", count);
	return (0);
}


Measured memory_bytes: 128
// ref: https://qiita.com/tubo28/items/e6076e9040da57368845
use std::io::{stdin, Read};
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut sa: Vec<char> = read::<String>().chars().rev().collect();
    let mut sb: Vec<char> = read::<String>().chars().rev().collect();
    let mut sc: Vec<char> = read::<String>().chars().rev().collect();

    let mut turn = 'a';
    let mut ans = "";
    loop {
        if turn == 'a' {
            if let Some(next) = sa.pop() {
                turn = next;
            } else {
                ans = "A";
                break;
            }
        }
        if turn == 'b' {
            if let Some(next) = sb.pop() {
                turn = next;
            } else {
                ans = "B";
                break;
            }
        }
        if turn == 'c' {
            if let Some(next) = sc.pop() {
                turn = next;
            } else {
                ans = "C";
                break;
            }
        }
    }

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

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

using Data = struct{
    int pos;
    string puzzle;
    int t;
};

constexpr int dx[] = {-1, 1, -4, 4};
const string correct{"01234567"};

int main(){
    map<string, int> min_root{{correct, 0}};
    
    queue<Data> q;
    q.push(Data{0, correct, 0});
    while(!q.empty()){
        Data d = q.front();
        q.pop();

        for(int i = 0; i < 4; ++i){
            int npos = d.pos+dx[i];

            if(npos < 0 || npos > 7 || (d.pos == 3 && npos == 4) || (d.pos == 4 && npos == 3)) continue;

            string npuzzle = d.puzzle;
            swap(npuzzle[d.pos], npuzzle[npos]);

            if(min_root.find(npuzzle) != end(min_root)) continue;

            min_root.emplace(make_pair(npuzzle, d.t+1));
            q.push(Data{npos, npuzzle, d.t+1});
        }
    }

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

    string puzzle{"********"};

    while (cin >> puzzle[0] >> puzzle[1] >> puzzle[2] >> puzzle[3] >> puzzle[4] >> puzzle[5] >> puzzle[6] >> puzzle[7]) {
        cout << min_root[puzzle] << endl;
    }
}


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

#define printl(s) cout << s << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using pii = pair<int, int>;
using si = set<int>;

const ll modSeed = pow(10,9) + 7;
const int INF = 100'000'000;

template <typename T>
vector<T> getVector(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
ll N,ans;

int main(){
  cin >> N;
  N*=3;
  auto inputs = getVector<ll>(N);
  sort(inputs.begin(),inputs.end(),greater<ll>());
  N/=3;
  N*=2;
  rep(i,N){
    if((i+1)%2==0){
      ans +=inputs[i];
    } 
  }
  printl(ans);
}


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

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

    int h, w, d;
    cin >> h >> w >> d;
    map<int, pair<int, int>> pos;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int a;
            cin >> a;
            a--;
            pos[a] = {i, j};
        }
    }

    vector<vector<int>> dist(d);
    for (int i = 0; i < d; i++) {
        dist[i].push_back(0);
        for (int j = i + d; j < h * w; j += d) {
            dist[i].push_back(dist[i].back() + abs(pos[j - d].first - pos[j].first) +
                              abs(pos[j - d].second - pos[j].second));
        }
    }

    int q;
    cin >> q;
    while (q--) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        int k = a % d;
        cout << dist[k][(b - k) / d] - dist[k][(a - k) / d] << '\n';
    }
}


Measured memory_bytes: 11008
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::vec::Vec;
use std::{vec, cmp, num};


struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

// create Vec<char> from String
#[allow(dead_code)]
fn to_chars(s: String) -> vec::Vec<char> {
    let mut cs = s.chars();
    let mut res = vec::Vec::new();
    while let Some(c) = cs.next() {
        res.push(c);
    }
    res
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let x: i32 = sc.read();
    let a: i32 = sc.read();
    let b: i32 = sc.read();
    println!("{}", (x - a) - (x - a) / b * b);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

vector<int> makesosu(int n){
    vector<char> line(n*2+1, 1);
    vector<int> res;
    for(int i=2;i<=n*2;++i){
        if(line[i]){
            res.push_back(i);
            for(int j=i*2;j<=n*2;j+=i)line[j]=0;
        }
    }
    return res;
}

int main(){
    int N;
    while(cin>>N&&N){
        vector<int> line = makesosu(N);
        int ans = 0;
        foreach(i, line)
            if(i>N)++ans;
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 3436
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
using namespace std;
const int INF = 10000000000000000;
const int mod = 1000000007;
int test[345678];
signed main() {
	int n, m; cin >> n >> m;
	cout << min(n % m, m - n % m) << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#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 ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  
  string o,e;

  cin >> o >> e;

  string a = "";

  REP(i, (int)e.length()){
    a += o[i]; 
    a += e[i];
  }

  if(o.length() - e.length()){
    a += o[o.length() - 1];
  }

  cout << a << endl;

  return 0;
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
    return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
    return a / gcd(a, b) * b;
}

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

int main()
{
    int n;
    int sum = 0;
    int h[100];

    ci >> n;
    rep(i, n) {
	ci >> h[i];
	sum += h[i];
    }

    rep(i, n - 1) {
	sum -= min(h[i], h[i + 1]);
    }

    co << sum << en;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int main()
{
  //flash;
	string dal;
	cin>>dal;
	for (int i = 0; i < dal.size(); ++i)
	{
		if(i%2==0 && dal[i]=='L'){cout<<"No";return 0;}
		if(i%2==1 && dal[i]=='R'){cout<<"No";return 0;}
	}
	cout<<"Yes";
  return 0;
}
//code the AC sol !
// BS/queue/map


Measured memory_bytes: 256
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*N
dp[0]=0
for n in range(1,N):
    dp[n]=dp[n-1]+abs(h[n-1]+h[n])
    for i in range(max(0,n-K),n):
            dp[n]=min(dp[n],dp[i]+abs(h[n]-h[i]))
print(dp[N-1])

Measured memory_bytes: 52448
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = [1]
for i in range(n):  
    l.append(a[l[i]-1])
    
p = l.index(l[-1])
if k<=n:
  print(l[k])
  exit()
  
x = (k-n+1)%(n-p)
if x==0:
  print(l[n-1])
else:
  print(l[x+p-1])


Measured memory_bytes: 32384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AIZU {
	class Program {
		static int cin() { return int.Parse(Console.ReadLine()); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static int[] cins() {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(',');
			int[] Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }

		static void Main(string[] args)
		{
			int[] I;
			int sum = 0, ave = 0 ,count=0;
			while(true){
				I = cins();
				if (I.Length == 0)
					break;
				sum += I[0] * I[1];
				ave += I[1];
				count++;
			}
			ave = (int)Math.Round(((double)ave)/Math.Max(count,1), MidpointRounding.AwayFromZero);
			print(sum);
			print(ave);
		}
	}
}

Measured memory_bytes: 8976
S = str(input())
N = len(S)


def solve(S):
    # S: 文字列
    r = N % 2
    for i in range(1, N//2):
        s = S[:N-(2*i+r)]
        n = len(s)
        #print(s,i,n,s[:(n//2)],s[(n//2):])
        if s[:(n//2)] == s[(n//2):]:
            ans = N - (2 * i + r)
            break
    return ans


print(solve(S))

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

int ni(int x){
  int counter=0;
  while(x%2 == 0){
    x = x/2;
    counter ++;
  }
  return counter;
}

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  int sum=0;
  for(int i=0;i<N;i++){
    sum += ni(A.at(i));
  }
  cout << sum << endl;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n, k;
    cin >> n >> k;
    vector<int> d(k);
    rep(i, k) cin >> d[i];

    while(1) {
        int tmp = n;
        bool flag = true;
        while(tmp>0) {
            int a = tmp % 10;
            for(auto v : d) {
                if(v == a) {
                    flag = false;
                    break;
                }
            }
            if(!flag) break;
            tmp /= 10;
        }
        if(flag) {
            cout << n << endl;
            break;
        }
        n++;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define repit2(x) for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define Sort(v) sort(All(v))
#define SortR(v) sort(All(v), std::greater<__typeof(v[0])>())

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    string s;

	cin >> s;

	const int N = 753;
	int ans = INT_MAX;
	int n;

	int i, len = s.size() - 2;

	rep(i, len) {
		n = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');

		Min(ans, Abs(N - n));
	}

	Out(ans);
	
	return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    ans = 0
    for i in range(1, n+1):
        if (i%3==0) and (i%5==0):
            continue
        if (i%3==0):
            continue
        if (i%5==0):
            continue
        ans += i
    print(ans)
main()

Measured memory_bytes: 9168
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    if(n >= 64) cout << 64 << endl;
    else if(n >= 32) cout << 32 << endl;
    else if(n >= 16) cout << 16 << endl;
    else if(n >= 8) cout << 8 << endl;
    else if(n >= 4) cout << 4 << endl;
    else if(n >= 2) cout << 2 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
using namespace std;
typedef pair<int, int> pii;
const ll mod = 998244353;
const int sz = 2 * 1e5 + 50, mxn = 1e6 + 10;

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

	string s, t;
	cin >> s >> t;
	string ans = t + s;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
# import numpy as np
# import math
import sys
input = sys.stdin.readline

N = int(input())

T = []
A = []

for i in range(N):
    temp = list(map(int,input().split()))
    T.append(temp[0])
    A.append(temp[1])

for i in range(1,N):
    if (T[i-1] <= T[i]) & (A[i-1] <= A[i]):
        # print(T[i],A[i])
        continue
    else:
        rT = - ( - T[i-1] // T[i])
        rA = - ( - A[i-1] // A[i])
        temp = max(rT,rA)
        T[i] *= temp
        A[i] *= temp
        # print(T[i],A[i])

res = T[N-1] + A[N-1]

print(res)


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>

using namespace std;

#define rep(i, N) for(int i = 0;i < (int)N;i++)
#define LARGE INT_MAX / 2



int main() {
	int a, b;
	cin >> a >> b;
	cout << a / b << ' ' << a % b << ' ';
	cout << fixed << setprecision(6) << (double)a / b << endl;
	return 0;
}


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

int main(){
  int n,k, ans=0, dif=0;
  string s;
  cin>>n>>k>>s;

  REP(i,n-1){
    if(s.at(i)==s.at(i+1)) ans++;
    else dif++;
  }
  if(dif>=k*2) ans+=k*2;
  else ans+=dif;
  
  cout<<ans<<endl;
}

Measured memory_bytes: 512
N = gets.chomp.to_i
A = gets.chomp.split.map(&:to_i)

m0 = 0
0.upto(A.size-1).each do |i|
  if (i % 2 == 0)
    m0 += A[i]
  else
    m0 -= A[i]
  end
end

# p m0
m = []
m[0] = m0
1.upto(N-1).each do |i|
  m[i] = 2 * A[i-1] - m[i-1]
end

print m.join(" ")

Measured memory_bytes: 15180
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
sum =0;
for i in range(len(a)):
    sum += b[a[i]-1]
    if i +1 < n and a[i+1] - a[i] == 1:
        sum += c[a[i]-1]
print(sum)


Measured memory_bytes: 3064
#[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 = get!(usize);

    print!("Christmas ");
    for _ in 0..25 - n {
        print!("Eve ")
    }
    println!();
}


Measured memory_bytes: 8572
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
      static List<int> s = new List<int>();
       static List<int>[] t;
    static decimal result;
static StringBuilder sb = new StringBuilder();
static int N,M,K;
static long[,] table;
    static void Main()
    {
Read4();
      Read2();
      //左からa個，右からb個取り，c個戻す。a+b+c<=K a+b<=N
      for(int a=0;a<=K && a<=N;a++){
      for(int b=0;b<=K-a && b<=N-a;b++){
        if(a+b>N){continue;}
        int tmpr=0;
        var pr=new PriorityQueue<int,int>();
        
        for(int x=0;x<a;x++){pr.Add(s[x],s[x]);}
        for(int x=0;x<b;x++){pr.Add(s[N-1-x],s[N-1-x]);}
        
      for(int c=0;c<K-a-b;c++){
        int dasu;
 if(pr.Count>0){dasu=pr.Dequeue().Value;}else{break;}
        if(dasu>0){tmpr+=dasu;break;}
      }
        
        while(pr.Count>0){
        tmpr+=pr.Dequeue().Value;
        }
        result=Math.Max(result,tmpr);
      }
      }
      
      
                    Console.WriteLine(result.ToString());
}
    


    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }
 
    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read3()//1行複数項
   {
       string[] tmp = Console.ReadLine().Split(' ');
       for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
       N = int.Parse(tmp[0]);
       K = int.Parse(tmp[1]);
    }
    static void Read5()//N行K項
    {

    }

}
class PriorityQueue<TKey, TValue>
{
    SortedDictionary<TKey, Queue<TValue>> dict = new SortedDictionary<TKey, Queue<TValue>>();
    int count = 0;

    public int Count
   {
        get
       {
            return count;
       }
   }

   public void Add(TKey key, TValue value)
   {
       if (!dict.ContainsKey(key))
       {
           dict[key] = new Queue<TValue>();
       }
 
       dict[key].Enqueue(value);
       count++;
   }

    public KeyValuePair<TKey, TValue> Dequeue()
    {
        var queue = dict.First();
       if (queue.Value.Count <= 1)
        {
           dict.Remove(queue.Key);
        }
        count--;
        return new KeyValuePair<TKey, TValue>(queue.Key, queue.Value.Dequeue());
    }
}

Measured memory_bytes: 15824
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            string[] figures = new string[7];
            figures[0] = "1100000011";
            figures[1] = "1000000010000000100000001";
            figures[2] = "1111";
            figures[3] = "01000000110000001";
            figures[4] = "11000000011";
            figures[5] = "100000001100000001";
            figures[6] = "0110000011";

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {

                string map = "";
                map += input;

                for (int i = 0; i < 8; i++) map += Console.ReadLine();

                for (int i = 0; i < figures.Length; i++)
                {
                    if (map.Contains(figures[i]))
                    {
                        sb.AppendLine(((char)('A' + i)).ToString());
                        break;
                    }
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9708
# -*- coding: utf-8 -*-
# abc136/abc136_b
import sys
from math import log10

N = int(sys.stdin.readline().rstrip())
len_n = int(log10(N)) + 1
s = N - 10**(len_n - 1) + 1 if len_n % 2 else 0
for i in range(1, len_n, 2):
    s += 9 * 10**(i - 1)
print(s)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
  	if((a+b)%2 == 0){
    	cout << (a+b)/2 << endl;
    }else{
    	cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a * b / gcd(a, b); }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)


int main() {
	ll n,cnt=0;
	in(n);

	vll p(n), ps(n);
	rep(i, 0, n) {
		in(p[i]);
	}
	ps = p;
	sort(ps.begin(), ps.end());
	rep(i, 0, n) {
		if (p[i] != ps[i]) {
			cnt++;
		}
	}
	if (cnt == 0 || cnt == 2) {
		outn("YES");
	}
	else {
		outn("NO");
	}

	return 0;

	}
	

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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
   fast;
   int n,k;
   cin >> n >> k;

   int a[n];
   f(i,0,n) cin >> a[i];
   sort(a,a+n);

   int ans = 0;
   f(i,0,k) ans += a[i];

   cout << ans << "\n";
}

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

int main(void){
  int K, A, B, cnt;
  bool ans = false;
  cin >> K >> A >> B;
  cnt = B / K;
  for(int i = 1; i <= cnt; i++){
    if(A <= i * K && i * K <= B){
      ans = true;
      break;
    }
  }
  if(ans) cout << "OK" << endl;
  else cout << "NG" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define INF 0x7fffffff
#define ll long long
#define P pair<int,int>
#define MP(a,b) make_pair(a,b)
using namespace std;
bool vis[400005];
int n,m,dis[400005],head,tail,t,h[400005];
priority_queue<P> q;
set<int> in[400005];
struct E{int v,c,next;}g[800005];
void ins(int u,int v,int c){g[++t].v=v,g[t].c=c,g[t].next=h[u],h[u]=t;}
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}
int main(){
    
    while(scanf("%d%d",&n,&m)!=EOF){
        t=0 ;
        memset(h,0,sizeof(h)) ;
        for (int i=1;i<=n;i++) dis[i]=INT_MAX ;
        memset(vis,0,sizeof(vis)) ;
        for (int i=1;i<=200005;i++) in[i].clear() ;
        for(int i=1;i<=m;++i){
            int u,v,c;
            u=read(),v=read(),c=read();
            ins(u,v,c); ins(v,u,c);
        }
        while(!q.empty()) q.pop() ;
        q.push(MP(0,1)); dis[1]=0;
        while(!q.empty()){
            int u=q.top().second,cost=-q.top().first;
            q.pop();
            vis[u]=1;
            if(cost>dis[u]) continue;
            for(int j=h[u];j;j=g[j].next){
                if(vis[g[j].v]) continue;
                int v=g[j].v,c=g[j].c,d=dis[u]+(!in[u].count(c));
                if(d>dis[v]) continue;
                if(d<dis[v]){
                    q.push(MP(-d,v));
                    dis[v]=d;
                    in[v].clear();
                }
                in[v].insert(c);
            }
        }
        printf("%d\n",dis[n]==INT_MAX?-1:dis[n]);
    }
}


Measured memory_bytes: 39032
/*<---------------------------CONCEPTS LEARNT------------------------------>

<-------------------------------------------------------------------------->
            _           __                _      _____ _____ _____ 
  ___ _   _| |__   ___ / _|_ __ ___  __ _| | __ |___  |___  |___  |
 / __| | | | '_ \ / _ \ |_| '__/ _ \/ _` | |/ /    / /   / /   / / 
| (__| |_| | |_) |  __/  _| | |  __/ (_| |   <    / /   / /   / /  
 \___|\__,_|_.__/ \___|_| |_|  \___|\__,_|_|\_\  /_/   /_/   /_/   

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vi;
typedef vector<pll> vpll;
typedef unordered_map <ll,ll> umap ; 
//#pragma GCC optimize "trapv"
#define loop(i,a,b) for(ll i=a ;i<b;i++)
#define For(i,n) for(int i=0;i<(ll)n;i++)
#define Rev(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,n) for(int i=1;i<=n;++i)
#define F first
#define S second
#define pb push_back
#define em emplace_back
#define all(v) (v).begin(),(v).end()
#define mems(x, y) memset(x, y, sizeof(x))
#define sz(v) (v).size()
#define mp(a,b) make_pair(a,b)
#define pf(n) cout<<n<<"\n"
#define pff(n) cout << n << " " ; 
long const M=1e9+7;
const long mxN =1e5+2 ;
const long mxNN =1e6+2 ;
bool check_pal(string s){
    for(int l =0,r=sz(s)-1;l<=r;l++,r--){
        if(s[l] !=s[r])return false ;
    }
    return true ;
}
void solve(){
     string s ; cin >> s ;
     ll n = sz(s) ;
     string  s1 ="" ,s2="";
     for(int i =0;i<(n-1)/2;i++){
         s1+=s[i] ;
     }
     for(int i =(n+3)/2-1;i<=n-1;i++)s2[i]+=s[i] ;
     if(check_pal(s1) & check_pal(s2) & check_pal(s)){
         cout << "Yes" << endl ;
     }
     else cout << "No" << endl ;
}
int main() {
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     solve() ;
     //ll t ; cin >> t ; while(t--)solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

bool solve(){
  int n,a,b;
  cin>>n>>a>>b;

  if(a+b > n+1) return false;

  if((n+a-1)/a > b) return false;

  vector<int> ans;
  int p = 1;
  swap(a,b);
  while((n-p+1+a-1)/a < b){
    ans.pb(p);
    p++;
    b--;
  }

  while(p<=n){
    int len = min(a, n-p+1);
    for(int i=p+len-1; i>=p; i--) ans.pb(i);
    p += len;
  }

  rep(i,n) printf("%d%c", ans[i], " \n"[i==n-1]);

  return true;
}

int main(){
  if(!solve()) cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 3440
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;cin>>n;
  for(ll i=1;i<=3500;i++){
    for(ll j=1;j<=3500;j++){
      if(4*i*j-n*(i+j) == 0)continue;
      if((n*i*j)%(4*i*j-n*(i+j))==0&&(n*i*j)/(4*i*j-n*(i+j))>0){
        cout<<i<<" "<<j<<" "<<(n*i*j)/(4*i*j-n*(i+j))<<endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)

#define vll    vector<ll>
#define vvll   vector<vector<ll>>
#define all(x) (x).begin(),(x).end()

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

	string S;
	cin >> S;

	char c = '0';
	int count = 0;

	rep(i, N)
	{
		if (S[i] != c)
		{
			count++;
			c = S[i];
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 512
import java.io.*;
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
    private static final long MOD = (int)1e9 + 7;

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) a[i] = in.nextInt();

        long[][] dp = new long[n + 1][k + 1];
        long[][] pre = new long[n + 1][k + 1];

        for (int i = 0; i <= a[0]; ++i) dp[0][i] = 1;

        pre[0][0] = dp[0][0];
        for (int i = 1; i <= k; ++i) pre[0][i] = (pre[0][i - 1] + dp[0][i]) % MOD;

        for (int i = 1; i < n; ++i) {
            for (int j = 0; j <= k; ++j) {
                if (j > a[i]) {
                    dp[i][j] = (pre[i - 1][j] + MOD - pre[i - 1][j - a[i] - 1]) % MOD;
                } else {
                    dp[i][j] = pre[i - 1][j];
                }
            }

            pre[i][0] = dp[i][0] % MOD;
            for (int x = 1; x <= k; ++x) {
                pre[i][x] = (pre[i][x - 1] + dp[i][x]) % MOD;
            }
        }

        System.out.println(dp[n - 1][k] % MOD);
    }
}

Measured memory_bytes: 195720
#include <stdio.h>

int main(void)
{
    int a,b,c,d;

    scanf("%d %d %d %d", &a, &b, &c, &d);

    if ((a + b) > (c + d)) {
        puts("Left");
    } else if((a + b) < (c + d)) {
        puts("Right");
    } else {
        puts("Balanced");
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int a[200005];
vector<int> G[200005];
int ans[200005];

int main(void){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d",&a[i]);
		ans[a[i]-1]++;
	}
	for(int i=0;i<n;i++){
		printf("%d\n",ans[i]);
	}
	return 0;
}


Measured memory_bytes: 9876