akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

const int M = 13;

string s;
ll t = 1, ans;
ll dp[2][13];
int ho = 0, ge = 1;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    dp[ho][0] = 1;
    for (int i = (int)s.size()-1; i >= 0; i--) {
        rep(j,M) dp[ge][j] = 0;
        if (s[i] != '?') {
            int x = t*(s[i]-'0')%M;
            rep(j,M) {
                if (x == M) x -= M;
                dp[ge][x++] = dp[ho][j];
            }
        } else {
            int x = 0;
            rep(j,10) {
                int y = x;
                rep(k,M) {
                    if (y == M) y -= M;
                    dp[ge][y++] += dp[ho][k];
                }
                x += t;
                if (x >= M) x -= M;
            }
            rep(j,M) dp[ge][j] %= MOD;
        }
        t = t * 10 % M;
        swap(ho,ge);
    }
    cout << dp[ho][5] << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

class Z_algorithm {
public:
	void process(const char* str, int n) {
		v.resize(n);
		v[0] = n;
		int i = 1, j = 0;
		while (i < n) {
			while (i + j < n && str[j] == str[i + j]) ++j;
			v[i] = j;
			if (j == 0) { ++i; continue; }
			int k = 1;
			while (i + k < n && k + v[k] < j) v[i + k] = v[k], ++k;
			i += k; j -= k;
		}
	}
	void process(string S) {
		process(S.c_str(), S.length());
	}
	vector<int> v;
};

class Rolling_Hash {
public:
	Rolling_Hash() {
		v.clear();
	}
	void process(const char* str, int n, int width) {
		if (width > n) { return; }
		v.resize(n - width + 1);
		ll p1 = 0, p2 = 0;
		ll t1 = 1, t2 = 1;
		{
			ll k = width;
			ll d1 = digit1;
			ll d2 = digit2;
			while (k > 0) {
				if (k & 1) {
					t1 *= d1;
					t1 %= mod1;
					t2 *= d2;
					t2 %= mod2;
				}
				k /= 2;
				d1 = (d1 * d1) % mod1;
				d2 = (d2 * d2) % mod2;
			}
		}
		for (int i = 0; i < width; i++) {
			p1 *= digit1; p1 += str[i]; p1 %= mod1;
			p2 *= digit2; p2 += str[i]; p2 %= mod2;
		}
		int j = 0;
		v[j] = (p1 << 30) + p2; j++;
		for (int i = width; i < n; i++, j++) {
			p1 *= digit1; p1 += str[i] - str[i - width] * t1; p1 %= mod1;
			p2 *= digit2; p2 += str[i] - str[i - width] * t2; p2 %= mod2;
			if (p1 < 0) { p1 += mod1; }
			if (p2 < 0) { p2 += mod2; }
			v[j] = (p1 << 30) + p2;
		}
	}
	void process(string S, int width) {
		process(S.c_str(), S.length(), width);
	}

private:
	const ll digit1 = 10007LL;
	const ll digit2 = 10009LL;
	const ll mod1 = 1000000007LL;
	const ll mod2 = 1000000009LL;

public:
	vector<ll> v;
};

int main() {
	int N; string S;
	cin >> N >> S;
	Z_algorithm Z;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		Z.process(S.c_str() + i, N - i);
		for (int j = 1; j < N - i; j++) {
			ans = max(ans, min(j, Z.v[j]));
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))
    C = Counter(A)
    total = 0
    for x in C:
        total += C[x] * (C[x] - 1) // 2
    for a in A:
        ans = total - C[a] * (C[a] - 1) // 2 + (C[a] - 1) * (C[a] - 2) // 2
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 87756
n,w=map(int,input().split())
dp=[[0]*w for _ in range(n)]
for i in range(n):
  a,b=map(int,input().split())
  for j in range(w):
    if i==0:
      if j>a-2:dp[i][j]=b
    elif j>a-2:
      if j==a-1:dp[i][j]=max(b,dp[i-1][j])
      else:dp[i][j]=max(dp[i-1][j-a]+b,dp[i-1][j])
    else:dp[i][j]=dp[i-1][j]
print(dp[-1][-1])

Measured memory_bytes: 119660
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;


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

  ll A, B, C;
  cin >> A >> B >> C;


  cout << ((A+B+C==17 && min(min(A,B),C)==5 && max(max(A,B),C)==7) ? "YES" : "NO") << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int main() {
  int N;
  long long K;
  cin >> N >> K;

  map<int, long long> m;
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    m[a] += b;
  }

  for (const auto &p : m) {
    if (p.second >= K) {
      cout << p.first << endl;
      break;
    }
    K -= p.second;
  }
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    int x = x2, y = y2;
    int dx = x2 - x1, dy = y2 - y1;
    rep(i, 2){
        swap(dx, dy);
        dx = -dx;
        x += dx;
        y += dy;
        cout << x << " " << y << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))

L.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        cnt = 0
        for k in range(j+1, N):
            if L[i] + L[j] > L[k]:
                if L[i] != L[j] and L[j] != L[k] and L[k] != L[i]:
                    cnt += 1
        ans += cnt

print(ans)


Measured memory_bytes: 9184
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int len = s.length();
    for(int i = 0;i < len;i ++)
    {
        if(s[i] == 'C')
        {
            for(int k = i+1;k < len;k ++)
            if(s[k] == 'F')
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main() {
  ll s, w;
  cin >> s >> w;
  if (s <= w) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}

Measured memory_bytes: 3640
W, H, N = map(int, input().split())
R = [list(map(int, input().split())) for _ in range(N)]
X,Y = [0, W],[0, H]
for r in R:
  if r[2]==1:
    X[0] = max(X[0], r[0])
  elif r[2]==2:
    X[1] = min(X[1], r[0])
  elif r[2]==3:
    Y[0] = max(Y[0], r[1])
  else:
    Y[1] = min(Y[1], r[1])
print(max(0, (X[1]-X[0]))*max(0, (Y[1]-Y[0])))

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
long long xx5(long long i){
  return i * i * i * i * i;
}


int main(){
  long long x; cin >> x;
  long long a = 0,b = 0;
  for (a = -200; a <= 200; a++)
  {
    for (b = -200; b <= 200; b++)
    {
      if(xx5(a) - xx5(b) == x)
      goto OUT;
    }
    
  }
  OUT:
  cout << a << " "<< b << endl;
} 

Measured memory_bytes: 3588
# C
n, k = map(int, input().split())
count = 0
a = 0
for i in range(1,n+1):
    if i % k == 0:
        count += 1
    elif i % k == k // 2:
        a += 1
if k % 2 == 1:
    print(count**3)
else:
    print(count**3 + a**3)

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

int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
    }
  }

  for (int j = 0; j < w + 2; j++) {
    cout << "#";
  }
  cout << endl;
  for (int i = 0; i < h; i++) {
    cout << "#";
    for (int j = 0; j < w; j++) {
      cout << s[i][j];
    }
    cout << "#" << endl;
  }
  for (int j = 0; j < w + 2; j++) {
    cout << "#";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
//17
#include<iostream>
#include<algorithm>
#include<map>
#include<string>
#include<queue>
#include<vector>
#include<set>

using namespace std;

struct E{
  string t;
  int d;
};

struct S{
  string v;
  int r,d;
  bool operator<(S a)const{
    return d>a.d;
  }
};

int main(){
  for(int n,mm,cap;cin>>n>>mm>>cap,n|mm|cap;){
    cap*=10;
    string src,dest;
    cin>>src>>dest;
    map<string,vector<E> > m;
    for(int i=0;i<n;i++){
      string c[2];
      int d;
      cin>>c[0]>>c[1]>>d;
      for(int j=0;j<2;j++){
	E ce={c[j^1],d};
	m[c[j]].push_back(ce);
      }
    }
    set<string> gs;
    for(int i=0;i<mm;i++){
      string s;
      cin>>s;
      gs.insert(s);
    }
    priority_queue<S> que;
    S is={src,cap,0};
    que.push(is);
    map<string,map<int,int> > p;
    while(!que.empty()){
      S c=que.top();
      if(c.v==dest)break;
      que.pop();
      map<int,int>::iterator it=p[c.v].upper_bound(c.r-1);
      if(it!=p[c.v].end()&&it->second<=c.d)continue;
      p[c.v][c.r]=c.d;
      for(int i=0;i<m[c.v].size();i++){
	if(m[c.v][i].d<=c.r){
	  S n={m[c.v][i].t,c.r-m[c.v][i].d,c.d+m[c.v][i].d};
	  if(gs.count(n.v)){
	    n.r=cap;
	  }
	  que.push(n);
	}
      }
    }
    cout<<(que.empty()?-1:que.top().d)<<endl;
  }
  return 0;
}

Measured memory_bytes: 51188
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

long i;
long r1[100000];

int main() {
	long q, n;
	scanf("%d", &n);
	long t;
	long counts = 0;
	for (i = 0; i < n; ++i) {
		scanf("%d", &r1[i]);
	}

	scanf("%d", &q);
	for (int j = 0; j < q; ++j) {
		scanf("%d", &t);
		if (*lower_bound(r1, r1 + n, t) == t)
			counts++;
	}
	printf("%d\n", counts);
	return 0;
}


Measured memory_bytes: 3920
n = gets.to_i
arr = gets.split(' ').map!(&:to_i).sort!

min = arr.first
max = arr.last

point = (min + max) / 2

ans = Float::INFINITY
(min..max).each do |point|
  total = 0
  arr.each do |x|
    total += (x - point) ** 2
  end
  if total < ans
    ans = total
  end
end

puts ans


Measured memory_bytes: 1916
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#include <boost/multiprecision/cpp_int.hpp>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;
namespace mp = boost::multiprecision;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    int A[N],B[N];
    rep(i,N) cin >> A[i] >> B[i];
    mp::cpp_int ans=0; int pos=0;
    rep(i,N){
        ans+=(A[i]*B[i]+pos)/9;
        pos=(A[i]*B[i]+pos)%9;
        ans+=B[i];
    }
    if(pos==0 && ans!=0) ans--; 
    cout << ans-1  << endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    int a[n];
    for(int i=0; i<n; i++) {
    	scanf("%d", &a[i]);
    }
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for(int i=2; i<n; i++) {
    	dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
    }
    printf("%d\n", dp[n-1]);
    return 0;
}

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

using namespace std;

int k,t,i,j,a[105];

int main(){
	scanf("%d%d", &k, &t);
	for(i = 0; i < t; i++)
	scanf("%d", &a[i]);
	
	int res = 0;
	int last = -1;
	for(i = 0; i < k; i++){
		int mx = -1;
		int ind = -1;
		for(j = 0; j < t; j++){
			if(j == last || a[j] == 0) continue;
			if(a[j] > mx){
				mx = a[j];
				ind = j;
			}
		}
		
		if(mx == -1)
		res++;
		else{
			a[ind]--;
			last = ind;
		}
	}
	
	printf("%d\n", res);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(n);
// string p=s.substr(0,len);
// string q=s.insert(0,str);
// sort(arr, arr+n, greater<int>());
// cout<<fixed<<setprecision(9)<<pi<<endl
// const  double pi = acos(-1.0);
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	int x,y;
	cin>>x>>y;
	for(int i=0;i<=x;i++)
	{
		if((i*2)+(x-i)*4==y)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=100005;
int n,cnt;
vector <int> e[N];
int dis[N],fa[N];
int findfar(int x,int pre=0,int d=0){
	dis[x]=d,fa[x]=pre;
	int res=x;
	for (auto y : e[x])
		if (y!=pre){
			int z=findfar(y,x,d+1);
			if (dis[z]>dis[res])
				res=z;
		}
	return res;
}
vector <int> d,ans;
bool checkreverse(){
	vector <int> e=d;
	reverse(e.begin(),e.end());
	For(i,0,(int)d.size()-1)
		if (e[i]!=d[i])
			return e[i]<d[i];
	return 0;
}
int main(){
	n=read();
	For(i,1,n-1){
		int x=read(),y=read();
		e[x].pb(y),e[y].pb(x);
	}
	int x=findfar(1),y=findfar(x);
	for (int z=fa[y];z!=x;z=fa[z])
		d.pb(e[z].size()-2);
	if (checkreverse())
		reverse(d.begin(),d.end());
	ans.pb(cnt=1);
	for (auto i : d){
		For(j,cnt+2,cnt+i+1)
			ans.pb(j);
		ans.pb(cnt+1);
		cnt+=i+1;
	}
	ans.pb(n);
	if (ans.size()<n)
		puts("-1");
	else {
		for (auto i : ans)
			printf("%d ",i);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 14576
while True:
    x,y = map(int,input().split())
    if(x == 0): break

    n = int(input())
    kouji = [[False for i in range(x+1)] for j in range(y+1)]

    for i in range(n):
        xx,yy = map(int,input().split())
        kouji[yy][xx] = True
    dp = [[0 for i in range(x+1)] for j in range(y+1)]

    dp[1][1] = 1

    for i in range(1,y+1):
        for j in range(1,x+1):
            if (i == 1) and (j == 1) : continue
            if kouji[i][j] : 
                continue
            dp[i][j] = dp[i][j-1]+dp[i-1][j]

    print(dp[y][x])


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

bool ok(ll i) {
    string s = to_string(i);
    for (int j = 1; j < s.size(); j++) {
        if (abs(s[j] - s[j - 1]) > 1) {
            return false;
        }
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin >> k;
    ll lo = 0, hi = 4e9;
    while (hi - lo > 1) {
        ll mid = (hi + lo) / 2;
        string s = to_string(mid);
        vector<vector<vector<ll>>> dp(s.size(), vector<vector<ll>>(10, vector<ll>(2)));
        for (int i = 1; i < s[0] - '0'; i++) {
            dp[0][i][0] = 1;
        }
        dp[0][s[0] - '0'][1] = 1;
        for (int i = 0; i < s.size() - 1; i++) {
            for (int j = 0; j < 10; j++) {
                if (j) {
                    dp[i + 1][j - 1][0] += dp[i][j][0];
                }
                if (j != 9) {
                    dp[i + 1][j + 1][0] += dp[i][j][0];
                }
                dp[i + 1][j][0] += dp[i][j][0];
            }
            for (int j = 1; j < 10; j++) {
                dp[i + 1][j][0]++;
            }
            int j = s[i] - '0', k = s[i + 1] - '0';
            if (k > 1 + j) {
                dp[i + 1][j + 1][0] += dp[i][j][1];
                dp[i + 1][j][0] += dp[i][j][1];
                if (j) dp[i + 1][j - 1][0] += dp[i][j][1];
            } else if (k == 1 + j) {
                dp[i + 1][j + 1][1] += dp[i][j][1];
                dp[i + 1][j][0] += dp[i][j][1];
                if (j) dp[i + 1][j - 1][0] += dp[i][j][1];
            } else if (k == j) {
                dp[i + 1][j][1] += dp[i][j][1];
                if (j) dp[i + 1][j - 1][0] += dp[i][j][1];
            } else if (k == j - 1) {
                dp[i + 1][j - 1][1] += dp[i][j][1];
            }
        }
        ll sum = 0;
        for (int i = 0; i < 10; i++) {
            sum += dp[s.size() - 1][i][0] + dp[s.size() - 1][i][1];
        }
        if (mid == 31) {
            debug(dp);
        }
        if (sum >= k) {
            hi = mid;
        } else {
            lo = mid;
        }
    }
    cout << hi << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int a,b,c;

int main(){
	cin >>a >>b >>c;
  
	int tmp=b/a;
	cout << min(c,tmp)<<endl;
  	
  return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
template <class T> class Graph2 {
public:
	// ------ Basics ------ //
	static const T INF = numeric_limits<T>::max();
	int V, E; vector<vector<pair<int, T> > > G;
	Graph2() : V(0), E(0), G(vector<vector<pair<int, T> > >()) {}
	Graph2(int v) : V(v), E(0), G(vector<vector<pair<int, T> > >(v)) {}
	Graph2(vector<vector<pair<int, T> > > g) : V(g.size()), G(g) { for (int i = 0; i < g.size(); i++) E += g[i].size(); }
	int size() { return V; }
	void add1(int v1, int v2, T w) { G[v1].push_back(make_pair(v2, w)); E++; }
	void add2(int v1, int v2, T w) { add1(v1, v2, w); add1(v2, v1, w); }
	bool operator==(const Graph2& g) const { return G == g.G; }
	bool operator!=(const Graph2& g) const { return G != g.G; }
	vector<pair<int, T> > operator[](int x) { return G[x]; }

	// ------ Algorithms ------ //
	vector<T> dist(int s) {
		priority_queue<pair<T, int> > que; que.push(make_pair(0, s));
		vector<T> d(V, INF); d[s] = 0;
		while (!que.empty()) {
			pair<T, int> t = que.top(); que.pop();
			int u = t.second;
			for (int i = 0; i < G[u].size(); i++) {
				int v = G[u][i].first; T e = G[u][i].second;
				if (d[v] > d[u] + e) {
					d[v] = d[u] + e;
					que.push(make_pair(-d[v], v));
				}
			}
		}
		return d;
	}
	long long treediameter() {
		vector<int> v1 = dist(0);
		vector<int> v2 = dist(max_element(v1.begin(), v1.end()) - v1.begin());
		return *max_element(v2.begin(), v2.end());
	}
};
int V, s, t, w;
int main() {
	scanf("%d", &V);
	Graph2<int> G(V);
	for(int i = 0; i < V - 1; i++) {
		scanf("%d%d%d", &s, &t, &w);
		G.add2(s, t, w);
	}
	cout << G.treediameter() << endl;
}

Measured memory_bytes: 10072
#include <iostream>

using namespace std;
int main()
{
	int a, b;
	int e=1001;
	cin >> a >> b;
	for (int i = 0; i < a; i++) {
		int c, d;
		cin >> c >> d;
		if (c < e&&d <= b)e = c;
	}
	if (e == 1001)cout<<"TLE"<<endl;
	else {
		cout << e << endl;
	}
}

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

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

int main(void){

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

    roop(i, m){
        ans += a[i];
    }

    cout << (n >= ans ? n-ans : -1) << endl;

    return 0;
}


Measured memory_bytes: 7212
# ALDS_1_A.

def intinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def show(a):
    # 配列aの中身を出力する。
    _str = ""
    for i in range(len(a) - 1): _str += str(a[i]) + " "
    _str += str(a[len(a) - 1])
    print(_str)

def main():
    n = int(input())
    a = intinput()
    # a[0]から順に、挿入していく。
    for i in range(n):
        # a[i]を順次前の数とswapしていき、
        # 前の数の方が大きくなかったら止める。
        cur = i
        while cur > 0:
            if a[cur - 1] > a[cur]:
                a[cur - 1], a[cur] = a[cur], a[cur - 1]
            else: break
            cur -= 1
        show(a)

if __name__ == "__main__":
    main()

# Accepted.


Measured memory_bytes: 5604
/*
ABC165-C AC
https://atcoder.jp/contests/abc165/tasks/abc165_c
深さ優先探索 : 数列を生成する
*/

/*
概要
長さNの整数列を作る
使える整数は1からM
数列の要件は
1 <= A_1 <= A_2 ... A_N <= M

ちなみに完成した数列に一定規則で点数を与えて最大を取っている
*/

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

int N, M, Q;
vi a(50), b(50), c(50), d(50);

int score(vi &A){
  //配列Aの得点を返す
  int ans = 0;
  for(int i=0; i<Q; i++){
    if(A[b[i]]-A[a[i]]==c[i])ans+=d[i];
  }
  return ans;
}

void showv(vi &A){
  for(int x: A)cout<<x<<",";cout<<endl;
}

int dfs(){
  //最大ポイントを返す
  int ans = 0;
  vector<vi> uncalced;//発見したけど計算してない配列の情報

  uncalced.push_back({});
  //初期状態を空配列にすると、最初のステップで1桁放り込める

  while(!uncalced.empty()){
    vi current = uncalced.back();//積んである最後尾の配列を読む
    //showv(current);
    uncalced.pop_back();
    //いずれにせよcurrentについての操作はもうしないので捨てる
    if(current.size()==N){
      //showv(current);
      //N桁になってたら
      //ポイント求めて
      //最大値更新
      ans = max(ans, score(current));
    }else{
      //短かったら伸ばしたのを積む
      //last : 付け足しの最小値
      int last = (current.empty()? 1: current.back());
      
/*
ここ、uncalcedのemptyを判定条件にすると（間違い）、最後の{1}をひっぱた時にuncalced.empty()==trueになる。


DFS_revでは、for(int i=M; i>=last; i--){
なのでスタックに大きい方から入れていたから、最終盤に取り出すのは{4}である

このとき、last=4になるはずなのだが"uncalced.empty()==true"なのでlast=1になってしまう


*/


      //cout<<"last="<<last<<endl;
      //空になったところに0を積まれると0,0,0,...ができてしまう
      //空になってここの処理に来るのは一番最初{}を引っこ抜いたとき
      for(int i=last; i<=M; i++){
        //currentにiをくっつけて積む
        vi next = current;
        next.push_back(i);
        uncalced.push_back(next);
      }
    }
  }
  
  return ans;
}

int main(){
    cin>>N>>M>>Q;
  for(int i=0; i<Q; i++){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
    a[i]--;
    b[i]--;
  }

  int ans = dfs();

  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
const int N = 200003;
int n, ans, cnt;
char str[N];
int main(){
	scanf("%s", str + 1); n = strlen(str + 1);
	for(Rint i = 1;i <= n;i ++)
		if(str[i] == 'S'){
			++ cnt;
		} else if(str[i] == 'T' && cnt > 0) -- cnt, ++ ans;
	printf("%d", n - (ans << 1));
}

Measured memory_bytes: 384
S = input()
s = list(S)
def is_strong_palindrome(strings):
    a = len(strings)
    b = (len(strings) - 1) // 2
    c = (len(strings) + 3) // 2
    for h in range(a // 2):
        if strings[h] != strings[-h-1]:
            return False
    for i in range(b // 2):
        if strings[i] != strings[(b-i-1)]:
            return False
    for j in range(b // 2):
        if strings[c+j-1] != strings[a-j-1]:
            return False
    return True
if is_strong_palindrome(s) == True:
    print('Yes')
else:
    print('No')

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

int C(int n) {
   return (n * (n - 1)) / 2;
}
int main() {

   ios_base::sync_with_stdio(0);
   cin.tie(0);

   int n, m;
   cin >> n >> m;
   cout << C(n) + C(m) << endl;
   return 0;
}

Measured memory_bytes: 256
from fractions import gcd
MOD=10**9+7
def lcm(x,y):return x*y//gcd(x,y)
def inv(x):return pow(x,MOD-2,MOD)
def main():
  n,*a=map(int,open(0).read().split())
  L=1
  for i in a:L=lcm(L,i)
  L=L%MOD
  ans=0
  for i in a:ans=(ans+L*inv(i))%MOD  
  print(ans)
main()

Measured memory_bytes: 67672
#include<iostream>
#include<queue>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#include<string>// 加法 S.size() s.substr(l,r=s.size()-l) -> l文字目からr文字分
#include<cmath>//三角関数,rad
#include<algorithm>//__gcd()　lower_bound(a+l,a+r,x)-a でindex
// vector -> min/max({vector}) 
// 配列   -> *min_element(a+l,a+r)  *忘れず lとrで[l,r) 
//reverse(a+l,a+r)   配列aの[l,r)を逆順に strはreverse(S.begin(),S.end())
//sort(a+l,a+r,greater <int>()) 配列aの[l,r)昇順sort,大きい順はgreater<type>()
//vectorならv.begin(),v.end()
#include<ctime>//"clock()/CLOCKS_PER_SEC で秒数
#include<vector>//v.push_back(x),v.pop_back()
#include<queue>//q.push(x),front()で先頭を返す,pop()で削除, size(),empty()
#include<functional>//vector,queueと併用でpriority_queue
//宣言は priority_queue< Type, vector<Type>, greater<Type>> Q1; 
// pq.push(x),top()で参照 pop()で削除   greaterで最小 lessで最大がtopに
using namespace std;
typedef pair<int,int> P;
const int inf = 10e7;

int main(){

int n,qq,a,b;
cin>>n>>qq;
vector<vector<int>> edges(n);
vector<vector<int>> rank;
rep(z,n-1){cin>>a>>b;
edges.at(--a).emplace_back(--b);
edges.at(b).emplace_back(a);
}
vector<int> bb(1,0);
rank.emplace_back(bb);
vector<unsigned long long> cnter(n,0ull),res(n+1,0ull);
vector<int> par(n,-1);
queue<int> q;
par.at(0)=n;
q.push(0);
q.push(-1);vector<int> v;
while(!q.empty()){
  int a=q.front();q.pop();
  if (a==-1){
    if(v.empty())break;
    else{rank.emplace_back(v);q.push(-1);v={};}
    }
  else{
    for(int k:edges.at(a)){
      if (par.at(k)==-1){par.at(k)=a;v.emplace_back(k);q.push(k);}
    }}
}
rep(eem,qq){
  unsigned long long r,v;cin>>r>>v;cnter.at(--r)=cnter.at(r)+v;
}
res.at(0)=cnter.at(0);
for(vector<int> vv:rank){for (int jj:vv){res.at(jj)=res.at(par.at(jj))+cnter.at(jj);
                                        }}
rep(u,n-1){cout<<res.at(u)<<' ';}cout<<res.at(n-1)<<'\n';
//rep(i,n){cout<<cnter.at(i)<<'a';}
}

Measured memory_bytes: 28844
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<tuple>
#include<vector>
#include<map>
#include<numeric>
#include<limits>
#include<type_traits>
using namespace std;
static const int MAX_N = 100010;

int main(void){
  long long int N, A[MAX_N], B[MAX_N];
  long long int ans;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  for(int i = 0; i < N; i++){
    cin >> B[i];
  }
  long long int b_sum = 0, a_sum = 0;
  for(int i = 0; i < N; i++){
    a_sum += A[i];
    b_sum += B[i];
  }
  if(a_sum < b_sum){ans = -1;}
  else{
    ans = 0;//ansを初期化
    long long int diff[MAX_N];
    for(int i = 0; i < N; i++){
      diff[i] = A[i] - B[i];//目標まであと何点か？
    }
    long long int minus_sum = 0;
    for(int i = 0; i < N; i++){
      if(diff[i] < 0){
        minus_sum += diff[i];
        ans++;//マイナスの個数を数える
      }
    }
    sort(diff, diff + N, greater<long long int>());
    for(int i = 0; i < N; i++){
      if(minus_sum >= 0){break;}
      else{
        minus_sum += diff[i];
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<vector<ll>> v(N, vector<ll>(N, 0));
    for(int i=0; i<N; ++i) {
        for(int j=0; j<N; ++j) {
            cin >> v[i][j];
        }
    }
    ll ret = 0;
    for(int i=0; i<N; ++i) {
        for(int j=i+1; j<N; ++j) {
            ret += min(v[i][j], v[j][i]);
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 3236
N = int(input())
data = []
for _ in range(N):
    data.append(int(input()))

data_set = sorted(data, reverse=True)

max1, max2 = data_set[0], data_set[1]

for i in data:
    if i == max1:
        print(max2)
    else:
        print(max1)


Measured memory_bytes: 14112
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


ll T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while(cin >> n >> m){
        vi d(n);
        REP(i, n) cin >> d[i];
        ll ans = 0, c = 0;
        REP(i, n) {
            REP(j, i) {
                ans += (d[i] < d[j]);
                c += d[i] != d[j];
            }
        }
        cout << (m * (m - 1) / 2 % MOD * c % MOD + ans % MOD * m) % MOD << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int64_t modPow(int64_t a, int64_t n, int64_t p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  int64_t t = modPow(a, n / 2, p);
  return (t * t) % p;
}

int main(){
  int64_t N;
  int64_t M;
  int64_t K;
  vector<int64_t> A(200000,0);
  vector<int64_t> B(200000,0);
  vector<int64_t> MM(200000,0);
  cin >> N >> M >> K;
  MM.at(0)=M;
  A.at(0)=1;
  B.at(0)=1;
  for(int64_t i=1;i<N;i++){
    MM.at(i)=MM.at(i-1)*(M-1);
    MM.at(i)%=998244353;
    A.at(i)=A.at(i-1)*(N-i);
    A.at(i)%=998244353;
    B.at(i)=modPow(i,998244351,998244353)*B.at(i-1);
    B.at(i)%=998244353;
  }
  int64_t ans=0;
  for(int i=0;i<=K;i++){
    ans+=((MM.at(N-1-i)*A.at(i))%998244353)*B.at(i);
    ans%=998244353;
  }
  cout << ans << endl;
}

Measured memory_bytes: 7840
#include<bits/stdc++.h>
using ll = long long;
using  INT = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)

using namespace std;
/*........................................DEFINE FUNCTIONS.........................................*/
struct UnionFind {
	vector<int> d; //iが子ならd[i]は親のidでiが親ならd[i]は -サイズ
	UnionFind(int n): d(n, -1) {}
	int find(int x) {
		if (d.at(x) < 0)return x;//親なら自分自身の番号を返す
		else return d.at(x) = find(d.at(x)); //経路圧縮　メモ化
	}
	bool unite(int x, int y) { //voidでもいいが、くっつけられるか判定できた方が嬉しいときもある
		x = find(x); y = find(y); //根同士をくっつけるため
		if (x == y) return false;//統合できない(しない)
		//if (-d.at(x) < -d.at(y)) swap(x, y);
		d.at(x)+= d.at(y); //親のサイズの更新 サイズが大きい方に小さい方を統合
		d.at(y) = x;//yは親ではなくなったのでyの親をｘに設定
		return true;//統合できた
	}
	int size(int x) {return -d.at(find(x));}
	bool same(int x, int y) {return find(x) == find(y);}
};

/*....................................DEFINE GLOBAL VARIABLES .....................................*/



/*.........................................kemkemG0................................................*/
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int N, M, K;
	cin>>N>>M>>K;
	UnionFind uf(N);

	Graph AB(N), CD(N);
	REP(i, M) {
		int a, b;
		cin >> a >> b; a--; b--;
		uf.unite(a,b);

		AB.at(a).push_back(b);
		AB.at(b).push_back(a);
	}
	REP(i, K) {
		int c, d;
		cin >> c >> d; c--; d--;
		CD.at(c).push_back(d);
		CD.at(d).push_back(c);
	}

	REP(i,N){
		int num=uf.size(i);
		num-=(AB.at(i).size() + 1 );//直の友達と自分を引く
		for(auto b:CD.at(i)){
			if(uf.same(i,b))num--;
		}
		cout<<num<<" ";
	}
	cout<<endl;



	return 0;
}







Measured memory_bytes: 15704
#include <bits/stdc++.h>
#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 irep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<(a*b*c==175?"YES":"NO")<<endl;
}


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

vector< vector<int> > C;
int h,w;

void print_dist(vector<vector<int> > D)
{
  for (ll i = 1; i <= h; i++)
  {
    for (ll j = 1; j <= w; j++)
    {
      cout << D[i][j] << " ";
    }
    cout << endl;
  }
  
}

vector<vector<int> > dist_init(int a, int b)
{
  vector< vector<int> > D;
  vector<int> v;
  D.push_back(v);
  rep(w+2) D[0].push_back(INF);
  for (int i = 0; i < h; i++)
  {
    D.push_back(v);
    D[i+1].push_back(INF);
    for (int j = 0; j < w; j++)
    {
      if ( i==a && j == b ) D[i+1].push_back(0);
      else D[i+1].push_back(INF);
    }
    D[i+1].push_back(INF);
  }
  D.push_back(v);
  rep(w+2) D[h+1].push_back(INF);

  return D;
}

ll max_dist(int a, int b)
{
//  cout << "a = " << a << ", b = " << b << endl;
  vector< vector<int> > D = dist_init(a,b);

  int flag = 1;
  while ( flag == 1 )
  {
    flag = 0;
    for (ll i = 1; i <= h; i++)
    {
      for (ll j = 1; j <= w; j++)
      {
        if (C[i-1][j-1]==1) continue;
        int mini = D[i-1][j]+1;
        mini = min(mini,D[i][j-1]+1);
        mini = min(mini,D[i][j+1]+1);
        mini = min(mini,D[i+1][j]+1);

        if (mini < D[i][j])
        {
          flag = 1;
          D[i][j] = mini;
        }
      }      
    }
//    print_dist(D);
//    cout << endl;
  }

  int tmp = 0;
  for (ll i = 1; i <= h; i++)
  {
    for (ll j = 1; j <= w; j++)
    {
      if (C[i-1][j-1]==1) continue;
      tmp = max (tmp,D[i][j]);
    }
  }
//  cout << tmp << endl;
//  cout << "---------------" << endl;
  return tmp;
}

int main()
{
  cin >> h >> w;

  for (ll i = 0; i < h; i++)
  {
    vector<int> v;
    C.push_back(v);
    for (ll j = 0; j < w; j++)
    {
      char s;
      cin >> s;
      if ( s=='.' ) C[i].push_back(0);
      else C[i].push_back(1);
    } 
  }
  
  ll tmp = 0;

  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      if (C[i][j]==1) continue;
      tmp = max (tmp, max_dist(i,j));
    }
  }
  
  cout << tmp << endl;

  return 0;
}

Measured memory_bytes: 256
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
typedef long long ll;

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

const ll mod = 1000000007;
class BIT{
  vector<ll> bit;
public:
  BIT(int n) : bit(n + 1) {}
  void add(int idx, ll val){
    idx++;
    while(idx < (int)bit.size()){
      (bit[idx] += val) %= mod;
      idx += idx & -idx;
    }
  }
  ll sum(int i){
    ll s = 0;
    i++;
    while(i > 0){
      (s += bit[i]) %= mod;
      i -= i & -i;
    }
    return s;
  }

  void swap(BIT &other){
    bit.swap(other.bit);
  }
};


int main(){
  const int n = getInt();
  const int l = getInt();

  vector<int> x(n);
  vector<int> a(n);
  REP(i,n) x[i] = getInt();
  REP(i,n) a[i] = getInt();


  BIT dp(l + 1);
  dp.add(0, 1);

  REP(i,n){
    BIT next(l + 1);
    const int xx = x[i];
    const int aa = a[i];

    if(aa != 0){
      for(int p = xx; p < l; p += aa){
        next.add(p + 1, dp.sum(p));
      }
    }else{
      next.add(xx + 1, dp.sum(xx));
    }

    dp.swap(next);
  }

  printf("%d\n", (int)dp.sum(l));

  return 0;
}

Measured memory_bytes: 1152
/*QAQ三连：以前的题都补了吗，今天的题都做了吗，不会的算法都会了吗*/
/*金桔退役三连：退役选手不学不会不练*/
#include <bits/stdc++.h>
#define LDQ 1000000007
#define QAQ 0x3f3f3f3f
#define PI 3.14159265358979323846
using namespace std;
long long a[200001],b[200001],c[200001],d[200001],e[200001];
long long find(long long t[],long long x)
{
    if(t[x]==x)
    {
        return x;
    }
    else
    {
        return t[x]=find(t,t[x]);
    }
}
int main()
{
    long long x,y,i,n,k,l;
    scanf("%lld %lld %lld",&n,&k,&l);
    for(i=1;n>=i;i++)
    {
        a[i]=i;
        b[i]=i;
    }
    for(i=1;k>=i;i++)
    {
        scanf("%lld %lld",&x,&y);
        x=find(a,x);
        y=find(a,y);
        a[y]=x;
    }
    for(i=1;l>=i;i++)
    {
        scanf("%lld %lld",&x,&y);
        x=find(b,x);
        y=find(b,y);
        b[y]=x;
    }
    for(i=1;n>=i;i++)
    {
        c[i]=d[i]=find(a,i)+(n+1)*find(b,i);
    }
    sort(d+1,d+n+1);
    for(i=1;n>=i;i++)
    {
        x=lower_bound(d+1,d+n+1,c[i])-d;
        e[x]++;
    }
    for(i=1;n>=i;i++)
    {
        x=lower_bound(d+1,d+n+1,c[i])-d;
        if(i!=1)
        {
            printf(" ");
        }
        printf("%lld",e[x]);
    }
    return 0;
}


Measured memory_bytes: 8320
#include<stdio.h>
int main(void){
    int a,b,c,d,total,x,y;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        total=a+b+c+d;
        x=total/60,y=total%60;
        printf("%d\n%d\n",x,y);
    return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
const int ININF = 1000000;
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;
}

using Graph = vector<vector<int>>;
int N, M;
Graph G;
vector<int> color; //色（1or-1）
//二部グラフかの判定（連結の場合）
bool dfs(int v, int c) {
    color[v] = c;
    for(auto e : G[v]) {
        //隣接している頂点が同じ色なら即false;
        if(color[e] == c) {
            return false;
        }
        //隣接している頂点が塗られていないなら塗る。falseだったらfalse返す。
        if(color[e] == 0 && !dfs(e, -c)) {
            return false;
        }
    }
    return true;
}
int main() {
    cin >> N >> M;
    G.assign(N, vector<int>());
    color.assign(N, 0);
    rep(i, 0, M) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    //二部グラフかの判定（連結の場合）
    if(dfs(0, 1)) {
        int b = 0;
        int w = 0;
        rep(i, 0, N) {
            if(color[i] == 1) {
                b++;
            } else {
                w++;
            }
        }
        cout << 1LL * b * w - M << endl;
    } else {
        cout << 1LL * N * (N - 1) / 2 - M << endl;
    }
}


Measured memory_bytes: 6528
package main

import (
	"fmt"
)

func main() {

	var X int

	fmt.Scan(&X)


	sum:=0
	

		if X >=500{

		sum =(X/500)*1000

		X = X % 500
		}

		if X >= 5{

			sum += (X/5)*5
		}

		fmt.Println(sum)

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin>>k;
    long long ans=0;
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=k;j++)
        {
            for(int z=1;z<=k;z++)
            {
                int x=__gcd(i,j);
                ans+=__gcd(x,z);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3632
//*******************************************************************************
//       DoublyLinkedList                 
//*******************************************************************************
//     < ???????????? >
//       DoublyLinkedList ??????????????????
//       STL ??? list ????????¨??????????£??????????
//*******************************************************************************
#include <iostream>
using namespace  std;

struct StList
{
  int  m_nKey;
  StList *m_poPrev;
  StList *m_poNext;
  
  StList() :
    m_nKey(0), m_poPrev(nullptr), m_poNext(nullptr)
  { }

  StList(int nNum, StList &roHead) :
    m_nKey(nNum), m_poPrev(&roHead), m_poNext(roHead.m_poNext)
  { }

  ~StList() { }
};

void fnLinkedListSet(StList &roHead, StList &roTrail)
{
  char acCmd[80];
  int nMaxCmd, nNum;

  cin >> nMaxCmd;
  for (int i = 0; i < nMaxCmd; i++)
  {
    cin >> acCmd;
    if (acCmd[0] == 'i')
    {
      cin >> nNum;
      StList *poList = new StList(nNum, roHead);
      roHead.m_poNext->m_poPrev = poList;
      roHead.m_poNext = poList;
    }
    else if (acCmd[6] == 'F')
    {
      StList *poList = roHead.m_poNext;
      if (poList != &roTrail)
      {
        poList->m_poNext->m_poPrev = poList->m_poPrev;
        roHead.m_poNext          = poList->m_poNext;
        delete poList;
      }
    }
    else if (acCmd[6] == 'L')
    {
      StList *poList = roTrail.m_poPrev;
      if (poList != &roHead)
      {
        roTrail.m_poPrev         = poList->m_poPrev;
        poList->m_poPrev->m_poNext = poList->m_poNext;
        delete poList;
      }
    }
    else if (acCmd[0] == 'd')
    {
      cin >> nNum;
      StList *poList = roHead.m_poNext;
      while (poList != &roTrail)
      {
        if (poList->m_nKey == nNum)
        {
          poList->m_poNext->m_poPrev = poList->m_poPrev;     
          poList->m_poPrev->m_poNext = poList->m_poNext;
          delete poList;
          break;
        }
        poList = poList->m_poNext;
      }
    }
  }
}

void fnLinkedListGet(StList &roHead, StList &roTrail)
{
  StList *poList = roHead.m_poNext;
  while (poList != &roTrail)
  {
    if (poList != roHead.m_poNext) cout << " ";
    cout << poList->m_nKey;
    poList = poList->m_poNext;
    delete poList->m_poPrev;
  }
  cout << endl;
}

int main()
{
  StList oHead, oTrail;
  oHead.m_poNext  = &oTrail;
  oTrail.m_poPrev = &oHead;
 
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  fnLinkedListSet(oHead, oTrail);
  fnLinkedListGet(oHead, oTrail);

  return 0;
}

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

int n, m, q;
string s, t;
int suma[MAXN], sumb[MAXN];

bool read() {
    if (!(cin >> s >> t))
        return false;

    cin >> q;
    return true;
}

void solve() {
    n = sz(s);
    m = sz(t);

    forn (i, n)
        suma[i + 1] = suma[i] + (s[i] == 'A' ? 1 : 2);

    forn (j, m)
        sumb[j + 1] = sumb[j] + (t[j] == 'A' ? 1 : 2);

    while (q --> 0) {
        int l1, r1, l2, r2;
        cin >> l1 >> r1 >> l2 >> r2;

        if ((suma[r1] - suma[l1 - 1] - sumb[r2] + sumb[l2 - 1]) % 3 == 0)
            cout << "YES\n";
        else
            cout << "NO\n";
    }
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 5456
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
num=0
cnt=0
for i in range(n):
    if a[num]==2:
        cnt+=1
        print(cnt)
        break
    elif cnt==n-1:
        print("-1")
        break
    else:
        num=a[num]-1
        cnt+=1

Measured memory_bytes: 7084
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

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

    double sum = 0;
    for (int i = 0; i < N; ++i) {
        int a; cin >> a;
        sum += 1.0 / a;
    }

    cout << 1.0 / sum;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inputs = Console.ReadLine().Split(' ');
            int a, b, c, d;// e;
            a = int.Parse(inputs[0]);
            b = int.Parse(inputs[1]);
            c = int.Parse(inputs[2]);

            d = a - b;

            if(d >= c)
            {
                Console.WriteLine(0);
            }
            else
            {
                if(c - d >= 0)
                {
                    Console.WriteLine(c - d);
                }
                else
                {
                    Console.WriteLine(0);

                }
            }

        }
    }
}


Measured memory_bytes: 11092
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    vi a(n+1);
    for(int i = 0; i <= n; i++) cin >> a[i];
    ll ans = 0;
    vi b(n);
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n; i++){
        int x = min(a[i], b[i]);
        a[i] -= x;
        b[i] -= x;
        ans += x;
        x = min(a[i+1], b[i]);
        a[i+1] -= x;
        b[i] -= x;
        ans += x;
    }
    cout << ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define SANKOU(n, a, b) cout << ((n) ? (#a) : (#b)) << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
string S;
int s[201000];
int L;
int a, b;
void solve()
{
    int ans = 0;
    char A = 'A', B = 'B', C = 'C';
    L = (int)S.size();
    for (int i = L - 1; i >= 0; i--) {
        if (S[i] == A) {
            ans += b;
        } else if (i > 0 && S[i] == C && S[i - 1] == B) {
            b++;
            i--;
        } else {
            b = 0;
        }
    }
    cout << ans << endl;
}

signed main()
{
    cin >> S;
    solve();
    return 0;
}


Measured memory_bytes: 640