akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
int main() {
	ll a,b;
	cin >> a >> b;
	if ((a + b) % 2==0) {
		cout << (a + b) / 2;
	}
	else {

		cout << "IMPOSSIBLE";
	}
}
	


Measured memory_bytes: 3612
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
pair<int, int> p1[200001], p2[200001];

int main() {
    int n;
    cin >> n;
    int sq = sqrt(8*n + 1);
    if(sq * sq == 8* n + 1){
        cout << "Yes\n";
        int a = (sq - 1)/2;
        cout << (a + 1) << "\n";
        int ans[a + 1][a];
        int now = 1;
        for(int i = 0; i < a; i++){
            for(int j = 0; j + i < a; j++){
                ans[i][i + j] = now;
                ans[i + 1 + j][i] = now;
                now++;
            }
        }
        for(int i = 0; i <= a; i++){
            cout << a << " ";
            for(int j = 0; j < a; j++){
                cout << ans[i][j] << " ";
            }
            cout << "\n";
        }
    }else{
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define LiangJiaJun main
#define ll long long
#define INF 1999122700
#define MOD 1000000007
using namespace std;
int f[1004][1004],n,m;
char mp[1004][1004];
int w33ha(){
    memset(f,0,sizeof(f));
    for(int i=1;i<=n;i++)scanf("%s",mp[i]+1);
    if(mp[1][1]!='#')f[1][1]=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(i==1&&j==1)continue;
            if(mp[i][j]=='#')continue;
            f[i][j]=(f[i-1][j]+f[i][j-1])%MOD;
        }
    }
    printf("%d\n",f[n][m]);
    return 0;
}
int LiangJiaJun(){
    while(scanf("%d%d",&n,&m)!=EOF)w33ha();
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}




int main(void) {
  ll N;
  cin >> N;
  ll ans=INF;
  ll w[111];
  ll i;
  
  ll l=0, r=0;
  
  for(i=0; i<N; i++) {
    cin >> w[i];
    r+=w[i];
  }
  
  ans=r;
  
  for(i=0; i<N; i++) {
    l+=w[i];
    r-=w[i];
    chmin(ans, abs(l-r));
  }
  
  pt(ans);
  
}
  
  


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
#define mod 1e9 + 7;

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

	ll a, b, c,n, k;
	string s;
	vi v(3);
	rep(i,3)
	cin >> v[i];
	sort(all(v));
	cout << (v[2] - v[1]) + (v[1] - v[0]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	int H,W;
	char s[50][51];

	scanf("%d %d",&H,&W);
	for(int i=0;i<H;i++){
		scanf("%s",&s[i]);
	}

	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(s[i][j]=='.') s[i][j]='0';
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(s[i][j]=='#'){
				if(i>0 && s[i-1][j]!='#') s[i-1][j]++;
				if(i<H-1 && s[i+1][j]!='#') s[i+1][j]++;
				if(j>0 && s[i][j-1]!='#') s[i][j-1]++;
				if(j<W-1 && s[i][j+1]!='#') s[i][j+1]++;
				if(i>0&&j>0 && s[i-1][j-1]!='#') s[i-1][j-1]++;
				if(i>0&&j<W-1 && s[i-1][j+1]!='#') s[i-1][j+1]++;
				if(i<H-1&&j>0 && s[i+1][j-1]!='#') s[i+1][j-1]++;
				if(i<H-1&&j<W-1 && s[i+1][j+1]!='#') s[i+1][j+1]++;
			}
		}
	}

	for(int i=0;i<H;i++){
		printf("%s\n",s[i]);
	}

	return 0;
}


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

int main(){
  int i, j, H, W;
  cin >> H >> W;
  
  vector<string> A(H);
  for(i = 0; i < H; i++){
  	cin >> A.at(i);
  }
  vector<int> h(H), w(W);
  for(i = 0; i < H; i++){
    for(j = 0; j < W; j++){
  		if(A.at(i).at(j) == '#') break;
      	if(j == W-1) h.at(i) = 1;
    }
  }
  for(i = 0; i < W; i++){
    for(j = 0; j < H; j++){
  		if(A.at(j).at(i) == '#') break;
      	if(j == H-1) w.at(i) = 1;
    }
  }
  for(i = 0; i < H; i++){
    for(j = 0; j < W; j++){
      if(h.at(i) == 0 && w.at(j) == 0) cout << A.at(i).at(j);
    }
    if(h.at(i) == 0) cout << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main(){
    int n;
    double ans,num1=0.0,num2=1.0;
    cin >> n;
    double a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        
    }
    
    for(int i=0;i<n;i++){
        num1 = num1 + (1/a[i]);
    }
    ans = 1/num1;
    cout << ans << endl; 
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
use itertools::Itertools;
use std::cmp::{max, min};
use std::collections::*;
use std::i64;
use std::io::{stdin, Read};
use std::usize;

trait ChMinMax {
    fn chmin(&mut self, other: Self);
    fn chmax(&mut self, other: Self);
}
impl<T> ChMinMax for T
where
    T: PartialOrd,
{
    fn chmin(&mut self, other: Self) {
        if *self > other {
            *self = other
        }
    }
    fn chmax(&mut self, other: Self) {
        if *self < other {
            *self = other
        }
    }
}

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, m: usize);
    let mut sl = vec![];
    for _ in 0..m {
        parse!(it, k: usize, s: [usize; k]);
        let mut ss = 0;
        for si in s {
            ss += 1 << (si - 1)
        }
        sl.push(ss);
    }
    parse!(it, p: [usize; m]);
    let mut ret = 0;
    for s in 0usize..(1 << n) {
        if (0..m).all(|i| (sl[i] & s).count_ones() % 2 == p[i] as u32) {
            ret += 1;
        }
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

int main() {
    string s;
    cin >> s;
    vector<int> num(s.size(), 0);
    int p = -1;
    int N = s.size();
    for (int i = 0; i < N; i++) {
        if (s[i] == 'R') {
            p = i;
        } else if (p == -1) {
            num[0]++;
        } else {
            if ((p - i) % 2 == 0) {
                num[p]++;
            } else {
                num[p + 1]++;
            }
        }
    }
    p = -1;
    for (int i = N - 1; i >= 0; i--) {
        if (s[i] == 'L') {
            p = i;
        } else if (p == -1) {
            num[N - 1]++;
        } else {
            if ((i - p) % 2 == 0) {
                num[p]++;
            } else {
                num[p - 1]++;
            }
        }
    }
    for (int i = 0; i < N; i++) {
        cout << num[i];
        if (i != N - 1) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
    cout << endl;
}

Measured memory_bytes: 1024
def solve(n, h, w, a, b):
    ans = 0
    for i in range(n):
        if (a[i] >= h) and (b[i] >= w):
            ans += 1
    return ans

n, h, w = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(n, h, w, a, b))

Measured memory_bytes: 3064
package main

import "fmt"

func sum(s string) int {
	sum := 0
	for _, c := range s {
		sum += int(c - '0')
	}
	return sum
}

func main() {
	var s string
	for {
		fmt.Scan(&s)
		if s[0] == '0' {
			break
		}
		fmt.Println(sum(s))
	}
}



Measured memory_bytes: 1136
<?php
fscanf(STDIN, "%d %d", $N, $X);
$numArray = explode(" ", trim(fgets(STDIN)));

$count=1;
$D =0;
for($i=0;$i<$N;$i++){
  $D = $D + $numArray[$i];
  if($D<=$X){
    $count++;
  }
}
   
  echo  $count."\n";

 

 
?>

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

int main(){
    string s;
    int a, b;

    for(int i = 0; i < 9; i++){
        cin >> s >> a >> b;
        cout << s << " " << a+b << " " << 200*a + 300*b << endl;
    }

    return 0;
}


Measured memory_bytes: 3140
import java.util.*;
public class Main{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int[] a=new int[5];
    int m=0;
    for(int i=0;i<5;i++)
    {
       a[i]=sc.nextInt();
      if(a[i]==0)
         m=i+1;
    }
    System.out.println(m);
  }
}

Measured memory_bytes: 35692
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    AB = []
    for _ in range(N):
        A, B = map(int, readline().split())
        AB.append((A,B))
    AB.sort(key=lambda x:x[1])
    time_count = 0
    for i in range(N):
        A = AB[i][0]
        B = AB[i][1]
        time_count += A
        if time_count>B:
            print('No')
            break
        else:
            continue
    else:
        print('Yes')

if __name__ == '__main__':
    main()


Measured memory_bytes: 31804
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N, M;
vv<pair<int, int>> graph;
vector<int> num;
vector<bool> bw;

int dfs(int v, int from) {
    for (const auto& u : graph[v]) {
        if (u.first == from) continue;
        if (num[u.first]) {
            if (num[v] + num[u.first] > u.second) return bw[v] ? 1 : -1;
            else if (num[v] + num[u.first] < u.second) return bw[v] ? -1 : 1;
            else continue;
        }
        bw[u.first] = !bw[v];
        int n = u.second - num[v];
        if (n <= 0) return bw[v] ? 1 : -1;
        num[u.first] = n;
        int r = dfs(u.first, v);
        if (r) return r;
    }
    return 0;
}

int main() {
    cin >> N >> M;
    graph.resize(N);
    rep(i, M) {
        int u, v, s;
        cin >> u >> v >> s;
        u--; v--;
        graph[u].emplace_back(v, s);
        graph[v].emplace_back(u, s);
    }

    bw.resize(N);
    bw[0] = true;
    int ll = 0, lh = 1e9;
    while (lh - ll > 1) {
        int lm = (ll + lh) / 2;
        num.assign(N, 0);
        num[0] = lm;
        int r = dfs(0, -1);
        if (r >= 0) lh = lm;
        else ll = lm;
    }
    int hl = 1, hh = 1e9 + 1;
    while (hh - hl > 1) {
        int hm = (hl + hh) / 2;
        num.assign(N, 0);
        num[0] = hm;
        int r = dfs(0, -1);
        if (r <= 0) hl = hm;
        else hh = hm;
    }

    num.assign(N, 0);
    num[0] = lh;
    write(dfs(0, -1) ? 0 : hl - lh + 1);
}

Measured memory_bytes: 13952
fn main() {
    let ap = read_vec::<usize>();
    let sum = ap[0] * 3 + ap[1];
    println!("{}", sum / 2);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

int n, m;
vector<int> G[100010];

// 2部グラフ判定
struct BipartiteGraph{
    int n;    
    vector<int> color;
    BipartiteGraph(int _n){
        n = _n;
        color.resize(n, 0);
    }
    bool dfs(int v, int c){
        color[v] = c;
        bool res = true;
        for(int i = 0; i < G[v].size(); i++){
            if(color[G[v][i]] == c) res &= false;
            if(color[G[v][i]] == 0) res &= dfs(G[v][i], -c);
        }
        return res;
    }
    bool isBipartiteGraph(){
        bool res = true;
        for(int i = 0; i < n; i++){
            if(color[i] == 0){
                res &= dfs(i, 1);
            }
        }
        return res;
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    rep(i, 0, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    BipartiteGraph bg(n);
    bool f = bg.isBipartiteGraph();
    if(f){
        int a = 0, b = 0;
        rep(i, 0, n){
            if(bg.color[i] == 1) a++;
            else b++;
        }
        cout << a * b - m << endl;
    }else{
        cout << n * (n - 1) / 2 - m << endl;
    }
}

Measured memory_bytes: 7552
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		String str;
		Scanner scan = new Scanner(System.in);
		str = scan.nextLine();
		StringBuilder sb = new StringBuilder();
		for (int i = str.length() - 1; i >= 0; i--) {
			sb.append(str.charAt(i));
		}
		String str2 = new String(sb);
		System.out.println(str2);
	}
}

Measured memory_bytes: 17124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
#define pb push_back
ll n,m;
queue<pair<ll,ll>> q;
vector<ll>edge[(ll)1e5+10];
ll c[(ll)1e5+10];
void bfs(ll x){
    for(ll i:edge[x]){
        if(c[i]==-1)q.push({x,i});
    }
    while(!q.empty()){
        ll nx=q.front().first,ni=q.front().second;q.pop();
        //cout<<nx<<" "<<ni<<endl;
        if(c[ni]==-1){c[ni]=nx;
            for(ll i:edge[ni]){
                if(c[i]==-1)q.push({ni,i});
            }
        }
    }
}
int main(void){
    cin>>n>>m;
    rep(0,i,n)c[i]=-1;
    rep(0,i,m){
        ll a,b;
        cin>>a>>b;
        --a,--b;
        edge[a].pb(b);
        edge[b].pb(a);
    }
    bfs(0);
    bool t=true;
    rep(1,i,n)if(c[i]==-1)t=false;
    if(t){
        cout<<"Yes"<<endl;
        rep(1,i,n)cout<<c[i]+1<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 15424
// AOJ 2180: Water Tank
// 2017.11.03 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define EPS 1e-7
#define MIN(a,b) ((a)<=(b)?(a):(b))

int n, l, s[86402], t[86402], u[86402];

int check(double *v, double a)
{
	int i, x;
	double e;

	for (e = *v, x = 0, i = 0; i < n; i++) {
		e = MIN(l, e + a*(s[i]-x));
		x = s[i];
		e = MIN(l, e + (t[i]-x)*(a-u[i]));
		if (e < 0) { *v = e; return 1; }
		x = t[i];
	}
	*v = MIN(l, e + a*(86400-x));
	return 0;
}

int calc(double a)
{
	int i;
	double v[3];
	for (v[0] = l, i = 0; i < 2; i++) {
		if (check(v+i, a)) return 0;
		v[i+1] = v[i];
	}
	return fabs(v[0]-v[1]) <= EPS;
}

int main()
{
	int i;
	double up, low, mid;

	while (scanf("%d%d", &n, &l) && n > 0) {
		for (i = 0; i < n; i++) scanf("%d%d%d", s+i, t+i, u+i);
		low = 0, up = 1e7;

		while (fabs(low - up) > EPS) {
			mid = (low + up)/2;
			if (calc(mid)) up = mid; else low = mid;
		}
		printf("%.8lf\n", up);
	}
}

Measured memory_bytes: 2740
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath> 
#include <tuple>
#include <bitset>
#include<string>
//pair sort firstに揃う

#define int long long
#define double long double
#define Rap(n,i) for(int (i)=0;(i)<(n);(i)++)
#define Pr(n) cout<<n<<endl;
#define PairV vector<pair<int , int> >
#define F first
#define S second
#define Vector1 vector<int>
#define VectorS vector<string>
#define vector2 vector<vector<int> >
#define index(v,x) find((v).begin(), (v).end(), (x))-(v).begin()
#define ctoi(c) (int)(c-'0')
#define incin(n) int (n); cin>>(n);
#define incin2(n,m) int (n),(m); cin >> (n)>>(m);
#define stcin(s) string (s); cin>>(s);
#define all(v) (v).begin() , (v).end()
namespace Mathf
{
    const int INF = 1000000000000;
    const double PI = 3.14159274;
    const double Rad2Deg = 57.29578;
    const double log2(double a,double b);
    const double log2(double a,double b){
        return log(b)/log(a);
    }
} // namespace Mathf

using namespace std;

int MD(pair<int,int> a,pair<int,int> b){//ManhattanDisRance
    return abs(a.first-b.first) + abs(a.second-b.second);
}
int MOD(int a,int b){
    return abs(a%b);
}
template <typename T1,typename T2> bool Comp (pair<T1,T2> a,pair<T1,T2> b){
    if(a.first!=b.first){
        return a.first<b.first;//first昇順
    }
    if(a.second!=b.second){
        return a.second > b.second;//second降順
    }else{
        return  true;
    }
}
double Dis(pair<int,int> a,pair<int,int> b){
    return sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
}
int Step(int N){
    if(N==0){
        return 1;
    }else{
        return N*Step(N-1);
    }
}
int Pemu(int n,int r){
    int ans = n;
    for(int i=0;i<r;i++){
        ans*=(ans-i);
    }
    return ans;
}
int Comb(int n,int m){
    int ans=n;
    for(int i=0;i<m;m++){
        ans*=(ans-i);
    }
    return ans/Step(m);
}
int Digit(int x){
    string ss = to_string(x);
    int size = ss.size();
    int sum = 0;
    for(int i=0;i<size;i++){
        sum+=ctoi(ss[i]);
    }
    return sum;
}
signed  main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

   incin2(n,t);
   PairV ct(n);
   Rap(n,i){
       cin >> ct.at(i).first >> ct.at(i).second;
   }
   int cost = 1000000000;
   Rap(n,i){
       if(ct[i].second<=t){
           if(ct[i].first<cost){
               cost = ct[i].first;
           }
       }
   }
   if(cost < 1000000000){
       cout<<cost<<endl;
   }else{
       cout<<"TLE"<<endl;
   }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int H,W,h,w;

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

    return 0;
}


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9



int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a, b; cin >> a >> b;

    int n = b-a;
    int ans = n * (n-1) / 2 - a;
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    int n;
    cin >> n;
    int ans = 0;
    vector<vector<P>> data(n);
    rep(i, n) {
        int a;
        cin >> a;
        rep(j, a) {
            int x, y;
            cin >> x >> y;
            x--;
            data[i].push_back(P(x, y));
        }
    }
    
    rep(i, pow(2, n)) {
        bool ok = true;
        rep(j, n) {
            int v = i>>j & 1;
            if (v==0) continue;
            for (auto p: data[j]) {
                if ((i>>p.first&1)!=p.second) ok = false;
            }
        }
        if (ok) {
            int num = __builtin_popcount(i);
            if (num>ans) ans = num;
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

int main(){
  
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
 if(A+B>C+D){
   cout << "Left" << endl;
 }
  else if (A+B<C+D){
    cout << "Right" << endl;
  }
  else if (A+B==C+D){
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <fstream>
#include<string>
#include<sstream>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
#include <math.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long long int MOD = 1000000007;
const int INF = 1000000007;
const double EPS = 1e-10;
const double PI = 3.14159265359;
const int N = 100005;
//cout << fixed << std::setprecision(9)
//--------------------------
 
ll dp[N][2];
vector<int> edge[N];
int n, u, v;
 
void dfs(int x, int last)
{
	dp[x][0] = dp[x][1] = 1;
	for (auto to : edge[x]) {
		if (to == last) continue;
		dfs(to, x);
		dp[x][0] = dp[x][0] * ((dp[to][0] + dp[to][1]) % MOD) % MOD;
		dp[x][1] = dp[x][1] * dp[to][0] % MOD;
	}
}
 
int main()
{
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> u >> v;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
 
	dfs(1, -1);
	cout << (dp[1][0] + dp[1][1]) % MOD << endl;
 
	return 0;
}

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

#define int long long

int32_t main()
{
	int n, r;
	cin >> n >> r;
		
	if (n >= 10)
		cout << r << endl;
	else
		cout << r + 100 * (10 - n) << endl;
	return 0;
}

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

using namespace std;

long long N;
vector<long long> A;

int main()
{
    cin >> N;
    long long sum = 0;
    
    for (int i = 0; i <= N - 1; i++)
    {
        long long a;
        cin >> a;
        sum += a;
        A.push_back(a);
    }
    long long NN = (N * (N + 1)) / 2;
    if (sum % NN != 0)
    {
        cout << "NO" << endl;
        return 0;
    }
    long long p = (long long)(sum / NN);
    bool f = true;
    long long cnt = 0;
    for (int i = 0; i < N; i++)
    {
        long long hoge = p - (A[(i+1)%N]-A[i]);
        if(hoge % N != 0 || hoge < 0)
        {
            f = false;
            break;
        }
        else
        {
            cnt += hoge / N;
        }
    }

    if(cnt != p)
    {
        f = false;
    }

    if (f == true)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 1400
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    n=int(input())
    a=list(map(int,input().split()))
    a=sorted(a,reverse=True)
    if n%2==0:
        a1=a[0:n//2]
        a2=a[n//2:]
    else:
        a1=a[0:n//2+1]
        a2=a[n//2+1:]
#    print(a,a1,a2)
    count=0
    if n>=3:
        for i in range(len(a1)):
            count+=a1[i]
        for i in range(1,len(a2)):
            count+=a1[i]
    else:
        count=a[0]
    print(count)

if __name__ == "__main__":

    main()

Measured memory_bytes: 100040
S=input()
chk = [False, False, False]
if S[0]=="A":
    chk[0]=True

ind = 0
for i in range(2, len(S)-1):
    if S[i]=="C":
        chk[1]=True
        ind=i

chk[2]=True
for i in range(len(S)):
    if i==ind or i==0:
        continue
    if S[i].isupper():
        chk[2]=False

if chk[0] and chk[1] and chk[2]:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 9148
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
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; }
using namespace std;


int main(){
  string S;
  cin>>S;
  REP(i,S.size()) cout<<"x";
  cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	string str;
	cin>>str;
	int i = 0;
	int len = str.length();
	while((str[i] != '\0')&&(i< len)){
		if(str[i] == 'C'){
			while(str[++i] != '\0'){
				if(str[i] == 'F'){
					cout<<"Yes";
					return 0;
				}
			}
		}
		i++;
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

int main() {
    int N;
    int sum = 0;
    cin >> N;

    for (int i = 1; i <= N; i++) {
        sum += i;
    }

    cout << sum << endl;

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

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

void solve() {
  int x;
  cin >> x;
  cout << lcm(x, 360) / x << endl;
}


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

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

constexpr int INF = (1 << 30) - 1;
constexpr int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
constexpr int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

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 / gcd(a, b) * b ); }

int main()
{
	int N, M;
	ll ans = 0ll;
	map < int , int > mp;

	cin >> N >> M;

	int sum = 0;
	mp[0] = 1;
	for ( int i = 0; i < N; i++ ) {
		int A;
		cin >> A;
		(sum += A) %= M;
		ans += mp[sum];
		mp[sum]++;
	}

	cout << ans << endl;

	return ( 0 );
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

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

    int n=s.size();
    int ans=INF;
    bool o=true;
    char y=s[0];
    rep(i,n){
        if(s[i]!=y) o=false;
    }

    if(o){
        cout<<0<<endl;
        return 0;
    }

    rep(i,n){
        char x=s[i];
        string t=s;
        int tmp=0;
        while(1){
            tmp++;
            string tt="";
            rep(j,t.size()-1){
                if(t[j]==x || t[j+1]==x) tt+=x;
                else tt+=t[j];
            }
            bool ok=true;
            rep(j,tt.size()){
                if(tt[j]!=x) ok=false;
            }
            if(ok) break;
            t=tt;
        }
        ans=min(ans,tmp);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3612
// 1_nikkei2019_2qual_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n / 2; i++){
        int j = n - i;
        if(i != j) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define ll long long
#define pii pair<int,int>
const int mod=1e9+7;
int lcs[3001][3001];
int solve(int i,int j,string &s,string &t){
    if(i<0 || j<0) return 0;
    if(lcs[i][j]!=-1) return lcs[i][j];
    if(i==0 || j==0) lcs[i][j]=0;
    else if(s[i-1]==t[j-1]){
        lcs[i][j]=1+solve(i-1,j-1,s,t);
        int t1=solve(i-1,j,s,t);
        t1=solve(i,j-1,s,t);
    }
    else{
        lcs[i][j]=max(solve(i-1,j,s,t),solve(i,j-1,s,t));
    }
    return lcs[i][j];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("inputf.txt","r",stdin);
    freopen("outputf.txt","w",stdout);
#endif
    
    string s,t;
    cin>>s>>t;
    memset(lcs,-1,sizeof(lcs));
    int n=s.length(),m=t.length();
    //cout<<n<<" "<<m<<"\n";
    int len=solve(n,m,s,t);
    char ans[len];
    int i=n,j=m,k=len-1;
    while(i>0 && j>0){
        if(s[i-1]==t[j-1]){
            //cout<<s[i];
            ans[k]=s[i-1];
            k--;
            i--;
            j--;
        }
        else if(lcs[i-1][j]>lcs[i][j-1]) i--;
        else j--;
    }
    for(int i=0;i<len;i++){
        cout<<ans[i];
    }
    return 0;
}

Measured memory_bytes: 39208
h,w=map(int,input().split())
n=input()
v=[]
for i,a in enumerate(list(map(int,input().split()))):
    v+=[i+1]*a
for j in range(h):
    if j%2==0:
        u = v[w*j:w*(j+1)]
    else:
        u = v[w*(j+1)-1:w*j-1:-1]
    print(" ".join(map(str,u)))

Measured memory_bytes: 3572
A = int(input())
B = int(input())
C = int(input())
money = int(input())
ii = 0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if 500*i+100*j+50*k == money:
        ii += 1
print(ii)

Measured memory_bytes: 9040
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;
using namespace std;


int main(){
	string S,T; cin >> S; cin >> T;
    bool f = true;
    REP(i,S.size()) if(S[i] != T[i]) f = false;
    if(f) cout << "Yes";
    else cout << "No";
  	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll n,a,b;
  cin >> n >> a >> b;
  if(a%2==b%2){
    cout << (b-a)/2 << endl;
    return 0;
  }
  else{
    ll ans =0;
    if(a-1 < n-b){
      ans+=a;
      ans += ((b-a)-1)/2;
    }
    else{
      ans+=n-b+1;
      ans += (n-(a+n-b+1))/2;
    }
    cout << ans << endl;
  }
  
  return 0;
    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first;
#define se second;
#define print(x,y) (cout << (x) << (y))
#define inf INT_MAX
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,bool> pib;
typedef vector<pii> vii;
typedef vector<pib> vib;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<string,string> pss;
typedef vector<pss> vss;
const int MOD = 1e9 + 7; //998244353;


int main(){
    boost;
    int a , b;
    cin >> a >> b;
    string sa = "" , sb = "";
    for(int i = 0;i<a;i++)sb += to_string(b);
    for(int i = 0;i<b;i++)sa += to_string(a);
    if(sa < sb) cout << sa; else cout << sb;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
typedef long long int ll;
#define pb         push_back
#define mp         make_pair
#define F          first
#define S          second
#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define pll        pair<ll,ll>
#define pii        pair<int,int>
#define all(v)     v.begin(),v.end()
#define M          1000000321

using namespace std;
bool isPrime(ll n)
{
    if(n<=1)
        return false;
    if(n<=3)
        return true;
    if(n%2==0 || n%3==0)
        return false;

    for(ll i=5;i*i<=n;i=i+6)
        if(n%i==0|| n%(i+2)==0)
            return false;

    return true;
}

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

}

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



int main()
{
 ios::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
 ll n,k;
 cin>>n>>k;
 vector<ll> h;
 ll a;
 h.pb(0);
 fl(i,0,n)
 {
    cin>>a;
    h.pb(a);
  }
  ll dp[n+1];
  memset(dp,-1,sizeof(dp));
  dp[1]=0;
  fl(i,2,n+1)
  {
    ll j=i-1,c=1;
    while(j>=1 && c<=k)
    {
        if(dp[i]==-1)
            dp[i]=dp[j]+abs(h[i]-h[j]);
        else
            dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
        j--;
        c++;
    }
  }
 cout << dp[n];
}

Measured memory_bytes: 1908
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    s = input()
    t = input()
    ns = len(s)+1
    nt = len(t)+1
    ssa = [0]*ns
    ssb = [0]*ns
    sta = [0]*nt
    stb = [0]*nt
    for i,si in enumerate(s):
        if si == "A":
            da = 1
            db = 0
        else:
            da = 0
            db = 1
        ssa[i+1] = ssa[i]+da
        ssb[i+1] = ssb[i]+db
    for i,ti in enumerate(t):
        if ti == "A":
            da = 1
            db = 0
        else:
            da = 0
            db = 1
        sta[i+1] = sta[i]+da
        stb[i+1] = stb[i]+db

    q = int(ipt())
    for _ in range(q):
        a,b,c,d = map(int,ipt().split())
        da = ssa[b]-ssa[a-1]-sta[d]+sta[c-1]
        db = ssb[b]-ssb[a-1]-stb[d]+stb[c-1]
        if (da-db)%3 == 0:
            print("YES")
        else:
            print("NO")

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 56404
#include <stdio.h>

int main(){
   int i,n;
   long s;

   scanf("%d",&n);
   s=0;
   for (i=1;i<=n;i++) 
   if (i%3==0 || i%5==0) continue;
   else                  s+=i;
   printf("%ld\n",s);
   return 0;
}


Measured memory_bytes: 1736
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int array[] = new int[3];
		for (int i = 0; i < 3; i++)
			array[i] = sc.nextInt();
		bubbleSort(array);
		System.out.println(array[0] + " " + array[1] + " " + array[2]);

	}

	static void swap(int[] array, int a, int b) {
		int temp = array[a];
		array[a] = array[b];
		array[b] = temp;
	}

	static void bubbleSort(int[] array) {
		for (int i = 0; i < array.length - 1; i++) {
			for (int j = array.length - 1; j > i; j--) {
				if (array[j - 1] > array[j])
					swap(array, j - 1, j);
			}
		}
	}

}

Measured memory_bytes: 26188
#include <iostream>

using namespace std;

int main(void)
{
    int A, B;
    cin >> A >> B;

    if(A == 1) A = 14;
    if(B == 1) B = 14;
    if(A > B) cout << "Alice" << endl;
    else if(A < B) cout << "Bob" << endl;
    else cout << "Draw" << endl;
    return 0;
}

Measured memory_bytes: 888
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),m=sc.nextInt();
        int[] count = new int[m];
        int ans = 0;
        for(int i = 1;i<=n;i++){
            int k = sc.nextInt();
            for(int j = 0;j<k;j++){
                count[sc.nextInt()-1] ++;
            }
        }
        for(int i =0;i<m;i++){
            if(count[i]==n){
                ans ++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)

lli maxA(lli a,lli b,lli c){
	lli rtn = max(a,b);
	rtn = max(rtn,c);
	return rtn;
}
lli minA(lli a,lli b,lli c){
	lli rtn = min(a,b);
	rtn = min(rtn,c);
	return rtn;
}

signed main(){

	lli n;
	cin>>n;
	vector<lli> p(n);
 	REP(i,0,n)cin>>p[i];

 	lli cnt=0;
 	for(lli i=1;i<n-1;i++){
 		lli maxB = maxA(p[i-1],p[i],p[i+1]);
 		lli minB = minA(p[i-1],p[i],p[i+1]);
 		if(p[i] != maxB && p[i] != minB)cnt++;
 	}

 	cout<<cnt<<endl;


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

struct edge{ int to,cost; };
vector<int> dikstra(int s,vector<vector<edge>> G){
  typedef pair<int, int> P;
  const int INF = 1LL << 60;

  priority_queue<P,vector<P>,greater<P>> que;
  vector<int> d(G.size(),INF); //sからの最短距離
  d[s] = 0;
  que.push({0,s}); //{最短距離,頂点}

  while( !que.empty() ){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(auto e : G[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push( {d[e.to],e.to} );
      }
    }
  }
  return d;
}

signed main(){

  int n, u, v; cin >> n >> u >> v;
  u--, v--;
  vector<vector<edge>> G(n);
  for(int i = 0; i < n-1; i++){
    int a, b; cin >> a >> b;
    a--, b--;
    G[a].push_back({b, 1});
    G[b].push_back({a, 1});
  }

  auto dp = dikstra(u, G);
  auto dp2 = dikstra(v, G);
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(dp[i] < dp2[i]){
      ans = max(ans, dp2[i] - 1);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 16800
a=[0]*3
b=[0]*3
c=[]
for i in range(3):
    c.append(list(map(int, input().strip().split())))

a[0]=0
b[0]=c[0][0]
b[1]=c[0][1]
b[2]=c[0][2]
a[1]=c[1][0]-b[0]
a[2]=c[2][0]-b[0]

fl=True
for i in range(3):
    for j in range(3):
        if c[i][j]!=a[i]+b[j]:
            fl=False
if fl:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder.Abc173
{
    class F
    {
        public static void Main()
        {
            var n = long.Parse(Console.ReadLine());

            var count = n * (n + 1) * (n + 2) / 6L;

            for (int i = 0; i < n - 1; i++)
            {
                var uv = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                var (u, v) = uv[0] < uv[1] ? (uv[0], uv[1]) : (uv[1], uv[0]);
                count -= u * (n - v + 1);
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 47028
/*考虑最左端和最右端人数
分别为A和B
若A>=B，显然B个人都投A，相当于删掉最右端
最左端人数变为A+B
考虑删除序列
显然最先删除的点一定最晚到达
开个栈模拟这个过程即可*/
#include<bits/stdc++.h>
#define N 500005
#define int long long 
using namespace std;
int n,s,z;
struct Node{int x,y;}a[N];
inline bool cmp(Node aa,Node bb){return aa.x<bb.x;}
signed main(){
	scanf("%lld%lld",&n,&s);
	for (int i=1;i<=n;i++) scanf("%lld%lld",&a[i].x,&a[i].y);
	sort(a+1,a+n+1,cmp);
	int l=1;int r=n;
	while (l<=r){
		if (a[l].x>=s){
			z+=a[r].x-s;
			break;
		}
		if (a[r].x<=s){
			z+=s-a[l].x;
			break;
		}
		z+=a[r].x-a[l].x;
		if (a[l].y>=a[r].y){
			while (l<r&&a[l].y>=a[r].y) a[l].y+=a[r--].y;
		}
		else {
			while (l<r&&a[l].y<a[r].y) a[r].y+=a[l++].y;
		}
	}
	printf("%lld\n",z);
	return 0;
}

Measured memory_bytes: 1792