akhauriyash/Code-Regression huggingface dataset:
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<typeof((c).front())>())
#define SZ(x) ((int)(x).size())
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1e9;
// const ll INF = 1e15;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------


int main() {
  string s;
  cin >> s;
  REP(i, s.length()) {
    if (i % 2 == 0) {
      cout << s[i];
    }
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<set>

int main(){
    int N, a;
    std::cin >> N;
    std::set<int> st;
    for(int i = 0; i < N; i++){
        std::cin >> a;
        if(st.find(a) == st.end()) st.insert(a);
        else st.erase(a);
    }
    
    std::cout << st.size() << std::endl;
 }


Measured memory_bytes: 4864
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

  int ans = 2000000000;
  for (int m = -100; m <= 100; ++m) {
    int cost = 0;
    for (int i = 0; i < N; ++i) {
      cost += (a[i] - m) * (a[i] - m);
    }
    ans = min(ans, cost);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int dp[301][301], cost[301][301];

int calc(string s, string t){
    int n = s.length();
    REP(i,n+1) REP(j,n+1) cost[i][j] = 0;
    REP(i,n){
        REP(j,n){
            if (s[i] == t[j]) cost[n-1-i][n-1-j] = 1;
        }
    }
    FORR(i,n-2,0) FORR(j,n-2,0) cost[i][j] += cost[i+1][j+1];
    REP(i,n+1) REP(j,n+1) dp[i][j] = 1e9;
    dp[0][0] = 0;
    REP(i,n+1){
        REP(j,n+1){
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]+cost[i][j]);
            dp[i][j+1] = min(dp[i][j+1], dp[i][j]+cost[i][j]);
        }
    }
    return dp[n][n];
}

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> c(h);
    REP(i,h) cin >> c[i];

    int ans = 0;
    REP(j,w-1){
        string s1, s2;
        REP(i,h){
            s1 += c[i][j];
            s2 += c[i][j+1];
        }
        ans += calc(s1,s2);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
typedef long long int ll;
typedef unsigned long long int ull;
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}

int main(){
    int n;scanf("%d",&n);
    int p[200000];for(int i=0;i<n;i++)scanf("%d",&p[i]);
    int locate[200000]={};
    int ans=0;
    int min=99999999;
    for(int i=0;i<n;i++){
        if(min>p[i]){
            min=p[i];
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
using namespace std;
#define sd(n) scanf("%d", &n)
#define sdd(n, m) scanf("%d%d", &n, &m)
#define sddd(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n, m) printf("%d %d\n", n, m)
#define pddd(n, m, z) printf("%d %d %d\n", n, m, z)
#define pld(n) printf("%lld\n", n)
#define pldd(n, m) printf("%lld %lld\n", n, m)
#define plddd(n, m, z) printf("%lld %lld %lld\n", n, m, z)
#define sld(n) scanf("%lld", &n)
#define sldd(n, m) scanf("%lld%lld", &n, &m)
#define slddd(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)
#define sf(n) scanf("%lf", &n)
#define sc(n) scanf("%c", &n)
#define sff(n, m) scanf("%lf%lf", &n, &m)
#define sfff(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)
#define ss(str) scanf("%s", str)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = a; i >= n; i--)
#define mem(a, n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ce i == n ? '\n' : ' '
#define mod(x) ((x) % MOD)
#define gcd(a, b) __gcd(a, b)
#define lowbit(x) (x & -x)
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
	int ret = 0, sgn = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-')
			sgn = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		ret = ret * 10 + ch - '0';
		ch = getchar();
	}
	return ret * sgn;
}
inline void Out(int a) //ê?3?ía1ò
{
	if (a > 9)
		Out(a / 10);
	putchar(a % 10 + '0');
}

ll gcd(ll a, ll b)
{
	return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
///快速幂m^k%mod
ll qpow(ll x, ll n, ll mod)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = (res * x) % mod;
		x = x * x % mod, n >>= 1;
	}
	return res;
}

const int N = 2e5 + 10;
int n, ans;
;
string s;
map<string, int> mp;

int main()
{
	sd(n);
	mp.clear();
	ans = 0;
	rep(i, 1, n)
	{
		cin >> s;
		if (!mp[s])
			ans++;
		mp[s]++;
	}
	pd(ans);
	return 0;
}


Measured memory_bytes: 19348
input_line = input().split()
target_divide = int(input_line[0])
num_target = int(input_line[1])

if target_divide == 0:
    counter = 0
    current_num = 0
    while counter < num_target:
        current_num += 1
        if current_num % 100 == 0:
            continue
        else:
            counter += 1

    print(str(current_num))
    exit(0)

elif target_divide == 1:
    counter = 0
    current_num = 0
    while counter < num_target:
        current_num += 100
        if current_num % 10000 != 0 and current_num % 1000000 != 0:
            counter += 1

    print(str(current_num))

else:
    counter = 0
    current_num = 0
    while counter < num_target:
        current_num += 10000
        if current_num % 1000000 != 0:
            counter += 1

    print(str(current_num))


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

int main(){
    int A,B,C,X,way=0;
    cin>>A>>B>>C>>X;
    for(int a=min(X/500,A);a>=0;a--)
    {
        int sumB = X-a*500;
        // 判断当前B最大有几张
        for(int b=min(sumB/100,B);b>=0;b--)
        {
            int sumC = sumB-b*100;
            if(sumC%50==0&&sumC/50<=C)
                way++;
        }
    }
    cout<<way<<endl;
    return 0;
}


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

int main( void )
{
	register int i, j;

	register bool isPrime[50001 + 1];
	isPrime[2] = true;
	for ( i = 3; i < 50001; i += 2 )
	{
		isPrime[i] = true;
	}

	for ( i = 3; i < 50001; i += 2 )
	{
		for ( j = i + i; j < 50001; j += i )
		{
			isPrime[j] = false;
		}
	}

	int cnt = 1;
	int primes[5500];
	primes[0] = 2;
	for ( i = 3; i < 50001; i += 2 )
	{
		if ( isPrime[i] )
		{
			primes[cnt] = i;
			cnt++;
		}
	}

	int n;
	while ( cin >> n && n != 0 )
	{
		int kotae = 0;
		for ( i = 0; i < cnt; i++ )
		{
			if ( primes[i] <= n / 2 )
			{
				if ( isPrime[n-primes[i]] )
					kotae++;
			}
		}
		cout << kotae << endl;
	}

	return 0;
}

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

bool isSameNum(int a, int b, int c) {
    if(a == b && b == c) return true;
    return false;
}

bool isGoodIncre(int a, int b, int c) {
    if(a == b-1 && b == c-1) return true;
    return false;
}

bool isOKSet(int a, int b, int c) {
    return isSameNum(a, b, c) || isGoodIncre(a, b, c);
}

int main() {
    vector<int> num(9);
    vector<char> col(9);
    vector<int> rst;
    int n; cin >> n;
    for(int k = 0; k < n; k++) {
        for(int j = 0; j < 2; j++) {
            for(int i = 0; i < 9; i++) {
                if(j == 0) {
                    cin >> num[i]; 
                } else {
                    cin >> col[i];
                }
            }
        }

        for(int i = 0; i < 9; i++) {
            if(col[i] == 'G') {
                num[i] += 10;
            } else if(col[i] == 'B') {
                num[i] += 10;
            }
        }
        sort(num.begin(), num.end());
        bool flg = false;
        do {
            if(isOKSet(num[0], num[1], num[2]) && isOKSet(num[3], num[4], num[5]) && isOKSet(num[6], num[7], num[8])) {
                rst.push_back(1);
                flg = true;
                break;
            }
        } while(next_permutation(num.begin(), num.end()));
        if(flg == false) rst.push_back(0);
    }

    for(auto i : rst) cout << i << endl;
    

    return 0;
}



Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#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){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<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;}

#define INF 1120000000

template<typename T>
class SegTree {
private:
  int n;
  vector<T> data;
public:
  SegTree(int m){
    n=1;
    while(n<m) n*=2;
    data = vector<T>(2*n, 0);
  }
  void update(int l, int r, T v){
    for(l+=n, r+=n; l<r; l/=2, r/=2){
      if(l&1) data[l++] += v;
      if(r&1) data[--r] += v;
    }
  }
  T get(int k){
    k += n;
    T ret = data[k];
    while(k>0){
      k = k/2;
      ret += data[k];
    }
    return ret;
  }
};

int main(){
  int n,q;
  cin>>n>>q;
  SegTree<long> st(n);

  rep(_,q){
    int t; cin>>t;
    if(t==0){
      int l,r,v;
      cin>>l>>r>>v;
      st.update(l-1,r,v);
    }
    else {
      int i;
      cin>>i;
      cout << st.get(i-1) << endl;
    }
  }

  return 0;
}

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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> arr(n), dp(n + 1, INT_MAX);
	for(int i = 0; i < n; ++i) {
		cin >> arr[i];
	}

	dp[0] = 0;  
	for(int i = 1; i < n; ++i) {
		for(int j = i - 1; j >= 0 && i - j <= k; --j) {
			dp[i] = min(dp[i], abs(arr[j] - arr[i]) + dp[j]);
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 3936
#include<iostream>
#define int long long
using namespace std;
int size[100001],fa[100001];
int find(int x){
	if(x!=fa[x])
		fa[x]=find(fa[x]);
	return fa[x];
}
signed main(){
	int n,m;
	cin>>n>>m;
	struct edge{
		int u;
		int v;
	}e[m+1];
	int ans[m+1];
	for(int i=1;i<=m;++i)
		cin>>e[i].u>>e[i].v;
	for(int i=1;i<=n;++i)
		size[i]=1;
	for(int i=1;i<=n;++i)
		fa[i]=i;
	ans[m]=n*(n-1)/2;
	for(int i=m;i>=2;--i){
		int x=find(e[i].u);
		int y=find(e[i].v);
		if(x==y)
			ans[i-1]=ans[i];
		else{
			ans[i-1]=ans[i]-size[x]*size[y];
			size[x]+=size[y];
			fa[y]=fa[x];
		}
	}
	for(int i=1;i<=m;++i)
		cout<<ans[i]<<endl;
	return 0;
}

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

signed main() {
    int N, x;
    cin >> N >> x;

    int n = 2 * N - 1;
    if (x == 1 || x == n) {
        return cout << "No" << endl, 0;
    }
    cout << "Yes";

    int num = 1;
    for (int i = 1; i <= n; i++) {
        cout << endl;
        if (i >= N - 1 && i <= N + 1) {
            cout << x + i - N;
            continue;
        }
        if (num >= x - 1 && num <= x + 1) {
            num = x + 2;
        }
        cout << num++;
    }
    cout << endl;
}


Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    static Node nodeRoot;
    static StringBuilder sb = new StringBuilder();

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for (int i = 0; i < n; i++) {
            String s = br.readLine();
            if (s.charAt(0) == 'i') {
                int m = Integer.parseInt(s.substring(7));
                if (nodeRoot == null) {
                    nodeRoot = new Node(m);
                    continue;
                }
                insert(m, nodeRoot);
            } else if (s.charAt(0) == 'p') {
                sb.append(" ");
                inorder(nodeRoot);
                sb.deleteCharAt(sb.length() - 1).append("\n").append(" ");
                preorder(nodeRoot);
                sb.deleteCharAt(sb.length() - 1).append("\n");
            } else {
                int m = Integer.parseInt(s.substring(5));
                sb.append(find(m, nodeRoot) ? "yes\n" : "no\n");

            }
        }
        System.out.print(sb);
    }

    private static boolean find(int m, Node node) {
        if (node == null) return false;
        if (m > node.value) {
            return find(m, node.right);
        } else if (m < node.value) {
            return find(m, node.left);
        } else {
            return true;
        }
    }

    private static void preorder(Node node) {
        if (node == null) return;
        sb.append(node.value).append(" ");
        preorder(node.left);
        preorder(node.right);
    }

    private static void inorder(Node node) {
        if (node == null) return;
        inorder(node.left);
        sb.append(node.value).append(" ");
        inorder(node.right);
    }

    private static void insert(int m, Node node) {
        if (m > node.value) {
            if (node.right == null) node.right = new Node(m);
            else insert(m, node.right);
        } else {
            if (node.left == null) node.left = new Node(m);
            else insert(m, node.left);
        }
    }

    static class Node {
        int value;
        Node left;
        Node right;

        public Node(int value) {
            this.value = value;
        }
    }
}


Measured memory_bytes: 102324
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        A: i32,
        B: i32,
        C: i32,
    }

    let mut arr = vec![A, B, C];
    arr.sort();

    let ans = arr[2] * 10 + arr[1] + arr[0];
    println!("{}", ans);
}


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

int main() {
  int X;
  cin >> X;
  int uresi = 0;
  int countYen = X / 500;
  int remain = X % 500;
  uresi += countYen * 1000;
  countYen = remain / 5;
  uresi += countYen * 5;
  cout << uresi << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int main(){
  ll k;
  int n;
  cin >> k >> n;
  vector<ll> a(n);
  for(int i=0;i<n;i++) cin >> a[i];

  vector<ll> dist(n);
  for(int i=0;i<n-1;i++) dist[i] = a[i+1]-a[i];
  dist[n-1] = a[0] + k-a[n-1];

  ll sum = 0;
  for(int i=0;i<n;i++){
    sum += dist[i];
  }

  ll m = 0;
  for(int i=0;i<n;i++){
    m = max(m,dist[i]);
  }

  ll ans = sum-m;
  cout << ans << endl;
}


Measured memory_bytes: 3328
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define mod 1000000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	int n,x,y;
	cin>>n>>x>>y;
	int dp[n][n];
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n-1;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			dp[i][j] = min(j-i, abs(x-i)+1+abs(y-j));
		}
	}
	map<int,int> mp;
	for(int i=1;i<=n-1;i++)
		for(int j=i+1;j<=n;j++)
			++mp[dp[i][j]];
	vector<int> ans(n+1,0);
    for(auto it: mp)
		ans[it.fi] = it.se;
    for(int i=1;i<=n-1;i++)
        cout<<ans[i]<<"\n";
	return 0;	
}

Measured memory_bytes: 16000
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

#define MAX_V 200000
struct edge{int to,cap,rev;};
 
vector<edge> G[MAX_V];
bool used[MAX_V];
 
void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}
 
int dfs(int v,int t,int f){
  int i;
  if(v==t)return f;
  used[v]=true;
  rep(i,G[v].size()){
    edge &e=G[v][i];
    if(!used[e.to] && e.cap>0){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G[e.to][e.rev].cap+=d;
	return d;
      }
    }
  }
  return 0;
}
 
int max_flow(int s,int t){
  int flow=0;
  while(1){
    memset(used,0,sizeof(used));
    int f=dfs(s,t,INF);
    if(f==0)return flow;
    flow+=f;
  }
}

int main(void) {
  int i,j;
  int n;
  cin>>n;
  vi a(n),b(n),c(n),d(n);
  rep(i,n)cin>>a[i]>>b[i];
  rep(i,n)cin>>c[i]>>d[i];

  int cnst=n+5;

  rep(i,n){
    add_edge(0,cnst+i,1);
    add_edge(2*cnst+i,3*cnst,1);
  }

  rep(i,n)rep(j,n)
    if(a[i]<c[j] && b[i]<d[j]){
      add_edge(cnst+i,2*cnst+j,1);
  }

  cout<<max_flow(0,3*cnst)<<endl;

}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(ll i=a ; i<b; i++)
int main()
{ ll n; cin>>n; ll a[n][3]; f(i,0,n) { f(j,0,3) { cin>>a[i][j];  } } 
f(i1,1,n) { a[i1][0]=a[i1][0]+max(a[i1-1][1],a[i1-1][2]); 
a[i1][1]=a[i1][1]+max(a[i1-1][0],a[i1-1][2]);
a[i1][2]=a[i1][2]+max(a[i1-1][1],a[i1-1][0]);
}
ll ans=0; ans=max(ans,a[n-1][0]); 
ans=max(ans,a[n-1][1]); 
ans=max(ans,a[n-1][2]); 
cout<<ans<<"\n";

}

Measured memory_bytes: 5916
#include<stdio.h>
int main(void)
{
	int n,s[1000],p[1000],q[1000],r[1000],a,b,c,x,i,flg;
	while(1){
		scanf("%d",&n);
		if(n==0)	break;
		for(i=0;i<n;i++){
			scanf("%d %d %d %d",&s[i],&p[i],&q[i],&r[i]);
		}
		scanf("%d %d %d %d",&a,&b,&c,&x);
		flg=0;
		for(i=0;i<n;i++){
			if(p[i]<=a&&q[i]<=b&&r[i]<=c&&4*p[i]+9*q[i]+4*r[i]<=x){
				printf("%d\n",s[i]);
				flg=1;
			}
		}
		if(flg==0)	printf("NA\n");
	}
	return 0;
}



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

bool rec(string s) {
  if (s.size() <= 3) {
    return s == "ABC";
  }
  int n = s.size();
  for (char c : "ABC"s) {
    string t;
    int i = 0;
    bool found = false;
    while (i < n) {
      if (s.substr(i, 3) == "ABC") {
        found = true;
        t += c;
        i += 3;
      } else if (s[i] == c) {
        break;
      } else {
        t += s[i];
        ++i;
      }
    }
    if (i < n) {
      continue;
    }
    if (not found) {
      return false;
    }
    if (rec(t)) {
      return true;
    }
  }
  return false;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  cout << (rec(s) ? "Yes\n" : "No\n");
}



Measured memory_bytes: 21828
#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
# input=sys.stdin.readline
from collections import deque
import heapq
from itertools import combinations

n,m,q=map(int,input().split())

l=[]
for i in range(q):
    l.append(list(map(int,input().split())))
x=[i for i in range(n+m-1)]
com=list(combinations(x,m-1))
ans=0
for i in com:
    z=[]
    f=0
    p=1
    # print(i)
    for j in range(m+n-1):
        if j in i:
            p+=1
            continue
        z.append(p)
    tmp=0
    for j in range(q):
        a,b,c,d=l[j]
        a-=1
        b-=1
        if z[b]-z[a]==c:
            tmp+=d
    ans=max(ans,tmp)
print(ans)







Measured memory_bytes: 85276
#include <bits/stdc++.h>
#define pb push_back
#define mkp make_pair
#define llu unsigned long long int
#define ll long long
#define ld long double
#define foi(a, n) for (int i = a; i < n; i++)
#define foj(a, n) for (int j = a; j < n; j++)
#define foin(a, n) for (int i = n; i >= a; i--)
#define fojn(a, n) for (int j = n; j >= a; j--)
#define isp2(x) x && (!(x & (x - 1)))
#define ee 1000000007
#define fio                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
#define cases                                                                  \
  long long t;                                                                 \
  cin >> t;                                                                    \
  while (t--)

using namespace std;

int main() {
  ll n;
  cin >> n;
  ll a[n];
  for (ll i = 0; i < n; ++i)
    cin >> a[i];
  for (ll i = 1; i < n; ++i)
    a[i] += a[i - 1];
  ll ans = INT_MAX;
  for (ll i = 0; i < n; ++i) {
    ans = min(ans, abs(a[i] - (a[n - 1] - a[i])));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
using namespace std;


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

/* vector<int> A(N); 
　xの二乗:  pow(x, 2.0) 
    小さい順: sort(v.begin(), v.end());
*/
 
int main() {
  
  string A,C;
  int B;
  cin >> A;
  B = A.size();
  C="";
  rep(i,B){
  	C+="x";
  }
  
  cout << C << endl;
}

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

int main() {
	int N;
	int t[100010];
	int x[100010];
	int y[100010];
	cin >> N;
	t[0]=0;
	x[0]=0;
	y[0]=0;
	int i;
	for(i=1; i<=N; ++i) cin >> t[i] >> x[i] >> y[i];
	bool possible=true;
	for(i=1; i<=N; ++i)
	{
	    if(t[i]%2 != (x[i]+y[i])%2 || t[i] - t[i - 1] < abs(x[i] - x[i - 1])+abs(y[i] - y[i - 1])) possible=false;
	}
	if(possible) cout << "Yes" <<endl;
	else cout << "No" << endl;
	return 0;
}


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

int main(){
  ll a,b,c,d,ans=0;cin>>a>>b>>c>>d;
  ans=max({a*c,a*d,b*c,b*d});

  cout<<ans;
}

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

using namespace std;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0); cerr.tie(0);
  vector<int> ans(1e4 + 5);
  for (int x = 1; x <= 105; x++) {
    for (int y = 1; y <= 105; y++) {
      for (int z = 1; z <= 105; z++) {
        int s = x*x + y*y + z*z + x*y + y*z + x*z;
        if (s < 1e4 + 5) {
	  ans[s]++;
	}
      }
    }
  }
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<string> s(n);

    int t = 0;
    int f = 0;
    int e = 0;
    int d = 0;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        int l = s[i].size();
        int ind = 0;
        int f_ind = 0;
        while ((f_ind = s[i].find("AB", ind)) >= 0) {
            t++;
            ind = f_ind + 1;
        }
        int c = 0;
        if (s[i][0] == 'B') {
            f++;
            c++;
        }
        if (s[i][l - 1] == 'A') {
            e++;
            c++;
        }
        if (c == 2) {
            d++;
        }
    }

    if (d > 0 && f == d && e == d) {
        f--;
    }

    cout << t + min(f, e) << endl;
}


Measured memory_bytes: 768
N = int(input())

import collections

S_list = [input() for i in range(N)]

S_count = collections.Counter(S_list)

if 'AC' in S_count:
    print('AC x {}'.format(S_count['AC']))
else:
    print('AC x 0')

if 'WA' in S_count:
    print('WA x {}'.format(S_count['WA']))
else:
    print('WA x 0')
if 'TLE' in S_count:
    print('TLE x {}'.format(S_count['TLE']))
else:
    print('TLE x 0')
if 'RE' in S_count:
    print('RE x {}'.format(S_count['RE']))
else:
    print('RE x 0')

Measured memory_bytes: 78776
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int N = S.size();

    bool ok = false;
    if (S[0] == S[N-1]) {
        if (N%2==0) ok = true;
    } else {
        if (N%2==1) ok = true;
    }

    cout << (ok ? "First" : "Second") << endl;
}

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

using namespace std;

#define USE_IOSTREAM \
{\
	ios::sync_with_stdio(false);\
	cin.tie(0);\
	cout.tie(0);\
}

#define pii pair<int, int>
#define mp make_pair

typedef long long ll;


const int N = 2e5 + 1000;

pii tr[N];
map<int, int> mm;
int a[N];
int winNum[N];
int h[N];

void dfs(int u)
{
	if (!tr[u].first)
	{
		h[u] = 0;
		return;
	}
	
	dfs(tr[u].first);
	dfs(tr[u].second);
	h[u] = max(h[tr[u].first], h[tr[u].second]) + 1;
}

int main()
{
	USE_IOSTREAM;
	int n, i, u, v;
	cin >> n;
	for (i = 2; i <= n; i++)
	{
		cin >> a[i];
		
		winNum[a[i]]++;
	}
	
	
	for (i = 1; i <= n; i++)
	{
		mm[i] = i;
	}
	
	set<pii> Q;
	for (i = 1; i <= n; i++)
	{
		if (winNum[i] == 0)
		{
			Q.insert({0, i});
		}
	}
	
	int m = n;
	while (!Q.empty())
	{
		u = Q.begin()->second;
		Q.erase(Q.begin());
		winNum[a[u]]--;
		
		tr[++m] = {mm[u], mm[a[u]]};
		h[m] = max(h[mm[u]], h[mm[a[u]]]) + 1;
		mm[u] = 0;
		mm[a[u]] = m;
		
		if (winNum[a[u]] == 0 && a[u] != 1)
		{
			Q.insert({h[mm[a[u]]], a[u]});
		}
	}
	
	//dfs(mm[1]);
	
	cout << h[mm[1]] << endl;
	return 0;
}

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

int main() {
    int n, ans = 0;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n - 1; i++) {
        cin >> c[i];
    }
    for (int i = 0; i < n; i++) {
        ans += b[a[i]];
        if (i && a[i] == a[i - 1] + 1) ans += c[a[i - 1]];
    }
    cout << ans << endl;
    return 0;
}

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


using namespace std;


constexpr auto BASE = 998244353;



int N;
vector<int> D;

int main()
{

	cin >> N;
	D = vector<int>(N);

	auto C = vector<int>(N, 0);

	long long ans = 1;

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

		C[D[i]]++;

		if (i == 0 && D[i] > 0
			|| i >0 && D[i] ==0) {
			ans = 0;
		}
	}

	if (ans == 0) {
		cout << 0 << endl;
		return 0;
	}

	int i = 1;
	for ( ; i < N; i++) {
		if (C[i] == 0) {
			break;
		}

		for (int j = 0; j < C[i]; j++) {
			ans = (ans*C[i - 1]) % BASE;
		}
	}

	for (i++; i < N; i++) {
		if (C[i] > 0) {
			ans = 0;
			break;
		}
	}


	cout << ans << endl;

	return 0;


}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int s; double w, h;
    while(scanf("%d,%lg,%lg", &s, &w, &h) != EOF){
        if(w/h/h >= 25) cout << s << "\n";
    }
    return 0;
}


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

int main(){
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	for(int i=0; i<n/2; i++){
		if(s[i] != s[n-1-i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >>n;
  ll a[n],j[n],c[n];
  for(ll i=0;i<n;i++){
    j[i]=0;
    c[i]=0;
  }
  for(ll i=0;i<n;i++){
    cin >> a[i];
    if(i+a[i]<n)j[i+a[i]]++;
    if(i-a[i]>0)c[i-a[i]]++;
  }
  ll ans=0;
  for(ll i=0;i<n;i++){
    ans+=j[i]*c[i];
  }
  cout << ans;
  
}


Measured memory_bytes: 8320
#include <iostream>

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		int s=0;
		for(int i=1;i*i<=n;i++){
			if(n%i==0) s+=i,s+=n/i;
			if(i*i==n) s-=i;
			if(n/i==n) s-=n/i; 
		}
		if(n>s)  cout<<"deficient number"<<endl;
		if(n==s) cout<<"perfect number"<<endl;
		if(n<s)  cout<<"abundant number"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1148
#include<iostream> 
#include<string>
using namespace std;
int main()
{
//	int t;
//	cin>>t;
// 	while(t--)
//	{
		string s;
		getline(cin,s);
		std::string::iterator it; 
		long long int i=0,j;
		int flag=0;
		for(it=s.begin();it!=s.end();it++)
		{
			i+=((int)(*it)-48);
		}
		//cout<<i<<'\n';
		if(i%9==0)
		{
			cout<<"Yes"<<'\n';
		}
		else
		{
			cout<<"No"<<'\n';
		}
//	}
}

Measured memory_bytes: 3744
<?php
$l=(int)trim(fgets(STDIN));

#$s=$l%60;$l-=$s;$l/=60;$m=$l%60;$l-=$m;$l/=60;

$h=floor($l/3600);
$m=floor($l%3600/60);
$s=$l%60;

echo $h.':'.$m.':'.$s."\n";
#echo "{$h}:{$m}:{$s}\n";

Measured memory_bytes: 15248
from bisect import*
e=enumerate
M=998244353
R,G,B=[],[],[]
n=int(input())
for i,c in e(input()):
  if c=='R':R+=i,
  elif c=='G':G+=i,
  else:B+=i,
l,m,r=[],[],[]
for i,t in e(zip(R,G,B)):
  a,b,c=sorted(t)
  l+=a,
  m+=b,
  r+=c,
s=1
for i,b in e(m):
  s=s*(bisect(l,b)-i)*(i-bisect(r,b)+1)*(i+1)%M
print(s)

Measured memory_bytes: 76376
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[5][14],n,m,x,s=0,h=0,c=0,d=0;
	char ch;
	for(int i=1;i<5;i++){
		for(int j=1;j<14;j++){
			a[i][j]=0;
		}
	}
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> ch >> x;
		if(ch=='S'){
			a[1][x]=x;
			s++;
		}else if(ch=='H'){
			a[2][x]=x;
			h++;
		}else if(ch=='C'){
			a[3][x]=x;
			c++;
		}else if(ch=='D'){
			a[4][x]=x;
			d++;
		}
	}
	for(int i=1;i<5;i++){
		for(int j=1;j<14;j++){
			if(a[i][j]==0){
				if(i==1) cout << "S ";
				else if(i==2) cout << "H ";
				else if(i==3) cout << "C ";
				else if(i==4) cout << "D ";
				cout << j << endl;
			}
		}
	}
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,r,s,p;
  cin >> n >> k >> r >> s >> p;
  string t;cin >> t;
  vector<string> c(k,"");
  map<char,int> mp;
  mp['r']=p;
  mp['s']=r;
  mp['p']=s;
  for(int i=0;i<n;i++){
    c[i%k]+=t[i];
  }
  int ans=0;
  for(int i=0;i<k;i++){
    int u=c[i].size();
    int cnt=1;
    for(int j=0;j<u-1;j++){
      if(c[i][j]==c[i][j+1]){
        cnt++;
      }
      else{
        ans+=mp[c[i][j]]*((cnt+1)/2);
        cnt=1;
      }
    }
    ans+=mp[c[i][u-1]]*((cnt+1)/2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 5120
#include<stdio.h>
int data[10];

void myScan(){
	int i;
	for(i=0;i<10;i++){
		scanf("%d",&data[i]);
	}
	return;
}


int slove(void){
	int i,j,top[2]={0,0};
	myScan();
	for(i=0;i<10;i++){
		for(j=0;j<2;j++){
			if(data[i]>top[j]){
				top[j]=data[i];
				j=-1;
				break;
			}
		}
		if(j!=-1){
			return 0;
		}
	}
	return 1;
}

int main(void){
	int i,datasetNum;
	scanf("%d",&datasetNum);
	for(i=0;i<datasetNum;i++){
		printf(slove()? "YES\n" : "NO\n");
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <climits>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

  vector<int> a(n);
  for(int i = 0; i < n; ++i) cin >> a[i];

  const int m {*max_element(begin(a),end(a))};

  int r;
  const int x {m/2};
  int d {INT_MAX};
  if(m & 1){
    const int y {x+1};
    for(int i = 0; i < n; ++i){
      if(a[i] == m) continue;
      
      if(abs(x-a[i]) < d){
        d = abs(x-a[i]);
        r = a[i];
      }else if(abs(y-a[i]) < d){
        d = abs(y-a[i]);
        r = a[i];
      }
    }
  }else{
    for(int i = 0; i < n; ++i){
      if(a[i] == m) continue;
            
      if(abs(x-a[i]) < d){
        d = abs(x-a[i]);
        r = a[i];
      }
    }
  }
  
  cout << m << " " << r << endl;
}

Measured memory_bytes: 640
using System;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var S = Console.ReadLine();

            var result = 0;
            for (int i = 0; i < S.Length / 2; i++)
            {
                if (S[i] != S[S.Length - 1 - i])
                {
                    result++;
                }
            }
            Console.WriteLine(result);
        }
    }
}

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

using namespace std;
long long int  mo[10001],A,B,C,a,b,c,m[10001],ans[1100],n;
int main(){
    while(1){
    fill(mo,mo+10000,0);
    fill(m,m+10000,2);
cin >> a >> b >> c >> n;
if(a==0&&b==0&&c==0)break;
for(int i=0;i<n;i++){
    cin >> mo[i] >> mo[i+n] >> mo[i+n+n] >> ans[i];
    if(ans[i]==1){
        m[mo[i]]=1;
        m[mo[i+n]]=1;
        m[mo[i+n+n]]=1;
    }
}
for(int j=0;j<n;j++){
    if(m[mo[j]]==1&&m[mo[j+n]]==1&&ans[j]==0){m[mo[j+n+n]]=0;}
    else if(m[mo[j+n]]==1&&m[mo[j+n+n]]==1&&ans[j]==0){m[mo[j]]=0;}
    else if(m[mo[j]]==1&&m[mo[j+n+n]]==1&&ans[j]==0){m[mo[j+n]]=0;}
}
for(int i=1;i<=a+b+c;i++){
        cout << m[i] << endl;
}
}
return 0;
}

Measured memory_bytes: 1320
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		int d = a + b;
		int sum = 0;
		
		if(d <= c*2) {
			sum += Math.min(x,y) * d;
			if(x > y) {
				sum += (x - y) * a;
			}
			else {
				sum += (y - x) * b;
			}
			System.out.println(sum);
		}
		
		if(d > c*2) {
			sum += Math.min(x,y) * 2 * c;
			if(x > y) {
				if(2*c > a) {
				   sum += (x - y) * a;
				}
				if(2*c <= a) {
					sum += (x - y) * 2 * c;
				}
			}
			if(x <= y) {
				if(2*c> b) {
					   sum += (y - x) * b;
					}
			    if(2*c <= b){
						sum += (y - x) * 2 * c;
					}
				}
			System.out.println(sum);
		}
		

	}

}


Measured memory_bytes: 21716
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


SIZE = 101
table = [None]*(SIZE)


while True:
    N = int(input())
    if N == 0:
        break

    TMP = list(map(int,input().split()))

    ans = -1
    count = 0

    while True:

        for i in range(SIZE):
            table[i] = 0

        for i in range(len(TMP)):
            table[TMP[i]] += 1

        WORK = []

        for i in range(len(TMP)):
            WORK.append(table[TMP[i]])

        FLG = True
        for i in range(len(TMP)):
            if TMP[i] != WORK[i]:
                FLG = False
                break

        if FLG == True:
            ans = count
            break

        for i in range(len(WORK)):
            TMP[i] = WORK[i]

        count += 1

    print("%d"%(ans))
    print(' '.join(map(str,TMP)))


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y, z;
    cin >> x >> y;
    while(y != 0) {
        z = x % y;
        x = y;
        y = z;
    }
    cout << x << '\n';
    return 0;
}

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

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

    int h[n];
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }

    int dp[n];
    for(int i = 0; i < n; i++){
        dp[i] = 0;
    }

    dp[1] = abs(h[0] - h[1]);
    for(int i = 2; i < n; i++){
        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
        int k = dp[i - 2] + abs(h[i] - h[i - 2]);
        if(dp[i] > k){
            dp[i] = k;
        }
    }

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

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>

typedef struct{

  double x;
  double y;
  
}xy;

void kock(int,xy,xy);

int main( ){

  xy p1,p2;
  int n;

  p1.x=0.0;
  p1.y=0.0;
  p2.x=100.0;
  p2.y=0.0;

  scanf("%d",&n);


  
  printf("%lf %lf\n",p1.x,p1.y);

  kock(n,p1,p2);

  printf("%lf %lf\n",p2.x,p2.y); 
  
  return 0;

}

void kock(int n,xy p1,xy p2){
  
  xy s,t,u;
  if (n==0) return ;

  s.x=(2.0*p1.x+1.0*p2.x)/3.0;
  s.y=(2.0*p1.y+1.0*p2.y)/3.0;
  t.x=(1.0*p1.x+2.0*p2.x)/3.0;
  t.y=(1.0*p1.y+2.0*p2.y)/3.0;

  // printf("%lf\n",cos(M_PI/3));
  
  u.x=(t.x-s.x)*(cos(M_PI/3.0))-(t.y-s.y)*(sin(M_PI/3.0))+s.x;
  u.y=(t.x-s.x)*(sin(M_PI/3.0))+(t.y-s.y)*(cos(M_PI/3.0))+s.y;
  

  kock(n-1,p1,s);
  printf("%lf %lf\n",s.x,s.y);

  kock(n-1,s,u);
  printf("%lf %lf\n",u.x,u.y);

  kock(n-1,u,t);
  printf("%lf %lf\n",t.x,t.y);

 
  kock(n-1,t,p2);

  

}

Measured memory_bytes: 636
#include <bits/stdc++.h>
 
#define pb push_back
#define lp(i,a,b) for(int i = a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mk make_pair
#define sz size()
 
const int MAXN = 5e3+10 ;
const ll prime = 37 ;
const ll MOD = 3e9+10;
 
using namespace std ;

int n ;
char str[MAXN] ;
ll pot[MAXN] , pref[MAXN] ;
map<ll,int> mapa ;

ll mod(ll x)
{
	if(x<0) x += MOD * MOD ;
	return x %= MOD ;
}

int g(char c) { return c - 'a' + 1 ; } 

int main()
{
	
	pot[0] = 1LL ;
	lp(i,1,MAXN) pot[i] = mod(pot[i-1] * prime) ;
	
	scanf("%d", &n) ;
	scanf("%s", str ) ;
	
	pref[0] = g( str[0] ) ;
	
	lp(i,1,n) pref[i] = mod( pref[i-1] * prime + g( str[i] ) ) ;
	
	
	int maior = 0 ;
	
	int l = 0 , r = n , mid ;
	
	while( l <= r )
	{
		mid = (l+r)/2 ;
		bool ok = false ;
		mapa.clear() ;
		
		
		for(int i = 0 ; i + mid - 1 < n ; i++ )
		{
			int j = i + mid - 1 ;
			
			ll val = mod(pref[j] - pot[j-i+1] * ( i == 0 ? 0LL : pref[i-1] ) ) ;
			
			if( mapa.find(val) == mapa.end() )
			{
				mapa.insert({val , j}) ;
				continue ;
			}
			
			if( mapa.find(val)->ss < i ) 
			{
				ok = true ;
				maior = mid ;
			}

		}
		
		if(ok) l = mid + 1 ;
		else r = mid -1 ;
		
	}
		
	
	printf("%d\n", maior ) ;
	
}









Measured memory_bytes: 640
import sys
import math
import bisect
import re

def solve(s, t):
    n = len(s)
    for i in range(n):
        if s == t:
            return True
        s = s[1:] + s[0:1]
    return False

def main():
    s = input()
    t = input()
    if solve(s, t):
        print('Yes')
    else:
        print('No')

if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
	buf = make([]byte, 1000)
)

func scanText() string{
	sc.Scan()
	return sc.Text()
}

func scanTextArray(n int) []string {
	out := make([]string, n)
	for i, v := range(strings.Split(scanText(), "")) {
		out[i] = v
	}
	return out
}

func scanInt() int {
	out, e := strconv.Atoi(scanText())
	if e != nil {
        panic(e)
    }
	return out
}

func scanIntArray(n int) []int {
	out := make([]int, n)
	for i, v := range(strings.Split(scanText(), " ")) {
		num, e := strconv.Atoi(v)
		if e != nil {
			panic(e)
		}
		out[i] = num
	}
	return out
}
//  template end

var (
	coins = [6]int{500, 100, 50, 10, 5, 1}
)

func f(data int) {
	ans := 0
	change := 1000 - data
	for _, v := range coins {
		for ;v <= change; {
			change -= v
			ans++
		}
	}
	fmt.Println(ans)
}

func main() {
	sc.Buffer(buf, 10000)
	for{
		data := scanInt()
		if data == 0 {
			break
		}
		f(data)
	}
}


Measured memory_bytes: 1056
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
using ll = long long;

int main() {
  ll n; cin >> n;
  ll m; cin >> m;
  vector<vector<ll>> ab(n, vector<ll>(2));
  rep(i, n) {
    cin >> ab.at(i).at(0);
    cin >> ab.at(i).at(1);
  }
  sort(ab.begin(), ab.end());
  ll ans = 0;
  rep(i, n) {
    if (ab.at(i).at(1) <= m) {
      ans += ab.at(i).at(0) * ab.at(i).at(1);
      m -= ab.at(i).at(1);
    } else {
      ans += ab.at(i).at(0) * m;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>

using namespace std;

int A,B;
typedef long long ll;

int main(){
	cin >> A >> B;
	int ans = 0;
	for(int i=A;i<=B;i++){
		string S = to_string(i);
		//cout << S << endl;
		if(S[0]==S[4] && S[1] == S[3]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
from math import factorial

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

def dist(i, j):
    return np.sqrt((x[i]-x[j])**2 + (y[i] - y[j])**2)

matrix = np.zeros((N, N))
for i in range(N*N):
    iy = i%N
    ix = i//N
    if iy > ix:
        matrix[ix, iy] = dist(ix, iy)

avepath = np.sum(matrix)*2/N
print(avepath)

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

int main()
{
    int w, h, x, y, r;
    int c_l, c_r, c_u, c_d;

    cin >> w >> h >> x >> y >> r;
    c_l = x - r;    // ????????????
    c_r = x + r;    // ????????????
    c_u = y + r;    // ????????????
    c_d = y - r;    // ????????????

    if (0 <= c_l && c_r <= w && 0 <= c_d && c_u <= h) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

void solve()
{
  string s; cin >> s;
  ll n; cin >> n;
  ll ans = 0;
  ll cnt = 0;
  ll ft = 0;
  ll h = 0;

  int i = 0;
  for(h = 1 ; s[h] == s[0]; h++) ;
  if(h == s.size()) {
    cout << ( n * s.size() / 2 ) << endl;
    return;
  }
  i = 0;
  while(i < s.size()) {
    int j;
    for(j = 1; s[i] == s[i + j]; j++);
    cnt += j / 2;
    i += j;
  }
  int k;
  for(k = 1; s[s.size()-1-k] == s[s.size()-1]; k++);
  
  ans = cnt * n - (s[0] == s[s.size()-1] ? ( h / 2 + k / 2 - (h + k) / 2) * (n - 1): 0);
  
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


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

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

int main()
{
    int x,y,z,k;cin>>x>>y>>z>>k;
    ll a[x],b[y],c[z];
    
    rep(i,x)cin>>a[i];
    rep(i,y)cin>>b[i];
    rep(i,z)cin>>c[i];
    
    vector<ll>vec;
    vector<ll>vec2;
    
    rep(i,x){
        rep(j,y){
            vec.push_back(a[i]+b[j]);
        }
    }
    sort(vec.begin(),vec.end(),greater<ll>());
    
    rep(i,min(k,x*y)){
        rep(j,z){
            vec2.push_back(vec[i]+c[j]);
        }
    }
    sort(vec2.begin(),vec2.end(),greater<ll>());
    
    rep(i,k){
        cout<<vec2[i]<<endl;
    }

   return 0;
}

Measured memory_bytes: 42724
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int dp[11][2][2][2][2][2];
int a[4]={3, 5, 7, 0};

int main(){
  string s;
  cin >> s;
  int ssz=s.size();
  dp[0][1][0][0][0][0]=1;
  rep(i, ssz){
    rep(smaller, 2){
      rep(j, 2){
        rep(k, 2){
          rep(l, 2){
            rep(m, 2){
            rep(ai, 4){
              if(ai==3 && m==1)continue;
              int ni=i+1;
              int nsmaller=smaller;
              if(smaller==1){
                if((int)(s[i]-'0')<a[ai])continue;
                if((int)(s[i]-'0')>a[ai]){
                  nsmaller=0;
                }
              }
              int nj=j, nk=k, nl=l, nm=m;
              if(j==0 && ai==0){
                nj=1;
              }
              if(k==0 && ai==1){
                nk=1;
              }
              if(l==0 && ai==2){
                nl=1;
              }
              if(m==0 && ai!=3){
                nm=1;
              }
              dp[ni][nsmaller][nj][nk][nl][nm]+=dp[i][smaller][j][k][l][m];
            }
          }
          }
        }
      }
    }
  }
  cout << dp[ssz][0][1][1][1][1]+dp[ssz][1][1][1][1][1] << endl;
  return 0;
}


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

int main() {
  string N;
  cin >> N;
  if(N.at(0) == '7' || N.at(1) == '7' || N.at(2) == '7'){
    cout << "Yes" << endl;
  }
  else {cout << "No" << endl;}
}
    


Measured memory_bytes: 3556