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

using namespace std;

int main()
{
  int n;
  cin >> n;
  int dp[n][3];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 3; ++j)
      dp[i][j] = 0;
  cin >> dp[0][0] >> dp[0][1] >> dp[0][2];
  for (int i = 1; i < n; ++i)
  {
    int pts[3];
    cin >> pts[0] >> pts[1] >> pts[2];
    for (int j = 0; j < 3; ++j)
      for (int k = 1; k <= 2; ++k)
	dp[i][(j+k)%3] = max(dp[i][(j+k)%3], dp[i-1][j] + pts[(j+k)%3]);
  }
  cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << '\n';
}


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

ca = [list(map(int,input().split())) for i in range(n)]
sum = [list([0] * (m+1)) for i in range(2**n)]

min_value = -1

for i in range(2**n):
    flg = 0
    for j in range(n):
        if i & 2**j:
            sum[i][0] += ca[j][0]
            for k in range(m):
                sum[i][k+1] += ca[j][k+1]
    for k in range(m):
        if (sum[i][k+1] < x):
            flg = 1
            break

    if (sum[i][0] < min_value or min_value == -1) and flg == 0:
        min_value = sum[i][0]

print(min_value)

Measured memory_bytes: 11276
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  string s;
  cin>>n>>s;
  for(int i=0; i<n; i++){
    int count=0;
    for(char c='a'; c<='z'; c++){
      bool left=false,right=false;
      for(int j=0; j<i; j++) {
        if(s[j]==c) left=true;
      }
      for(int j=i; j<n; j++) {
        if(s[j]==c) right=true;
      }
      if(left && right) count++;
    }
    ans = max(ans,count);
  }
  cout<<ans;
}

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

#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pqMax priority_queue<int>
#define pqMin priority_queue<int, vector<int>, greater<int>>
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie();                        \
    cout.tie()
int n, t, i, j, k;

void solve() {
    cin >> n >> k;
    vi a(n);
    for (int &i : a) cin >> i;
    vector<bool> dp(k + 1);
    for (int stones = 0; stones <= k; stones++) {
        for (int x : a) {
            if (stones - x >= 0 && !dp[stones - x]) {
                dp[stones] = true;
            }
        }
    }
    cout << (dp[k] ? "First" : "Second") << '\n';
}

int32_t main() {
    FAST;
    solve();
}

Measured memory_bytes: 256
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

//repeat
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

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

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

int main () {
	int n;
	cin >> n;
	string a,b,c;
	cin >>a>>b>>c;

	int cnt = 0;
	rep(i, n) {
		if (a[i] == b[i]) {
			if (b[i] != c[i]) {
				cnt++;
			}
		} else if(c[i] == b[i]){
			if (a[i] != b[i]) {
				cnt++;
			}
		} else if (a[i] == c[i]) {
			if (a[i] != b[i]) {
				cnt++;
			}
		} else if(a[i]!=b[i] && b[i]!=c[i]){
			cnt += 2;
		}
	}
	cout << cnt << endl;
}


 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pii = pair<int, int>;
 
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x first
#define y second
 
const int MOD = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0}; 
const char dir[] = {'R', 'L', 'D', 'U'};
 
int add(int a, int b){
    a += b;
    if(a >= MOD){
        a -= MOD;
    }
    return a;
}
 
int sub(int a, int b){
    a -= b;
    if(a < 0) a += MOD;
    return a;
}
 
int mult(int a, int b){
    return ((ll) a * b) % MOD;
}
 
void setIO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    freopen((s+".in").c_str(),"r",stdin);
//    freopen((s+".text").c_str(),"w",stdout);
}
 
//ctrl q is comment
//ctrl b is run
//ctrl s is compile
//alt r is search & replace
//alt d is delete a line
 
int grid[1001][1001];
bool vis[1001][1001], added[1001][1001];
int h, w;
queue<pair<pii, int>> q;

void dfs(int x, int y, int wv){
    if(x < 0 || x >= h || y < 0 || y >= w || vis[x][y] || grid[x][y]) return;
    if(!added[x][y]) {
        q.push(mp(mp(x, y), wv));
        added[x][y] = true;
    }
    vis[x][y] = true;
    for(int i = 0; i < 4; ++i){
        dfs(x + dx[i], y + dy[i], wv);
    }
}
 
int main(){
    setIO();
    cin >> h >> w;
    int ch, cw, dh, dw; cin >> ch >> cw >> dh >> dw;
    --ch; --cw; --dh; --dw;
    for(int i = 0; i < h; ++i){
        string s; cin >> s;
        for(int j = 0; j < w; ++j){
            grid[i][j] = s[j] == '.' ? 0 : 1;
        }
    }
    int amt = 0;
    q.push(mp(mp(dh, dw), 1));
    dfs(dh, dw, 1);
    added[dh][dw] = true;
    while(!vis[ch][cw] && q.size()){
        auto cur = q.front(); q.pop();
        for(int i = -2; i <= 2; ++i){
            for(int j = -2; j <= 2; ++j){
                if(!i && !j) continue;
                if(cur.x.x + i < 0 || cur.x.x + i >= h || cur.x.y + j < 0 || cur.x.y + j >= w) continue;
                if(!vis[cur.x.x + i][cur.x.y + j] && !grid[cur.x.x + i][cur.x.y + j]){
                    dfs(cur.x.x + i, cur.x.y + j, cur.y + 1);
                }
            }
        }
        amt = cur.y;
    }
    if(!vis[ch][cw]) cout << -1 << "\n";
    else cout << amt << "\n";
}

Measured memory_bytes: 9568
#include <queue>
#include <utility>
#include <string>
#include <iostream>

using namespace std;

int main(){
    pair<string, int> schedule;
    queue<pair <string, int> > Q;
    int total = 0;
    int n,q;
    cin >> n >> q;
    for(int i=0;i<n;i++){
        string s;
        int ms;
        cin >> s >> ms;
        schedule = make_pair(s, ms);
        Q.push(schedule);
    }
    while(!Q.empty()){
        if(Q.front().second<=q){
            total += Q.front().second;
            cout << Q.front().first << " " << total << endl;
            Q.pop();
        }
        else{
            total += q;
            schedule = make_pair(Q.front().first,Q.front().second-q);
            Q.pop();
            Q.push(schedule);
        }
    }
}

Measured memory_bytes: 4408
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);

		boolean isContinue = true;

		//?????°???????´?????????????
		int[] score = new int[3];
		//????????????????´????????????¬????????§????????????
		ArrayList<String> list = new ArrayList<String>();

		while(isContinue){

			int m = scan.nextInt();
			int f = scan.nextInt();
			int r = scan.nextInt();


			int intScore = 0;
			//????????????????????´??????intScore????¨????
			if(m != -1 && f != -1){
				intScore = m + f;
			}

			//while????????????????????¶
			if(m == -1 && f == -1 && r == -1){
				isContinue = false;
				scan.close();

			//????????????????????????????????????list???????´?
			}else if(m == -1 || f == -1 || intScore < 30 ){

				list.add("F");
			}else if(80 <= intScore){

				list.add("A");
			}else if(65 <= intScore){

				list.add("B");
			}else if(50 <= intScore){

				list.add("C");
			}else if(30 <= intScore &&  50 <= r){

				list.add("C");

			}else{

				list.add("D");
			}
			//System.out.println("list.size():" + list.size());
		}

		for(int i = 0; i < list.size(); i++){

			System.out.println(list.get(i));
		}

	}
}

Measured memory_bytes: 19652
N = int(input())
p = list(map(float,input().split()))
DP = [[0 for i in range((N+1)//2)] for i in range(N)]
DP[0][0] = p[0]
if N > 1:
    DP[0][1] = 1-p[0]
for i in range(1,N):
    for j in range((N+1)//2):
        DP[i][j] += p[i]*DP[i-1][j]
        if j != 0:
            DP[i][j] += (1-p[i])*DP[i-1][j-1]
print(sum(DP[-1]))

Measured memory_bytes: 153224
import Data.List
import Control.Monad

solve :: [[Int]] -> [Int] -> [Double] -> Double
solve inData prev ans
 | null inData = sum ans
 | otherwise   = solve (tail inData) (head inData) (newAns:ans)
   where newAns = sqrt $ fromIntegral ((prev !! 0 - (head inData) !! 0) ^ 2 + (prev !! 1 - (head inData) !! 1) ^ 2) 

solve' :: [[[Int]]] -> [Double] -> Double
solve' xyLists ans
 | null xyLists = (sum ans) / fromIntegral (length ans)
 | otherwise    = solve' (tail xyLists) (newAns:ans)
   where newAns = solve (tail (head xyLists)) (head (head xyLists)) []

main = do
 n <- read <$> getLine :: IO Int
 xyList <- replicateM n (map read . words <$> getLine) :: IO[[Int]]
 print $ solve' (permutations xyList) []


Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define trav(x, v) for(auto &x : v)
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<vi> vvi;

int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n;
	ll x;
	cin >> n >> x;

	vector<ll> bs(n), ls(n), us(n);
	rep(i,0,n) cin >> bs[i] >> ls[i] >> us[i];

	ll aoki = 0;
	rep(i,0,n) aoki += ll(ls[i]) * bs[i];

	vector<ll> sc(n);
	rep(i,0,n) sc[i] = ll(us[i]) * x - ll(us[i] - ls[i]) * bs[i];

	vi perm(n);
	iota(all(perm), 0);
	sort(all(perm), [&](int i, int j){
		return sc[i] > sc[j];
	});
	ll s1, s2 = 0;
	ll cnt;
	rep(ix,0,n){
		s2 += sc[perm[ix]];
		if(s2 == aoki){
			cout << ll(ix+1)*x << endl;
			return 0;
		}
		if(s2 > aoki){
			s1 = s2 - sc[perm[ix]];
			cnt = ix;
			break;
		}
	}
	ll ans = ll(n)*x;
	rep(ix,0,n){
		int i = perm[ix];
		ll tob = sc[i] <= sc[perm[cnt]] ? aoki - s1 : aoki - s2 + sc[i];
		ll cur;
		if(tob <= bs[i]*ls[i]){
			cur = (tob+ls[i]-1)/ls[i];
		} else {
			cur = (tob + ll(us[i]-ls[i])*bs[i] + us[i]-1) / us[i];
		}
		ans = min(ans, ll(cnt)*x + cur);
	}	
	cout << ans << endl;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
bool isprime[55557];
int main(){
    FOR(i,2,55556){
        isprime[i] = true;
    }
    FOR(i,2,55556){
        if(isprime[i]){
            int no = i*2;
            while(no<=55556){
                isprime[no] = false;
                no+=i;
            }
        }
    }
    vector<int> oneprime;
    REP(i,55556){
        if(isprime[i] && i%5==1){
            oneprime.push_back(i);
        }
    }
    int n; cin >> n;
    REP(i,n){
        cout << oneprime[i] ;
        if(i!=n-1){
            cout << " ";
        }else{
            cout << endl;
        }
    }
    

}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

int main(void){
	int h,w;
	cin>>h>>w;
	vector<string> S;
	string s;
	rep(i,h){
		cin>>s;
		S.push_back(s);
	}
	vector<vector<int>> tate,yoko;
	rep(i,h){
		tate.push_back(vector<int>());
		yoko.push_back(vector<int>());
		rep(j,w){
			tate[i].push_back(0);
			yoko[i].push_back(0);
		}
	}

	rep(i,h){
		int count = 0;
		int xi = 0;
		rep(j,w){
			if(S[i][j] == '#'){
				while(xi < j){
					yoko[i][xi] = count;
					xi++;
				}
				yoko[i][xi] = 0;
				xi++;
				count = 0;
			}else{
				count++;
			}
		}
		if(count > 0){
			while(xi < w){
				yoko[i][xi] = count;
				xi++;
			}
		}
	}

	rep(j,w){
		int count = 0;
		int yi = 0;
		rep(i,h){
			if(S[i][j] == '#'){
				while(yi < i){
					tate[yi][j] = count;
					yi++;
				}
				tate[yi][j] = 0;
				yi++;
				count = 0;
			}else{
				count++;
			}

		}
		if(count > 0){
			while(yi < h){
				tate[yi][j] = count;
				yi++;
			}
		}
	}
	int ans = 0;
	rep(i,h){
		rep(j,w){
			//cout<<yoko[i][j]<<" ";
			chmax(ans, tate[i][j] + yoko[i][j] - 1);
		}
		//cout<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 36608
#include<iostream>
#include<algorithm>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a)
	{
		return parent[a]!=a?parent[a]=find(parent[a]):a;
	}
	bool same(int a,int b)
	{
		return find(a)==find(b);
	}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
};
int N;
long x[50],y[50];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>x[i]>>y[i];
	int ans=N;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)
	{
		long p=x[i]-x[j],q=y[i]-y[j];
		if(p==0&&q==0)continue;
		int now=N;
		UF uf(N);
		for(int k=0;k<N;k++)
		{
			for(int l=0;l<N;l++)
			{
				if(x[l]+p==x[k]&&y[l]+q==y[k]||x[l]-p==x[k]&&y[l]-q==y[k])
				{
					now-=uf.unite(l,k);
				}
			}
		}
		ans=min(ans,now);
	}
	cout<<ans<<endl;
}


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

int main() {
   string a;
   
  
   cin >> a;
   if(a=="a"||a=="e"||a=="i"||a=="o"||a=="u"){
     
     cout << "vowel" << endl;
     
   }else{
     
     
       cout << "consonant" << endl;
       
   }
  
  
  
 
    
 
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      FastIO
      lld a, b;
      lld k, i;
      cin >> a;
      cin >> b;
      cin >> k;
      if (a > k)
      {
      	a-= k;
      	k = 0;
      }
      else
      {
      	k-= a;
      	a = 0;
      }
      if (b > k)
      {
      	b-= k;
      	k = 0;
      }
      else
      {
      	k-= b;
      	b = 0;
      }
      cout << a << " " << b << "\n";
      return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
#include<fstream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;


int main(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k%2==0){
        cout<<a-b<<endl;
    }
    else{
        cout<<b-a<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
visited = [[False]*w for _ in range(h)]
flag = True
for y in range(h):
    for x in range(w):
        if s[y][x]=='#':
            flag = False
            for dy,dx in ((1,0),(0,1),(-1,0),(0,-1)):
                ny,nx = y+dy,x+dx
                if 0<=ny<h and 0<=nx<w and s[ny][nx]=='#':
                    flag = True
                    break
        
        if not flag:
            break
    if not flag:
        break


if flag:
    print('Yes')
else:
    print('No')

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

int main(void)
{
    int n, m;
    int *k, **s, *p;
    int pattern = 1;
    int count = 0;
    cin >> n >> m;
    k = new int[m];
    s = new int*[m];
    p = new int[m];
    for (int i = 0; i < n; i++) {
        pattern *= 2;
    }
    count = pattern;
    for (int i = 0; i < m; i++) {
        cin >> k[i];
        s[i] = new int[k[i]];
        for (int j = 0; j < k[i]; j++) {
            cin >> s[i][j];
            s[i][j] -= 1;
        }
    }
    for (int i = 0; i < m; i++) {
        cin >> p[i];
    }
    for (int bits = 0; bits < pattern; bits++) {
        for (int i = 0; i < m; i++) {
            int l = 0;
            for (int j = 0; j < k[i]; j++) {
                l += (bits >> s[i][j]) & 1;
            }
            if (l % 2 != p[i]) {
                count--;
                break;
            }
        }
    }
    cout << count << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string.h>
#include <string>
using namespace std;

int main()
{
    string S;
    cin>>S;
    for(int i=0 ; i<S.size() ; i++)
    {
        if(S[i]==',')
            cout<<" ";
        else
            cout<<S[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
### constant

INF = 1 << 30
MAX_D = 20000

### subroutines

### main

loop do
  n, m, cn, st, gl = gets.split.map(&:to_i)
  break if (n | m | cn | st | gl) == 0

  st -= 1
  gl -= 1
  
  edges = cn.times.map{n.times.map{n.times.map{nil}}}
  nbrs = cn.times.map{n.times.map{[]}}
  
  m.times do
    xi, yi, di, ci = gets.split.map(&:to_i)
    xi -= 1
    yi -= 1
    ci -= 1

    if edges[ci][xi][yi].nil?
      edges[ci][xi][yi] = edges[ci][yi][xi] = di
      nbrs[ci][xi] << yi
      nbrs[ci][yi] << xi
    elsif edges[ci][xi][yi] > di
      edges[ci][xi][yi] = edges[ci][yi][xi] = di
    end
  end
  #p edges
  #p nbrs

  pns = gets.split.map(&:to_i)
  cpr = cn.times.map{[0]}
  
  for ci in (0...cn)
    qis = gets.split.map(&:to_i) + [INF]
    ris = gets.split.map(&:to_i)

    k = 0
    for d in (1..MAX_D)
      k += 1 if qis[k] < d
      cpr[ci][d] = cpr[ci][d - 1] + ris[k]
    end
  end    
  #p $qis
  #p $ris
  #p $fis

  min_ds = cn.times.map{n.times.map{n.times.map{INF}}}
  
  for ci in (0...cn)
    for st0 in (0...n)
      dists = n.times.map{INF}
      dists[st0] = 0
      q = [st0]

      while ! q.empty?
        u = q.min{|a, b| dists[a] <=> dists[b]}
        q.delete(u)

        ud = dists[u]
        for v in nbrs[ci][u]
          nvd = ud + edges[ci][u][v]
          vd = dists[v]
          if vd > nvd
            q << v if vd >= INF
            dists[v] = nvd
          end
        end
      end

      for gl0 in (0...n)
        next if st0 == gl0
        d = dists[gl0]
        if min_ds[ci][st0][gl0] > d
          min_ds[ci][st0][gl0] = d
        end
      end
    end
  end
  #p min_ds

  costs = n.times.map{n.times.map{INF}}

  for st0 in (0...n)
    for gl0 in (0...n)
      next if st0 == gl0
      min_c = INF
      for ci in (0...cn)
        md = min_ds[ci][st0][gl0]
        if md < INF
          pr = cpr[ci][md]
          costs[st0][gl0] = pr if costs[st0][gl0] > pr
        end
      end
    end
  end
  #p costs

  prices = n.times.map{INF}
  prices[st] = 0
  q = [st]

  while ! q.empty?
    u = q.min{|a, b| prices[a] <=> prices[b]}
    q.delete(u)

    break if u == gl

    up = prices[u]

    for v in (0...n)
      cv = costs[u][v]
      next if cv >= INF

      nvp = up + cv
      vp = prices[v]

      if vp > nvp
        q << v if vp >= INF
        prices[v] = nvp
      end
    end
  end

  puts (prices[gl] >= INF) ? -1 : prices[gl]
end

Measured memory_bytes: 17400
function comp(a, b) {
  const len = a.length > b.length ? a.length : b.length

  for (let i = 0; i < len; i++) {
    if (a[i] === undefined) return -1
    if (b[i] === undefined) return 1
    if (a[i] < b[i]) {
      return -1
    } else if (a[i] > b[i]) {
      return 1
    }
  }
}

function main(input) {
  const inputs =input.split('\n')
  const [N] = inputs[0].split(' ').map(Number)
  const S = inputs.slice(1)

  // 辞書順に
  // 最も多く出たものを出力
  S.sort(comp)
  // console.log(S)
  let count = {}
  let max = 0
  for (let i = 0; i < N; i++) {
    if (count[S[i]] === undefined) count[S[i]] = 0
    count[S[i]] += 1
    if (max < count[S[i]]) max = count[S[i]]
  }
  // console.log(count, max)
  for (let i = 0; i < N; i++) {
    // console.log(count[S[i]], max)
    if (count[S[i]] === max) {
      console.log(S[i])
      count[S[i]] = -1
    }
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 109644
import itertools

n = int(input())

city_pos = [list(map(int, input().split())) for _ in range(n)]

dist_list = list()
dist_way = list(itertools.permutations(range(n)))

for dist_i in dist_way:
  dist = 0
  for i in range(len(dist_i)-1):
    dist += ((city_pos[dist_i[i]][0] - city_pos[dist_i[i+1]][0])**2 + (city_pos[dist_i[i]][1] - city_pos[dist_i[i+1]][1])**2)**(0.5)
  
  dist_list.append(dist)
  
print(sum(dist_list)/len(dist_list))

Measured memory_bytes: 9460
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int N;
  string S;
  cin >> N >> S;
  
  //各，変化回数最小値
  vvi dp(N, vi(2, INF));
  
  dp[0][0] = S[0] == '.' ? 0 : 1;
  dp[0][1] = S[0] == '#' ? 0 : 1;
  
  for(int i=1; i<N; i++) {
    dp[i][0] = dp[i-1][0] + (S[i] == '.' ? 0 : 1);
    dp[i][1] = min(dp[i-1][1], dp[i-1][0]) + (S[i] == '#' ? 0 : 1);
  }
  
  fin(min(dp[N-1][0], dp[N-1][1]));
}

Measured memory_bytes: 11412
// A - Ice Tea Store
// https://atcoder.jp/contests/agc019/tasks/agc019_a
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define eb emplace_back
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, q, s, d, n, w, ans = 0, count = 0;
  string t;
  cin >> q >> h >> s >> d;
  cin >> n;
  h = min(h, 2 * q);
  s = min(s, 2 * h);
  if (2 * s <= d)
  {
    ans = s * n;
  }
  else
  {
    ans = n / 2 * d + (n % 2) * s;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;

const long long MOD = (long long)1e9 + 7;
int n, h[100009], dp[100009], k;


int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> h[i];
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= k; j++)
			if (i + j < n)
				dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
	}
	cout << dp[n - 1] << "\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
// Last Change: 04/04/2019 00:25:29.
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

ll D, G;
vector<int> p;
vector<ll> c;

ll Cal(ll val, ll ans, ll depth, int which) {
  if (val >= G) {
    return ans;
  }

  if (depth == D) {
    for (int i = D; i >= 1; --i) {
      if ((which >> (D - i)) & 1) {
        // do nothing
      } else {
        ll diff = G - val;
        if (diff > (i * (p[i - 1] - 1))) {
          val += i * (p[i - 1] - 1);
          ans += p[i - 1] - 1;
        } else {
          ans += diff / i;
          if ((diff % i) > 0) {
            ++ans;
          }
          return ans;
        }
      }
    }
    if (val < G) {
      return numeric_limits<ll>::max();
    }
  }

  ll high, low;
  low = Cal(val, ans, depth + 1, which << 1);

  val += (depth + 1) * p[depth] + c[depth];
  ans += p[depth];
  high = Cal(val, ans, depth + 1, (which << 1) | 1);

  return min(high, low);
}

int main() {
  cin >> D >> G;
  G /= 100;
  p.resize(D);
  c.resize(D);

  for (int i = 0; i < D; ++i) {
    ll ipt;
    cin >> p[i] >> ipt;
    c[i] = ipt / 100;
  }

  ll ans = Cal(0, 0, 0, 0);
  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for(ll i=0; i<N; ++i)

ll max(ll a, ll b) {return a < b ? b : a; }

void dfs(vector<vector<int>>& aj, unordered_set<int>& remainings, int& accm, int current) {
  if(remainings.size() == 0) {
    ++accm;
    return;
  }
  
  for(int j = 0; j < aj[current].size(); ++j) {
    if(aj[current][j] && remainings.find(j) != remainings.end()) {
      //隣接していてまだ見ていない
      remainings.erase(j);
      dfs(aj, remainings, accm, j);
      remainings.insert(j);
    }
  }
}

int main() {
  int N, M;
  
  cin >> N >> M;
  vector<vector<int>> aj(N, vector<int>(N));
  for(int i=0; i<M; ++i) {
    int a, b;
    cin >> a >> b;
    aj[a-1][b-1] = 1;
    aj[b-1][a-1] = 1;
  }
  
  //DFSでパスを探す
  //隣接行列に変換したほうが探索が楽か.そうでもない．好みの問題．
  unordered_set<int> rem;
  for(int i=1; i<N; ++i) rem.insert(i);
  int accm = 0;
  
  dfs(aj, rem, accm, 0);
  
  cout << accm << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a;
int main()
{
	long long a,b,n,i,ans=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
    	cin>>a>>b;
    	ans+=b-a+1;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

long dif4(long a1, long a2, long a3, long a4){
	long max=a1, min=a1;
	if(max<a2) max=a2;
	if(max<a3) max=a3;
	if(max<a4) max=a4;
	if(min>a2) min=a2;
	if(min>a3) min=a3;
	if(min>a4) min=a4;
	return max-min;
}

int n;
long a[200001];
int bs(long k){
	int l=0, r=n;
	while(l<=r){
		int m=(l+r)/2;
		if(a[m]>=k) r=m-1; else l=m+1;
	}
	return l;
}
int main(void){
	n=nextint();
	for(int i=0; i<n; i++){
		a[i+1]=a[i]+nextint();
	}
	long ans=LONG_MAX;
	for(int i2=2; i2<=n-2; i2++){
		int i1 = bs((a[i2]+1)/2);
		int i3 = bs(a[i2]+(a[n]-a[i2]+1)/2);
		if(i1!=i2){
			if(i3!=n){
				long now = dif4(a[n]-a[i3], a[i3]-a[i2], a[i2]-a[i1], a[i1]-a[0]);
				if(now<ans) ans=now;
			}
			if(i3!=i2+1){
				long now = dif4(a[n]-a[i3-1], a[i3-1]-a[i2], a[i2]-a[i1], a[i1]-a[0]);
				if(now<ans) ans=now;
			}
		}
		if(i1!=1){
			if(i3!=n){
				long now = dif4(a[n]-a[i3], a[i3]-a[i2], a[i2]-a[i1-1], a[i1-1]-a[0]);
				if(now<ans) ans=now;
			}
			if(i3!=i2+1){
				long now = dif4(a[n]-a[i3-1], a[i3-1]-a[i2], a[i2]-a[i1-1], a[i1-1]-a[0]);
				if(now<ans) ans=now;
			}
		}
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

#define _GLIBCXX_DEBAC
using namespace std;
	


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










Measured memory_bytes: 256
/* ITP1_8_D: Ring */

#include <iostream>
#include <string>
using namespace std;

bool has_word(string s, string word) {
    return s.find(word, 0) != string::npos;
}

int main() {
    string s, word;
    cin >> s >> word;
    cout << ( has_word(s + s, word) ? "Yes" : "No" ) << endl;
    return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

int main() {
  ll n, m, d;
  double ans;

  cin >> n >> m >> d;

  if (d == 0) {
    ans = (1.0 / n) * (m-1);
  } else {
    ans = (2.0 * (n-d)) / (n*n) * (m-1);
  }

  printf("%.10lf\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int res=0;
    char c;
    bool zf=0;
    while(((c=getchar())<'0'||c>'9')&&c!= '-');
    if(c=='-')zf=1;
    else res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
    if(zf)return -res;
    return res;
}
int _data[100005];
int Max,now,ans;
signed main(){
	int n=read(),c=read(),k=read();
	for(register int i=1;i<=n;i++){
		_data[i]=read();
	}
	sort(_data+1,_data+n+1);
	for(register int i=1;i<=n;i++){
		if(!now||Max<_data[i])Max=_data[i]+k,now=c-1,ans++;
		else now--;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4120
n = int(input())
a = [int(i) for i in input().split()]

if n % 2 == 0:
    lis1 = a[::2]
    lis2 = a[::-2]
    ans = lis2 + lis1
else:
    lis1 = a[::-2]
    lis2 = a[1::2]
    ans = lis1 + lis2
ans = map(str, ans)
print(' '.join(ans))

Measured memory_bytes: 36248
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
const int maxn = 1e6+7;

int main(){
	int n;
	cin>>n;
	int *a=new int[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	cout<<a[n-1]-a[0]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
const int MAX = 1e6 + 100;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 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) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// COMinit();
// COM(w+h-2,w-1);
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false); 
    ll x,y;
    cin >> x >> y;
    ll a,b;
    ll cnt= 0;
    COMinit();
    if(abs(2*x-y)%3==0 && (2*y-x)%3==0){
        a= (2*x-y)/3;
        b= (2*y-x)/3;
        if(~(a|b)>>63) {
            cnt= COM(a+b, a);
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 23680
import java.util.*;
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 K = sc.nextInt();
		sc.close();

		int ans = 0;
		List<Integer> inputList = new ArrayList<>();
		inputList.add(A);
		inputList.add(B);
		inputList.add(C);
		Collections.sort(inputList);
		ans = inputList.get(2);
		for(int i=0; i<K; i++) {
			ans *=2;
		}

		ans = ans + inputList.get(0) + inputList.get(1);

		System.out.println(ans);
	}


}

Measured memory_bytes: 21716
import scala.io.{StdIn => in}

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  val s = in.readLine.toCharArray()
  for(i <- 0 until s.size by 2) {
    out.print(s(i))
  }

  out.println
  out.flush
}

Measured memory_bytes: 29304
use proconio::input;
use std::collections::HashMap;
fn main() {
    input!{
        n:usize,mut a:[i64;n],
    }
    let mut s:Vec<i64>=vec![0;n+1];
    s[0]=0;
    for i in 0..n{
        s[i+1]=s[i]+a[i];
    }
    s.sort();
    let mut ans:i64=0;
    let mut map=HashMap::<i64,i64>::new();
    for &x in s.iter(){
        *map.entry(x).or_insert(0)+=1;
    }
    for (_,v) in &map{
        ans+=v*(v-1)/2;
    }
    println!("{}",ans);
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX

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

int main(){

  vector<string> s(3);
  rep(i, 3) cin >> s[i];
  
  vector<int> cnt(3, 0);
  int n = 0;
  
  while(1){
	if(cnt[n] == s[n].size()){
	  	cout << (char)('A' + n) << endl;
		break;
	  }	  
  	int tmp = n;
  	n = (s[n][cnt[n]] - 'a');
  	cnt[tmp]++;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>   
using namespace std;
#define N 10000
#define REP(i, n) for(int i=0; i<n; i++)
string s;
int n;
int a[3]={0,0,0};
int main(void){
    cin>>s;
    n=s.size()-1;
//bit全探索
    for(int i=0;i<(1<<n);i++){ //000 +++ 111 ---
        int sum=s[0]-'0';
        for(int j=0;j<n;j++){
            if(1&(i>>j)){//j番目が1ならば
                sum+=s[j+1]-'0';
                a[j]=0;
            }else{
                sum-=s[j+1]-'0';
                a[j]=1;
            }          
        }
        if(sum==7){
           int b=s[0]-'0';
           printf("%d",b);
           for(int j=0;j<n;j++){
               if(a[j]==0){
                printf("+");    
               }else{
                printf("-");   
               }
               int b=s[j+1]-'0';
               printf("%d",b);
           }
           printf("=7"); 
           break;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
	int N,ANS=0;
	vector<char> SS;
	string S;
	cin >> N >> S;

	for(int i=0;i<N;i++){
		char a;
		a=S[i];
		SS.push_back(a);
	}
	for(int i=1;i<N;i++){
		if(SS[i-1]!=SS[i]){
			ANS++;
		}
	}
	cout << ANS+1 << endl;

}

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


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

#define INF bit(60)

#define DBGP 1


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

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

typedef pair<li, li> PI;


li n, k;
li a[100100];

int main() {
    cin >> n >> k;
    li one = -1;
    rin{
        cin >> a[i];
        if (a[i] == 1) {
            one = i;
        }
    }

    li res = 0;
    li now = 0;
    while (now < n) {
        if (now >= n - 1) {
            break;
        }
        ++res;
        now += k - 1;
    }
    cout << res << endl;


    return 0;
}

Measured memory_bytes: 1024
n = int(input())
d = 0
a = [[0 for i in range(10)] for j in range(10)]
for i in range(1,n+1):
	f = i//10**d
	l = i%10
	a[f][l] += 1
	if(i == 10**(d+1)-1):
		d += 1
ans = 0
for i in range(1,10):
	for j in range(1,10):
		ans += a[i][j]*a[j][i]
print(ans)

Measured memory_bytes: 40784
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(30);
#define ll long long
#define pi 3.14159265359
using namespace std;

int main()
{
    IOS;

    int a;
    cin>>a;
    cout<<a+a*a+a*a*a;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }


main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int n = sz(s);
    int l = 1, r = n;
    while (l < r) {
        int mid = (l + r) >> 1;
        bool ok = false;
        for (int p = 0; p < 2; p++) {
            int a = p, b = mid;
            if ((a % 2) != (b % 2)) --b;
            bool flag = false;
            for (int i = 0; i < n; i++) {
                if (s[i] == '0') {
                    --a, --b;
                }
                else if (s[i] == '1') {
                    ++a, ++b;
                }
                else --a, ++b;
                if (a < 0) a += 2;
                if (b > mid) b -= 2;
                if (a > b) {
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                ok = true;
                break;
            }
        }
        if (ok) r = mid;
        else l = mid + 1;
    }
    cout << r << '\n';
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int t[125];
int v[125];

double vel[25252*2];
int tsum;

int main(){
  cin>>n;
  REP(i,n)cin>>t[i];
  REP(i,n)cin>>v[i];
  t[n] = 0;
  v[n] = 0;
  n++;
  tsum = accumulate(t,t+n,0)*2;
  REP(i,tsum+1)vel[i] = 12525252;
  vel[0] = 0;
  REP(i,n){
    int head = accumulate(t,t+i,0)*2;
    int tail = head + t[i]*2;
    CHMIN(vel[head], (double)v[i]);
    FORR(j,0,head){
      CHMIN(vel[j], vel[j+1]+0.5);
    }
    FOR(j,head+1,tail+1){
      CHMIN(vel[j], vel[j-1]+0.5);
      CHMIN(vel[j], (double)v[i]);
    }
  }
  double ans = 0.0;
  REP(i,tsum){
    double x = vel[i];
    double y = vel[i+1];
    ans += (x==y) ? x*0.5 : (x+y)*0.25;
  }
  printf("%.9f\n", ans);
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main()
{
    int m, n, l, i, c, k;
    int a[100][100], b[100][100];

    scanf("%d%d%d", &n, &m, &l);
    for (i = 0; n > i; i++)
    {
        for (c = 0; m > c; c++)
        {
            scanf("%d", &a[i][c]);
        }
    }
    for (i = 0; m > i; i++)
    {
        for (c = 0; l > c; c++)
        {
            scanf("%d", &b[i][c]);
        }
    }

    for (i = 0; n > i; i++)
    {
        for (c = 0; l > c; c++)
        {
            long long int buf = 0;
            for (k = 0; m > k; k++)
            {
                buf += a[i][k] * b[k][c];
            }
            printf("%lld", buf);
            if (c != l - 1)
                printf(" ");
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2104
#include<stdio.h>
#define N 1000000
int C[N],n;
int search(int k){
  int l=0,r=n,mi;
  while(l<r){
    mi=(l+r)/2;
    if(k==C[mi]){
      return 1;
    }
    if(k>C[mi]){
      l=mi+1;
    }
    else if(k<C[mi]){
      r=mi;
    }
  }
  return 0;
}
int main(){
  int i,a,b,s=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&C[i]);
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&b);
    if(search(b))
      s++;
  }
  printf("%d\n",s);
  return 0;
}



Measured memory_bytes: 2148