akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

int main(){
    string S;
    const char *s = NULL;
    cin >> S;
    s = S.c_str();
    long long N = S.length();
    long long i, j, k;
    bool count;
    long long max = 0;
    for(i = 0; i <= N-1; i++){
        for(j = 0; j <= N-i-1; j++){
            count = 1;
            for(k = i; k <= N-j-1; k++){
                if(s[k] == 'A' || s[k] == 'C' || s[k] == 'G' || s[k] == 'T') continue;
                else{
                    count = 0;
                    break;
                }
            }
            if(count == 1){
                if(max < N -i -j){
                    max = N-i-j;
                }
            }
        }
    }
    cout << max << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 504
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

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

    int N;
    cin >> N;
    vector<int> h(N);
    REP(i, N) cin >> h[i];

    int dp[N];
    dp[0] = 0;
    FOR(i, 1, N) {
        dp[i] = INF32;
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1)
            chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

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

    return 0;
}

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

enum EResult { ETaro, EHanako, EDraw };

EResult decideWinner(const std::string& taro, const std::string& hanako) {
  for (int i = 0; i < taro.size(); i++) {
    const char &tc = taro[i], &hc = hanako[i];
    if (tc > hc) return ETaro;
    if (tc < hc) return EHanako;
    if (tc == hc) {
      int nextIndex = i + 1;
      if (nextIndex == taro.size() || nextIndex == hanako.size()) {
        if (taro.size() > hanako.size()) return ETaro;
        if (taro.size() < hanako.size()) return EHanako;
        break;
      }
    }
  }
  return EDraw;
}

int main() {
  int n, tScore = 0, hScore = 0;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::string taro, hanako;
    std::cin >> taro >> hanako;

    switch (decideWinner(taro, hanako)) {
      case ETaro:
        tScore += 3;
        break;
      case EHanako:
        hScore += 3;
        break;
      case EDraw:
        tScore += 1;
        hScore += 1;
        break;
    }
  }

  std::cout << tScore << ' ' << hScore << std::endl;
  return 0;
}



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


def main():
    h, w = map(int, input().split())
    ch, cw = map(int, input().split())
    dh, dw = map(int, input().split())
    
    ch += 1
    cw += 1
    dh += 1
    dw += 1
    
    
    s = ["#"*(w+4)]
    s.append("#"*(w+4))
    for i in range(h):
        s.append("##" + input()[:-1] + "##")
    s.append("#"*(w+4))
    s.append("#"*(w+4))
    
    
    ans = [[-1]*(w+4) for _ in range(h+4)]
    for i in range(h+4):
        for j in range(w+4):
            if s[i][j] == "#":
                ans[i][j] = -2
    ans[ch][cw] = 0
    
    move = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    move2 = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2), \
             (-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2), \
             (0, -2), (0, -1), (0, 0), (0, 1), (0, 2), \
             (1, -2), (1, -1), (1, 0), (1, 1), (1, 2), \
             (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)]
        
    not_yet = [(ch, cw)]
    one_time = []
    
    while len(not_yet) > 0:
        x, y = not_yet.pop()
        one_time.append((x, y))
        for (p, q) in move:
            v1, v2 = x+p, y+q
            if ans[v1][v2] == -1:
                not_yet.append((v1, v2))
                ans[v1][v2] = ans[x][y]
                
        if len(not_yet) == 0:
            while len(one_time) > 0:
                x2, y2 = one_time.pop()
                for (v1, v2) in move2:
                    i, j = x2+v1, y2+v2
                    if ans[i][j] == -1:
                        ans[i][j] = ans[x2][y2]+1
                        not_yet.append((i, j))
          
    print(ans[dh][dw])
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 84800
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        BigInteger[] a = new BigInteger[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextBigInteger();
        }
        Arrays.parallelSort(a);
        for (int i = 0; i < n - 1; i++) {
            a[i + 1] = (a[i].multiply(a[i + 1])).divide(getGcd(a[i], a[i + 1]));
        }
        System.out.println(a[n - 1]);
    }

    private static BigInteger getGcd(BigInteger x, BigInteger y) {
        return y == BigInteger.ZERO ? x : getGcd(y, x.mod(y));
    }
}

Measured memory_bytes: 23252
#include <iostream>

using namespace std;

main(void)
{
  int i, j, n, q, S[100000], T[50000],ans = 0;

  cin >> n ;

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

  cin >> q;

  for(i = 0;i < q;i++){
    cin >> T[i];
  }

  int mid, left, right;

  for(i = 0;i < q;i++){
    mid = n / 2;
    left = 0;
    right = n;
    while(left < right){
      if(S[mid] == T[i]){
	ans++;
	break;
      }
      else if(S[mid] < T[i]){
	left = mid + 1;
	mid = (right + left) / 2;
      }
      else{
	right = mid;
	mid = (right + left) / 2;
      }
    }
  }

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



Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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 dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
vector<bool> seen;
vector<ll> res;
vector<vector<pair<ll,ll>>> g;
void dfs(ll u, ll prev_c){
    seen[u] = true;
    ll c = 1;
    for(auto v : g[u]){
        if(seen[v.fi]) continue;
        if(prev_c == c) c++;
        res[v.se] = c;
        dfs(v.fi,c++);
    }
}
int main(){
    ll n; cin >> n;
    g.resize(n);
    rep(i,0,n-1){
        ll a, b; cin >> a >> b;
        a--; b--;
        g[a].pb(mp(b,i));
        g[b].pb(mp(a,i));
    }
    //次数
    vector<ll> cnt(n);
    rep(i,0,n) cnt[i] = g[i].size();
    //最大次数の頂点
    pair<ll,ll> p = mp(0,-1);
    rep(i,0,n) p = mp(max(p.fi,cnt[i]),i);
    //最大次数の頂点からdfs
    seen.assign(n,false);
    res.assign(n,0);
    dfs(p.se, -1);
    //出力
    cout << p.fi << ednl;
    rep(i,0,n-1) cout << res[i] << ednl; 
}

Measured memory_bytes: 9472
# -*- coding: utf-8 -*-
import sys

def main():
	a, b, c = map(int, input().split(" "))

	ans = 1
	if a != b:
		ans = ans + 1
	if a != c and b != c:
		ans = ans + 1

	print(ans)

if __name__ == "__main__":
	main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pob pop_back
#define MP make_pair
#define VI vector<int>
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.F<<","<<_p.S<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}

const ll MaxN=1e5+5;
const ll MOD=1000000007;
const ll INF=ll(1e18);

ll n,a,b;
bool c;
bool ok[105];
void init(){
	cin>>n>>a>>b;
	ok[a]=ok[b]=true;
}
bool out(ll x){
	if(x>n||x<=0||ok[x]==true) return false;
	return true;
}
void build(){

}

void sol(){
	while(1){
		if(!c){
			ok[a]=false;
			if(a>b){
				a--;
				if(!out(a)) break;
				ok[a]=true;
			}
			else{
				a++;
				if(!out(a)) break;
				ok[a]=true;
			}
			debug("t");
		}
		else{
			ok[b]=false;
			if(a>b){
				b++;
				if(!out(b)) break;
				ok[b]=true;
			}
			else{
				b--;
				if(!out(b)) break;
				ok[b]=true;
			}
		}
		c=!c;
	}
	if(!c) cout<<"Borys"<<endl;
	else cout<<"Alice"<<endl;
}

int main(){
	IOS();
	init();
	build();
	sol();
	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define in(x, l, r) (ll)(l) <= (x) && (x) < (ll)(r)

int main() {
    ll m = 1000000007;
    int S;
    cin >> S;
    if (S <= 2) {
        cout << 0 << endl;
        return 0;
    }
    if (S <= 5) {
        cout << 1 << endl;
        return 0;
    }
    vector<ll> dp(S+1,0);
    dp[0] = dp[1] = dp[2] = 0;
    dp[3] = dp[4] = dp[5] = 1;
    ll sum_3 = 0;
    rep(i,6,S+1) {
        sum_3 += dp[i-3];
        sum_3 %= m;
        dp[i] = (sum_3 + 1) % m;
    }
    cout << dp[S] << endl;
}

Measured memory_bytes: 3620
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int N = scan.nextInt();
        //int M = scan.nextInt();
        ArrayList al1 = new ArrayList(Arrays.asList(0,1,6,8));
        int num = N%10;
         if(num==3){
             System.out.println("bon");
         }else if(al1.contains(num)) {
             System.out.println("pon");
         }
         else{
             System.out.println("hon");
         }
    }
}

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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> l(N);
  
  for(int i=0;i<N;i++){
    cin >> l.at(i);
  }
  
  sort(l.begin(),l.end(),greater<int>());
  
  int sum = 0;
  for(int i=0;i<K;i++){
    sum += l.at(i);
  }
  cout << sum << endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a[4][3][10]={0};
	int n, b, f, r, v;
	int i, j, k;
	scanf("%d", &n);
	for(i=0; i<n; i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);
		a[b-1][f-1][r-1]+=v;
	}
	for(i=0; i<4; i++) {
		for(j=0; j<3; j++) {
			for(k=0; k<10; k++) {
				printf("%2d", a[i][j][k]);
			}
			putchar('\n');
			if(i<3 && j==2) printf("####################\n");
		}
	}
	
	return 0;
}


Measured memory_bytes: 620
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

int main() {
	int N,M; cin >> N>>M;
	long long ans = 1,mod= 1000000007;
	if (N == M)ans *= 2;
	for (int i = 0; ; i++) {
		if ((N == 0 && M > 1) || (N > 1 && M == 0)){ans = 0; break;}
		if (N == 0 || M == 0)break;
		ans = ans*N%mod*M%mod;
		N--; M--;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;


int main(){FIN

    ll x;cin>>x;
    ll c=0;
    ll m = 100;
    while(1){
        c++;
        m *= 1.01;
        if(m>=x) break;
    }
    cout<<c<<endl;
    return 0;
}

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

int fun(vector<int>& v,int i,vector<int>& dp) {
	if (dp[i] != 1e6) {
		return dp[i];
	}
	if (i == v.size()) {
	
		return 1e5;
	}
	int ans = 0;
	if (i + 2 < v.size()) {
		
		ans = ans + min(abs(v[i] - v[i + 1]) + fun(v, i + 1,dp), abs(v[i] - v[i + 2]) + fun(v, i + 2,dp));
	}
	else if (i + 1 < v.size()) {
		ans = ans + abs(v[i] - v[i + 1]) + fun(v, i + 1,dp);


	}
	dp[i] = ans;
	 return ans;
}

int main() {
	int n;
	cin >> n;
	vector<int> v;
	for (int i = 0;i < n;i++) {
		int x;
		cin >> x;
		v.push_back(x);

	}
	vector<int> dp(v.size(), 1e6);
	cout<<fun(v, 0,dp);
}

Measured memory_bytes: 4216
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define PAIR pair <int,int>
#define x first
#define d second
#define lson rt << 1,l,m
#define rson rt << 1|1,m+1,r
using namespace std;
typedef long long ll;
const int N = 2e5+5;
const ll M = 998244353;

ll dp[N];
int R[N],b[N],t[N << 2];
PAIR a[N];

inline void pushup(int rt){
	t[rt] = max(t[rt << 1],t[rt << 1|1]);
	return ;
}

inline void build(int rt,int l,int r){
	if(l == r){
		t[rt] = l;
		return ;
	}
	int m = (l+r) >> 1;
	build(lson);build(rson);
	pushup(rt);
	return ;
}

inline int query(int rt,int l,int r,int L,int R){
	if(L <= l && r <= R) return t[rt];
	int res = 0,m = (l+r) >> 1;
	if(L <= m) res = max(res,query(lson,L,R));
	if(R > m) res = max(res,query(rson,L,R));
	return res;
}

inline void add(int rt,int l,int r,int pos,int val){
	t[rt] = max(t[rt],val);
	if(l == r){
		t[rt] = val;
		return ;
	}
	int m = (l+r) >> 1;
	if(pos <= m) add(lson,pos,val);
	else add(rson,pos,val);
	return ;
}

int main(){
	int n,cnt;
	scanf("%d",&n);
	for(int i = 1;i <= n;++i) scanf("%d%d",&a[i].x,&a[i].d),b[i] = a[i].x;
    sort(a+1,a+n+1);build(1,1,n);
    sort(b+1,b+n+1);cnt = unique(b+1,b+n+1)-b-1;
    
    for(int i = n;i;--i){
    	int pos = upper_bound(b+1,b+cnt+1,a[i].x+a[i].d-1)-b-1;
    	R[i] = query(1,1,n,i,pos);
    	add(1,1,n,i,R[i]);
	}
	
	dp[n+1] = 1;
	for(int i = n;i;--i) dp[i] = (dp[i+1]+dp[R[i]+1])%M;
	printf("%lld\n",dp[1]);
	return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
int n,cnt,e,f[N],a[N],id[N],siz[N],res[N],head[N],link[N*2],to[N*2];
bool vis[111111];
map <int,int> mp;
bool cmp(int x,int y){return a[x]<a[y];}
void add(int u,int v){to[++e]=v,link[e]=head[u],head[u]=e;}
void dfs1(int u,int dep){
	siz[u]=1,res[id[1]]+=dep;
	for(int i=head[u];i;i=link[i])if(to[i]!=f[u])dfs1(to[i],dep+1),siz[u]+=siz[to[i]];
}
void dfs2(int u){for(int i=head[u];i;i=link[i])if(to[i]!=f[u])res[to[i]]=res[u]+n-2*siz[to[i]],dfs2(to[i]);}
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]),id[i]=i,mp[a[i]]=i,siz[i]=1;
	sort(id+1,id+n+1,cmp);
	for(int i=n;i>1;i--){
		int x=2*siz[id[i]]-n+a[id[i]];
		if(!mp.count(x)||n-2*siz[id[i]]<=0){printf("-1");return 0;}
		int pos=mp[x];add(pos,id[i]),add(id[i],pos),siz[pos]+=siz[id[i]],f[id[i]]=pos;
	}
	dfs1(id[1],0),dfs2(id[1]);
	for(int i=1;i<=n;i++)if(a[i]!=res[i]){printf("-1");return 0;}
	for(int i=2;i<=n;i++)printf("%lld %lld\n",f[id[i]],id[i]);
}


Measured memory_bytes: 17024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

vector<int> used;

vector<vector<int>> g;

void dfs(int cur, int ch, vector<int> &h) {
    h[cur] = ch;
    used[cur] = 1;
    for (auto t : g[cur]) {
        if (!used[t]) {
            dfs(t, ch + 1, h);
        }
    }
}

int mys(int len) {
    return len - 1;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    int a, b;
    cin >> n >> a >> b;
    a--;
    b--;
    used.resize(n);
    g.resize(n);
    for (int i = 0; i + 1 < n; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector<int> ha(n);
    vector<int> hb(n);
    dfs(a, 0, ha);
    fill(used.begin(), used.end(), 0);
    dfs(b, 0, hb);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (hb[i] > ha[i]) {
            ans = max(ans, ha[i] + mys(hb[i] - ha[i]));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 10752
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#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 ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

class UnionFind
{
public:
    UnionFind(){};
    ~UnionFind(){};
    void init(int num_entries) {
        num_entries_ = num_entries;
        par_.resize(num_entries_);
        rank_.resize(num_entries_, 0);
        member_num_.resize(num_entries_, 1);
        REP(i, num_entries_) {
            par_[i] = i;
        }
    }
    int find(int x) {
        if (par_[x] == x) return x;
        else return par_[x] = find(par_[x]);
    }
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return;
        if (rank_[x] < rank_[y]) {
            par_[x] = y;
            member_num_[y] += member_num_[x];
            member_num_[x] = 0;
        } else {
            par_[y] = x;
            member_num_[x] += member_num_[y];
            member_num_[y] = 0;
            if (rank_[x] == rank_[y]) rank_[x]++;
        }
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) {
        return member_num_[this->find(x)];
    }
private:
    int num_entries_;
    std::vector<int> par_;
    std::vector<int> rank_;
    std::vector<int> member_num_;
};

int main(void)
{
    cin.sync_with_stdio(false);
    ll N, M, K;
    cin >> N >> M >> K;

    vector<int> friends(N);
    vector<int> blocks(N);
    vector<pair<ll, ll>> ABs(M);
    REP(m, M) {
        ll a, b;
        cin >> a >> b;
        --a; --b;
        ABs[m] = mp(a, b);
        friends[a]++;
        friends[b]++;
    }
    vector<pair<ll, ll>> CDs(K);
    REP(k, K) {
        ll c, d;
        cin >> c >> d;
        --c; --d;
        CDs[k] = mp(c, d);
        blocks[c]++;
        blocks[d]++;
    }

    UnionFind uf;
    uf.init(N);

    for (auto& ab: ABs) {
        ll a = ab.first;
        ll b = ab.second;
        uf.unite(a, b);
    }

    // つながっているがblockの数を数える
    vector<int> connect_but_blocks(N);
    for (auto& cd: CDs) {
        ll c = cd.first;
        ll d = cd.second;
        if (uf.same(c, d)) {
            connect_but_blocks[c]++;
            connect_but_blocks[d]++;
        }
    }
    


    // REP(i, N) {
    //     auto s = uf.size(i);
    //     cout << "size:" << s << endl;
    // }

    REP(i, N) {
        auto s = uf.size(i);
        if (i != 0) cout << " ";
        cout << (s - friends[i] - connect_but_blocks[i] - 1);
    }
    cout << endl;
    

    return 0;
}


Measured memory_bytes: 6272
import java.text.NumberFormat;
import java.util.Scanner;

public class Main {
	@SuppressWarnings("resource")
	public static void main(String[] args){
		Scanner sc  = new Scanner(System.in);
		
		while(sc.hasNextLine()){
			double preX,preY;
			String[] s = sc.nextLine().split("[\\s]+");
			double[] data = new double[s.length];
			for(int i=0;i<s.length;i++){
				data[i] = Double.parseDouble(s[i]);
			}
			
			
			preX = (((data[2]*data[4])-(data[1]*data[5])) / ((data[0]*data[4])-(data[1]*data[3])));
			preY = (((data[0]*data[5])-(data[2]*data[3])) / ((data[0]*data[4])-(data[1]*data[3])));
			
			
			NumberFormat nf = NumberFormat.getInstance();
			nf.setMaximumFractionDigits(3);
			nf.setMinimumFractionDigits(3);
			
			if (preX == -0) preX = 0;
			if (preY == -0) preY = 0;
			
			System.out.println(nf.format(preX)+" "+nf.format(preY));
		}
	}
}

Measured memory_bytes: 17220
def main():
    S_ = input()
    T = input()

    f(S_, T)


def f(s, t):
    l_t = len(t)
    for i in reversed(range(len(s)-l_t+1)):
        b = s[i:i+l_t]
        c = sum(c1 == c2 or c2 == "?" for c1, c2 in zip(t, b))

        if c == len(t):
            ans = s[:i].replace("?", "a") + t + s[i+l_t:].replace("?", "a")
            print(ans)
            return

    print("UNRESTORABLE")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/*input
7
1 2 3 4 5 6
*/
 
 
 
#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second 
#define pb push_back   
 
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _f(#VA_ARGS, __VA_ARGS_)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
typedef unordered_set<int> usi;
 
ll i,j,k,c=0,m;
ll n;

void solve() 
{

cin>>n;
ll a[n];
vector <int> v[n+1];

for(i=1;i<n;i++)
{
    cin>>a[i];
    v[a[i]].pb(i);

}
for(i=1;i<=n;i++)
{
cout<<v[i].size()<<endl;

}

}










            












     
 
 
 
 
signed main()
{
 
    // inputFile;
    fast;
    int T = 1;
//cin >> T;

    while(T--){

      
        solve();

        cout << endl;
        
        
 
    }
    
    
    return 0;
 
}

Measured memory_bytes: 16148
n = int(input())
a = sorted(list(map(int, input().split())))

a_max = a[-1]
dp = [1]*a_max

for i in set(a):
    j = 2
    while i*j <= a_max:
        dp[i*j-1] = 0
        j += 1

a.append(0)
ans = 0
for i in range(n):
    if dp[a[i]-1] and a[i-1] != a[i] and a[i] != a[i+1]:
        ans += 1
print(ans)


Measured memory_bytes: 40256
from math import floor
N = int(input())
X = list(map(int,input().split()))
avg = sum(X)/N
l = floor(avg)
r = floor(avg)+1
ans1 = sum([(x-l)**2 for x in X])
ans2 = sum([(x-r)**2 for x in X])
print(min(ans1,ans2))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
  int a[31]={1,1,2};
  int n;
  loop(i,3,31)a[i]=a[i-1]+a[i-2]+a[i-3];
  while(cin>>n,n)cout<<(a[n]-1)/365/10+1<<endl;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const ll LLINF = 1LL<<60;
vector<int> dp;//dp[i + 1] : i円にするための最小動作
int main() {
    ll N, M; cin >> N >> M;
    if(M - 2 * N < 0){
        cout << M / 2 << endl;
    }else{
        M = M - 2 * N;
        cout << N + M / 4 << endl;
    }
    return 0;
}


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

long long int N,D;
long long int X[200007];
long long int Y[200007];

int main(){
    cin >> N >> D;
    long long int res = 0;
    for(int i = 1;i < N+1;i++){
        cin >> X[i] >> Y[i];

        if(X[i] * X[i] + Y[i] * Y[i] <= D * D){
            res++;
        }
    }

    cout << res << endl;



}

Measured memory_bytes: 6744
#include <bits/stdc++.h>
#include <math.h>
#include <time.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll n ; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    sort(a.begin(),a.end());

    ll x = a.at(n-1);
    ll ans1 = 0;
    ll first=x,second=x,goukei=2*x;
    for(int i=0;i<(n-1)/2;i++){
        if(i%2){
            ll m = 1+(i/2);
            first = a.at(n-2*m);
            second = a.at(n-2*m-1);
            ans1 += abs(first+second-goukei); 
        }else{
            ll m = i/2;
            first = a.at(2*m);
            second = a.at(2*m+1);
            ans1 += abs(first+second-goukei);            
        }
        goukei = first+second;
    }
    if(n%4==2){
        ll y = a.at(n/2 - 1);
        ans1 += max(abs(first-y),abs(second-y));
    }else if(n%4==0){
        ll y = a.at(n/2);
        ans1 += max(abs(first-y),abs(second-y));
    }

    x = a.at(0);
    ll ans2 = 0;
    first=x,second=x,goukei=2*x;
    for(int i=0;i<(n-1)/2;i++){
        if(i%2==0){
            ll m = 1+(i/2);
            first = a.at(n-2*m+1);
            second = a.at(n-2*m);
            ans2 += abs(first+second-goukei); 
        }else{
            ll m = i/2;
            first = a.at(2*m+1);
            second = a.at(2*m+2);
            ans2 += abs(first+second-goukei);            
        }
        goukei = first+second;
    }
    if(n%4==0){
        ll y = a.at(n/2 - 1);
        ans2 += max(abs(first-y),abs(second-y));
    } else if(n%4==2){
        ll y = a.at(n/2);
        ans2 += max(abs(first-y),abs(second-y));
    }
  
    //cout << ans1 << ans2 << endl;
    cout << max(ans1,ans2) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  if (a < b) return gcd(b, a);

  return gcd(b, a % b);
}

ll lcm(ll x, ll y) { return (x * y) / gcd(x, y); }

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

  int n, m;
  cin >> n >> m;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  bool ok = true;
  for (int i = 1; i < n; i++) {
    int cntX = 0, cntY = 0;

    int x = a[i];
    int y = a[i - 1];
    while (x % 2 == 0) {
      x /= 2;
      cntX++;
    }

    while (y % 2 == 0) {
      y /= 2;
      cntY++;
    }

    if (cntX != cntY) {
      ok = false;
      break;
    }
  }

  ll vlcm = a[0] / 2;
  for (int i = 1; i < n; i++) {
    a[i] /= 2;
    vlcm = lcm(a[i], vlcm);
    if(vlcm > m) {
      ok = false;
      break;
    }
  }

  ll ans = 0;

  if (ok) {
    ll mul = 1;
    while (vlcm * mul <= m) {
      ans++;
      mul += 2;
    }

    cout << ans << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define INF 		2000000007
#define MOD			10e9+7
#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;


vector<int> h(110);

int f(int s,int e,int m){
	//cout << s << " " << e << endl;
	if(s>e)return 0;
	if(s==e) return h[s]-m;
	int minl=h[s];
	int p=s;
	REPS(i,s+1,e+1){
		if(minl > h[i]){
			minl = h[i];
			p = i;
		}
	}
	return f(s,p-1,minl)+f(p+1,e,minl) + minl - m;
}

int main(){
	int N;cin>>N;
	REP(i,N)cin>>h[i];

	cout << f(0,N-1,0) << 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 eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    int n, x;
    cin >> n >> x;

    vector<int> l(n);
    rep(i, n) cin >> l[i];

    int sum = 0;
    int cnt = 1;
    for(int i = 0; i < n; ++i){
        sum += l[i];
        if(sum > x) break;
        ++cnt;
    }
    ppp(cnt);

    return 0;
}


Measured memory_bytes: 256
while 1:
    n=int(input())
    if n==0:break
    a={}
    for _ in range(n):
        b,c=input().strip().split()
        a[b]=c
    d=''
    for _ in range(int(input())):
        e=input().strip()
        d+=a[e] if e in a else e
    print(d)

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

char t[200005], d[200005];
int n, q;
string s;

int check(int m) {
    for (int i = 0; i < q; i++) {
        if (s[m] == t[i]) {
            if (d[i] == 'L')
                m--;
            else
                m++;
        }
        if (m < 0)
            return 1;
        else if (m >= n)
            return 2;
    }
    return 0;
}

int main() {
    cin >> n >> q;
    cin >> s;
    for (int i = 0; i < q; i++) cin >> t[i] >> d[i];
    int l1 = -1, r1 = n;
    int l2 = -1, r2 = n;
    while (r1 - l1 > 1) {
        int mid = (l1 + r1) / 2;
        if (check(mid) == 1)
            l1 = mid;
        else
            r1 = mid;
    }
    while (r2 - l2 > 1) {
        int mid = (l2 + r2) / 2;
        if (check(mid) == 2)
            r2 = mid;
        else
            l2 = mid;
    }
    cout << max(0, l2 - r1 + 1) << endl;
    return 0;
}


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

int Solve(const int n, const vector<string>& s) {
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    char a[] = {s[0][i], s[1][i], s[2][i]};
    sort(a, a + 3);
    if (a[0] == a[2])
      continue;
    if (a[1] == a[0] || a[1] == a[2])
      ++ret;
    else
      ret += 2;
  }
  return ret;
}

int main() {
  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;
  cout << Solve(n, {a, b, c}) << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
  
}
int z=10000000;
int x=-10000000;
int64_t c=0;
for(int i=0;i<n;i++){
z=min(z,a[i]);
x=max(x,a[i]);
c+=a[i];
}
cout<<z<<" "<<x<<" "<<c<<endl;
}


Measured memory_bytes: 3120
#include <iostream>
#include <deque>

int main()
{
	std::deque<int> d;
	int dist[100010] = { 0 };
	dist[1] = 1;
	d.push_back(1);
	
	int k;
	std::cin >> k;
	
	for (int i = 0; i <= k; ++i)
		dist[i] = 100000000;
	dist[1] = 1;
	
	while (d.size())
	{
		int x = d.front();
		d.pop_front();
		
		if (dist[(x * 10) % k] > dist[x])
		{
			dist[(x * 10) % k] = dist[x];
			d.push_front((x * 10) % k);
		}
		if (dist[(x + 1) % k] > dist[x] + 1)
		{
			dist[(x + 1) % k] = dist[x] + 1;
			d.push_back((x + 1) % k);
		}
	}
	
	std::cout << dist[0];
}

Measured memory_bytes: 896
#include <iostream>

using std::cin;
using std::cout;

int n;
int A[2000];

bool fanc(int loc,int num)
{
	if (num == 0){ return true; }
	if (num<0||loc >= n){ return false; }
	if (fanc(loc + 1, num - A[loc]))return true;
	if (fanc(loc + 1, num))return true;
	return false;
}

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

	cin >> n;

	for (size_t i = 0; i < n; i++)
	{
		cin >> A[i];
	}
	cin >> m;
	int a;
	for (size_t i = 0; i < m; i++)
	{
		cin >> a;
		if (fanc(0, a)){ cout << "yes\n"; }
		else{ cout << "no\n"; }
	}

	return 0;
}

Measured memory_bytes: 1180
/**
 * MatrixMultiplication.cpp
 * Create:20180424
 * Description:n * mの行列Aとm * l の行列Bを入力し、
 * それらの積であるn * lの行列Cを出力するプログラム。
 */
#include <iostream>
#include <string.h>

int main(int argc, char* argv[]){
  int n, m, l;

  // 要素数の入力と配列の作成
  std::cin >> n >> m >> l;
  long int a[n][m];
  long int b[m][l];
  long int c[n][l];
  // 初期化
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  memset(c, 0, sizeof(c));

  // A行列の入力
  for (int i = 0; i < n; i++){
    for (int j = 0; j < m; j++){
      std::cin >> a[i][j];
    }
  }

  // B行列の入力
  for (int i = 0; i < m; i++){
    for (int j = 0; j < l; j++){
      std::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++){
      std::cout << c[i][j];
      if (l - 1 != j)
        std::cout << " ";
    }
    std::cout << std::endl;
  }

  return 0;
}


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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll L, R, D, ans=0, tmp=0;
vector<ll> A;

signed main(){
    cin >> L >> R >> D;
    L += D-1;
    ll l = L/D;
    ll r = R/D;
    cout << r-l+1 << endl;
    return 0;
}

Measured memory_bytes: 3444
a,b,c = map(int,input().split())
k=int(input())

for i in range(k):
    if c<=a or c<=b:
        c=2*c
    elif b<=a:
        b=2*b
    else:
        pass

if c > b and b > a and c >a:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61532
import heapq
import math

n, m = list(map(int, input().split()))
a = list(map(lambda x: int(x) * (-1), input().split()))
heapq.heapify(a)

for _ in range(m):
    heapq.heappush(a, math.ceil(heapq.heappop(a) / 2))

print(-sum(a))


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

public class Main {

    public static void main(String arg[]){

        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        int[] ara1 = new int[n];
        int[] ara2 = new int[n];

        ArrayList<Integer> diff = new ArrayList<>();

        for(int i=0;i<n;i++){
            ara1[i] = scanner.nextInt();
        }

        for(int i=0;i<n;i++){
            ara2[i] = scanner.nextInt();
            //diff.add(ara2[i] - ara1[i]);
        }


        int sum=0;

        for(int i=0;i<n;i++){
            if(ara1[i]>ara2[i]){
                sum+=ara1[i]-ara2[i];
            }
        }

        prln(sum);


    }

    public static void prln(Object line){
        System.out.println(line);
    }

    public static void pr(Object line){
        System.out.print(line);
    }

}


Measured memory_bytes: 23252
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class CNumbersOnACircle {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n;
        in>>n;
        vector<int> a(n),b(n);
        for(auto &i:a) in>>i;
        priority_queue<pair<int,int>> pq;
        fr(i,n){
            in>>b[i];
            if(a[i]>b[i]){
                out<<-1<<endl;
                return;
            }
        }
        fr(i,n){
            if(b[i]>a[i]&&b[i]>b[(i+n-1)%n]+b[(i+1)%n]) pq.emplace(b[i],i);
        }
        ll ans=0;
        while(!pq.empty()){
            auto p=pq.top();pq.pop();
            auto f=p.first,s=p.second;
            //cout<<f<<" "<<s<<endl;
            auto qw=b[(s+n-1)%n]+b[(s+1)%n];
            if((b[s]-a[s])%qw==0){
                ans+=(b[s]-a[s])/qw;
                b[s]=a[s];
                int i=(s+n-1)%n;
                if(b[i]>a[i]&&b[i]>b[(i+n-1)%n]+b[(i+1)%n]) pq.emplace(b[i],i);
                i=(s+1)%n;
                if(b[i]>a[i]&&b[i]>b[(i+n-1)%n]+b[(i+1)%n]) pq.emplace(b[i],i);
                continue;
            }
            auto k=f/qw;
            ans+=k;
            b[s]-=k*(b[(s+n-1)%n]+b[(s+1)%n]);
            if(k==0||b[s]<a[s]){
                out<<-1<<endl;
                return;
            }
            int i=(s+n-1)%n;
            if(b[i]>a[i]&&b[i]>b[(i+n-1)%n]+b[(i+1)%n]) pq.emplace(b[i],i);
            i=(s+1)%n;
            if(b[i]>a[i]&&b[i]>b[(i+n-1)%n]+b[(i+1)%n]) pq.emplace(b[i],i);
        }
        bool f=false;
        fr(i,n) if(a[i]!=b[i]) f=true;
        if(f){
            out<<-1<<endl;
            return;
        }
        out<<ans<<endl;
    }
};

int main() {
    CNumbersOnACircle solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 2936
import Control.Applicative
import Control.Monad
import Data.Function

main :: IO ()
main =
    fix $ \loop -> do
        [a,b] <- map read . words <$> getLine
        unless ([a,b] == [0,0]) $ do
            replicateM_ a (putStrLn (replicate b '#'))
            putStrLn ""
            loop


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

#define mp make_pair
#define pb push_back
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0)
#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout)
#define sz(x) ((int)((x).size()))
#define len(x) ((int)((x).length()))
#define x first
#define y second
#define foreach(it, v) for (auto it : v)
#define rep(it, n) for (int it = 0; it < n; ++it)
#define forin(it, l, r) for (int it = l; it < r; ++it)
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1 << 31) - 1;
const ll LINF = (1ll << 63) - 1;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1e9 + 7;
const double EPS = 1e-7;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
mt19937 mmtw(MOD);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }
template <class T> T arr_max(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] > res) res = a[i]; return res; }
template <class T> T arr_min(T a[], int n) { T res = a[0]; for (int i = 1; i < n; ++i) if (a[i] < res) res = a[i]; return res; }
////////////////////////////////////////////////////////////////////////////////////////////////

string s;

int main() {
    FAST_IO;
    cin >> s;
    rep(i, len(s)) {
        if (i % 2 == 0) {
            cout << s[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 592
program a
implicit none
character(10) :: S

read(*,*) S
S = trim(S)

if (S=="Sunny") then
write(*,'(a6)') "Cloudy"
else if (S=="Cloudy") then
write(*,'(a5)') "Rainy"
else if (S=="Rainy") then
write(*,'(a5)') "Sunny"
end if

end program

Measured memory_bytes: 768
#include<iostream>

using namespace std;

int main(){
 int h,w;
  cin >> h >> w;
 char c[h][w]; 
  for(int i=0;i<h;i++){
  for(int j=0;j<w;j++){
   cin >> c[i][j];
  }  
  }
  
  for(int i=0;i<h;i++){
  for(int j=0;j<w-1;j++){
   cout << c[i][j];
  }  
   cout << c[i][w-1] << endl;
    
   for(int j=0;j<w-1;j++){
   cout << c[i][j];
  }  
     cout << c[i][w-1] << endl;
  
  }
  
    
}

Measured memory_bytes: 256
# AOJ 1110: Patience
# Python3 2018.7.8 bal4u

pair = [[1,4,5], [2,4,5,6], [3,5,6,7], [6,7], [5,8,9],
	[6,8,9,10], [7,9,10,11], [10,11], [9,12,13], [10,12,13,14],
	[11,13,14,15], [14,15], [13,16,17], [14,16,17,18], [15,17,18,19],
	[18,19], [17], [18], [19]]

def combi(cd, n):
	global ans
	ans = min(ans, n)
	if n == 0: return True
	for p in range(n-1):
		a = (cd >> (p*3)) & 7
		for q in pair[p]:
			b = (cd >> (q*3)) & 7
			if a != b: continue
			b1 =  cd             & ((1<<(p*3))-1)
			b2 = (cd >> (p+1)*3) & ((1<<(q-p-1)*3)-1)
			b3 = (cd >> (q+1)*3) & ((1<<(n-q-1)*3)-1)
			nc = b1 | (b2<<(p*3)) | (b3<<(q-1)*3)
			if combi(nc, n-2): return True
	return False

for _ in range(int(input())):
	k = []
	for i in range(5):
		k.extend(list(map(int, input().split())))
	card = 0
	for i in range(19, -1, -1): card = (card<<3)|k[i]
	ans = 20
	combi(card, 20)
	print(ans)



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

void fast(){
ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}

#define ll				long long
#define rep(i,x,y)  	for(__typeof(x) i=x;i<=y;i++)
#define repi(i,x,y) 	for(__typeof(x) i=x;i>=y;i--)
#define vfor(it,x)		for(__typeof(x.begin()) it= x.begin() ; it!=x.end(); it++)
#define vfori(it,x)		for(__typeof(x.begin()) it= x.end() ; it!=x.begin(); it--)
#define test(t)    	    cin >> t;while(t--)
#define yes             cout <<"YES"<<endl;
#define no              cout <<"NO"<<endl;
#define debug(x)		cout << #x <<" = "<<x<<" ";	
#define pi              3.14159265358979323846 

// a/b  mod m= a⋅b^(−1) mod m
// b^(-1)mod m = b^(m-2) mod m   and m is a prime number

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;     
  
    x = x % p;   
    while (y) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;  
        x = (x*x) % p; 
    } 
    return res; 
} 
 
ll nCrModP(ll n, ll r, ll p) 
{ 
    if (!r) 
      return 1; 
  
    ll fac[n+1]; 
    fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p; 
}

ll pow_mod(ll x,ll n,ll m)
{
    if (n == 0) 
    	return 1;
	ll t;
    t = pow_mod(x, n/2, m);
 	if(n%2==0)
        return t * t  % m;
    else
        return t * t * x  % m;
}

int main()
{	
	fast();
	ll n;
	cin >> n;
	ll t;
	t = pow(n,2)+pow(n,3) + n;
	cout << t << endl;
}


Measured memory_bytes: 4116
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define M 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;


int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int d, t, s;
    cin>>d>>t>>s;
    double dist = (double)d;
    double time = (double)t;
    double speed = (double)s;
    double reqs = dist/time;

    if(abs(reqs - speed) < 1e-9) cout<<"Yes";
    else if (reqs < speed) {
       cout<<"Yes"; 
    }
    else cout<<"No";
return 0;
}

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

int partition(int A[],int p,int r){
  int x = A[r];
  int i = p - 1;
  for(int j=p; j<r; j++)
    if(A[j] <= x) swap(A[++i],A[j]);
  swap(A[i+1],A[r]);
  return i+1;
}



int main(){
  int n,A[100010];  
  cin>>n;
  for(int i=0;i<n;i++) cin>>A[i];
  int idx = partition(A,0,n-1);
  for(int i=0;i<n;i++){
    if(i)cout<<" ";
    if(i==idx)cout<<"[";
    cout<<A[i];
    if(i==idx)cout<<"]";
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3356