akhauriyash/Code-Regression huggingface dataset:
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N;
    cin >> N;

    vector<ll> A(N), B(N);
    REP(i, N)
    cin >> A[i] >> B[i];

    ll ans = 0;
    REPD(i, N)
    {
        ll R = (A[i] + ans) % B[i];
        if (R != 0)
            ans += B[i] - R;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4376
/*
 * @Author: BilyHurington
 * @Date: 2020-06-13 20:03:44
 * @LastEditors: BilyHurington
 * @LastEditTime: 2020-06-13 20:07:48
 */ 
#include<bits/stdc++.h>
using namespace std;
long long A,V,B,W,T;
int main(){
    scanf("%lld %lld %lld %lld %lld",&A,&V,&B,&W,&T);
    if((V-W)*T>=abs(A-B)) printf("YES");
    else printf("NO");
    return 0;
}

Measured memory_bytes: 3724
#!/usr/bin/rdmd
import std.cstream;

int main(){
	int i,n;
	int[] a=new int[31];
	a[0]=a[1]=1;a[2]=2;
	for(i=3;i<31;i++)a[i]=a[i-1]+a[i-2]+a[i-3];
	for(;din.readf(&n),n;)dout.writefln((a[n]+3649)/3650);
	return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>

int main(void)
{
   int n, m, k[30], a[30][30], i, f, z=0, x[30]={0};

   scanf("%d%d",&n,&m);
   for(i=0;i<n;i++){
      scanf("%d",&k[i]);
      for(f=0;f<k[i];f++){
         scanf("%d",&a[i][f]);
         x[a[i][f]-1]++;
      }
   }

   for(i=0;i<m;i++)
      if(x[i]==n)
         z++;

   printf("%d\n",z);
   return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl


int main(){
    int n;
    cin>>n;
    vi mi(26,INF);
    REP(i,n){
        string s;
        cin>>s;
        int cnt[26]={};
        REPARR(j,s){
            cnt[s[j]-'a']++;
        }
        REP(j,26){
            chmin(mi[j],cnt[j]);
        }
    }
    REP(i,26){
        REP(j,mi[i]){
            cout<<(char)(i+'a');
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const ll INF = 1LL << 60;
const ll MOD = (ll) 1e9 + 7;

int main(){
    int n;
    cin >> n;
    map<int, int> m;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        m[a]++;
    }
    int ans = 0;
    for (auto&& p : m) {
        ans += p.second % 2;
    }
    cout << ans << "\n";
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, k;
  cin >> a >> b >> k;
  ll c = 0;
  vll ans;
  for (int i = 1; i <= 100; i++) {
    if (a % i == 0 && b % i == 0) {
      c++;
      ans.push_back(i);
    }
  }
  cout << ans[ans.size() - k] << endl;
  return 0;
}


Measured memory_bytes: 256
N,W=map(int,input().split())
dp=[[0]*(W+1) for _ in range(N+1)]
for i in range(1,N+1):
  w,v=map(int,input().split())
  for j in range(1,W+1):
    if j>=w:
      dp[i][j]=max(dp[i-1][j-w]+v,dp[i-1][j])
    else:
      dp[i][j]=dp[i-1][j]
print(dp[N][W])

Measured memory_bytes: 119916
#include "cstdio"
#include "vector"
#include "map"
using namespace std;
map<int,int> m;
vector<int> vec;
int main()
{
	int i,n,a,len,count=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a);
		if(m.count(a)==0)
		{
			vec.push_back(a);
		}
		m[a]++;
	}
	len=vec.size();
	for(i=0;i<len;i++)
	{
		a=vec[i];
		if(m[a]<a)
		{
			count+=m[a];
		}
		else
		{
			count+=m[a]-a;
		}
	}
	printf("%d\n",count);
	return 0;
}

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

  
int main(){
 int n;
  cin >> n;
  if(n%2==1){
  VI count(n/2+1);
  int ans=0;
  rep(j,n/2+1){
 rep(i,n){
   if((2*j+1)%(i+1)==0){
     count.at(j)++;
   }
 }
   if(count.at(j)==8) ans++;
  }
  cout <<ans <<endl;
  }
  else{
  VI count(n/2);
  int ans=0;
  rep(j,n/2){
 rep(i,n){
   if((2*j+1)%(i+1)==0){
     count.at(j)++;
   }
 }
   if(count.at(j)==8) ans++;
  }
  cout <<ans <<endl;
  }
 }

Measured memory_bytes: 256
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from scipy.sparse import coo_matrix
from scipy.sparse.csgraph import maximum_bipartite_matching
def resolve():
    n = int(input())
    A = [tuple(map(int, input().split())) for _ in range(n)]
    B = [tuple(map(int, input().split())) for _ in range(n)]

    weights = []
    rows = []
    columns = []
    for i in range(n):
        ax, ay = A[i]
        for j in range(n):
            bx, by = B[j]
            if ax < bx and ay < by:
                weights.append(1)
                rows.append(i)
                columns.append(j)

    graph = coo_matrix((weights, (rows, columns)), shape = (n, n))
    ans = sum(maximum_bipartite_matching(graph) >= 0)
    print(ans)
resolve()

Measured memory_bytes: 38092
/*
ID: computerbox --> Huseyn Hajiyev
LANG: C++
TASK: target_mode_on
*/
#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 2000
//cin.ignore (7777, '\n');

using namespace std;

#define debug(args...)(Debugger()) , args
class Debugger
{
  public:
  Debugger(const std::string& _separator=", ") :
  first(true),separator(_separator){}
  template<typename ObjectType>
  Debugger& operator,(const ObjectType& v)
  {
        if(!first)cerr<<separator;
        cerr<<v;
        first=false;
        return *this;
  }
  ~Debugger() {cerr<<endl;}      
  private:
    bool first;
    string separator;
};
 
template <typename T1, typename T2>
inline ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
   return os<<"("<<p.first<<", "<<p.second<<")";
}
template<typename T>
inline ostream &operator<<(ostream & os,const vector<T>& v)
{
    bool first=true;
    os<<"[";
    for(unsigned ll i=0;i<v.size();i++)
    {
        if(!first)os<<", ";
        os<<v[i];
        first=false;
    }
        return os<<"]";
}
template<typename T>
inline ostream &operator<<(ostream & os,const set<T>&v)
{
    bool first=true;
    os<<"[";
    for(typename set<T>::const_iterator ii=v.begin();ii!=v.end();++ii)
    {
        if(!first)os<<", ";
        os<<*ii;
        first=false;
    }
    return os<<"]";
}
template<typename T1, typename T2>
inline ostream &operator<<(ostream & os,const map<T1, T2>&v)
{
        bool first=true;
        os<<"[";
        for(typename map<T1,T2>::const_iterator ii=v.begin(); ii!=v.end();++ii)
        {
            if(!first)os<<", ";
            os<<*ii;
            first=false;
        }
        return os<<"]";
}

ll n,k;


vector<ll>massiv;
int main(){
FAST_READ;
//cin.tie(0);
cin>>n>>k;
for(ll i=1;i<=n;i++)
{
  ll x;
  cin>>x;
  massiv.pb(x);
}
ll cnt=0;
sort(all(massiv));
for(ll i=0;i<massiv.size()-1;i++)
{
  if(k>=massiv[i]){cnt++;k-=massiv[i];}
}
if(k==massiv[massiv.size()-1])cnt++;
cout<<cnt<<endl;




return 0;
} 


Measured memory_bytes: 256
import java.util.*;
public class Main {
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
  	long N = sc.nextLong(); //1 <= N <= 10^9
	long cnt = 0;
	for(long i=N-1;i>0;i--){
     	 cnt += i;
    }
  	System.out.println(cnt);                           
}
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N, M; cin >> N >> M;
    vector<LP> lpv;
    rep(i,N){
        int a; cin >> a;
        lpv.push_back(make_pair(a, 1));
    }
    rep(i, M){
        int b, c; cin >> b >> c;
        lpv.push_back(make_pair(c, b));
    }

    sort(all(lpv));
    reverse(all(lpv));

    int n = 0;
    ll res=0;
    for(auto a: lpv){
        if(n+a.second > N){
            res += a.first * (N-n);
            break;
        }else{
            res += a.first * a.second;
            n += a.second;
        }
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 10608
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	Scanner in = new Scanner(System.in);
	int W, H;
	int[][] map;
	int[][][] dist;
	int[] cost = new int[4];
	PriorityQueue<State> pq;
	
	int[] vx = {1, 0, -1, 0};
	int[] vy = {0, 1, 0, -1};
	
	class State implements Comparable<State> {
		int x, y, d;
		
		public State(int x, int y, int d) {
			this.x = x;
			this.y = y;
			this.d = d;
		}

		@Override
		public int compareTo(State s) {
			int d1 = dist[y][x][d], d2 = dist[s.y][s.x][s.d];
			if (d1 < d2) return -1;
			else if (d1 > d2) return 1;
			return 0;
		}
	}
	
	void dijkstra() {
		if (pq.isEmpty()) return;
		State s = pq.poll();
		int cmd = map[s.y][s.x];
		for (int i = 0; i < vx.length; i++) {
			int c = (cmd == i) ? 0 : cost[i];
			int dir = (s.d + i) % 4;
			int nx = s.x + vx[dir], ny = s.y + vy[dir];
			if (nx >= 0 && nx < W && ny >= 0 && ny < H) {
				if (dist[ny][nx][dir] > dist[s.y][s.x][s.d] + c) {
					dist[ny][nx][dir] = dist[s.y][s.x][s.d] + c;
					pq.add(new State(nx, ny, dir));
				}
			}
		}
		
		dijkstra();
	}
	
	public void run() {
		while (true) {
			W = in.nextInt();
			H = in.nextInt();
			if ((W|H) == 0) break;
			map = new int[H][W];
			dist = new int[H][W][4];
			
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					map[i][j] = in.nextInt();
					Arrays.fill(dist[i][j], Integer.MAX_VALUE);
				}
			}
			
			for (int i = 0; i < 4; i++) 
				cost[i] = in.nextInt();
			
			pq = new PriorityQueue<State>();
			dist[0][0][0] = 0;
			pq.add(new State(0, 0, 0));
			
			dijkstra();
			
			System.out.println(Math.min(dist[H-1][W-1][0], dist[H-1][W-1][1]));
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main() {
	ll n,t_max;
	cin >> n >> t_max;
	vector<ll> t(n);
	rep(i,n) cin >> t[i];
	ll ans = 0;
	for(int i=1;i<n;i++) {
		ans += min(t_max, t[i] - t[i-1]);
	}
	ans += t_max;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const int mod=1e9+7;
const ll inf = 1LL << 60;
const ld pi = (acos(-1));
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }




int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int a,b,c,d; cin >> a >> b >> c >> d;
  int p=c/b, q=a/d;
  string ans="No";
  if(c%b!=0) p++;
  if(a%d!=0) q++;
  if(p<=q) ans="Yes";
  cout << ans << endl;
  
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n;cin>>n&&n;){
		vi a(n+1);
		rep(i,n) cin>>a[i+1];

		int sum=0;
		rep(i,n+1) sum+=abs(a[(i+1)%(n+1)]-a[i]);

		vi b(n+1);
		repi(i,1,n+1){
			int l=a[i-1],r=a[(i+1)%(n+1)];
			cout<<sum-(abs(a[i]-l)+abs(r-a[i])-abs(r-l))<<endl;
		}
	}
}


Measured memory_bytes: 2048
sentense = ""
while True:
    try:
        line = input()
        sentense += line.lower()
    except EOFError:
        break
        
alphabet = "abcdefghijklmnopqrstuvwxyz"

for i in range(26):
    print(alphabet[i] + " : " + str(sentense.count(alphabet[i])))


Measured memory_bytes: 5564
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    ll n,k;cin>>n>>k;
    vector<ll> v[n+1];
    rep(i,0,n-1){
        ll a,b;cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
        
    }
    queue<ll> q;
    q.push(1);
    bool used[n+1];
    fill(used,used+n+1,false);
    used[1]=true;
    ll par[n+1];
    par[1]=0;
    while(q.size()>0){
        ll now=q.front();q.pop();
        rep(i,0,v[now].size()){
            ll ne=v[now][i];
            if(used[ne])continue;
            used[ne]=true;
            par[ne]=now;
            q.push(ne);
        }
    }
    fill(used,used+n+1,false);
    rep(i,1,n+1){
        if(par[i]>0)used[par[i]]=true;
    }
    q.push(1);
    fill(used,used+n+1,false);
    used[1]=true;
    ll ans=k;
    queue<ll> di;
    di.push(1);
    while(q.size()>0){
        ll now=q.front();
        q.pop();
        ll d=di.front();di.pop();
        //cout<<now<<" "<<v[now].size()<<endl;
        //cout<<ans<<endl;
        if(d==1){
            if(v[now].size()>=k){
                cout<<0<<endl;
                return 0;
            }
            ll cnt=0;
            rep(i,0,v[now].size()){
                if(used[v[now][i]])continue;
                ans*=k-1-cnt;
                cnt++;
                ans%=mod;
                q.push(v[now][i]);
                used[v[now][i]]=true;
                di.push(2);
            }
        }
        else{
            if(v[now].size()>=k){
                cout<<0<<endl;
                return 0;
            }
            ll cnt=0;
            rep(i,0,v[now].size()){
                if(used[v[now][i]])continue;
                ans*=k-2-cnt;
                cnt++;
                ans%=mod;
                q.push(v[now][i]);
                di.push(2);
                used[v[now][i]]=true;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 9076
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1001001001
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    int a,b; cin >> a >> b;
    cout << a*b << endl;
}

Measured memory_bytes: 3632
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let l: usize = sc.read();
    let r: usize = sc.read();
    let d: usize = sc.read();

    let mut ans = 0;
    for x in l..=r {
        if x % d == 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 2276
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	IOS;
	string s;
	cin >> s;
	int a = s.size() - 2;
	string ans = s[0] + to_string(a) + s[s.size() - 1];
	cout << ans << endl;
}



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

int main () {
  int N;
  cin >> N;
  vector<string> W(N);
  set<string> s;
  rep(i,N) {
    cin >> W[i];
    s.insert(W[i]);
  }

  bool valid = (s.size() == N);
  for(int i = 0; i < N - 1 && valid; i++) {
    valid = (W[i][W[i].size()-1] == W[i+1][0]);
  }

  cout << (valid ? "Yes" : "No") << endl;
  return 0;
}


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

int main()
{
    
    int n;
    cin>>n;
    long long sum=0;
    for(int i=0;i<n;i++)
    {
        int l,r;
        cin>>l>>r;
        sum+= (r-l+1);
    }
    cout<<sum<<"\n";
    return 0;
}


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

ll powmod(ll a, ll b){
    if(b==0) return 1;
    if(b%2==1) return (a*powmod(a,b-1)) % p;
    else{
        ll x = powmod(a,b/2);
        return (x*x) % p;
    }
}

int main(){
    int n,k;
    cin >> n >> k;
    ll tot = 0;
    k = min(k,n-1);
    vector<ll> a(n+1),b(n+1);
    a.at(0) = 1;
    rep(i,n){
        a.at(i+1) = a.at(i) * (i+1) % p;
    }
    rep(i,n+1){
        b.at(i) = powmod(a.at(i),p-2);
    }
    rep(i, k+1){
        ll x = a.at(n) * b.at(n-i) % p * b.at(i) % p;
        ll y = a.at(n-1) * b.at(n-i-1) % p * b.at(i) % p;

        tot += x * y % p;
        tot %= p;
    }
    cout << tot << endl;
    return 0;
}

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

template <typename Cap, typename Cost>
struct Graph {
  const Cost INF = numeric_limits<Cost>::max();
  struct Edge {
    int to, rev;
    Cap cap;
    Cost cost;
    Edge(int to, Cap cap, Cost cost, int rev)
      : to(to), cap(cap), cost(cost), rev(rev) {}
  };
  vector<vector<Edge>> g;
  int n;
  Graph(int n) : n(n) {
    g.assign(n, vector<Edge>());
  }
  void add_edge(int v, int u, Cap cap = 1, Cost cost = 0) {
    g[v].emplace_back(u, cap, cost, (int) g[u].size());
    g[u].emplace_back(v, 0, -cost, (int) g[v].size() - 1);
  }
  vector<Edge>& operator[](int x) {
    return g[x];
  }
  Cost min_cost_flow(int s, int t, Cap f) {
    Cost ret = 0;
    while (f > 0) {
      vector<Cost> dist(n, INF);
      vector<int> prevv(n), preve(n);
      dist[s] = 0;
      while (true) {
        bool update = false;
        for (int v = 0; v < n; v++) {
          for (int i = 0; i < g[v].size(); i++) {
            auto &e = g[v][i];
            if (e.cap == 0) continue;
            if (dist[v] == INF || dist[e.to] <= dist[v] + e.cost) continue;
            dist[e.to] = dist[v] + e.cost;
            prevv[e.to] = v, preve[e.to] = i;
            update = true;
          }
        }
        if (!update) break;
      }
      if (dist[t] == INF) return INF;
      Cap cap = f;
      for (int v = t; v != s; v = prevv[v]) {
        cap = min(cap, g[prevv[v]][preve[v]].cap);
      }
      f -= cap;
      ret += cap * dist[t];
      for (int v = t; v != s; v = prevv[v]) {
        auto &e = g[prevv[v]][preve[v]];
        e.cap -= cap;
        g[v][e.rev].cap += cap;
      }
    }
    return ret;
  }
};

int main() {
  int n, m, f;
  cin >> n >> m >> f;
  Graph<int, int> g(n);
  for (int i = 0; i < m; i++) {
    int u, v, c, d;
    cin >> u >> v >> c >> d;
    g.add_edge(u, v, c, d);
  }
  int ans = g.min_cost_flow(0, n - 1, f);
  if (ans == g.INF) {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3152
N, M = map(int, input().split())
H = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
ans = 0
for i in range(N):
    ok = True
    for nex in G[i]:
        if H[i] <= H[nex]:
            ok = False
            break
    if ok:
        ans += 1
print(ans)


Measured memory_bytes: 92736
#include <bits/stdc++.h>
#define rep(i,a,n) for (register int i=a;i<=n;i++)
#define per(i,a,n) for (register int i=n;i>=a;i--)
#define FOR(i,a,n,x) for (register int i=a;i<=n;i+=x)
#define ROF(i,a,n,x) for (register int i=n;i>=a;i-=x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define VI vector<int>
#define ll long long
#define ull unsigned long long
#define lowbit(x) ((x)&(-x))
#define mem(i, a) memset(i, a, sizeof(i))
#define sqr(x) ((x)*(x))
#define ls (p << 1)
#define rs (p << 1 | 1)
using namespace std;

template <typename T>

inline void read(T &X) {
  X = 0; char ch = 0; T op = 1;
  for(; ch > '9' || ch < '0'; ch = getchar())
    if(ch == '-') op = -1;
  for(; ch >= '0' && ch <= '9'; ch = getchar())
    X = (X << 3) + (X << 1) + ch - 48;
  X *= op;
}

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;

string s;

int main() {
#ifdef WiLe
  freopen ("input.txt", "rt", stdin);
#endif

  cin >> s;
  int len = s.length();
  rep (i, 0, len-1) if (s[i] == '7') {puts("Yes");return 0;}
  
  puts("No");

#ifdef WiLe
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}
/*
# author : WiLe
# date : 2020/04/16
*/

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define mod 1e9+7
typedef long long ll; 
typedef vector<long long> vi; 
typedef pair<int, int> ii; 
typedef vector<ii> vii; 
typedef set<int> si; 
typedef map<string, int> msi; 
 
int main(){
  ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll a,b,c,d,x,y;
    cin>>a>>b>>c>>d;
    if(b>=c) cout<<"Yes";
  else if(d>=a) cout<<"No";
  else{
    x=c/b;
  if(c%b!=0) x+=1;
  y=a/d;
  if(a%d!=0) y+=1;
    if(x<=y) cout<<"Yes";
    else cout<<"No";
  }
  return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll h,w;
  string s[200];
  cin >> h >> w;
  rep(i,h){
    cin >> s[i];
    cout << s[i] << endl << s[i] << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int l = Integer.parseInt(sc.next());
        int[] x = new int[n+1];
        x[0] = 0;
        for(int i = 1;i<n+1;i++){
            x[i] = x[i-1] + Integer.parseInt(sc.next());
        }
        int ans = 0;
        for(int i = 0;i<n+1;i++){
            if(x[i] > l){
                ans = i;
                break;
            }
            if(i == n){
                ans = i + 1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#/usr/bin/env python

n = int(input())
a = [int(input()) for _ in range(n)]

lighted = [0] 
ans = 0 

for i in range(n):
    u = lighted[-1]
    v = a[u]-1
    ans += 1
    if v == 1:
        print(ans)
        exit()
    lighted.append(v)

print(-1)


Measured memory_bytes: 16708
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string A, B, C;
  cin >> A >> B >> C;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (A.at(i) == B.at(i) && B.at(i) != C.at(i)) {
      ans++;
    }
    else if (A.at(i) == C.at(i) && B.at(i) != C.at(i)) {
      ans++;
    }
    else if (B.at(i) == C.at(i) && B.at(i) != A.at(i)) {
      ans++;
    }
    else if (A.at(i) != B.at(i) && B.at(i) != C.at(i) && A.at(i) != C.at(i)) {
      ans += 2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n;
string s;

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n >> s;
   string t = "";
   for (int i = 0; i < n; i ++) {
      t += s[i];
      string t1 = "";
      for (int j = i + 1; j < n; j ++)
         t1 += s[j];
      if (t == t1) cout << "Yes", exit (0);            
   }
   cout << "No";
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
import math
from itertools import permutations, combinations
from collections import deque, defaultdict

sys.setrecursionlimit(10**7)
N = int(input())
edges = [[] for _ in range(N)]
nodeinput = defaultdict(int) # (node index, node index) -> index
for i in range(N-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
    if a > b:
        a, b = b, a
    nodeinput[(a-1, b-1)] = i

seen = [0]*N
output = [0]*(N-1) # color

stack = deque()
stack.append([(0, -1)]) # node index, parent color
maxcolor = 0
while stack[0]:
    nstack = []
    cstack = stack.pop()
    #print('cstack:', cstack)
    for val in cstack:
        ni, pc = val
        seen[ni] = 1
        color = 1
        if color == pc:
            color += 1
        for edgei in edges[ni]:
            if seen[edgei] == 0:
                nstack.append((edgei, color))
                if ni > edgei: # keep: ni < edgei
                    ni, edgei = edgei, ni
                output[nodeinput[(ni, edgei)]
                ] = color
                if maxcolor < color:
                    maxcolor = color
                color += 1
                if color == pc:
                    color += 1
    stack.append(nstack)

print(maxcolor)
for out in output:
    print(out)


Measured memory_bytes: 47560
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    to = defaultdict(list)
    ot = defaultdict(list)
    for _ in range(m):
        s, t = map(int, input().split())
        s, t = s - 1, t - 1
        to[s].append(t)
        ot[t].append(s)
    # print(to)
    # 各頂点からゴールまでの期待値
    ev = [0] * n
    for u in range(n - 2, -1, -1):
        s = 0
        for ku in to[u]:
            s += ev[ku]
        ev[u] = s / len(to[u]) + 1
    # print(ev)
    # 各辺を通る確率
    pe = [[0] * n for _ in range(n)]
    # 各頂点を通る確率
    pn = [0] * n
    # 各頂点を通る確率を計算
    for u in range(n):
        p = 0
        for ou in ot[u]:
            p += pe[ou][u]
        if u == 0: p = 1
        pn[u] = p
        sz = len(to[u])
        for ku in to[u]:
            pe[u][ku] = p / sz
    # print(pn)
    # 変化量の最大値
    dx = 0
    for u in range(n - 1):
        sz = len(to[u])
        if sz == 1: continue
        mx = 0
        for ku in to[u]:
            mx = max(ev[ku], mx)
        nev = ((ev[u] - 1) * sz - mx) / (sz - 1) + 1
        de = pn[u] * (ev[u] - nev)
        dx = max(dx, de)
        # print(u, mx, de, nev)
    print(ev[0] - dx)

main()


Measured memory_bytes: 20468
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
const int maxn = 500005;

int n;
ll a,b,c,d;
pair<ll,ll> getRange(ll vall,ll valr) {
  ll l=-maxn,r=maxn,ret=-maxn;
  while(l<=r) {
    ll m=(l+r)/2;
    if(m*d>=vall&&m*d<=valr) {
      ret=m;
      break;
    }
    if(m*d<vall)l=m+1;
    else r=m-1;
  }
  if(ret==-maxn)return make_pair(maxn,-maxn);
  return make_pair(ret,ret);
}
bool check() {
  if(d==0LL&&a!=b)return false;
  ll x=abs(b-a);
  n-=1;
  for(int i=-n; i<=n; i++) {
    int j=n-abs(i);
    ll tmp=x-i*c;
    if(tmp%d==0) {
      ll tmp2=tmp/d;
      tmp2=abs(tmp2);
      if(tmp2<=j&&(!((j-tmp2)&1)))return true;
    }
    auto pr=getRange(x-d-i*c,x-c-i*c);
    if(pr.first==pr.second) {
      ll tmp2=abs(pr.first);
      if(tmp2<=j&&((j-tmp2)&1))return true;
    }
    pr=getRange(x+c-i*c,x+d-i*c);
    if(pr.first==pr.second) {
      ll tmp2=abs(pr.first);
      if(tmp2<=j&&((j-tmp2)&1))return true;
    }
  }
  return false;
}

int main() {
#ifdef suiyuan2009
  freopen("in.cpp","r",stdin);
#endif
  cin>>n>>a>>b>>c>>d;
  if(check())cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[5]={'a','e','i','o','u'};
int main(){
    char c;
    c=getchar();
    if(c==a[0] || c==a[1] || c==a[2] || c==a[3] || c==a[4])
        cout<<"vowel"<<endl;
    else
        cout<<"consonant"<<endl;
    return 0;
}

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

A=[]
for i in range(N):
    x,y,h=map(int,input().split())
    A.append([h,x,y])
A.sort(reverse=True)

for i in range(101):
    for j in range(101):
        for k in range(N):
            H = A[k][0] + abs(j-A[k][1]) + abs(i-A[k][2])
            flg = True
            for l in A:
                if l[0]!=max(0,H-abs(j-l[1])-abs(i-l[2])):
                    flg = False
                    break
            if flg == True:
                print(j,i,H)
                exit()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  long i=0;
  long len;
  string s;
  cin >> s;
  len = s.length();
  for(i=0;i<len;i+=2){
  cout << s[i];
    }
    cout << endl;
  return 0;
}

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

const long long MOD = (long long)1e9 + 7;
const int N = (int)1e6;

long long fast(long long a, long long p) {
    if (p == 0) return (long long)1;
    long long res = fast(a, p >> 1);
    res = (res * res) % MOD;
    if (p & 1) res = (res * a) % MOD;
    return res;
}

long long fact[N+5];

int start() {
    fact[0] = (long long)1;
    for (int i=1; i<=N; i++) {
        fact[i] = (fact[i-1] * (long long)i) % MOD;
    }
    return 0;
}

long long nCk(int n, int k) {
    long long res = (fact[n] * fast(fact[n-k], MOD-2)) % MOD;
    return (res * fast(fact[k], MOD-2)) % MOD;
}

int main() {
    start();

    int a,b; scanf("%d %d", &a, &b);
    if (a > b) swap(a,b);

    int diff = b - a;
    if (2*a < b || (a - diff) % 3 != 0) {
        printf("0\n");
    } else {
        long long res = nCk(diff + (a - diff) / 3 * 2, (a - diff) / 3);
        printf("%lld\n", res);
    }
    return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;

int main()
{
    int N, D, X;
    cin >> N;
    cin >> D >> X;
    int A[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        sum += (int)ceil((float)D / A[i]);
    }

    cout << sum + X << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    A, B, C = map(int, input().split())
    K = int(input())
    for i in range(K):
        if A >= B:
            B *= 2
        elif B >= C:
            C *= 2
    if A < B and B < C:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9168
import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;

public class Main {

	static char[] arr;
	static BigInteger[][][] dp;
	static BigInteger zero = BigInteger.ZERO, one = BigInteger.ONE;

	public static BigInteger dp(int idx, int less, int rem) {
		if (rem < 0)
			return zero;
		if (idx == arr.length)
			return rem == 0 ? one : zero;
		if (dp[idx][less][rem] != null)
			return dp[idx][less][rem];
		if (less == 1) {
			BigInteger ans = zero;
			ans = ans.add(dp(idx + 1, less, rem));
			for (int i = 1; i <= 9; i++) {
				ans = ans.add(dp(idx + 1, less, rem - 1));
			}
			return dp[idx][less][rem] = ans;
		} else {
			BigInteger ans = zero;
			ans = ans.add((dp(idx + 1, arr[idx] == '0' ? 0 : 1, rem)));
			for (char i = '1'; i < arr[idx]; i++) {
				ans = ans.add((dp(idx + 1, 1, rem - 1)));
			}
			if (arr[idx] != '0')
				ans = ans.add((dp(idx + 1, 0, rem - 1)));
			return dp[idx][less][rem] = ans;
		}
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		arr = sc.next().toCharArray();
		int k = sc.nextInt();
		dp = new BigInteger[arr.length][2][k + 1];

		pw.println(dp(0, 0, k));
		pw.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArr(int n) throws IOException {
			int[] arr = new int[n];
			for (int i = 0; i < arr.length; i++)
				arr[i] = nextInt();
			return arr;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  int ans = 0;
  for (int i = 0; i < n-2; i++) {
    if (p[i] < p[i+1] && p[i+1] < p[i+2]) ans++;
    else if (p[i] > p[i+1] && p[i+1] > p[i+2]) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

typedef int64_t ll;

int main(){
    string S;
    ll Q;
    cin >> S;
    cin >> Q;
    int T,F;
    char C;
    string front = "";
    string back = "";
    bool rev = false;
    for(int i=0;i<Q;i++){
        cin >> T;
        if(T==1){
            rev = !rev;
        }else{
            cin >> F >> C;
            if (F==1){
                if(rev) back.push_back(C);
                else front.push_back(C);
            } else{
                if(rev) front.push_back(C);
                else back.push_back(C);                
            }
        }
    }

    if(rev){
        reverse(back.begin(),back.end());
        reverse(S.begin(),S.end());
         cout << back << S << front << endl;
    }
    else{
        reverse(front.begin(),front.end());
        cout << front << S << back << endl;
    }  
}

Measured memory_bytes: 1088