akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector> 
#include <cmath>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <cerrno>
#include <cfenv>
#include <stack>
#include <math.h>
#include <iomanip>
#include <limits>
#include <queue>
#define ll long long int
#define pb push_back
#define mp make_pair

using namespace std;

int main(){

    int n;
    cin >> n;
    int keep = n;
    int cnt = 0;
    ll ans = 0;

    while(1){
        if (cnt % 2 == 0 && n >= 10)
        {
            ans += pow(10, cnt + 1) - pow(10,cnt);
        }
        else if (n < 10 && cnt % 2 == 0)
        {
            ans += keep - pow(10,cnt) + 1;
            break;
        }
        else if(n < 10) break;
        
        n /= 10;
        cnt++;
    }

    cout << ans << endl;

    return 0;
}

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

const int W = (int) 1e5 + 5;
const int N = 105;
const ll INF = (ll) 1e13;
pair<int,int> a[N];
ll dp[W][N];
int n,w;

ll solve(ll sum , int idx)
{
    if(sum > w)
        return -INF;
    if(idx == n)
        return 0;
    ll &ret = dp[sum][idx];
    if(ret != -1)
        return ret;
    return ret = max(a[idx].second + solve(sum + a[idx].first,idx+1),solve(sum,idx+1));
}

int main()
{
    ios :: sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> w;
    for(int i = 0;i < n;++i)
    {
        int x,y;
        cin >> x >> y;
        a[i] = {x,y};
    }
    memset(dp,-1,sizeof dp);
    cout << solve(0,0);
    return 0;
}


Measured memory_bytes: 82304
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int sum = a + b;
			int count = 0;
			while (sum > 0) {
				sum /= 10;
				count ++;
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 20440
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <ctime>

#define ll long long
#define ld long double
#define mod 1000000007
#define inf 1e6
using namespace std;
//ifstream cin("input.txt"); ofstream cout("output.txt");
//ifstream cin("pageant.in"); ofstream cout("pageant.out");
struct str {
	ll x, v;
};
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll n, c;
	cin >> n >> c;
	vector<str> a(n + 2);
	a[n + 1].x = c;
	a[n+1].v = 0;
	for(int i = 1; i <= n; i++) {
		cin >> a[i].x >> a[i].v;
	}
	vector<ll> p(n + 1), s(n + 2), mx_p(n + 1), mx_s(n + 2);
	for (int i = 1; i <= n; i++) {
		p[i] = p[i - 1] + a[i - 1].x - a[i].x + a[i].v;
		mx_p[i] = max(mx_p[i-1], p[i]);
	}
	for (int i = n; i >= 1; i--) {
		s[i] = s[i + 1] + a[i].v - (c - a[i].x) + (c - a[i + 1].x);
		mx_s[i] = max(s[i], mx_s[i + 1]);
	}
	ll best = 0;
	for (int i = 0; i <= n; i++) {
		ll cur = p[i];
		if (a[i].x < mx_s[i + 1]) {
			cur += mx_s[i + 1] - a[i].x;
		}
		best = max(best, cur);
	}
	for (int i = 0; i <= n; i++) {
		ll cur = s[n - i + 1];
		if (c - a[n-i+1].x < mx_p[n - i]) {
			cur += mx_p[n - i] - c + a[n-i+1].x;
		}
		best = max(best, cur);
	}
	cout << best;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define int long long
int INF = 1e9+7;
signed main() {
    int N;
    string S;
    cin >> N >> S;
    vector<int>cnt(26,1);
    for(int i = 0; i < N; i++) {
        cnt[S[i]-'a']++;
    }
    int res = 1;
    for(int i = 0; i < 26; i++) {
        res*=cnt[i];
        res = res%INF;
    }
    cout << res-1 << endl;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int a[n+1]={0};
    int ans=0;
    while(k--){
        int d;
        cin>>d;
        for(int i=0;i<d;i++){
            int lu;
            cin>>lu;
            a[lu]++;
        }
    }
    for(int i=1;i<=n;i++){
        if(a[i]==0){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3648
X = int(input())

if 400 <= X <= 599:
    print("8")
elif 600 <= X <= 799:
    print("7")
elif 800 <= X <= 999:
    print("6")
elif 1000 <= X <= 1199:
    print("5")
elif 1200 <= X <= 1399:
    print("4")
elif 1400 <= X <= 1599:
    print("3")
elif 1600 <= X <= 1799:
    print("2")
else:
    print("1")

Measured memory_bytes: 9180
#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include <deque>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
using namespace std;
typedef pair<long long,long long> pii;
long double a;
int d[4];
int sign[2] = {1,-1};
int main() {
	string s;
	cin >> s;
	for (int i = 0 ; i < 4 ; ++i) {
		d[i] = s[i] - '0';
	}
	for (int i = 0 ; i < 2 ; ++i) {
		for (int j = 0 ; j < 2 ; ++j) {
			for (int k = 0 ; k < 2 ; ++k) {
				for (int f = 0; f < 2 ; ++f) {
					int s = d[0] * sign[i] + d[1] * sign[j] + d[2] * sign[k] + d[3] * sign[f];
					int res[4] = {d[0]*sign[i],d[1]*sign[j],d[2] * sign[k],d[3] *sign[f]};
					if (s == 7) {
						cout << res[0];
						for (int a = 1 ; a < 4 ; ++a) {
							if (res[a] < 0) cout << res[a];
							else cout << "+" << res[a];
						}
						cout << "=7";
						return 0;
					}
				}
			}
		}
	}

}


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

public class Main {

    private static final String BLANK = " ";

    private static final String ANSWER_YES = "YES";

    private static final String ANSWER_NO = "NO";

    public static void main(String[] args) {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int count = 0;

        try {
            count = Integer.valueOf(in.readLine());

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

                String[] dataArray = in.readLine().split(BLANK);

                if (drop(dataArray)) {
                    System.out.println(ANSWER_YES);
                } else {
                    System.out.println(ANSWER_NO);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static boolean drop(String[] dataArray) {

        int max = 0;
        int min = 0;

        for (String data : dataArray) {
            int num = Integer.valueOf(data);

            if (num > max) {
                max = num;
            } else if (num > min) {
                min = num;
            } else {
                return false;
            }
        }

        return true;
    }
}

Measured memory_bytes: 17084
n = int(input())
p = list(map(int,input().split()))

ans = 0
for i in range(n-2):
    if p[i]<p[i+1]<p[i+2]:
        ans += 1
    elif p[i+2]<p[i+1]<p[i]:
        ans += 1
        
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define show(x) cout<<x<<'\n'
#define showh(x) cout<<x<<' '
#define go(i,a,n) for(ll i=a;i<n;i++)
#define gor(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[100001];
bool ispoweroftwo(ll x)
{
    return x && !(x & (x-1));
}
ll xorcal(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==1)
        return 1;
    if(n%4==2)
        return n+1;
    if(n%4==3)
        return 0;
}
void sieve(ll n)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }
}
bool isprime(ll n)
{
    if (n<=1) return false;
    if (n<=3) return true;

    if(n%2==0 or n%3==0) return false;

    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0 or n%(i+2)==0) return false;
    }
    return true;
}

ll modinverse(ll a,ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m; a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

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

ll power(ll A, ll B)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;

    ll y;
    if (B % 2 == 0) {
        y = power(A, B / 2);
        y = (y * y) % mod;
    }

    else {
        y = A % mod;
        y = (y * power(A, B - 1) % mod) % mod;
    }

    return (ll)((y + mod) % mod);
}
bool recur(string s1,string s2 ,ll m,ll n)
{
    if(m==0) return false;
    if(n==0) return true;
    if(s1[m-1]==s2[n-1])
    {
        return recur(s1,s2,m-1,n-1);
    }
    return recur(s1,s2,m-1,n);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,d;
    cin>>n>>d;
    ll r=0,ans=0;
    while(r<n)
    {
        ans++;
        r+=(2*d)+1;
    }
    show(ans);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a, b;
	int i, j;

	while (1) {
		scanf("%d %d", &a, &b);
		if (a == 0 && b == 0) {
			break;
		}
		for (i = 0; i < a; i++) {
			for (j = 0; j < b; j++) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}


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

using ll = long long;

int main(){
    ll n, m;
    cin >> n >> m;
    const ll simple = min(n, m/2), extra = m-2*simple,
        rez = simple + extra / 4;
    cout << rez << endl;
    return 0; }


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
const ll INF = (ll)1e18 + 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n; cin >> n;
    string s[n];
    int c[4]; c[0]=0;c[1]=0;c[2]=0;c[3]=0;
    rep(i,n){
        cin >> s[i];
        if(s[i]=="AC"){
            c[0]++;
        }else if(s[i]=="WA"){
            c[1]++;
        }else if(s[i]=="TLE"){
            c[2]++;
        }else{
            c[3]++;
        }
    }
    cout << "AC x ";
    cout << c[0] << ln;
    cout << "WA x ";
    cout << c[1] << ln;
    cout << "TLE x ";
    cout << c[2] << ln;
    cout << "RE x ";
    cout << c[3] << ln;    
    return 0;    
}

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

public class Coin{
	public static void Main()
	{
		string[] line = Console.ReadLine().Split();
		int n = int.Parse(line[0]);
		int m = int.Parse(line[1]);
		
		var c = ReadLineAndToIntList();
		//c.Dump();
		
		var t = Enumerable.Repeat(int.MaxValue, n + 1).ToArray();
		t[0] = 0;
		for (int i = 0; i < m; i++)
		{
			for (int j = c[i]; j < n+1; j++)
			{
				t[j] = Math.Min(t[j], t[j - c[i]] + 1);
			}
		}
		//t.Dump();
		
		Console.WriteLine(t[n]);
	}
	
	//??????????????????????????????
	public static List<int> ReadLineAndToIntList()
	{
		return Console.ReadLine().Split().Select (int.Parse).ToList();
	}
// Define other methods and classes here
}

Measured memory_bytes: 20884
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,n) for(int i=1;i<=n;i++)
using namespace std;

int main(){
int N;
cin >> N;
long long A[N+1];
long long sum=0;
rep2(i,N){
    cin >>A[i];
    sum+=A[i];
}
long long Asum=0;

for(int i=1;i<=(N-1)/2;i++){
    Asum+=A[i*2];
}
long long X[N+2];
X[1]=sum-2*Asum;




for(int i=1;i<=N;i++){
    X[i+1]=2*A[i]-X[i];
    cout <<X[i]<<" ";
}

    

 return 0;
}

Measured memory_bytes: 2816
#include <stdio.h>

int main () {

    int i, j, c, N, t;
    int a[100];

    t = 0;

    scanf("%d", &N);

    for (i = 0; i < N; i++)
        scanf("%d", &a[i]);

    for (i = 0; i < N; i++) {
        for (j = N - 1; j > 0; j--) {
             if (a[j] < a[j - 1]) {
                 c = a[j];
                 a[j] = a[j - 1];
                 a[j - 1] = c;
                 t += 1;
             }
        }
    }

    for (i = 0; i < N - 1; i++) 
        printf("%d ", a[i]);
        printf("%d", a[N - 1]);
        puts("");
        printf("%d\n", t);

    return 0;

}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define prDouble(x) cout<<fixed<<setprecision(10)<<x;

int main()
{
    li j,i,n,k;
    cin>>n>>k;
    li a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    li dp[k+1];
    dp[0]=0;
    sort(a,a+n);
    for(i=1;i<=k;i++)
    {
        dp[i]=0;

        for(j=0;j<n;j++)
        {
            if(!dp[i-a[j]] && (i-a[j])>=0)
            {
                dp[i]=1;
                break;
            }
        }
    }
    if(dp[k])
    {
        cout<<"First";
    }
    else
    {
        cout<<"Second";
    }

    return 0;
}


Measured memory_bytes: 4356
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/

int main(){
    int N; cin >> N;
    vector<ll> a(N);
    int dp[25]; fill(dp,dp+25,0);
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    int in = 0;
    ll ans = 0;
    //cout << "check : " << endl;

    for (int i = 0; i < N; i++){
        if (i != 0){
            for (int num = 0; num < 22; num++){
                if (1 << num & a[i-1]){
                    //dp[num] == 1でないとダメ
                    //cout << "dp[" << num << "] = " << dp[num] << endl;
                    dp[num]--;
                }
            }
        }
        //cout << "check : " << endl;
        while(true){
            bool flg = true;
            if (in == N) break;
            for (int num = 0; num < 22; num++){
                if (1 << num & a[in]){
                    if (dp[num] == 1){
                        flg = false;
                    }
                }
            }
            if (!flg) break;
            for (int num = 0; num < 22; num++){
                if (1 << num & a[in]){
                    dp[num]++;
                }
            }
            in++;
        }
        //cout << "ans : " << ans << endl;
        ans += (in-i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
using namespace std;
typedef long long ll;

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

  for(int i=0;i<=n;i++) {
    int cc=0;
    int t=i;
    while(t>0) cc+= t%6,t/=6;
    t=n-i;
    while(t>0) cc += t%9,t/=9;
    if(ans>cc) ans=cc;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
	input!(n: usize);
	input!(k: usize);
	input!(x: usize);
	input!(y: usize);

	if n <= k {
		println!("{}", n * x);
	}
	else {
		println!("{}", (k*x)+((n-k)*y))
	}
}



Measured memory_bytes: 2188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=1000000000;

bool cmp(pair<int,int> a, pair<int,int> b){
	return a.second<b.second;
}
const int N  = 100010;
int dp[N], visited[N];
vector<int> v[N];
void dfs(int i){
	visited[i]=1;
	for(int j=0;j<v[i].size();j++){
		if(!visited[v[i][j]]) dfs(v[i][j]);
		
			dp[i]= max(dp[i],dp[v[i][j]]+1);
	
	}
}


int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
     int n,m;
     cin >>n>>m;
     
     for(int i=0;i<m;i++){
     	int a,b;
     	cin >>a>>b;
     	v[a].push_back(b);
	 }
	 for(int i=1;i<=n;i++){
	 	if(!visited[i]) dfs(i);
	 }
	 int ans=0;
	 for(int i=0;i<=n;i++){
	 	ans=max(ans,dp[i]);
	 }
	 cout <<ans<<"\n";
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define ForE(it,v) for(auto it : v)
#define mod 1000000007
#define All(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
template<class T> T gcd(T a,T b) {return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b) {return a/gcd(a,b)*b; }
template<class T> bool isPrime(T num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (T i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

using namespace std;

int a,b,c;
int n,m,k,cnt;
string s,t;

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

        //vectorに入力
        vi v(n+1);
        rep(i,n)cin>>v[i];

        double x=0,y=0;
        rep(i,n-k+1)
        {
                if(i==0)
                {
                        rep(j,k)x+=v[j];
                }else
                {
                        x-=v[i-1];
                        x+=v[i+k-1];
                }

                y=max(y,x);
                //cout<<y<<endl;
        }

        y=(y+k)/2;
        printf("%.12lf\n",y);
}

Measured memory_bytes: 1024
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine()) {
			String s = sc.nextLine();
			if (s.equals(".")) {
				break;
			}
			Deque<Character> dq = new ArrayDeque<Character>();
			boolean valid = true;
			for(int i=0;i<s.length();i++) {
				char c = s.charAt(i);
				if (c == '(' || c == '[') {
					dq.offerFirst(c);
				}
				if (c == ')' || c == ']') {
					if (dq.isEmpty()) {
						valid = false;
						break;
					}
					char c2 = dq.pollFirst();
					if ((c2 == '(' && c == ']') || (c2 == '[' && c == ')')) {
						valid = false;
					}
				}
			}
			if (!dq.isEmpty()) {
				valid = false;
			}
			System.out.println(valid ? "yes" : "no");
		}
	}

}

Measured memory_bytes: 32676
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N)
  {
    cin >> a[i];
  }
  int dir = 0;
  int ans = 0;
  rep(i, N - 1)
  {
    if (dir == 0)
    {
      if (a[i] < a[i + 1])
      {
        dir = 1;
      }
      if (a[i] > a[i + 1])
      {
        dir = -1;
      }
    }
    else if ((dir == 1 && a[i] > a[i + 1]) || (dir == -1 && a[i] < a[i + 1]))
    {
      ans++;
      dir = 0;
    }
  }
  cout << ans + 1 << endl;
  return 0;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll int ara[]={11,10,9,8,7};
    ll int n,i,j,k,mini=180000000000000000;
    cin>>n;

    if(n<=6) cout<<1<<endl;
    else{
        //for(i=0;i<5;i++){
            ll int mod=n%11;
            ll int sum=n/11;
            sum=(sum*2);
            if(mod>0 && mod<=6) sum++;
            else if(mod>6 && mod<11) sum+=2;
            //mini=min(sum,mini);
        //}
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std ;
 int main(){
 string S;
 string T;
 int a=0;
 cin>>S>>T;
 if(S[0]==T[0]){
  a++;
 }
 if(S[1]==T[1]){
    a++;
 }
 if(S[2]==T[2]){
        a++;
    }
 cout<<a;
 return 0;
 }


Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
list1,list2 = [],[]
for i in range(N):
    list1.append((a[i],i+1))
list1.sort()
# print(list1)
for i in range(N):
    list2.append(str(list1[i][1]))
# print(list2)
print(" ".join(list2))

Measured memory_bytes: 25340
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}


signed main(){
    int t,d,l;
    while(cin>>t>>d>>l,t){
        int x=0,res=0;
        rep(i,t){
            if(x)res++;
            int y;cin>>y;
            if(x)x--;
            if(y>=l)x=d;
        }
        cout<<res<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3108
n,m = map(int,input().split())

dac = {}
for i in range(1,n+1):
    dac[str(i)] = 0
dwa = {}
for i in range(1,n+1):
    dwa[str(i)] = 0

for i in range(m):
    p,s = input().split()
    if s == 'AC':
        dac[p] = 1
    if s == 'WA' and dac[p] == 0:
        dwa[p] += 1

ac = 0
wa = 0

for k,v in dac.items():
    ac += v

for k,v in dwa.items():
    if dac[k] == 1:
        wa += v

print(ac,wa)

Measured memory_bytes: 112844
def search(a, x, y, w, h, count)
  if x+1 < w and a[y][x+1] != nil and a[y][x+1] == '.' and not count.include? [x+1,y]
    count << [x+1,y]
    search(a, x+1, y, w, h, count)
  end
  if x-1 >= 0 and a[y][x-1] != nil and a[y][x-1] == '.' and not count.include? [x-1,y]
    count << [x-1,y]
    search(a, x-1, y, w, h, count)
  end
  if y+1 < h and a[y+1][x] != nil and a[y+1][x] == '.' and not count.include? [x,y+1]
    count << [x,y+1]
    search(a, x, y+1, w, h, count)
  end
  if y-1 >= 0 and a[y-1][x] != nil and a[y-1][x] == '.' and not count.include? [x,y-1]
    count << [x,y-1]
    search(a, x, y-1, w, h, count)
  end
end

loop do
  w, h = gets.split.map(&:to_i)
  exit if w == 0 and h == 0
  a = h.times.map.with_index{gets.chomp.chars}

  x = y = 0
  y = a.find_index{|a| a.index("@")}
  x = a[y].index("@")

  count = []
  search(a, x, y, w, h, count)
  puts (count.length + 1)
end

Measured memory_bytes: 6176
from itertools import permutations
N,M = map(int,input().split())
table=[[]for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    table[a-1].append(b-1)
    table[b-1].append(a-1)
 
def f(L,k):
    for a in L:
        if a==k:
            return True
    return False
 
S=[i for i in range(1,N)]
ans =0
for s in permutations(S,N-1):
    flag =True
    if not f(table[0],s[0]):
        continue
    for i in range(N-2):
        if not f(table[s[i]],s[i+1]):
            flag =False
    if flag:
        ans+=1
print(ans)

Measured memory_bytes: 3064
n = gets.to_i
as = gets.chomp.split.map(&:to_i)
sum_a = Array.new(n,0)
ans = 10 ** 18
as.each_with_index do |a,i|
  if i != 0
    sum_a[i] = sum_a[i-1] + a
  else
    sum_a[i] = a
  end
end

sum = sum_a[-1]
sum_a.each_with_index do |j,k|
  next if k == n - 1
  ans = (sum - j*2).abs if ans > (sum - j*2).abs
end

puts ans


Measured memory_bytes: 18052
#include <stdio.h>

int main(void)
{
	int i, n;
	int x;

	scanf("%d", &n);

	for(i=1; i<=n; i++){
		x = i;
		if(x%3 == 0){
			printf(" %d", i);
		} else if(x%10 == 3){
			printf(" %d", i);
		} else {
			//printf("C%d\n", x);
			x /= 10;
			//printf("%d\n", x);
			while(x){
				if(x%10 == 3){
					printf(" %d", i);
					break;
				}
				x /=10;
			}
		}
	}
	printf("\n");
	return 0;
}

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

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

  // ここにプログラムを追記
  for (int i = 0; i < N; i++){
    string S;
    cin >> S;
     
    if (S == "Y") {
      cout << "Four" << endl;
      break;
    }
    
    else if(i < N - 1) {
      continue;
    }
    
    cout << "Three" << endl;
  } 
}


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

using namespace std;


int main()
{
    int N;
    cin >> N;
    long long int ans = 1;
    for(int i = 0; i < N; i++)
    {
        long long int a;
        cin >> a;
        if(a == 0)
        {
            ans = 0;
            break;
        }
        if(ans == -1) continue;
        if(ans > 1000000000000000000 / a)
        {
            ans = -1;
        }
        if(ans == -1) continue;
        ans = ans * a;
        if(ans > 1000000000000000000) ans = -1;
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;

int N;

int idx(int l, int r){
    if(0<=l && l<r && r<=N)
        return N*r+l;
    else
        return N*(N+1);
}

int main(){
    static ll dp[400*401+1];
    ll a[400], sum[401];
    cin >> N;
    for(int i=0;i<N;i++) cin >> a[i];
    sum[0] = 0;
    for(int i=1;i<=N;i++) sum[i] = sum[i-1] + a[i-1];

    for(int i=0;i<N;i++) dp[idx(i,i+1)] = 0;
    dp[N*(N+1)] = 1e17;

    for(int len=2;len<=N;len++){
        for(int l=0;l+len<=N;l++){
            dp[idx(l, l+len)] = 1e17;
            for(int sep=l+1;sep<l+len;sep++){
                dp[idx(l, l+len)] = min(dp[idx(l, l+len)], dp[idx(l, sep)]+dp[idx(sep, l+len)]+sum[l+len]-sum[l]);
            }
        }
    }

    cout << dp[idx(0, N)] << endl;
    
    return 0;
}

Measured memory_bytes: 1536
def main():
    N, K = map(int, input().split())
    *A, = map(int, input().split())

    t = 1
    for i in range(K, N):
        if A[i] > A[i - K]:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 31616
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

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

template<class T>inline bool maxi(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool mini(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

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

	string s; cin >> s;
	lint n, i=0; cin >> n;
	while (s.length() > i) {
		cout << s[i];
		i += n;
	}
	gc();
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
double eps = 1e-5;
int main() {
    long long a;
    double b;
    string s;
    cin >> a;
    cin >> b;
    cout <<  (long long)(a * (long long)(b*100)) / 100;
   // system("pause");
}

Measured memory_bytes: 3164
dishes = [input() for _ in range(5)]


def tanuki(dishes):
    sum_dishes = 0
    last_dish = 0
    last_tmp = 0
    for dish in dishes:
        tmp = 10 - int(dish[-1])
        dish = int(dish)
        if tmp == 10:
            sum_dishes += dish
        elif tmp > last_tmp:
            sum_dishes += last_dish + last_tmp
            last_dish = dish
            last_tmp = tmp
        else:
            sum_dishes += dish + tmp
    return sum_dishes + int(last_dish)


print(tanuki(dishes))

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

int main(){ 
    int n;
    cin>>n;
    int b=0;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    for(int i=0;i<n;i++){
        if(i%2==0){
        b+=a[i];
        }else{
            b-=a[i];
        }
    }
    cout<<b;
    return 0;
}


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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.14159265358979323846264338327950288419

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int co, n, m, s[105];

int main(){
	scanf("%d %d", &n, &m);
	FI(i, 1, m){
		scanf("%d", &s[i]);
		if(s[i] & 1) co++;
	}
	if(n & 1) co++;
	if(m == 1){
		if(s[1] == 1) printf("1\n1\n1\n");
		else printf("%d\n2\n1 %d\n", s[1], s[1] - 1);
		return 0;
	}
	if(co > 2){
		printf("Impossible\n");
		return 0;
	}
	else if(co == 2){
		if(n & 1){
			//one odd, potentially another
			FI(i, 2, m) if(s[i] & 1){
				swap(s[i], s[1]);
				break;
			}
			//s[1] is odd
			FI(i, 1, m) printf("%d%c", s[i], i == m ? '\n':' ');
			printf("%d\n", m);
			printf("%d ", s[1] + 1);
			FI(i, 2, m - 1) printf("%d ", s[i]);
			printf("%d\n", s[m] - 1);
		}
		else{
			//two odds, length is even
			int p1 = -1, p2 = -1;
			FI(i, 1, m) if(s[i] & 1){
				if(p1 == -1) p1 = i;
				else p2 = i;
			}
			swap(s[1], s[p1]);
			swap(s[m], s[p2]);
			FI(i, 1, m) printf("%d%c", s[i], i == m ? '\n':' ');
			if(s[1] == 1) printf("%d\n", m - 1);
			else printf("%d\n", m);
			if(s[1] > 1) printf("%d ", s[1] - 1);
			FI(i, 2, m - 1) printf("%d ", s[i]);
			printf("%d\n", s[m] + 1);
		}
	}
	else if(co == 1){
		assert(false); //can never happen
	}
	else{
		//everything even :)
		FI(i, 1, m) printf("%d%c", s[i], i == m ? '\n':' ');
		printf("%d\n", m + 1);
		printf("1");
		FI(i, 1, m - 1) printf(" %d", s[i]);
		printf(" %d\n", s[m] - 1);
	}
	return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for i in range(1, n+1):
    d[i] = 0
l = [1]
x = 1
if n >= k:
    for i in range(k):
        x = a[x-1]
    print(x)
    exit()
for i in range(n):
    x = a[x-1]
    if d[x] == 1:
        k -= l.index(x)
        print(l[l.index(x):][k%(l.index(x)-len(l))])
        exit()
    l.append(x)
    d[x] += 1
print(x)

Measured memory_bytes: 40512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ld pie=3.1415926535;
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,m; cin>>n>>m;
    vector<vector<int>> path(n);
    rep(i,m){
        int a,b; cin>>a>>b;
        a--; b--;
        path[a].push_back(b);
        path[b].push_back(a);
    }

    vector<int> dis(n,inf);
dis[0]=0;
priority_queue<pp, vector<pp>, greater<pp>> pq;
pq.push(mk(0,0));

int cost,s,to,w;
while(!(pq.empty())){
            tie(cost,s)=pq.top(); pq.pop();
            if(cost!=dis[s]) continue;
            for(auto p : path[s]){
                w=1; to=p;
                if(dis[to]>cost+w){
                    dis[to]=cost+w;
                    pq.push(mk(dis[to],to));
                }
            }
}
    if(dis[n-1]==2) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 13936
N, M = map(int, input().split(" "))
Xs = map(int, input().split(" "))

X_lst = sorted(Xs)
dX = sorted([X_lst[i+1] - X_lst[i] for i in range(len(X_lst)-1)])
if N >= M:
  print(0)
elif N == 1:
  print(sum(dX))
else:
  print(sum(dX[:-(N-1)]))

Measured memory_bytes: 13968
#include<iostream>
#include<cstdio>
#include<algorithm>
#define MAX 2010
using namespace std;
int nums[MAX]={0};
int main(){
	int n,x,y;
	scanf("%d %d %d",&n,&x,&y);
	
	for(int i=1;i<=n;i++){
		//¼ÆËãi j 
		for(int j=i+1;j<=n;j++){
			int dis=j-i;
			dis=min(dis,abs(x-i)+abs(y-j)+1);
			dis=min(dis,abs(y-i)+abs(x-j)+1);
			nums[dis]+=1;
		} 
	}
	for(int i=1;i<=n-1;i++){
		printf("%d\n",nums[i]);
	}
	return 0;
}

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

int main() {
  
  int n;
  cin >> n;
  int ans = 10000;
  int t = 0;
  
  for (int i = 0; i <= 10; i++){
    int x = 1000 * i;
    if(n == x){
      cout << 0 << endl;
      t = 1;
      break;
    }
    else if(n - x < 0){
      int y = (n - x) * -1;
      if (y < ans){
        ans = y;
      }
    }
    
  }
  
  
  
  if(t == 0){
    cout << ans <<endl;
  }
  
  

}





Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

ll k, s;

int main(){
	ll ans = 0;
	cin >> k >> s;
	REP(i, k + 1){
		REP(j, k + 1){
			if (s - (i + j) <= k&&s >= (i + j))ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {

int A,B,C,X,D;
	D=0;
	X=0;
	cin>>A>>B>>C>>X;
	for(int a=0;a<=A;++a){
		for(int b=0;b<=B;++b){
			for(int c=0;c<=C;++c)
	{
		if(X==500*a+100*b+50*c) ++D;
			}
		}
	}
	cout<<D<<endl;
	
}

Measured memory_bytes: 3536
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		int n = scan.nextInt();
		int[] A = new int[n];
		for(int i=0; i<n; i++)A[i]=scan.nextInt();
		int r = k -(A[0]+(k-A[n-1]));
		int l = k-(A[1]-A[0]);
		int min = Math.min(r, l);
		for(int i=1; i<n-1; i++) {
			l = k-(A[i+1]-A[i]);
			min = Math.min(min, l);
		}
		System.out.println(min);
	}

}

Measured memory_bytes: 65504
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Maybe

--notFizzBuzz :: Int -> Int
--notFizzBuzz 

main :: IO ()
main = do 
    n <- fst . fromJust <$> ( BS.readInt <$> BS.getLine ) :: IO Int
    --cs <- getLine
    let f = (\x -> if mod x 3 == 0 || mod x 5 == 0 then 0 else x)
    let notFizzBuzz =  map f [1..n]
    print $ sum notFizzBuzz



Measured memory_bytes: 3724
#include <iostream>
#include <queue>
#include <vector>

class data 
{
public:
  int arrnum;
  int num;
  data (int arrnum , int num )
  {
    this->arrnum = arrnum;
    this->num = num;
  };
};

bool operator> (const data &data1 , const data &data2)
{
  return data1.num > data2.num;
};


int main(int argc, char **argv)
{
  int N,L,i,j;
  int min_arrnum=0;
  int min_num=0;
  
  std::cin >> N >> L;

  int *vec;
  vec = new int[N]; 

  for(i=0; i<N; i++)
    {
      std::cin >> vec[i];
    }

std::priority_queue< data, std::vector<data>, std::greater<data> > que;

 for(i=0;i<N;i++)
   {
     que.push(data(i,vec[i]));
     if(i < L-1) continue;
     while(que.top().arrnum <= i-L)
       que.pop();
     std::cout << que.top().num;
     if(i == N-1) 
       std::cout << std::endl;
     else 
       std::cout << " ";
   }

  return 0;
}


Measured memory_bytes: 15152
import numpy as np

N, Q = map(int, input().split())
S = np.array(list('_' + input()), dtype='U')

A = (S == 'A')
C = (S == 'C')
AC = A[:-1] & C[1:]
AC_cum = AC.cumsum()

for _ in range(Q):
    l, r = map(int, input().split())
    print(AC_cum[r-1] - AC_cum[l-1])

Measured memory_bytes: 17212
#include<stdio.h>

int main(){
  int A,B,C,i,j,N[3],temp;
  scanf("%d %d %d",&A,&B,&C);
  N[0] = A;
  N[1] = B;
  N[2] = C;
    for(j=0;j<3;j++){
      for(i=0;i<3;i++){
        if(N[i]<N[i+1]){
          temp = N[i];
          N[i] = N[i+1];
          N[i+1] = temp;
        }
      } 
    }
    
  printf("%d",N[0]*10+N[1]+N[2]);
  return 0;
}


Measured memory_bytes: 128
N=int(input())
S=input()
a=0
b=0
cnt=0
for i in range(N):
  if S[i]==')':
    b+=1
  else:
    a+=1
  cnt=max(cnt,b-a)
A='('*cnt+S
d=A.count(')')
e=A.count('(')
f=e-d
print(A+')'*f)

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

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

    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int count = 0;
    int total = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                total = 500 * i + 100 * j + 50 * k;
                if(total == x) ++count;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))+[0]     ###料理
B = list(map(int, input().split()))     ###満足度
C = list(map(int, input().split()))  +[0]   ###連ちゃん

sum=sum(B)

for i in range(N):
    if A[i+1]-A[i]==1:
        sum+=C[A[i]-1]

print(sum)



Measured memory_bytes: 3060
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

import math

dist = [[0] * N for _ in range(N)]
for i in range(N - 1):
    xi, yi = xy[i]
    for j in range(i + 1, N):
        xj, yj = xy[j]
        dist[i][j] = math.sqrt((xi - xj) ** 2 + (yi - yj) ** 2)
        dist[j][i] = dist[i][j]

import itertools

ans = 0
cases = list(itertools.permutations(range(N)))
for case in cases:
    for idx in range(N - 1):
        ans += dist[case[idx]][case[idx + 1]]
ans /= len(cases)

print(ans)

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

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

  int tot = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;

    tot += min(x, k - x) * 2;
  }
  cout << tot << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b>>c>>k;
    ans=a-b;
    if(k%2==1)Cout(ans*-1);
    else Cout(ans);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){

   int a[5],i,j,work;
   for(i=0;i<5;i++){
      scanf("%d",&a[i]);
   }
   for(i=0;i<4;i++){
      for(j=i+1;j<5;j++){
         if(a[i]<a[j]){
            work=a[i];
            a[i]=a[j];
            a[j]=work;
         }
      }
   }
   for(i=0;i<5;i++){
      if(i==4){
         printf("%d\n",a[i]);
         break;
      }   
      printf("%d ",a[i]);
  
   }


   return 0;
}

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

using namespace std;

string s;

void input()
{
  cin >> s;
}

void solve()
{
  string res = "";
  res += s[0];
  int cnt = 0;
  for(int i=1; i < s.length()-1; i++)
  {
    cnt++;
  }
  res += to_string(cnt);
  res += s[s.length()-1];
  cout << res;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  vl a(N);
  ll maxa = 0;
  rep(i, 0, N) {
    in(a[i]);
    maxa = max(maxa, a[i]);
  }

  ll mn = LINF;
  ll v;
  auto m = (long double)maxa / 2;
  rep(i, 0, N) {
    if (a[i] == maxa) continue;
    auto d = abs(m - a[i]);
    // cout << a[i] << " " << d << endl;
    if (d < mn) {
      v = a[i];
      mn = d;
    }
  }
  cout << maxa << " " << v << endl;
}


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

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

    vector<int64_t> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }

    int64_t diff;
    int64_t ans = 0;

    for (int i = 0; i < n - 1; i++)
    {
        if (a.at(i) > a.at(i + 1))
        {
            diff = a.at(i) - a.at(i + 1);
            ans += diff;
            a.at(i + 1) += diff;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4780
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define Aint(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

int modPow(int x, int p, int mod) {
    int ret = 1;
    while (p > 0) {
        if (p & 1)
            ret = ret * x % mod;
        x = x * x % mod;
        p >>= 1;
    }
    return ret;
}

class modCombination {
    vector<int> x, xi;

public:
    modCombination(int max) : x(max + 1), xi(max + 1) {
        x[0] = 0;
        x[1] = 1;
        for (int i = 2; i <= max; ++i) {
            x[i] = x[i - 1] * i % MOD;
        }
        xi[0]=1;
        for (int i = 1; i <= max; ++i) {
            xi[i] = modPow(x[i],MOD-2,MOD);
        }
    }

    int combination(int n,int r){
        return ((x[n]*xi[r]) % MOD) *xi[n-r] % MOD;
    }
};

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int h, w, a, b;
    cin >> h >> w >> a >> b;

    modCombination c(h+w+2);

    int ans = 0;
    REP(i, min(h - a, w - b)) {
        ans += c.combination(h - a - i - 1 + b + i, b + i) * c.combination(a + i + w - b - i - 1, w - b - i - 1) % MOD;
        ans %= MOD;
    }

    cout << ans << ENDL;

    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
using namespace std;
int dp[101][10001];
int main( void )
{
  int N,W;
  cin >> N >> W;
  for( int i=1; i<=N; i++ ){
    int v,w;
    cin >> v >> w;
    for( int j=0; j<=W; j++ ){
      if( j < w ){
        dp[i][j] = dp[i-1][j];
      } else {
        dp[i][j] = max( dp[i-1][j], dp[i-1][j-w] + v );
      }
    }
  }
  cout << dp[N][W] << endl;
  return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k; string s;
	cin >> n >> s >> k;
	for(int i=0;i<n;i++){
		if(s[i]-s[k-1] != 0) s[i] = '*';
	}
	cout << s << "\n";
	return 0;
}

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

int main() {
    bool lb = false;
    int n;
    while (cin >> n, n) {
        vector<pair<int,pair<int,string>>> v(n);
        string name;
        int win, lose, draw;
        for (int i=0; i<n; ++i) {
            cin >> name >> win >> lose >> draw;
            v[i] = make_pair(-win*3-draw, make_pair(i, name));
        }
        sort(v.begin(), v.end());
        if (lb) {
            cout << endl;
        } else {
            lb = true;
        }
        for (int i=0; i<n; ++i) {
            cout << v[i].second.second << "," << -v[i].first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1220