akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();
        int f = 0, c = 0;
        Queue<Integer> que = new ArrayDeque<>();
        for (int i = 0; i < s.length(); i++) {
            if (s.substring(i, i + 1).equals("R")) {
                if (f == 1) {
                    f = 0;
                    que.add(c);
                    c = 0;
                }
                c++;
            } else {
                if (f == 0) {
                    f = 1;
                    que.add(c);
                    c = 0;
                }
                c++;
                if (i == s.length() - 1) {
                    que.add(c);
                }
            }
        }
        int ans[] = new int[s.length()];
        int pos = 0;
        while (que.size() > 0) {
            int x = que.poll();
            int y = que.poll();
            if ((x + y) % 2 == 0) {
                pos += x;
                ans[pos - 1] = (x + y) / 2;
                ans[pos] = (x + y) / 2;
                pos += y;
            } else if (x % 2 == 0) {
                pos += x;
                ans[pos - 1] = (x + y) / 2;
                ans[pos] = (x + y) / 2 + 1;
                pos += y;
            } else {
                pos += x;
                ans[pos - 1] = (x + y) / 2 + 1;
                ans[pos] = (x + y) / 2;
                pos += y;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < (s.length() * 2 - 1); i++) {
            if (i % 2 == 0) {
                sb.append(ans[i / 2]);
            } else {
                sb.append(" ");
            }
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 32476
r,D,x2000=map(int,input().split())
x2001=r*x2000-D
x2002=r*x2001-D
x2003=r*x2002-D
x2004=r*x2003-D
x2005=r*x2004-D
x2006=r*x2005-D
x2007=r*x2006-D
x2008=r*x2007-D
x2009=r*x2008-D
x2010=r*x2009-D
print(x2001)
print(x2002)
print(x2003)
print(x2004)
print(x2005)
print(x2006)
print(x2007)
print(x2008)
print(x2009)
print(x2010)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
 
    int N,d[110],ans=0;

    cin >> N;

    for(int i=0;i<N;i++){
        cin>> d[i];
    }
    int num[110]={0};

    for(int i=0;i<N;i++){
        num[d[i]]= num[d[i]] + 1;
    }

    for(int i=0; i <= 100 ;i++){
        if(num[i]){
            ans = ans +1;
        }
    }

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

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

int main(){
  long long n, m, l, b[100][100], a[100][100], c[100][100] = {};
  cin >> n >> m >> l;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }
  for(int i = 0; i < m; i++){
    for(int j = 0; j < l; j++){
      cin >> b[i][j];
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      for(int k = 0; k < l; k++){
        c[i][k] += a[i][j] * b[j][k];
      }
    }
  }
  for(int i=0;i<n;i++){
				for(int j=0;j<l;j++){
					if(j!=l-1)cout<<c[i][j]<<" ";
					else cout<<c[i][j]<<endl;
				}
			}
}



Measured memory_bytes: 3332
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

int main()
{
  	ull a[51][2],x,y=0;//二维数组第0列存储总的layers数，第1列 存储总的P的个数，x从bottom开始
	  //的层数，y为在x层中有y个P 
	int n,i,j;;//n为总的level数
	cin>>n>>x;
	a[0][0]=1,a[0][1]=1;// level-0的总layers数和总P数均为1
	for(i=1;i<=n;i++)
	{
		a[i][0]=2*a[i-1][0]+3;//根据计算规则得出第i层与第i-1层的layers数之间的关系 
		a[i][1]=2*a[i-1][1]+1;//根据计算规则得出第i层与第i-1层的P数之间的关系 
	} 
	//计算x中的P总数y
	while(x>0) //x=0的话就不存在P的数量
	{
		//A level-L burger (L≥1) is a bun, a level-(L-1) burger, a patty, 
  		//another level-(L-1) burger and another bun
  		if(x==a[n][0]) 
		{
			y+=a[n][1];
			x=0;
		}
  		else if(x>=a[n][0]/2+1)
  		{
  			y+=a[n-1][1]+1;
  			x-=a[n][0]/2+1;
		} 
		else x--;//相当于将总数-1，即将B去掉1 
		//做完以上事情后需要将n减1
		n--; 
	} 
	cout<<y<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
#define MAX_N 100001
int par[MAX_N]; //親
int rnk[MAX_N]; //木の深さ
int num[MAX_N]; //ノード数
int frd[MAX_N]; //友達数
vector<int> B[MAX_N]; //ブロック隣接リスト

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i]=i;
    rnk[i]=0;
    num[i]=1;
  }
}

//木の根を求める
int find(int x){
  if(par[x]==x){
    return x;
  }else{
    return par[x]=find(par[x]);
  }
}

//xとyの属する集合を併合
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;

  if(rnk[x]<rnk[y]){
    par[x]=y;
    num[y]+=num[x];
  }else{
    par[y]=x;
    num[x]+=num[y];
    if(rnk[x]==rnk[y]) rnk[x]++;
  }
}

//xとyが同じ集合に属するか否か
bool same(int x, int y){
  return find(x)==find(y);
}

int main(){
  int n,m,k;cin>>n>>m>>k;
  init(n);
  REP(i,n) frd[i]=0;
  
  REP(i,m){
    int a,b;cin>>a>>b;a--;b--;
    unite(a,b);
    frd[a]++;
    frd[b]++;
  }
  REP(i,k){
    int a,b;cin>>a>>b;a--;b--;
    B[a].push_back(b);
    B[b].push_back(a);
  }
  
  REP(i,n){
    int ans=0;
    ans+=num[find(i)]-frd[i];
    REP(j,B[i].size()){
      int b=B[i][j];
      if(same(i,b)) ans--;
    }
   cout<<ans-1<<" ";
  }
}

Measured memory_bytes: 7552
#include <iostream>
#include <iomanip>
#include <map>
#include <vector>
#include <cmath>
#include <string> // これがないとstringの出力がエラー
#include <sstream>
#include <algorithm>
#include <bitset>
#include <list>
#include <set>
using namespace std;

typedef long long ll;

void flip(string& str, int n) {
	str[n] = '0';
	str[n + 1] = '1';
	str[n + 2] = '0';
}

int cnt = 0;
void dfs(int N, ll current, vector<int> nums)
{
	if (N == nums.size()) {
		if (current % 2 == 0)
			cnt++;
		return;
	}
	for (int i = -1; i < 2; ++i) {
		dfs(N + 1, current * (nums[N] + i), nums);
	}
}

void pA()
{
	int N; cin >> N;
	vector<int> nums(N);
	for (auto& i : nums)
		cin >> i;
	dfs(0, 1, nums);
	cout << cnt << endl;
}

void pB()
{
	int H, W; cin >> H >> W;
	vector<string> mp(H);
	for (auto& m : mp)
		cin >> m;

	int dx[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
	int dy[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (mp[i][j] == '.') {
				int cnt = 0;
				for (int k = 0; k < 8; ++k) {
					int ny = i + dy[k];
					int nx = j + dx[k];
					if (ny < 0 || ny >= H) continue;
					if (nx < 0 || nx >= W) continue;
					if (mp[i + dy[k]][j + dx[k]] == '#')
						cnt++;
				}
				mp[i][j] = '0' + cnt;
			}
		}
	}

	for (auto m : mp)
		cout << m << endl;
}

unsigned bit_count(unsigned n)
{
	unsigned i = 0;

	while (n) {
		i += n & 1;
		n >>= 1;
	}

	return i;
}

int N, M;
set<int> path[100004];

ll addPath()
{
	ll cnt = 0;
	for (int n0 = 1; n0 <= N; ++n0) {
		for (auto n1 : path[n0]) {
			if (n0 == n1) continue;
			for (auto n2 : path[n1]) {
				if (n1 == n2) continue;
				if (n0 == n2) continue;
				for (auto n3 : path[n2]) {
					if (n2 == n3) continue;
					if (n1 == n3) continue;
					if (n0 == n3) continue;
					if (path[n0].find(n3) == path[n0].end()) {
						cnt++;
						path[n0].insert(n3);
						path[n3].insert(n0);
					}
				}
			}
		}
	}
	return cnt;
}

void pC()
{
	cin >> N >> M;
	for (int m = 0; m < M; ++m) {
		int a, b; cin >> a >> b;
		path[a].insert(b);
		path[b].insert(a);
	}

	cout << addPath() << endl;
}

void pD()
{
	int N, K; cin >> N >> K;
	vector< pair<ll, ll> > pt1(N), pt2(N);
	for (int i = 0; i < N; ++i) {
		cin >> pt1[i].first >> pt1[i].second;
		pt2[i].first = pt1[i].second;
		pt2[i].second = pt1[i].first;
	}

	sort(pt1.begin(), pt1.end());

	sort(pt2.begin(), pt2.end());

	vector<int> pt12(N), pt21(N);
	for (int i = 0; i < N; ++i) {
		pair<ll, ll> p1 = pt1[i];
		for (int j = 0; j < N; ++j) {
			if (p1.first == pt2[j].second && p1.second == pt2[j].first) {
				pt12[i] = j;
				pt21[j] = i;
				break;
			}
		}
	}

	ll minimum = INT64_MAX;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			ll sq = abs(pt1[i].first - pt1[j].first) * abs(pt1[i].second - pt1[j].second);
			if (sq == 0)
				continue;
			ll p1 = i;
			ll p2 = pt12[i];
			ll p1n = j;
			ll p2n = pt12[j];
			ll num = max(max(p1n, p1) - min(p1n, p1), max(p2, p2n) - min(p2, p2n)) + 1;
			cerr << sq << " " << num << endl;
			if (num >= K)
				minimum = min(minimum, sq);
		}
	}

	cout << minimum << endl;
}

int main()
{
	pA();

	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int n, m, k, ans;
pair<int, int>a[100005];
int main () {
  scanf("%d %d", &n, &m);
  for (int i=0; i<n; i++){
    scanf("%d %d", &a[i].first, &a[i].second);
  }
  sort(a, a+n);
  priority_queue<int>pq;
  for (int i=1; i<=m; i++) {
    while (k<n && a[k].first <= i) {
      pq.push(a[k].second);
      k++;
    }
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll N;
vector<ll> p;

int main(){
    cin >> N;
    p.resize(N);
    rep(i,N){
        cin >> p[i];
        p[i]--;
    }

    ll cnt = 0;
    for(ll i=0;i<N;i++){
        if(i==N-1){
            if(p[i] == i){
                cnt++;
            }
        }
        else if(p[i] == i){
            swap(p[i],p[i+1]);
            cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
#define f first
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define ull unsigned long long

using namespace std;
const int N = (int)(1e5 + 123);
const int INF = (int)(1e9 + 7);

int dp[N] , a[N]; 

int main() {
	int n;
	cin >> n;
	for (int i=1; i<=n; i++) {
		cin >> a[i];
	}                     
	for (int i=2; i<=n; i++) {
		dp[i] = INF;
	}                    
	for (int i=1; i<n; i++) {
		if (i+2 <= n) dp[i+2] = min(dp[i+2] , dp[i]+abs(a[i+2] - a[i]));
		dp[i+1] = min(dp[i+1] , dp[i]+abs(a[i+1] - a[i]));
	}
	cout <<dp[n];
	return 0;
}

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

  int main()
  {
	int n;
    cin >> n;
    vector<int> v(n);
    double sum=0, tmp=0, maxi=0;
    rep(i, n) cin >> v[i];
    sort(v.begin(), v.end());
    sum += v[0];
    for(int i = 1; i < n; i++) sum = (sum + v[i]) / 2; 
	cout << sum << endl;
    return 0;
  }


Measured memory_bytes: 256
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 200005;
const ll mm = 1e+18;
void solve()
{
    int a,b,h;
    cin>>a>>b>>h;
    int ans=(a+b)*h;
    ans/=2;
    pr(ans);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>

bool first_output = true;

void output(std::vector<int> pre, std::vector<int> in, int pre_left, int pre_right, int in_left, int in_right)
{
	if (pre_left == pre_right) return;
	if (pre_left + 1 == pre_right) {
		if (!first_output) std::cout << " ";
		else first_output = false;
		std::cout << pre[pre_left];
		return;
	}
	
	int root = pre[pre_left];
	int root_pos_in_in;
	for (int i=in_left; i<in_right; i++) {
		if (in[i] == root) { root_pos_in_in = i; break; }
	}
	int left_len = root_pos_in_in - in_left;
	int right_len = in_right - root_pos_in_in - 1;
	output(pre, in, pre_left + 1, pre_left + 1 + left_len, in_left, in_left + left_len);
	output(pre, in, pre_right - right_len, pre_right, in_right - right_len, in_right);
	
	if (!first_output) std::cout << " ";
	else first_output = false;
	std::cout << root;
}
	

int main()
{
	int n;
	std::cin >> n;
	std::vector<int> pre, in;
	for (int i=0; i<n; i++) {
		int node;
		std::cin >> node;
		pre.push_back(node);
	}
	for (int i=0; i<n; i++) {
		int node;
		std::cin >> node;
		in.push_back(node);
	}
	
	output(pre, in, 0, n, 0, n);
	std::cout << std::endl;
	
	return 0;
}
	




Measured memory_bytes: 3160
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()
    s = f.read_str()

    cand1 = collections.defaultdict(int)
    cand2 = collections.defaultdict(int)

    for mask in xrange(1<<n):
        red = ''
        blue = ''
        for i in xrange(n):
            ci = (mask>>i) & 1
            if ci:
                red += s[i]
            else:
                blue += s[i]
        cand1[(red,blue)] += 1

        red = ''
        blue = ''
        for i in xrange(n):
            ci = (mask>>i) & 1
            if ci:
                red += s[2*n-i-1]
            else:
                blue += s[2*n-i-1]
        cand2[(red,blue)] += 1

    ans = 0
    for k, v in cand1.items():
        ans += v * cand2[k]

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 213488
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
  string s, t;
  cin >> s;
  cin >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  if (s<t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main() {
	int h, w; cin >> h >> w;
	int dp[101][101];
	int i = 0, j = 0;
	int n; cin >> n;
	for (int l = 0; l < n; l++) {
		int k; cin >> k;
		for (int dfs = 0; dfs < k; dfs++) {
			dp[i][j] = l + 1;
			if (i % 2 == 0) if (j == w - 1)i++; else j++;
			else if (j == 0)i++; else j--;
		}
	}
	for (int bfs = 0; bfs < h; bfs++) {
		for (int dfs = 0; dfs < w; dfs++) {
			if (dfs)cout << ' ';
			cout << dp[bfs][dfs];
		}
		cout << endl;
	}
	char ch; cin >> ch;
}

Measured memory_bytes: 384
n, k = gets.split.map(&:to_i)
array = gets.split.map(&:to_i)
arr = Array.new(n+1, 0)

array.each_with_index do |a, i|
  arr[a] += 1
end

arr = arr.sort.reverse
sum = 0
arr[0..k-1].each do |a|
  sum += a
end

p n - sum


Measured memory_bytes: 19968
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;
  int total = 0;
  vector<int> list(n);
  for (int i=0; i<n; i++) {
    int t;
    cin >> t;
    list.at(i) = t;
    total += t;
  }
  int count = 0;
  for (int i=0; i<n; i++) {
    if (list.at(i)*4*m >= total) {
      count++;
    }
  }
  if (count >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3576
import math
A = []
N = int(input())
count = 0
for n in range(N):
    x = int(input())
    if x == 2:
        A.append(x)
        count += 1
    elif x % 2 == 0:
        pass
    elif x > 2:
        for i in range(3, int(math.sqrt(x))+2, 2):
            if x % i == 0:
                break
        else:
            count += 1
            A.append(x)
    
print(count)

Measured memory_bytes: 7732
using System;

class Program
{
    static void Main(string[] args)
    {
        int K = int.Parse(Console.ReadLine());

        long ans = 0;
        for (int i = 1; i <= K; i++)
            for (int j = 1; j <= K; j++)
                for (int k = 1; k <= K; k++)
                    ans += Gcd(Gcd(i, j), k);

        Console.WriteLine(ans);
    }

    static int Gcd(int a, int b)
    {
        if (a < b)
            return Gcd(b, a);
        while (b != 0)
        {
            int x = a % b;
            a = b;
            b = x;
        }
        return a;
    }
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

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

const int inf=1e9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

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

	vi dp(n,1e+9);
	dp[0]=0;
	for (int i = 0; i < n; i++){
		for (int j = 1; j <= k; j++){
			if(i+j>=n)continue;
			dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
		}
	}

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

	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        // long startTime = System.currentTimeMillis();

        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        scanner.close();

        String result = null;

        if (n >= 1000) {
            result = "ABD";
        } else {
            result = "ABC";
        }
        System.out.println(result);

        // System.out.println(System.currentTimeMillis() - startTime);
    }
}


Measured memory_bytes: 21716
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
char ans[4]={'A','C','G','T'};
int main()
{
	char ch;int f;
	scanf("%c",&ch);
	if(ch=='A')f=0;
	if(ch=='C')f=1;
	if(ch=='G')f=2;
	if(ch=='T')f=3;
	f=(3-f);
	printf("%c",ans[f]);
	return 0;
}


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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;
int main(int argc, char const *argv[])
{
	ll n;
	scanf("%lld",&n);
	// 10 to 26
	char str[50];
	int tot = 0;
	while(n)
	{
		n--;
		str[tot++] = n%26 + 'a';
		n /= 26;
	}
	while(tot)
	{
		putchar(str[--tot]);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 3764
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
char map[52][52];
int output[50][50];
void sarch(int x,int y) {
	int count=0;
	for (int i = -1; i <= 1; i++){for (int j = -1; j<= 1; ++j) {
			if (i == 0 && j == 0);
			else {
				if (map[x + 1][y + 1] == '#') { output[x][y] = -1; return; }
				else if (map[x + 1 + i][y + 1 + j] == '#')++count;
			}
		}}
	output[x][y] = count;
}
int main() {
	for (int i = 0; i < 52; ++i)for (int j = 0; j < 52; ++j)map[i][j] = '.';
	int h, w;
	std::cin >> h >> w;
	for (int i = 0; i < h; ++i) {
		std::string str;
		std::cin >> str;
		for (int j = 0; j < w; ++j)map[i+1][j+1] = str[j];
	}
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			sarch(i, j);
			if (output[i][j] == -1)std::cout << "#";
			else std::cout << output[i][j];
			if (j == w - 1)std::cout << "" << std::endl;
		}
	}
	 return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <queue>

#define CHECK_IMPL1(cond)                \
    if (!(cond)) {                       \
      DEBUG("expected cond: " << #cond); \
      assert(cond);                      \
    }

#define CHECK_IMPL2(cond, message)                                              \
    if (!(cond)) {                                                              \
      DEBUG("expected cond: " << #cond << " failed with message: " << message); \
      assert(cond);                                                             \
    }

#define CHECK_IMPL(_1, _2, NAME, ...) NAME
#define CHECK(...) CHECK_IMPL(__VA_ARGS__, CHECK_IMPL2, CHECK_IMPL1, CHECK_IMPL0)(__VA_ARGS__)

#ifdef __APPLE__
#define DEBUG(message) std::cerr << message << std::endl;
#else
#define DEBUG(message)
#endif

void solve() {
  int d, t, s;
  std::cin >> d >> t >> s;
  if (d <= t * s) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
}

int main() {
#ifdef __APPLE__
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  //std::cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3104
x, y = map(int, input().split())

c = 0
if x == 3:
    c = 100000
elif x == 2:
    c = 200000
elif x == 1:
    c = 300000

if y == 3:
    c += 100000
elif y == 2:
    c += 200000
elif y == 1:
    c += 300000

if c == 600000:
    c += 400000

print(c)



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

int main(){
	int k;
	string s;
	cin>>k>>s;
	if(k>=s.length()) return cout<<s<<endl,0;
	for(int i=0;i<k;i++){
		cout<<s[i];
	}

	cout<<"..."<<endl;
	return 0;
}


Measured memory_bytes: 3628
/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

const int INF{1001001001};
const lint LINF{1001001001001001001ll};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

signed main() {
  int n = in();
  string s;
  cin >> s;
  int x = 0, res = 0;
  rep(i, n) {
    if (s[i] == 'I') {
      res = max(res, x++);
    } else {
      res = max(res, x--);
    }
  }

  print(max(res, x));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,i;
    double sum1=0,sum2=0;
    cin>>N;
    int v[N];
    for(i=0;i<N;i++)
    {
        cin>>v[i];
    }
    sort(v,v+N);
    sum1 = (v[0]+0.0+v[1])/2;
    if(N==2)
    {
        cout << sum1 <<endl;
            return 0;
    }

        for(i=2;i<N;i++)
        {
            sum2 = (sum1+0.0+v[i])/2;
            sum1=sum2;
        }

        cout << sum2 << endl;


return 0;

}


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

int main(){
  ll n;
  cin>>n;
  vector<int> a;
  while(n>0){
    n--;
    a.push_back(n%26);
    n/=26;
  }
  reverse(a.begin(),a.end());
  string ans;
  rep(i,a.size()){
    ans+='a'+a[i];
  }
  cout<<ans<<endl;
}



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

bool is_conne(int, int);
int n, m;
std::vector<int> connect_dir[100000]{};
int visited_mother[100000] = {};

int main()
{
	int q, s, t;
	std::cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		std::cin >> s >> t;
		connect_dir[s].push_back(t);
		connect_dir[t].push_back(s);
	}
	for (int i = 0; i < n; ++i)
		visited_mother[i] = -1;

	std::cin >> q;
	for (int i = 0; i < q; ++i)
	{
		std::cin >> s >> t;
		if (is_conne(s, t))
			std::cout << "yes" << std::endl;
		else
			std::cout << "no" << std::endl;
	}
	return 0;
}

bool is_conne(int s, int t)
{
	if (visited_mother[s] != visited_mother[t]) return false;
	if (visited_mother[s] != -1) return true;

	visited_mother[s] = s;
	std::vector<int> visited_list{ s };
	int pre_size{ 0 };
	bool flag{};

	while (visited_list.size() != pre_size)
	{
		int now_size = visited_list.size();
		for (int i = pre_size; i < now_size; ++i)
			for (auto e : connect_dir[visited_list[i]])
			{
				if (visited_mother[e] != -1) continue;
				visited_mother[e] = s;
				visited_list.push_back(e);
				if (e == t) flag = true;
			}
		pre_size = now_size;
	}
	if (flag)
		return true;
	return false;
}


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

int main(){
  int h, w, n;  cin >> h >> w >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++)  cin >> a[i];
  vector<vector<int>> ans(h, vector<int>(w));
  int place = 0;
  for(int i=0; i<n; i++){
    for(int j=0; j<a[i]; j++){
      ans[place/w][place%w] = i+1;
      place++;
    }
  }

  for(int i=0; i<h; i++){
    if(i%2){
      for(int j=w-1; j>=0; j--)
        cout << ans[i][j] << " ";
    }else{
      for(int j=0; j<w; j++)
        cout << ans[i][j] << " ";
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3652
def resolve():
    import itertools
    n, m, q = map(int, input().split())
    cond = [list(map(int, input().split())) for _ in range(q)]
    #pos = list(itertools.combinations_with_replacement(range(1, m+1), n))
    ans = 0
    for i in list(itertools.combinations_with_replacement(range(1, m+1), n)):
        #test = list(pos[i])
        point = 0
        for j in range(q):
            if i[cond[j][1]-1] - i[cond[j][0]-1] == cond[j][2]:
                point += cond[j][3]
        ans = max(ans, point)
    print(ans)
resolve()

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a>=1)cout << "Positive" << endl;
    else if(b>=0)cout << "Zero" << endl;
    else {
        if((b-a)%2==0)cout << "Negative" << endl;
        else cout << "Positive" << endl;}
    return 0;
}

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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solution(String[] args) throws Exception{

		int N = nextInt();
		int[] C = new int[N];
		int[] S = new int[N];
		int[] F = new int[N];


		for(int i=0;i<N-1;i++){
			C[i]=nextInt();
			S[i]=nextInt();
			F[i]=nextInt();
		}

		for(int i=0;i<N;i++){
			int t=0;
			for(int k=i;k<N-1;k++){
				if(t<S[k]){
					//k駅の始発より前の場合は待つ為tはS[k]となる
					t=S[k];
				}else{
					//待たない場合はk駅の出発時間までの待ちを計算
					if(t%F[k]!=0){
						t+=F[k]-t%F[k];
					}
				}
				t+=C[k];
			}
			pw.println(t);
		}





	}

public static long lcm(long a, long b) {
	long x, y;

	return ((a / gcd(a, b)) * b);
}
public static long gcd(long a, long b) {
	long x, y;
	if (a < b) {
		x = b;
		y = a;
	} else {
		x = a;
		y = b;
	}
	long r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



Measured memory_bytes: 24020
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int N = Integer.parseInt(str);
        str = br.readLine();
        int red = 0;
        int blue = 0;
        for (String s:str.split("")){
            if (s.equals("R")){
                red++;
            } else {
                blue++;
            }
        }
        if (red > blue){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

typedef long long ll;

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

    for (int i = 0; i < N-1; i++) {
        if (a[i]+a[i+1] > x) {
            ans += (a[i]+a[i+1]-x);
            if (a[i+1] < (a[i]+a[i+1]-x)) {
                a[i+1] = 0;
                a[i] -= (a[i]-x);
                continue;
            }
            a[i+1] -= (a[i]+a[i+1]-x);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll ;
long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}
int main (){

    ll N,Nc,tmp=0;
    cin >> N;
    Nc = N;
    for(int i = 1; i <= 10; i++) {
        if(N < 10) {
          	tmp += N;
            break;
        }
        tmp += N % 10;
        N /= 10;
    }
    if(Nc % tmp) {
        cout << "No" << endl;
    }else {
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import itertools
H,W=map(int,input().split())
N=int(input())
a=itertools.chain(*(itertools.repeat(i+1, cnt) for i,cnt in enumerate(map(int,input().split()))))

for h in range(H):
	it = map(str, itertools.islice(a, W))
	if h % 2 == 1:
		it = reversed(list(it))
	print(" ".join(it))

Measured memory_bytes: 40816
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>

using namespace std;

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

const int INF = 1e9;
int D[101][101];
int E[101][101];
int memo[101][101];

int main() {

	int n, m, l;

	while (cin >> n >> m >> l && n) {

		rep(i, 101)rep(j, 101) {
			D[i][j] = INF;
			E[i][j] = 0;
			memo[i][j] = INF;
		}
		rep(i, m) {
			int a, b, d, e;
			cin >> a >> b >> d >> e;
			D[a][b] = D[b][a] = d;
			E[a][b] = E[b][a] = e;
		}
		queue<pair<int, int>> q;
		q.push(make_pair(1, l));
		memo[1][l] = 0;
		while (q.size()) {
			int now = q.front().first;
			int res = q.front().second;
			q.pop();
			for (int i = 1; i <= n; i++) {
				if (D[now][i] != INF) {
					if (res - D[now][i] >= 0) {
						if (memo[i][res - D[now][i]] > memo[now][res]) {
							memo[i][res - D[now][i]] = memo[now][res];
							q.push(make_pair(i, res - D[now][i]));
						}
					}
					if (memo[i][res] > memo[now][res] + E[now][i]) {
						memo[i][res] = memo[now][res] + E[now][i];
						q.push(make_pair(i, res));
					}
				}
			}
		}
		int ans = INF;
		for (int i = 0; i <= l; i++) {
			ans = min(ans, memo[n][i]);
		}
		cout << ans << endl;
	}
	return 0;
}

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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a < b) swap(a, b);
    ll ans = a;
    a--;
    ans += max(a, b);

    cout << ans << ln;
    return 0;
}

Measured memory_bytes: 256
# coding:UTF-8
import sys


def resultSur97(x):
    return x % (10 ** 9 + 7)


if __name__ == '__main__':
    # ------ 入力 ------#
    aList = list(map(int, input().split()))     # スペース区切り連続数字


    # ------ 出力 ------#
    if aList[0] <= aList[1] * aList[2]:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 9148
#include <stdio.h>
int n, x, y;
int dis[2000];
int qpt[100000], tail, head;
void bfs(int spt) {
	int vpt[2] = {1, -1};
	for (int i = 0; i < n; i++) {
		dis[i] = -1;
	}
	dis[spt] = 0;
	head = tail = 0;
	qpt[tail] = spt;
	tail++;
	while (head != tail) {
		for (int i = 0; i < 2; i++) {
			int npt = qpt[head] + vpt[i];
			if (0 <= npt && npt < n && dis[npt] == -1) {
				dis[npt] = dis[qpt[head]] + 1;
				qpt[tail] = npt;
				tail++;
			}
		}
		if (qpt[head] == x) {
			int npt = y;
			if (dis[npt] == -1) {
				dis[npt] = dis[qpt[head]] + 1;
				qpt[tail] = npt;
				tail++;
			}
		}
		if (qpt[head] == y) {
			int npt = x;
			if (dis[npt] == -1) {
				dis[npt] = dis[qpt[head]] + 1;
				qpt[tail] = npt;
				tail++;
			}
		}
		head++;
	}
}
int main() {
	int ans[2000] = {0};
	scanf("%d%d%d", &n, &x, &y);
	x--;
	y--;
	for (int i = 0; i < n; i++) {
		bfs(i);
		for (int j = i + 1; j < n; j++) {
			ans[dis[j] - 1]++;
		}
	}
	for (int i = 0; i < n - 1; i++) {
		printf("%d\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<vector>
#include<queue>
#define ll long long
ll read()
{
	ll tmp=0;char c=getchar(),f=1;
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9'){tmp=tmp*10+c-48;c=getchar();}
	return tmp*f;
}
using namespace std;
ll a[210][210];
int b[20],vis[20];
int n,m,r;
ll ans=1ll<<60;
void dfs(int dep,int now,ll dist)
{
	int i;
	if(dep==r){
		ans=min(ans,dist); return;
	}
	for(i=1;i<=r;i++)
		if(!vis[i]){
			vis[i]=1; dfs(dep+1,i,dist+a[b[now]][b[i]]); vis[i]=0;
		}
}
int main()
{
	int i,j,k;
	n=read(); m=read(); r=read();
	for(i=1;i<=r;i++)b[i]=read();
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			a[i][j]=1ll<<60;
	for(i=1;i<=m;i++){
		ll x=read(),y=read(),z=read();
		a[x][y]=min(a[x][y],z); a[y][x]=min(a[y][x],z);
	}
	for(k=1;k<=n;k++)
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				a[i][j]=min(a[i][k]+a[k][j],a[i][j]);
	for(i=1;i<=r;i++)vis[i]=0;
	for(i=1;i<=r;i++){
		vis[i]=1; dfs(1,i,0); vis[i]=0;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
n = int(input())
c = 0
l = [True]*(n+1)
a = [0]
idx = 1
for i in range(n):
  a.append(int(input()))

while True:
  if idx == 2:
    print(c)
    break
  else:
    if l[idx]:
      c += 1
      l[idx] = False
      idx = a[idx]
    else:
      print(-1)
      break
      

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

const int nax = 1e5+10, m = 3;
tuple<int,int,int> par[nax][m*2+1][m*2+1][m*2+1];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = 0; i <= n; i++) {
    for (int x = 0; x < m*2+1; x++) {
      for (int y = 0; y < m*2+1; y++) {
	for (int z = 0; z < m*2+1; z++) {
	  par[i][x][y][z] = {-1,-1,-1};
	}
      }
    }
  }
  par[0][m][m][m] = {0,0,0};
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    tuple<int,int,int> d[2];
    if (s == "AB") {
      d[0] = {1,-1,0};
      d[1] = {-1,1,0};
    } else if (s == "AC") {
      d[0] = {1,0,-1};
      d[1] = {-1,0,1};
    } else if (s == "BC") {
      d[0] = {0,1,-1};
      d[1] = {0,-1,1};
    } else assert(0);
    for (auto [dx,dy,dz] : d) {
      for (int x = 0; x < m*2+1; x++) {
	for (int y = 0; y < m*2+1; y++) {
	  for (int z = 0; z < m*2+1; z++) {
	    if (get<0>(par[i][x][y][z]) != -1 &&
		a+x-m+dx >= 0 && b+y-m+dy >= 0 && c+z-m+dz >= 0 &&
		x+dx >= 0 && x+dx < m*2+1 &&
		y+dy >= 0 && y+dy < m*2+1 &&
		z+dz >= 0 && z+dz < m*2+1) {
	      par[i+1][x+dx][y+dy][z+dz] = {x,y,z};
	    }
	  }
	}
      }
    }
  }
  for (int x = 0; x < m*2+1; x++) {
    for (int y = 0; y < m*2+1; y++) {
      for (int z = 0; z < m*2+1; z++) {
	if (get<0>(par[n][x][y][z]) != -1) {
	  cout << "Yes" << endl;
	  string ans;
	  for (int i = n; i; i--) {
	    auto [nx,ny,nz] = par[i][x][y][z];
	    if (x == nx+1) ans += 'A';
	    else if (y == ny+1) ans += 'B';
	    else if (z == nz+1) ans += 'C';
	    else assert(0);
	    x = nx, y = ny, z = nz;
	  }
	  reverse(ans.begin(), ans.end());
	  for (char ch : ans)
	    cout << ch << '\n';
	  return 0;
	}
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 405740
// 173

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <climits>
#include <string>
#include <cmath>

using namespace std;
using ll = long long int;
#define NUM 1000000007

int main(){
    int k;
    cin >> k;
    vector<ll> v;
    if(7%k == 0){
        cout << 1 << endl;
        return 0;
    }else if(k%2 == 0 || k%5 == 0){
        cout << -1 << endl;
        return 0;
    }else{
        v.push_back(7%k);
    }
    for(int i=1; i<k; i++){
        ll tmp = (v.at(i-1)*10 + 7)%k;
        if(tmp == 0){
            cout << i+1 << endl;
            return 0;
        }
        v.push_back(tmp);
    }
    return 0;
}



Measured memory_bytes: 11540
s = input()
t = input()
mindiff = float('inf')
for i in range(len(s) - len(t) + 1):
    diff = 0
    for j in range(len(t)):
        if s[i+j] != t[j]:
            diff += 1
    mindiff = min(diff, mindiff)
print(mindiff)

Measured memory_bytes: 9108
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for(int i=(s);i<(t);++i)
#define rng(obj) (obj).begin(), (obj).end()
#define rrng(obj) (obj).rbegin(), (obj).rend()
#define maxs(x,y) (x=max((x),(y)))
#define mins(x,y) (x=min((x),(y)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T>>
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<pii>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,v.size())i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(v.size())o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
bool comp(pair<char,int> a,pair<char,int> b){
  return a.se<b.se;
}
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------
bool f=true;

void Main(){
  map<ll,ll> m;
  ll n;
  cin>>n;
  vl a(n);
  cin>>a;
  rep(i,n){
    m[a[i]]++;
  }
  ll sum=0;
  for(auto k:m){
    sum+=(k.second)*(k.second-1)/2;
  }
  rep(i,n){
    if(m[a[i]]>1){
      cout<<sum-m[a[i]]+1<<endl;
    } else{
      cout<<sum<<endl;
    }
  }

} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

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

bool has3(int x){
    while(x){
        if(x % 10 == 3) return true;
        x /= 10;
    }
    return false;
}

int main(){
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        if(i % 3 == 0 || i % 10 == 3 || has3(i)) cout << " " << i;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3104
import sys
input = sys.stdin.readline

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

#Union Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

num = [0]*n

for i in range(m):
    a,b = map(int,input().split())
    unite(a-1,b-1)
    num[a-1] += 1
    num[b-1] += 1

edge = [[] for i in range(n)]

for i in range(k):
    c,d = map(int,input().split())
    edge[c-1].append(d-1)
    edge[d-1].append(c-1)


for i in range(n):
    cnt = size(i) - num[i] - 1
    for e in edge[i]:
        if same(e,i):
            cnt -= 1
    print(cnt,end=' ')


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

public class Main{
  public static void main(String[] args) {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))){
      boolean[] colors = new boolean[8];
      int master = 0;
      int N = Integer.parseInt(in.readLine());
      for(String s: in.readLine().split(" ")){
        int rating = Integer.parseInt(s);
        for(int i=0;i<8;i++){
          if(rating < (i+1)*400){
            colors[i] = colors[i] || true;
            break;
          }
        }
        if(rating>=3200){
          master++;
        }
      }
      int cnt=0;
      for(int i=0;i<8;i++){
        if(colors[i]){
          cnt++;
        }
      }
      int min = Math.max(1, cnt);
      int max = cnt+master;
      System.out.println(min+" "+max);
    }catch(IOException e){
      e.printStackTrace();
    }
  }
}


Measured memory_bytes: 21204
import Control.Monad
import Control.Applicative
import Data.List
 
main = do
  ss <- getLine
  putStrLn $ solve ss
 
solve :: String -> String
solve s = f s
  where
    f [] = []
    f ('p':'e':'a':'c':'h':ss) = 'a':'p':'p':'l':'e': (f ss)
    f ('a':'p':'p':'l':'e':ss) = 'p':'e':'a':'c':'h': (f ss)
    f (x:xs) = x : (f xs)


Measured memory_bytes: 3524