akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define REP(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)((x).size()))

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;

ll pcnt[3], plim[3];
int main() {
    int N, K, C;
    cin >> N >> K >> C;
    string S;
    vector<int> lnum(N + 1), rnum(N + 2);
    cin >> S;
    int maru = 0;
    rep(i, N){
        if (S[i] == 'o')maru++;
    }
    int ng_place = -C - 1;
    lnum[0] = 0;
    rep(i, N){
        if (S[i] == 'o' && i > ng_place){
            ng_place = i + C;
            lnum[i + 1] = lnum[i] + 1;
        } else {
            lnum[i + 1] = lnum[i];
        }
    }

    ng_place = N + C + 1;
    rnum[N + 1] = 0;
    for (int i = N - 1; i >= 0; i--){
        if (S[i] == 'o' && i < ng_place){
            ng_place = i - C;
            rnum[i + 1] = rnum[i + 2] + 1;
        } else {
            rnum[i + 1] = rnum[i + 2];
        }
    }
    
    rep(i, N){
        if (S[i] == 'o' && lnum[i] + rnum[i + 2] ==  K - 1){
            
            cout << i + 1<< endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3332
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
int main(){
    int n,d,x;
    cin>>n>>d>>x;
    int s=0;
    rep(i,0,n){
        int a;
        cin>>a;
        s+=(d-1)/a+1;
    }
    cout<<s+x;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define rev(r) reverse(r.begin(),r.end())
#define SORT(ar) sort(ar.begin(), ar.end())
#define sz(x) (int)(x).size()
#define len(x) (int)x.length()
#define in(a) scanf("%d",&a)
#define pr(x) printf("%d ",x)
#define endl '\n'
#define read(v,n) for(int h=0;h<n;h++) cin>>v[h];
#define fo(i,a,b) for(i=a;i<b;i++)
#define fi(i,a,b) for(i=a;i>=b;i--)
#define mo 1000000007
#define N 300007

int main()
{
    int n,i,j,k;
    cin>>n;
    int h[n];
    fo(i,0,n) cin>>h[i];
    int dp[n];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    fo(i,2,n)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;


int main(void){
    int n;
    string s;
    long long na[5];
    for(int i=0;i<5;i++){
        na[i] =0;
    }

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s;
        if(s[0]=='M'){na[0]++;}
        if(s[0]=='A'){na[1]++;}
        if(s[0]=='R'){na[2]++;}
        if(s[0]=='C'){na[3]++;}
        if(s[0]=='H'){na[4]++;}
    }

    long long ans=0;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++){
                ans = ans + 1LL * na[i] * na[j] * na[k];
            }
        }
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define MN 0LL
#define MX 20000000000000005
using namespace std;
int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	string s;
	cin>>s;
	while(1){
		s.pop_back();
		if(s.size()%2==1) continue;
		if(s.size()==0){
			cout<<0<<endl;
			return 0;
		} 
		if(s.substr(0,s.size()/2)==s.substr(s.size()/2)){
			cout<<s.size()<<endl;
			return 0;
		}
	}
	#ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_d
#include<bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[]) {
	int n;
	cin >> n;
	vector<int> a (n+1);
	vector<long long> dp (n+1);
	dp[1] = 1000;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 2; i <= n; i++) {
		dp[i] = dp[i-1];
		for (int j = 1; j <= i-1; j++) {
			long long num = dp[j]/a[j];
			long long tot = dp[j]-(num*a[j]) + (num*a[i]);
			dp[i] = max(dp[i], tot);
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<map>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const ll mod = 1000000007;
const ll INF = mod * mod;

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define stop char nyaa;cin>>nyaa;

void solve() {
	int n; cin >> n;
	vector<int> l(n);
	rep(i, n) {
		cin >> l[i];
	}
	sort(l.begin(), l.end());
	ll ans = 0;
	rep(i, n) {
		int le = 0;
		Rep(j, i + 1, n) {
			int inf = l[j] - l[i];
			while (le < i&&l[le] <= inf)le++;
			ans += i - le;
		}
	}
	cout << ans << endl;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();

	//stop
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}

int atcoder(){
    ll x,y,z,k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x),b(y),c(z);
    REPL(i,0,x) cin >> a[i];
    REPL(i,0,y) cin >> b[i];
    REPL(i,0,z) cin >> c[i];
    
    SRTVG(a);
    SRTVG(b);
    SRTVG(c);
    
    vector< tuple<ll,ll,ll,ll> > v;
    set< tuple<ll,ll,ll,ll> > st;
    v.push_back(make_tuple(a[0]+b[0]+c[0],0,0,0));
    
    while(true){
        ll e=get<1>(v[0]),f=get<2>(v[0]),g=get<3>(v[0]);
        st.insert(v[0]);
        if(st.size()>=k) break;
        v.erase(v.begin());
        auto E = make_tuple(a[e+1]+b[f]+c[g],e+1,f,g);
        auto F = make_tuple(a[e]+b[f+1]+c[g],e,f+1,g);
        auto G = make_tuple(a[e]+b[f]+c[g+1],e,f,g+1);
        if(e<x-1 && !st.count(E)) {v.push_back(E);}
        if(f<y-1 && !st.count(F)) {v.push_back(F);}
        if(g<z-1 && !st.count(G)) {v.push_back(G);}
        SRTVG(v);
        v.erase(unique(v.begin(),v.end()),v.end());
    }
    
    vector<ll> ans;
    for(auto x : st) ans.push_back(get<0>(x));
    for(ll i=k-1; i>=0; --i) cout << ans[i] << ENT;
    return 0;
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


Measured memory_bytes: 768
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    graph[x - 1].append(y - 1)

dp = [-1] * n
def count(a):
    if dp[a] != -1:
        return dp[a]
    else:
        dp[a] = 0
        for i in graph[a]:
            dp[a] = max(count(i) + 1, dp[a])
        return dp[a]

print(max([count(i) for i in range(n)]))


Measured memory_bytes: 130908
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [float("inf") for _ in range(N)]

def cost(n, m):
  return abs(h[n] - h[m])

dp[0] = 0

for i in range(N):
  for j in range(1, K + 1):
    if (i + j) <= N -1:
      dp[i + j] = min(dp[i + j], dp[i] + cost(i, i + j))

print(dp[-1])

Measured memory_bytes: 56928
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>n;
    vector<ll> u(n);
    vector<ll> v(n);
    vector<ll> w(n-1);
    rep(i,n) cin>>u[i];
    rep(i,n) cin>>v[i];
    rep(i,n-1) cin>>w[i];
    rep(i,n) sum+=v[i];
    rep(i,n-1){
        if(u[i]+1==u[i+1]) sum+=w[u[i]-1];
    }
    cout<<sum<<endl;

    return 0;
}


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

using namespace std;

int main() {
	int D; cin >> D;
	// cout << "Hello World";
	switch(D) {
		case 22: 
			cout << "Christmas Eve Eve Eve"; 
			break;
		case 23: 
			cout << "Christmas Eve Eve"; 
			break;
		case 24: 
			cout << "Christmas Eve"; 
			break;
		case 25: 
			cout << "Christmas"; 
			break;
	}
	return 0;
}

Measured memory_bytes: 3596
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto S = readln.split[0];
	int result = 10000;
	foreach (i; 0 .. S.length-2) { result = min( (S[i .. i+3].to!int - 753).abs, result); }
	result.writeln;
}


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

int bpow(int n){
  int a = 1;
  Rep(i,n){
    a = (a * 2) % 1000000007;
  }
  return a;
}

int main()
{
  int N;
  int data;
  int sum[100005] = {0};
  cin >> N;
  Rep(i,N){
    cin >> data;
    sum[data]++;
  }
  if(N % 2 == 1 && sum[0] != 1)cout << 0 << endl;
  else {
    int cnt = 1;
    int ans = 1;
    bool flag = false;
    if(N % 2){
      cnt = 2;
    }
    for(;cnt <= N - 1;cnt += 2){
      if(sum[cnt] != 2)flag = true;
    }
    if(flag)cout << 0 << endl;
    else cout << bpow(N / 2) << endl;
  }
 
  return 0;
}
	

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i, s, n) for(int i=s; i<n; i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  rep(i, N) cin >> h[i];

  int ans = 1e9;
  sort(h.begin(), h.end());
  rep(i, N-K+1) {
    ans = min(ans, h[i+K-1]-h[i]);
  }

  cout << ans << endl;

  return 0;
}


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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 200000;

int n;
int val[N + 5];
vector<int> G[N + 5];
int mx[N + 5], fa[N + 5], ans[N + 5];

void dfs(int u, int f = 0, int id = 0, int smx = 0) {
    fa[u] = f;

    if(fa[u] > fa[id]) {
        id = smx = u;
    } else {
        chkmax(smx, u);
    }

    if(fa[u] <= 1) {
        ++ val[u];
    } else {
        if(u > fa[id]) {
            ++ val[u];
        } else if(smx < mx[fa[id]]) {
            ++ val[fa[id]];
        } else ++ val[id];
    }

    for(auto v : G[u]) if(v != f) {
        chkmax(mx[v], std::max(mx[u], u));
        dfs(v, u, id, smx);
    }
}

void calc(int u, int f = 0, int s = 0) {
    s += val[u]; ans[u] = s;
    for(auto v : G[u]) if(v != f) calc(v, u, s);
}

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    read(n);
    for(int i = 1; i < n; ++i) {
        static int u, v;
        read(u), read(v);
        G[u].pb(v), G[v].pb(u);
    }

    dfs(1);
    calc(1);

    for(int i = 2; i <= n; ++i) printf("%d ", ans[i] - 1);

    return 0;
}



Measured memory_bytes: 30464
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
multiset<ll> st;
int main(){
    cin>>N;
    for(ll i=0;i<N;i++){
        ll A;
        cin>>A;
        st.insert(A);
    }
    ll ans=0;
    while(!st.empty()){
        auto it=st.end();
        it--;
        ll n=*it;
        st.erase(it);
        ll a=1;
        while(a<=n)a<<=1;
        it=st.find(a-n);
        if(it!=st.end()){
            st.erase(it);
            ans++;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 9600
n = int(input())

a = list(map(int,input().split()))

#print(a)

score1 = []
score2 = []

while len(a) > 0:
    pick = max(a)
    score1.append(pick)
    a.remove(pick)
    if len(a) == 0:
        break
    
    pick = max(a)
    score2.append(pick)
    a.remove(pick)
    
#print(score1)
#print(score2)
print(sum(score1) - sum(score2))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define P pair<ll,ll>

using namespace std;

int main(void){
  ll n, m;
  cin >> n >> m;
  
  vector<vector<ll>> edge(n, vector<ll>(0));
  for (int i = 0; i < m; i++){
    ll a, b;
    cin >> a >> b;
    
    a--;b--;
    edge[a].emplace_back(b);
    edge[b].emplace_back(a);
  }

  vector<ll> ans(n);
  vector<ll> dist(n, INF);
  priority_queue<P, vector<P>, greater<P> > Q;
  Q.push(P(0, 0));

  while (Q.size() != 0){
    P p = Q.top();
    Q.pop();
    ll f = p.first;
    ll u = p.second;
    if (dist[u] < f){
      continue;
    }
    dist[u] = f;
    for (int i = 0; i < edge[u].size(); i++){
      int v = edge[u][i];
      if (dist[v] > f + 1){
        dist[v] = f + 1;
        ans[v] = u;
        Q.push(P(f + 1, v));
      }
    }
  }

  cout << "Yes" << endl;
  for (int i = 1; i < n; i++){
    cout << ans[i] + 1 << endl;
  }

  return 0;
}


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

int a[105] = {};

int main() {
	int n;
	int ans = 0;
	cin >> n;
	for (int i = 0; i < n * 2; i++)
	{
		cin >> a[i];
	}

	sort(a, a + (n * 2));

	for (int i = 0; i < n * 2; i++)
	{
		if (i % 2 == 0) {
			ans += a[i];
		}

	}
	
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

struct QuickFind{
	vector<int> par;
	vector<vector<int>> group;
	QuickFind(int n) : par(n),group(n){
		for(int i = 0;i < n;i++){
			par[i] = i;
			group[i].push_back(i);
		}
	}
	int find(int x){
		return par[x];
	}
	void unite(int x,int y){
		x = par[x],y = par[y];
		if(x == y) return;
		if(group[x].size() < group[y].size()) swap(x,y);
		for(int v : group[y]) par[v] = x;
		group[x].insert(group[x].end(),group[y].begin(),group[y].end());
		group[y].clear();
		par[y] = x;
	}
	bool same(int x,int y){
		return par[x] == par[y];
	}
};

signed main(){
	int n,m,k;
	cin >> n >> m >> k;
	QuickFind uf(n);
	vector<int> G[100010];
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b; a--;b--;
		uf.unite(a,b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(int i = 0;i < k;i++){
		int c,d;
		cin >> c >> d; c--;d--;
		G[c].push_back(d);
		G[d].push_back(c);
	}
	for(int i = 0;i < n;i++){
		int ans = uf.group[uf.find(i)].size() - 1;
		for(int v : G[i]){
			if(uf.same(i,v)) ans--;
		}
		cout << (i ? " " : "") << ans;
	}
	cout << endl;
}

Measured memory_bytes: 17888
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc119/editorial.pdf
・公式解の再帰
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,A,B,C=MAP()
L=[INT() for i in range(N)]
ABC=[A,B,C]

def rec(i, a, b, c):
    if i==N:
        # a,b,cどれか1つでも0なら1本も竹を使ってないので無効
        if min(a, b, c)==0:
            return INF
        # 合体させてきたabcを伸縮させてそれぞれABCにする
        a=abs(A-a)
        b=abs(B-b)
        c=abs(C-c)
        # それぞれ1本目には合体コストが要らないので各-10で-30
        return a+b+c-30
    res=INF
    # i本目の竹は使わない
    res=min(res, rec(i+1, a, b, c))
    # i本目の竹をa(Aにする予定の集まり)に合体させる(b,cも同じ)
    res=min(res, rec(i+1, a+L[i], b, c)+10)
    res=min(res, rec(i+1, a, b+L[i], c)+10)
    res=min(res, rec(i+1, a, b, c+L[i])+10)
    return res

print(rec(0, 0, 0, 0))


Measured memory_bytes: 6092
# coding: utf-8

line = input()
tester = ""
for i, word in enumerate(line):
    if (i + 1) % 2 == 0:
        if word == "R":
            tester = "No"
            break
    else:
        if word == "L":
            tester = "No"
            break
if tester == "":
    tester = "Yes"
print(tester)

Measured memory_bytes: 2940
#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;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}
void solve()
{
    int n;
    cin >> n;
    if(n%2==0){
        cout << -1 << endl;
        return;
    }
    int t = 7, f = 10;
    int ans = 0;
    int k = 0;
    t %= n;
    for (int i = 0; i < 1000000;i++){
        k = (k+t)%n;
        if(k%n==0){
            cout << i + 1 << endl;
            return;
        }
        t =(t*10)%n;
    }
    cout << -1 << endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    //cin >> tc;
    while (tc--)
    {
        solve();
    }

    return 0;
}

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

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

signed main(){
	int A, B, i;
	scanf("%lld%lld", &A, &B);
	int g = gcd(A, B);
	int ans = 1;
	for(i = 2; i * i <= g; i++){
		if(g % i == 0){
			while(g % i == 0){
				g /= i;
			}
			ans++;
		}
	}
	if(g > 1){
		ans++;
	}
	printf("%lld\n", ans);
	return 0;
}

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

#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
#define R(i,a,b) for(int i=a;i<b;++i)
#define mem(a,b) memset(a,b,sizeof(a))

char s[200200];
int a[26];

int main()
{
   cin>>s;
   int len=strlen(s);
   ll ans=len*1LL*(len-1)/2;
   //printf("%I64d\n",ans);
   R(i,0,len)
   {
      a[s[i]-'a']++;
   }
   R(i,0,26)
   {
      ans=ans-a[i]*1LL*(a[i]-1)/2;
   }
   cout<<ans+1<<endl;
   return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=16,maxl=1<<16,mo=1e9+7;
int n,m,G[maxn],sum[maxl],mp[maxl],dp[maxl],xp[maxn*maxn];
int main()
{
	xp[0]=1;
	for (int i=1;i<maxn*maxn;i++) xp[i]=xp[i-1]*2%mo;
	cin>>n>>m;
	int ans=xp[m];
	int maxS=(1<<n)-1;
	for (int S=0;S<=maxS;S++)
	    for (int i=0;i<n;i++)
	        if (S&(1<<i))
	            mp[S]++;
	while (m--)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		u--;v--;
		G[u]|=(1<<v);
		for (int S=0;S<=maxS;S++)
		    if ((S&(1<<u))&&(S&(1<<v)))
		        sum[S]++;
	}
	for (int S=0;S<=maxS;S++)
	    if ((S&3)==3)
	    {
	    	dp[S]=1;
	        for (int U=(S-1)&S;U;U=(U-1)&S)
	        {
	        	if ((U&3)==3)
	        	{
	        		LL temp=1;
	        		for (int i=0;i<n;i++)
	        		    if (U&(1<<i))
	        		        temp=temp*xp[mp[G[i]&(S^U)]]%mo;
	        		temp=temp*xp[sum[S^U]]%mo;
	        		for (int i=0;i<n;i++)
	        		    if ((S^U)&(1<<i))
	        		        temp=temp*(xp[mp[G[i]&U]]-1)%mo;
	        		dp[S]=(dp[S]+temp)%mo;
				}
				if ((U&3)==0)
				{
	        		LL temp=1;
	        		for (int i=0;i<n;i++)
	        		    if (U&(1<<i))
	        		        temp=temp*xp[mp[G[i]&(S^U)]]%mo;
	        		temp=temp*dp[S^U]%mo;
	        		for (int i=0;i<n;i++)
	        		    if ((S^U)&(1<<i))
	        		        temp=temp*(xp[mp[G[i]&U]]-1)%mo;
	        		dp[S]=(dp[S]+temp)%mo;
				}
			}
		}
	cout<<(ans-dp[maxS]+mo)%mo;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#define f first
#define s second
using namespace std;
typedef long long ll;
const ll limit=1e6+2;
const ll maxN=1e9+2;
string s,st,st1;
bool f[limit];
long long t,n,x,test,tp=0,mp=0,temp=0,l,r,m,res=0,k;
long long b[limit],mi[limit],a[limit],c[limit];
vector <ll> d[limit];

int main()
{
    cin>>n>>m;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(ll i=1;i<=m;i++)
    {
        cin>>b[i]>>c[i];
        d[b[i]].push_back(c[i]);
        d[c[i]].push_back(b[i]);
    }
    for(ll i=1;i<=n;i++)
    {
        res=0;
        for(ll j=0;j<d[i].size();j++){
            res=max(res,a[d[i][j]]);
        }
        if(res<a[i]) temp++;//cout<<a[i]<<endl;}
    }
    cout<<temp;
}


Measured memory_bytes: 32892
a=list(input())
b=list(input())
c=list(input())
a=a[::-1]
b=b[::-1]
c=c[::-1]
t="a"

while 1:
    if len(a) and t=="a":
        t=a.pop()
    elif len(b) and t=="b":
        t=b.pop()
    elif len(c) and t=="c":
        t=c.pop()
    else:
        print(["A","B","C"][ord(t)-ord("a")])
        break


Measured memory_bytes: 38384
from collections import deque
h,w = map(int,input().split())
grid = []
dq = deque([])
dx = [1,-1,0,0]
dy = [0,0,1,-1]
ans = 0
d = [[-1 for i in range(w)] for j in range(h)]
for i in range(h):
    maze = list(input())
    for j in range(w):
        if maze[j] == "#":
            dq.append((j,i))
            d[i][j] = 0
    grid.append(maze)
while dq:
    x,y = dq.popleft()
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0 <= nx <= w-1 and 0 <= ny <= h-1 and grid[ny][nx] != "#" and d[ny][nx] == -1:
            dq.append((nx,ny))
            d[ny][nx] = d[y][x] + 1
            ans = max(ans,d[ny][nx])
print(ans)

Measured memory_bytes: 123996
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;
int stoi(string s)
{
    return atoi(s.c_str());
}
struct triangle
{
    triangle() { leg1 = leg2 = leg3 = 0; }
    bool isHyp()
    {
        if (leg1*leg1 + leg2*leg2 == leg3*leg3 || leg2*leg2 + leg3*leg3 == leg1*leg1 || leg3*leg3 + leg1*leg1 == leg2*leg2)
            return true;
        return false;
    }
    int leg1;
    int leg2;
    int leg3;
};
int main()
{
    int j;
    cin >> j;
    triangle* triData = new triangle[j];
    bool* results = new bool[j];
    string s;
    for (int i = 0; i < j; i++)
    {
        getline(cin, s, ' ');
        triData[i].leg1 = stoi(s);
        s.clear();
        getline(cin, s, ' ');
        triData[i].leg2 = stoi(s);
        s.clear();
        getline(cin, s);
        triData[i].leg3 = stoi(s);
        results[i] = triData[i].isHyp();
    }
    for (int i = 0; i < j; i++)
    {
        cout << (results[i] ? "YES" : "NO") << endl;
    }
    
    
    
    delete [] results;
    delete [] triData;
}

Measured memory_bytes: 1220
from fractions import gcd as GCD

N = int(input())
A = list(map(int, input().split()))

# GCD_LtoR[i] = GCD(A0, A1, ... , A(i-1))
GCD_LtoR = [None] * N
# GCD_LtoR[i] = GCD(Ai, A(i+1), ... , AN)
GCD_RtoL = [None] * N

GCD_LtoR[0] = A[0]
for i in range(1, N):
    GCD_LtoR[i] = GCD(A[i], GCD_LtoR[i-1])

GCD_RtoL[N-1] = A[N-1]
for i in range(N-2, -1, -1):
    GCD_RtoL[i] = GCD(A[i], GCD_RtoL[i+1])

GCD_max = GCD_RtoL[1]
for i in range(0, N-1):
    # Aに含まれるAi以外の要素のGCDを計算する
    GCD_ex_i = GCD(GCD_LtoR[i-1], GCD_RtoL[i+1])
    GCD_max = max(GCD_ex_i, GCD_max)
GCD_max = max(GCD_LtoR[N-2], GCD_max)
print(GCD_max)


Measured memory_bytes: 16152
x=int(input())
if 400<=x<=599:
  print(8)
elif 600<=x<=799:
  print(7)
elif 800<=x<=999:
  print(6)
elif 1000<=x<=1199:
  print(5)
elif 1200<=x<=1399:
  print(4)
elif 1400<=x<=1599:
  print(3)
elif 1600<=x<=1799:
  print(2)
elif 1800<=x<=1999:
  print(1)

Measured memory_bytes: 9052
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  if(N%2 == 1){
    cout << 0 << "\n";
    return 0;
  }

  int five = 5;
  int ans = 0;
  while(five <= N){
    ans += N/(five*2);
    five *= 5;
  }
  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
//第4 轮错误 +1 
//第2 轮错误 ，原因：输出a[0]应该将数组的每一行都拼接到a[0]上，而不是上一行 
#include<stdio.h>
#include<string.h>
int main()
{
	int n,l,i,j;
	char a[110][11000]={};
	char b[110]={};
	while(~scanf("%d%d",&n,&l)){
//		getchar();
		for(i=0;i<n;i++){//输入 
			scanf("%s",a[i]);
		}for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(strcmp(a[i],a[j])>0){
					strcpy(b,a[i]);
					strcpy(a[i],a[j]);
					strcpy(a[j],b); 
				}
			} 	
		}for(i=1;i<n;i++){//输出 
			strcat(a[0],a[i]);
		}printf("%s",a[0]);
		printf("\n");
	}
}

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

#define ff              first
#define ss              second
#define int             long long int
#define pb              push_back
#define mp12            make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pq1             priority_queue<int>
#define pqr1            priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)

void FIO(){
    #ifndef SHAILESH
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int modInv(int a,int b,int m){int res=1;a=a%m;while(b>0){if(b&1){res=(res*a)%m;}a=(a*a)%m;b=b>>1;}return res;}

int dp[100006][3]={};
int a[100005],b[100005],c[100005];
int n;

void solve(){
    cin>>n;
    for(int i=0;i<n;i++){
    	cin>>a[i]>>b[i]>>c[i];
    }
    memset(dp,-1,sizeof(dp));
    dp[1][0]=a[0];
    dp[1][1]=b[0];
    dp[1][2]=c[0];
    for(int i=2;i<=n;i++){
    	dp[i][0]=a[i-1]+max(dp[i-1][1],dp[i-1][2]);
    	dp[i][1]=b[i-1]+max(dp[i-1][0],dp[i-1][2]);
    	dp[i][2]=c[i-1]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
}

int32_t main()
{
    //FIO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    solve();


    return 0;
}

Measured memory_bytes: 8304
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

def win(m):
    if m == 0:
        return 2
    if m == 1:
        return  0
    if m == 2:
        return 1


N, K = MI()
RSP = LI()
RSP += [0]
T = input()

M = []
for t in T:
    if t == 'r':
        M.append(0)
    if t == 's':
        M.append(1)
    if t == 'p':
        M.append(2)

P = [win(m) for m in M]

for i in range(K, N):
    if P[i] == P[i - K]:
        P[i] = 3

PP = [RSP[p] for p in P]
print(sum(PP))


Measured memory_bytes: 55500
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int n0 = n / 1000, n1 = n % 1000 / 100, n2 = n % 100 / 10, n3 = n % 1000;
  if (((n0 == n1) && (n0 == n2)) || ((n1 == n3) && (n2 == n3))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
def main():
    from sys import stdin
    #r = stdin.readline()[:-1]
    n = int(stdin.readline()[:-1])   
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]

    if n == 1:
        print('Hello World')
    else:
        r = [int(stdin.readline()) for i in range(n)]
        print(r[0] + r[1])
   
if __name__ == '__main__':
    main()



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

int main() {
    int N;  cin >> N;
    vector<int> L(2 * N);
    for (int i = 0; i < 2 * N; ++i) cin >> L[i];
    sort(L.begin(), L.end());
    int ans = 0;
    // DUMP(L);
    for (int i = 0; i < 2 * N; i += 2) {
        // DUMP(i);
        ans += min(L[i], L[i + 1]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import itertools
import copy

N = int(input())
# N = (2 ** 4) * (3 ** 5) * (5 ** 2) * (7 ** 5)

# 素因数分解
# 戻り値: リスト
def prime_factor(n):
    ass = []
    for i in range(2,int(n**0.5)+1):
        while n % i==0:
            ass.append(i)
            n = n//i
    if n != 1:
        ass.append(n)
    return ass

pf = prime_factor(N)
if len(pf) == 0:
    print(0)
    exit()

d = {}
for i in pf:
    if i not in d:
        d[i] = 1
        continue
    d[i] += 1

exist_num = []
ans = 0
for k in d.keys():
    for c in range(1, 100):
        if d[k] >= c:
            exist_num.append(k ** c)
            ans += 1
            d[k] -= c

# l = []
# for k in d.keys():
#     if d[k] > 0:
#         for _ in range(d[k]):
#             l.append(k)
# for i in range(1, len(l)+1):
#     combs = list(itertools.combinations(l, i))
#     if len(combs) > 0:
#         for comb in combs:
#             d_tmp = copy.copy(d)
#             if max(d_tmp, key=d.get) not in comb:
#                 continue
#             n = 1
#             for j in comb:
#                 d_tmp[j] -= 1
#                 if d_tmp[j] < 0:
#                     break
#                 n *= j
#             if n not in exist_num and n != 1:
#                 print(n)
#                 ans += 1
#                 d = copy.copy(d_tmp)
#                 exist_num.append(n)
print(ans)

Measured memory_bytes: 9520
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, count = 0;
  cin >> A >> B;
  for(int i = A; i <= B; i++) {
    int rev_val = 0;
    for(int j = 1; j < 10001; j *= 10) {
      rev_val += i / j % 10 * 10000 / j;
    }
    if(i == rev_val) {
      count += 1;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  int a, b, t, x;
  
  std::cin >> t >> a >> b;
  
  if ((a * t) < b) {
    std::cout << a * t << std::endl;
  } else {
    std::cout << b << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans;
	if((b-a)%2 == 0){
		ans = (b - a) / 2;
	}
	else{
		ll c, d;
		if(n-b <= a-1){
			d = n;
			c = a + (n - b) + 1;
			ans = (n - b + 1) + (d - c) / 2;
		}
		else{
			c = 1;
			d = b - a;
			ans = a + (d - c) / 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
my_list = []
for _ in range(n):
    t = input().split()
    if t[0] == "0":
        my_list.append(int(t[1]))
    elif t[0] == "1":
        print(my_list[int(t[1])])
    else:
        my_list.pop(-1)




Measured memory_bytes: 13376
#include <stdio.h>

int main(void)
{
	int i;
	int sum = 0;
	int n[5];
	
	for (i = 0; i < 5; i++){
		scanf("%d", &n[i]);
		if (n[i] < 40){
			sum += 40;
		}
		else {
			sum += n[i];
		}
	}
	
	printf("%d\n", sum / 5);
	
	return (0);
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int main() {

	int a,b,sum;
	char c;


	while(1){
		cin>>a>>c>>b;
	switch (c) {
		case '+':

			sum = a+b;
			break;
		case '-':

			sum = a-b;
			break;
		case '*':

			sum = a*b;
			break;
		case '/':

			sum = a/b;
			break;
		case '?':
			return 0;
		default:
			break;
	}
	cout<<sum<<endl;
	}

}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int n,m;
bool v[100001], unvisited = false;
int ans[100001];
int dis[100001];
vector<int> adj[100001], newcurr;
int main(){
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    int a,b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  newcurr.push_back(1);
  int distance = 0;
  while(0 == 0){
    vector<int> curr = newcurr;
    newcurr.clear();
    if(curr.size() == 0){
      break;
    }
    for(int i = 0; i < curr.size(); i++ ){
      v[curr[i]] = true;
      dis[curr[i]] = distance;
    }
    distance++;
    for(int i = 0; i < curr.size(); i++){
      for(int j = 0; j < adj[curr[i]].size(); j++){
        if(!v[adj[curr[i]][j]]){
          ans[adj[curr[i]][j]] = curr[i];
          v[adj[curr[i]][j]] = true;
          newcurr.push_back(adj[curr[i]][j]);
        }
      }
    }
  }
  for(int i = 1; i <= n; i++){
    if(!v[i])
      unvisited = true;
  }
  if(unvisited){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
    for(int i = 2; i <= n; i++){
      cout << ans[i] << endl;
    }
  }
}

Measured memory_bytes: 11036
x = gets.split.map(&:to_i)

a = 0
b = 1
while x[0] > 0 && x[2] > 0
    x[b*2] -= x[a*2+1]
    a = (a + 1) % 2
    b = (b + 1) % 2
end

if x[0] > 0
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 14400
module Geometry = struct

  type t = { x : float; y : float }

  let eps = 1e-10

  let make x y = { x; y }

  let diff a b = { x = a.x -. b.x; y = a.y -. b.y }

  let cross a b = a.x *. b.y -. a.y *. b.x

  let parallel_p (p0, p1) (p2, p3) = abs_float (cross (diff p0 p1) (diff p2 p3)) < eps

end

module G = Geometry

let () =
  let n = read_int () in
  for _ = 0 to n - 1 do
    let (x1, y1, x2, y2, x3, y3, x4, y4) =
      Scanf.scanf "%f %f %f %f %f %f %f %f " (fun x1 y1 x2 y2 x3 y3 x4 y4 ->
        x1, y1, x2, y2, x3, y3, x4, y4) in
    print_endline
      (if G.parallel_p (G.make x1 y1, G.make x2 y2) (G.make x3 y3, G.make x4 y4)
       then "YES" else "NO")
  done

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {

    int n, m;
    cin >> n >> m;
    vector<pii> ab(n), cd(m);

    fo(i, n) cin >> ab[i].ff >> ab[i].ss;
    fo(i, m) cin >> cd[i].ff >> cd[i].ss;

    for ( auto p1 : ab ) {
        pii menor = {INF, -1};
        for ( int i = 0; i < m; i++ ) {
            int manhattan = abs(p1.ff - cd[i].ff) + abs(p1.ss - cd[i].ss);
            if ( manhattan < menor.ff ) menor = {manhattan, i + 1};
        }
        cout << menor.ss << endl;
    }


    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(){

	int h, w;
	int i, j;

	while(1){
		scanf("%d %d ", &h, &w);

	if(h==0&&w==0)break;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(i==0||i==h-1||j==0||j==w-1){
					printf("#");

				}else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 576
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

#define int long long
#define double long double

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define FILL(a,v)	fill(a,a+sizeof(a)/sizeof(*a),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e17 + 9;

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	
	int n;
	cin >> n;

	int T, A;
	cin >> T >> A;

	rep(i, n - 1) {
		int  t, a;
		cin >> t >> a;
		int mag = max((T + t - 1) / t, (A + a - 1) / a);
		T = t * mag;
		A = a * mag;
	}
	cout << T + A << endl;

	return 0; 
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,H; cin>>N>>H;
    ll ans=0;
    vector<ll> A(N+1,0);
    vector<ll> B(N+1,0);
    ll A_MAX=0;
    rep1(i,N){
        cin>>A[i]>>B[i];
        chmax(A_MAX,A[i]);
    }
    vector<ll> C;
    rep1(i,N){
        if(B[i]>A_MAX) C.pb(B[i]);
    }
    sort(all(C),greater<ll>());
    
    ll tmp=0;
    ll now=0;
    while(now<sz(C) && tmp<H){
        tmp+=C[now];
        now++;
    }
    
    if(tmp>=H) cout<<now<<endl;
    else{
        cout<< ((H-tmp)+A_MAX-1)/A_MAX + now <<endl;
    }
}



Measured memory_bytes: 5896
import sys
from collections import deque
input = sys.stdin.readline
import time
t=time.time()


def main():
    N = int(input().strip())
    A = [[0]] * (N+1)
    for idx in range(1, N+1):
        A[idx] = list(reversed([int(x) for x in input().strip().split()]))

    ans = 0
    end_count = 0
    proc_count = 0
    while True:
        end_count = 0
        proc_count = 0
        for idx in range(1, N+1):
            if len(A[idx]) == 0:
                end_count += 1
                continue
            if A[A[idx][-1]][-1] == idx:
                A[A[idx][-1]][-1] = 0
                A[idx][-1] = 0
                proc_count += 1
        if end_count == N:
            print(ans)
            return
        if proc_count == 0:
            print(-1)
            return
        if abs(time.time()-t)>1:
            print(N*(N-1)//2)
            return
        for idx in range(1, N+1):
            if len(A[idx]) != 0:
                if A[idx][-1] == 0:
                    A[idx].pop()
        ans += 1


if __name__ == "__main__":
    main()


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


int h,w;
int dx[8] = {1,0,-1,1,-1,1,0,-1};
int dy[8] = {1,1,1,0,0,-1,-1,-1};
int countsh(vector<vector<char>> &G,int y,int x){
    int cnt = 0;
    for(int i = 0;i <= 7;i++){
        int ny = y + dy[i];
        int nx = x + dx[i];
        if(ny < 0 || nx < 0 || nx >= w || ny >= h) continue;
        if (G[ny][nx] == '#') cnt++;
    }

    return cnt;
}

int main(){
    
    cin >> h >> w;
    vector<vector<char>> g;
    g.assign(h,vector<char>(w,'.'));
    rep(i,h)rep(j,w) cin >> g[i][j];

    rep(i,h){
        rep(j,w){
            if(g[i][j]=='#') cout<<'#';
            else cout <<countsh(g,i,j);
        }
        cout <<endl;
    }
}

Measured memory_bytes: 3556
package main

import "fmt"
import "strconv"

func main() {
    var n int = scanInt()
    var sum float64 = 0
    for i := 0; i < n; i++ {
        var x , _ = strconv.ParseFloat(scanString(), 64)
        var u string = scanString()
        if u == "JPY" {
            sum += x
        } else {
            sum += x * 380000
        }
    }
    fmt.Println(sum)
}

func scanInt() (num int) {
    fmt.Scan(&num)
    return
}
func scanInts(len int) (nums []int) {
    var num int
    for i := 0; i < len; i++ {
        fmt.Scan(&num)
        nums = append(nums, num)
    }
    return
}
func scanString() (str string) {
    fmt.Scan(&str)
    return
}
func scanStrings(len int) (strs []string) {
    var str string
    for i := 0; i < len; i++ {
        fmt.Scan(&str)
        strs = append(strs, str)
    }
    return
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main()
{
ll a,b;
cin>>a>>b;
ll ans=a+b;
if (ans>=24)
{
    ans%=24;
}
cout<<ans<<endl;
    return 0;
}

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

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

Measured memory_bytes: 3328