akhauriyash/Code-Regression huggingface dataset:
#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<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;


ll powmod(ll n,ll k, ll mod){
    ll ret=1;
    while(k){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}

int P;
map<int,int> mp;
ll solve(){
    int n;
    cin>>n;
    ll a[n];
    rep(i,n)cin>>a[i];
    ll x;
    cin>>x;
    ll res=1;
    for(auto q : mp){
        int p=q.first, m=q.second;
        ll tmp=P-1;
        int mi=m;
        rep(i,m){
            tmp/=p;
            rep(j,n){
                if(powmod(a[j],tmp,P)!=1)mi=min(i,mi);
            }
        }
        res*=powmod(p,mi,P);
    }
    ll ret=(P-1)/res;
    if(powmod(x,ret,P)==1){
        return 1;
    }
    else return 0;
}

int main(){
    ll t;
    cin>>P>>t;
    ll tmp=P-1;
    REP(i,2,1000000){
        if(tmp%i==0){
            while(tmp%i==0){
                mp[i]++;
                tmp/=i;
            }
        }
    }
    if(tmp>1)mp[tmp]++;
    rep(i,t){
        cout<<solve()<<endl;
    }
    return 0;
}


Measured memory_bytes: 3860
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpll vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
lld p1=1e9 + 7,p2=998244353;

void judge(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    
}

void fastio(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

// lld fac[5005]; 

// void getfac(lld p)
// {
//     fac[0] = 1; 
//     for (lld i=1 ; i<=5005; i++) 
//         fac[i] = fac[i-1]*i%p; 
// }    

// long long int nCrmodp(lld n, lld r,lld p) 
// { 
//    // Base case 
//    if (r==0) 
//       return 1; 
     
//     return (fac[n]* modInverse(fac[r], p) % p * 
//             modInverse(fac[n-r], p) % p) % p; 
// }


lld l,r,mid,ans=0;
lld n,i,j,k,g,m;
lld x,y,n1,n2,h,z,c;
lld aa=1;

lld ss=1;

void solve()
{ 
    cin>>n;
    if(n==1)
    {
        cout<<0;
        return ;
    }
    ans =0;
    x=01;
    for(i=0;i<n;i++)
    {
        x*=10;
        x%=p1;
    }
    ans=x;
    x=01;
    for(i=0;i<n;i++)
    {
        x*=9;
        x%=p1;
    }
    ans-=2*x;
    ans%=p1;
    ans+=p1;
    ans%=p1;
    x=01;
    for(i=0;i<n;i++)
    {
        x*=8;
        x%=p1;
    }
    ans+=x;
    ans%=p1;
    cout<<ans;
}

int main()
{
    // judge();
    fastio();
    lld t=1;
    // cin>>t;
    // lld p1 = 1e9 + 7;
    // getfac(p1);
    for(int i=0;i<t;i++)
    {
        // cout<<"Case #"<<i+1<<": ";
        solve();
        cout<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#include <sstream>
#include <set>
#include <queue>
#include <tuple>

using namespace std;

#define For(i,a,n)	for(int i = a;i < n;i++)
#define rep(i,n)	For(i,0,n)
#define clr(n)		memset(n,0,sizeof n)
#define all(n)		(n).begin(),(n).end()

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

const ll INF = 1e9;
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
bool cheak(int x, int y, int mx, int my){
	return x >= 0 && y >= 0 && x < mx &&  y < my;
}
int main()
{
	int n, m, s, g1, g2;
	while (cin >> n >> m >> s >> g1 >> g2 && n){
		ll d[301][301];
		rep(i, 301)rep(j, 301)d[i][j] = (i == j ? 0 : INF);
		
		rep(i, m){
			int b1, b2, c;
			cin >> b1 >> b2 >> c;
			d[b1][b2] = c;
		}

		For(k,1, n+1)For(i,1, n+1)For(j,1, n+1){
			d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
		}

		ll ans = INF;
		For(k, 1, n + 1){
			ans = min(ans, d[s][k] + d[k][g1] + d[k][g2]);
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1864
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	if(s=="ABC") cout<<"ARC\n";
	else cout<<"ABC\n";
	return 0;
}

Measured memory_bytes: 3652
main :: IO ()
main = do
    n <- readLn :: IO Int
    as1 <- sum' <$> getInts
    as2 <- reverse . sum' . reverse <$> getInts
--    print as1
--    print as2
    print $ solve n as1 as2

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve n as1 as2 = maximum $
                  flip map [0..n - 1] $ \i ->
                                         as1 !! i + as2 !! i

sum' = scanl1 (+)


Measured memory_bytes: 1020
#include <iostream>
#include <vector>
using namespace std;
long long N, ans;

void dfs(long long x, int use) {
    if (x > N) return;
    if (use == 0b111) ans++;
    dfs(x * 10 + 7, use | 0b100);
    dfs(x * 10 + 5, use | 0b010);
    dfs(x * 10 + 3, use | 0b001);
}

int main() {
    cin >> N;
    dfs(0, 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>

using namespace std;


int main() {
	int i, j, k;
	int n, a, b;

	cin >> n >> a >> b;

	int asum = 0;
	for (i = 1; i <= n; i++) {
		string str = to_string(i);
		int sum = 0;
		for (j = 0; j < str.length(); j++) {
			sum += ((int)str[j]-48);
		}
		if (sum >= a && sum <= b) {
			asum += i;
		}
	}

	cout << asum << endl;







	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <sstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = (a); i < _a; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define PI (2 * acos((double)0))
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define epsilon 0.0000001
using namespace std;


int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int min = 100000, max = -1;
  REP(i, n) {
    int t;
    cin >> t;
    if (min > t) {
      min = t;
    }
    if (t > max) {
      max = t;
    }
  }
  cout << max - min << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN
    
    int h, w, i, j;
    while (cin >> h >> w, h or w) {
        for (i = 0; i < h; i++) {
            for (j = 0; j < w; j++) {
                if ((i + j) % 2) cout << ".";
                else cout << "#";
            }
            cout << "\n";
        }
        cout << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;

using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}

int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	vector<int> data(N);
	for (int i = 0; i < N; i++)
	{
		int z;
		cin >> z;
		data[i] = z - 1;
	}
	int cnt = 0;
	int now = 0;
	int ans = 0;
	int i = 0;
	for(;;)
	{
		
		
	
		
		if (now == 1)
		{
			ans = i;
			break;
		}
		if (i >= N)
		{
			ans = -1;
			break;
		}
		i++;
		now = data[now];
	}
	cout << ans << endl;
	

	return 0;

}



Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<string>
#include<map>
#include<queue>

using namespace std;

int main(void){

    int n; cin >> n;
    vector<int> a(n);

    for(int i = 0;i < n;i++) cin >> a[i];

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

    cout << abs(a[0] - a[a.size()-1]) << endl;

    return 0;
}

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

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

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

  int n, i;
  cin >> n >> i;

  cout << n - i + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

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

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
    int a;cin>>a;
    cout<<(a<1200?"ABC":"ARC");
}



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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

vvint G;
vint ans;
int cnt = 0;
	
void Main() {
	int N, M; cin >> N >> M;
	G = vvint(N);
	ans = vint(N);
	vint mc(N, -1);
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	queue<int> que;
	que.push(0);
	mc[0] = 0;
	while (!que.empty()) {
		int u = que.front(); que.pop();
		for (auto &v : G[u]) {
			if (mc[v] == -1) {
				mc[v] = mc[u] + 1;
				ans[v] = u;
				que.push(v);
			}
		}
	}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 10648
N, K = map(int, input().split(" "))
As = list(map(int, input().split(" ")))

left_under_nums = [0 for i in range(N)]
right_under_nums = [0 for i in range(N)]

for i in range(N):
    for j in range(i+1, N):
        if As[i] > As[j]:
            if j < i: # left
                left_under_nums[i] += 1
            elif j > i: # right
                right_under_nums[i] += 1
        elif As[j] > As[i]:
            if i < j: # left
                left_under_nums[j] += 1
            elif i > j: # right
                right_under_nums[j] += 1

#print(left_under_nums)
#print(right_under_nums)

M = 10 ** 9 + 7

out = 0
keisu = (K)*(K-1) // 2
for i in range(N):
    all_num = left_under_nums[i] + right_under_nums[i]
    out += (right_under_nums[i] * K)
    out = out % M
    out += ( all_num * keisu )
    out = out % M

print(out)

Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>

char str[100001];

int main(void){
	register int i,len,ans=0,p=0;
	scanf("%s",str);
	for(i=0,len=strlen(str);i<len;++i)
		if(str[i]=='g')
			if(p>0)
				++ans,--p;
			else
				++p;
		else
			if(p>0)
				--p;
			else
				++p,--ans;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,dp[3005][3005],pref[3005][3005];
string s;

void add(int &a , int b){
	a += b;
	while(a >= 1000000007){
		a -= 1000000007;
	}
	while(a < 0){
		a += 1000000007;
	}
}

int main(){
	cin >> n >> s;
	for(int i = 0 ; i < n ; i += 1){
		dp[0][i] = 1;
	}
	for(int i = 0 ; i < n ; i += 1){
		if(s[i] == '<'){
			for(int k = 0 ; k <= n ; k += 1){
				if(k){
					add(pref[i][k],pref[i][k-1]);
				}
				add(dp[i][k],pref[i][k]);
				add(pref[i+1][0],dp[i][k]);
				add(pref[i+1][k],-dp[i][k]);
			}
		}else{
			for(int k = 0 ; k <= n ; k += 1){
				if(k){
					add(pref[i][k],pref[i][k-1]);
				}
				add(dp[i][k],pref[i][k]);
				add(pref[i+1][k],dp[i][k]);
				add(pref[i+1][n-i-1],-dp[i][k]);
			}
		}
	}
	cout << dp[n-1][0] << endl;
}

Measured memory_bytes: 70784
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

using PI = P<int, P<int, int> >;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r, c, k; cin >> r >> c >> k;
    V<PI> rcv(k);
    for (int i = 0; i < k; i++) {
        cin >> rcv[i].first >> rcv[i].second.first >> rcv[i].second.second;
        rcv[i].first--, rcv[i].second.first--;
    }
    sort(ALL(rcv), [&](PI i, PI j) {
        if (i.first == j.first) return i.second.first < j.second.first;
        return i.first < j.first;
    });

    vvll dp(4, vll(c, 0));
    int rcvi = 0;
    for (int i = 0; i < r; i++) {
        vvll ndp(4, vll(c, 0));
        for (int j = 0; j < c; j++) {
            if (j == 0) {
                ndp[0][0] = max({dp[0][0], dp[1][0], dp[2][0], dp[3][0]});
                if (rcv[rcvi].first == i && rcv[rcvi].second.first == j) {
                    PI rrr = rcv[rcvi]; rcvi++;
                    ndp[1][0] = ndp[0][0] + rrr.second.second;
                }
            } else {
                ndp[0][j] = max({dp[0][j], dp[1][j], dp[2][j], dp[3][j]});
                for (int ii = 0; ii < 4; ii++) chmax(ndp[ii][j], ndp[ii][j - 1]);

                if (rcv[rcvi].first == i && rcv[rcvi].second.first == j) {
                    PI rrr = rcv[rcvi]; rcvi++;
                    for (int ii = 2; ii >= 0; ii--) {
                        chmax(ndp[ii + 1][j], ndp[ii][j] + rrr.second.second);
                    }
                }
            }
        }
        // for (int j = 0; j < 4; j++) {
        //     cerr << "i j: " << i << ' ' << j << '\n';
        //     DEBUG_VLL(ndp[j])
        // }
        dp = ndp;
    }
    cout << max({dp[0].back(), dp[1].back(), dp[2].back(), dp[3].back()}) << '\n';
    return 0;
}


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

const int MOD = 1e9+7;
ll dp[1100100], sum[1100100];

int main(){
    ll n; cin >> n;
    dp[0] = 1; dp[1] = 1;
    sum[0] = 0; sum[1] = 1; sum[2] = 2;
    for (ll i = 2; i < n; i++){
        dp[i] = (dp[i-1] + sum[i-2]) % MOD;
        sum[i+1] = sum[i] + dp[i];
    }
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        if (i <= n-3) ans += dp[i] * ( (n-1)*(n-1) % MOD + i+2 ) % MOD;
        else if (i == n-2) ans += dp[i] * ( (n-1)*n % MOD ) % MOD;
        else if (i == n-1) ans += dp[i] * n % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);
typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

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

int main()
{
    ll n,m,l;
    cin >> n >> m >> l;
    vvll d1(n, vll(n));
    rep(i,n)rep(j,n){
        if(i == j)d1[i][j] = 0;
        else d1[i][j] = INF;
    }
    rep(i,m){
        ll a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        d1[a][b] = c;
        d1[b][a] = c;
    }

    //Washa
    rep(k,n)rep(i,n)rep(j,n)d1[i][j] = min(d1[i][j], d1[i][k] + d1[k][j]);

    /*rep(i,n){
        rep(j,n)cout << d1[i][j] << " ";
        cout << endl;
    }*/

    vvll d2(n, vll(n));
    rep(i,n)rep(j,n){
        if(i == j)d2[i][j] = 0;
        else if(d1[i][j] <= l)d2[i][j] = 1;
        else d2[i][j] = INF;
    }

    //Washa
    rep(k,n)rep(i,n)rep(j,n)d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
    
    /*cout << endl;
    rep(i,n){
        rep(j,n)cout << d2[i][j] << " ";
        cout << endl;
    }*/

    ll q;   cin >> q;
    vll ans(q);
    rep(i,q){
        ll s,t;
        cin >> s >> t;
        s--; t--;
        ans[i] = (d2[s][t] != INF)?d2[s][t]: 0;
    }

    rep(i,q)cout << ans[i] - 1 << endl;

    return 0;
}

Measured memory_bytes: 2688
X, Y, A, B, C = 2, 2, 2, 2, 2
prr = [8, 6]
qrr = [9, 1]
krr = [2, 1]


X, Y, A, B, C = 2, 2, 4, 4, 4
prr = [11, 12, 13, 14]
qrr = [21, 22, 23, 24]
krr = [1, 2, 3, 4]


X, Y, A, B, C = 1, 2, 2, 2, 1
prr = [2, 4]
qrr = [5, 1]
krr = [3]


X, Y, A, B, C = map(int,input().split())
prr = list(map(int,input().split()))
qrr = list(map(int,input().split()))
krr = list(map(int,input().split()))

def calculate(x, y, a, b, c, prr, qrr, krr):
    prr = sorted(prr,key=lambda x:-x)
    qrr = sorted(qrr, key=lambda x: -x)

    prr = prr[:x]
    qrr = qrr[:y]

    result = []
    result.extend(prr)
    result.extend(qrr)
    result.extend(krr)

    result = sorted(result,key=lambda x:-x)

    result = result[:(x+y)]

    print(sum(result))

calculate(X, Y, A, B, C, prr, qrr, krr)


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

int main() {
	long long a,b,h[200001],tot;
	cin >> a >> b;
	for(int i = 0;i < a;i++){
		cin >> h[i];
	}
	sort(h,h+a);
	for(int i = 0;i < a-b;i++){
		tot+=h[i];
	}
	cout << tot << '\n';
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
using namespace std;
int main(void){
    int Q[3][6]={{}};
    int J=0;
    
    for(int i=0;i<6;i=i+1){
        cin >> Q[1][i];
        Q[0][i]=Q[1][i];
    }
    for(int i=0;i<6;i=i+1){
        cin >> Q[2][i];
    }
    
    for(int j=0;j<9;j=j+1){
        if(Q[1][0]==Q[2][0]&&Q[1][5]==Q[2][5]){
            for(int k=0;k<6;k=k+1){
                if(Q[1][1]==Q[2][1]&&Q[1][2]==Q[2][2]&&Q[1][3]==Q[2][3]&&Q[1][4]==Q[2][4]){
                    J=7;
                }else{
                    Q[0][1]=Q[1][2];Q[0][2]=Q[1][4];Q[0][4]=Q[1][3];Q[0][3]=Q[1][1];
                    Q[1][1]=Q[0][1];Q[1][2]=Q[0][2];Q[1][3]=Q[0][3];Q[1][4]=Q[0][4];
                }
            }
        }else if(j!=2){
                Q[0][0]=Q[1][1];Q[0][1]=Q[1][5];Q[0][5]=Q[1][4];Q[0][4]=Q[1][0];
                Q[1][0]=Q[0][0];Q[1][1]=Q[0][1];Q[1][4]=Q[0][4];Q[1][5]=Q[0][5];
        }else{
                Q[0][0]=Q[1][3];Q[0][2]=Q[1][0];Q[0][3]=Q[1][5];Q[0][5]=Q[1][2];
                Q[1][0]=Q[0][0];Q[1][3]=Q[0][3];Q[1][2]=Q[0][2];Q[1][5]=Q[0][5];
        }
    }
    
    if(J==7){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

const int N = 101;

int n, m, k;
int ans[N][N], ile[N * N];

int main()
{
    _upgrade
    cin >> n >> m >> k;
    for(int i = 1; i <= k; i++)
        cin >> ile[i];
    int c = 1;
    for(int i = 0; i < n; i++)
    {
        if(!(i & 1))
        {
            for(int j = 0; j < m; j++)
            {
                ans[i][j] = c;
                ile[c]--;
                if(ile[c] == 0) c++;
            }
        }
        else
        {
            for(int j = m - 1; j + 1; j--)
            {
                ans[i][j] = c;
                ile[c]--;
                if(ile[c] == 0) c++;
            }
        }
    }
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cout << ans[i][j] << (j < m - 1 ? " " : "\n");
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int ans=0;
string n;
int main()
{
 		cin>>n;
	for(int i=0;i<3;i++)
	{
		if(n[i]=='1') ans++;
	}
		 cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef pair<int, int> PI;
typedef vector<PI> VPI;

struct Edge {
  int to, a, b;
  Edge(int to, int a, int b) : to(to), a(a), b(b) {}
};
struct State {
  int city;
  ll time;
  int poses;
  State(int city, ll time, int poses) : city(city), time(time), poses(poses) {}
  bool operator<(const State &s) const { return time > s.time; }
};

vector<vector<Edge>> g;
VPI exc;
const int MAXS = 2505;
const ll INF = 1e16;

priority_queue<State> q;
vector<vector<ll>> dist;
void push(int city, ll time, int poses) {
  if (poses < 0) {
    return;
  }
  if (dist.at(city).at(poses) <= time) {
    return;
  }
  dist.at(city).at(poses) = time;
  q.emplace(city, time, poses);
}

int main() {
  int n, m, s;
  cin >> n >> m >> s;
  s = min(s, MAXS - 1);

  g.resize(n);
  dist.resize(n);
  rep(i, n) {
    dist.at(i).resize(MAXS);
    fill(dist.at(i).begin(), dist.at(i).end(), INF);
  }
  rep(i, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    g.at(u).push_back(Edge(v, a, b));
    g.at(v).push_back(Edge(u, a, b));
  }
  rep(i, n) {
    int c, d;
    cin >> c >> d;
    exc.emplace_back(c, d);
  }
  q.emplace(0, 0, s);
  while (!q.empty()) {
    State qtop = q.top();
    q.pop();
    int city = qtop.city;
    int poses = qtop.poses;
    ll time = qtop.time;
    push(city, time + exc.at(city).second,
         min(MAXS - 1, poses + exc.at(city).first));
    for (auto e : g.at(city)) {
      push(e.to, time + e.b, poses - e.a);
    }
  }
  for (int i = 1; i < n; i++) {
    ll ans = INF;
    rep(j, MAXS) { ans = min(dist.at(i).at(j), ans); }
    cout << ans << endl;
  }
}


Measured memory_bytes: 7300
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
  int N;
  cin >> N;
  long long int a[N];
  for(int n = 0; n < N; ++n){
    cin >> a[n];
  }

  int count = 0;
  for(int n = 0; n < N; ++n){
    while(true){
      if(a[n] % 2 == 0){
        ++count;
        a[n] = a[n] / 2;
      }else{
        break;
      };
    }
  }
  cout << count << endl;
  return 0;
}


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


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

ii d[MAXn];

string s;

ii mv(ii a,ll l,ll nxt)
{
  {
    ii tmp = {a.X - l,a.Y};
    if(abs(tmp.X) + abs(tmp.Y) <= nxt)
    {
      s += "R";
      return tmp;
    }
  }
  {
    ii tmp = {a.X + l,a.Y};
    if(abs(tmp.X) + abs(tmp.Y) <= nxt)
    {
      s += "L";
      return tmp;
    }
  }
  {
    ii tmp = {a.X,a.Y - l};
    if(abs(tmp.X) + abs(tmp.Y) <= nxt)
    {
      s += "U";
      return tmp;
    }
  }
  {
    ii tmp = {a.X,a.Y + l};
    if(abs(tmp.X) + abs(tmp.Y) <= nxt)
    {
      s += "D";
      return tmp;
    }
  }
  debug(a,l,nxt);
  assert(0);
}

const ll K = 31;

int main()
{
    IOS();
    ll n;
    cin>>n;
    REP(i,n)cin>>d[i].X>>d[i].Y;
    REP(i,n-1)if(abs(d[i].X + d[i].Y) % 2 != abs(d[i+1].X + d[i+1].Y) % 2){
      cout<<-1<<endl;
      return 0;
    }
    ll fg = (d[0].X + d[0].Y) % 2 == 0;
    if(fg)cout<<K+1<<endl;
    else cout<<K<<endl;
    REP(i,K)cout<<(1LL<<i)<<" ";
    if(fg)cout<<1<<endl;
    else cout<<endl;
    REP(q,n)
    {
      ii now = d[q];
      s = "";
      if(fg)now = mv(now,1,(1LL<<(K)) - 1LL);
      for(ll i = K - 1;i >= 0;i--)
      {
        if(i == 0)now = mv(now,1,0);
        else now = mv(now,(1LL<<i),(1LL<<(i)) - 1LL);
      }
      assert(now == ii(0,0));
      reverse(ALL(s));
      cout<<s<<endl;
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return rand()%x;
}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=2005,M=200005,mod=1000000007;
int n,dp[N<<1][N<<1],c[N<<2][N<<1],a[M],b[M],ans;
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read(); b[i]=read();
		dp[-a[i]+N][-b[i]+N]++;
	}
	for(int i=1;i<2*N;i++){
		for(int j=1;j<2*N;j++){
			dp[i][j]=(dp[i-1][j]+dp[i][j-1]+dp[i][j])%mod;
		}
	}
	for(int i=0;i<4*N;i++){
		c[i][0]=1;
		for(int j=1;j<2*N&&j<=i;j++)c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
	}
	for(int i=1;i<=n;i++){ans=(ans+dp[a[i]+N][b[i]+N])%mod; ans=(ans-c[a[i]*2+b[i]*2][a[i]*2])%mod;}
	cout<<((ll)ans*(mod+1)/2%mod+mod)%mod<<endl;
}
/*
10*3*4
*/

Measured memory_bytes: 189952
// {{{ include and macros
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(a, b) for(int unsafe_cnt=a; unsafe_cnt < b;unsafe_cnt++)
#include <iostream>
// #include <stdio.h>
// #include <vector>
// #include <math.h>
// #include <algorithm>
// #include <string>
// #include <map>
// #include <set>
using namespace std;
// }}}

// {{{ put
void newline() {cout << endl;}
template <typename T> void display(T input){cout << input;}
template <typename T> void put(T input){display(input); newline();}
// }}}

int get_num(const int start, const int ans){
  int sum = 0;
  for(int i=start; i!=ans&&sum<ans; i++){
    sum+=i;
  }
  return (sum == ans) ? 1 : 0;
}

int main() {
  int n;
  while(cin >> n && n){
    int sum = 0;
    for(int i=1; i<n; i++){
      sum += get_num(i, n);
    }
    put(sum);
  }
}

Measured memory_bytes: 3060
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner console = new Scanner(System.in);

		int N = console.nextInt();
		int K = console.nextInt();

		int[] steps = new int[N];
		int[] status = new int[K+1];

		for(int i = 0; i < N; ++i){
			steps[i] = console.nextInt();
			status[steps[i]] = 1;
		}

		for (int k = 1; k<= K; k++){
			status[k] = 0;

			for (int i = 0; i < N; i++){
				int kDash = k-steps[i];
				if(kDash >= 0 && status[kDash] == 0){
					status[k] = 1;
				}
			}

		}
		if(status[K]==1){
			System.out.println("First");
		}
		else{
			System.out.println("Second");
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int64_t n; cin >> n;
	int64_t ans = 0;
	if(n % 2 == 1) {
		cout << 0 << '\n';
		return 0;
	}
	for(int64_t i = 5; i <= n; i *= 5) {
		ans += n / i / 2;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define ll long long int 
const ll mo=1e9+7;
ll a[100005], re[100005];
 
int main(){
 ll i,j,k,n,m,t;
  cin>>n>>m;
  ll f=0,pre=-1;
  for(i=0;i<m;i++){
    cin>>k;
    if(k-pre==1){
     f=1; 
    }
    pre=k;
    a[k]=1;
  }
  if(f) cout<<"0\n";
  else {
    re[0]=1;
    if(!a[1]) re[1]=1;
    else re[1]=0;
   
    for(i=2;i<=n;i++){
      if(a[i]) continue;
      re[i]=0;
      if(!a[i-1]) re[i]+=re[i-1], re[i]%=mo;
      if(!a[i-2]) re[i]+=re[i-2],re[i]%=mo;
    }
    cout<<re[n]<<"\n";
  }
}

Measured memory_bytes: 1792
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,ans,push
    integer(int64), allocatable:: a(:),b(:)

    read*, n
    allocate(a(n),b(n))
    do i=1,n
        read*, a(i),b(i)
    end do

    ans=0
    do i=n,1,-1
        push = mod(b(i)-mod(a(i)+ans,b(i)),b(i))
        ans = ans + push
    end do
    print'(i0)', ans
end program name

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int main() {
  int Ri,W,C,R;
  while(1){
    cin>>Ri>>W>>C>>R;
    if(Ri==0&&W==0&&C==0&&R==0) break;
    if(C*W <= Ri){
      cout<<0<<endl;
    }else{
      cout<<((C*W-Ri)+(R-1))/R<<endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ll long long
#define int long long
#define ull unsigned long long
#define ld long double
#define sb __builtin_popcount
#define vi vector<int>
#define vc vector<char>
#define ii pair<int, int>
#define pq priority_queue<ii, vector<ii>, greater<ii>>
#define vii vector<ii>
#define sz(a) int((a).size())
#define f(a, b) for (int i = a; i < b; i++)
#define fr(a, b) for (int i = a - 1; i >= b; i--)
#define tr(x, m) for (auto x : m)
#define in(a, b) (b.find(a) != string::npos)
#define minin(a) *min_element(all(a))
#define maxin(a) *max_element(all(a))
#define X first
#define Y second
#define fill(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) reverse(v.begin(), v.end())
#define unq(v) v.erase(unique(all(v)), v.end())
#define el "\n"
#define mx3(a, b, c) max(max(a, b), c)
#define mn3(a, b, c) min(min(a, b), c)
#define S(v) accumulate(all(v), (ll)0)
#define SP(n) cout.precision(n)
const ld PI = atan(1.0) * 4.0;
#define MOD = 1e9 + 7;
void start() {
    fio;
    SP(10);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
    start();
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (s.size() > n) {
        cout << s.substr(0, n) << "...";
    }
    else cout << s;
    return 0;
}

Measured memory_bytes: 3640
n,k,q = map(int,input().split())
a = [int(input()) for _ in range(q)]
s = [k-q]*n

for i in range(q):
  s[a[i]-1] +=1

for i in range(n):
  if s[i] <=0:
    print('No')
  else:
    print('Yes')

Measured memory_bytes: 10448
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define MAX_V 1000

/*
 * O(FE)
 */

//rev: G[to][rev]で逆辺にアクセスできるようにしている
struct edge {ll to, cap, rev;};
vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, ll cap){
  G[from].push_back((edge){to, cap, (int)G[to].size()});
  G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}

//vからtに流せたフローの量を返す　fはvが保持しているフローの量
ll dfs(int v, int t, ll f){
  if(v == t) return f;
  used[v] = true;
  for(int i=0;i<G[v].size();i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      ll d = dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

ll max_flow(int s, int t){
  ll flow = 0;
  for(;;){
    memset(used,0,sizeof(used));//usedを0で初期化してるだけ
    ll f = dfs(s,t,LINF);
    if(f==0) return flow;
    flow += f;
  }
}

int main(void){
  int n,m;cin>>n>>m;
  rep(i,m){
    int a,b,c;cin>>a>>b>>c;
    add_edge(a,b,c);
  }
  cout<<max_flow(0,n-1)<<endl;
  return 0;
}


Measured memory_bytes: 3284
def dfs(num):
  global visited
  for next_num in edge[num]:
    if visited[next_num]:
      continue
    if has_edge[num][next_num]:
      visited[next_num]=1
      dfs(next_num)
      
N,M = map(int,input().split())
ab = []
edge = [[] for x in range(N+1)]
has_edge = [[0 for x in range(N+1)] for x in range(N+1)]
for i in range(M):
  a,b = map(int,input().split())
  ab.append([a,b])
  edge[a].append(b)
  edge[b].append(a)
  has_edge[a][b] = 1
  has_edge[b][a] = 1
  
count = 0
for a,b in ab:
  visited = [0 for x in range(N+1)]
  visited[1] = 1
  has_edge[a][b] = 0
  has_edge[b][a] = 0
  dfs(1)
  if sum(visited) != N:
    count += 1
  has_edge[a][b] = 1
  has_edge[b][a] = 1
print(count)

Measured memory_bytes: 3188
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
//---------------------------------------------
 
int main(void)
{
ll n;

cin>>n;

ll ans =0;
for(int i=1;i<=n;i++)
{
if(i%3!=0&&i%5!=0) ans+= i;

}


cout<<ans<<endl;

}

Measured memory_bytes: 3636
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] a = new int[M];
        int[] b = new int[M];
        int[] c = new int[M];
        for (int i = 0; i < M; ++i) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
            c[i] = sc.nextInt();
        }

        System.out.println(solve(N, a, b, c));

        sc.close();
    }

    static int solve(int N, int[] a, int[] b, int[] c) {
        int[][] distances = new int[N][N];
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                distances[i][j] = (i == j) ? 0 : Integer.MAX_VALUE;
            }
        }

        for (int i = 0; i < a.length; ++i) {
            distances[a[i]][b[i]] = c[i];
            distances[b[i]][a[i]] = c[i];
        }

        for (int k = 0; k < N; ++k) {
            for (int i = 0; i < N; ++i) {
                for (int j = 0; j < N; ++j) {
                    if (distances[i][k] != Integer.MAX_VALUE && distances[k][j] != Integer.MAX_VALUE) {
                        distances[i][j] = Math.min(distances[i][j], distances[i][k] + distances[k][j]);
                    }
                }
            }
        }

        return (int) IntStream.range(0, a.length).filter(i -> c[i] > distances[a[i]][b[i]]).count();
    }
}

Measured memory_bytes: 29172
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <cassert>
using namespace std;
using VI = vector<long>;

class RangeIka {
    const int ST_SIZE = (1 << 20) - 1;
    int n;
    VI data;
    vector<VI> segtree;
    
    void init(int k, int l, int r) {
        if (r - l == 1) {
            segtree[k].push_back(data[l]);
        } else {
            int lch = k * 2 + 1;
            int rch = k * 2 + 2;
            init(lch, l, (l + r) / 2);
            init(rch, (l + r) / 2, r);
            segtree[k].resize(r - l);
            
            merge(segtree[lch].begin(), segtree[lch].end(), segtree[rch].begin(), segtree[rch].end(), segtree[k].begin());
        }
    }
    
    // number of x in [i, j)
    int query(int i, int j, long x, int k, int l, int r) {
        if (j <= l || r <= i) {
            return 0;
        }
        
        if (i <= l && r <= j) {
            return upper_bound(segtree[k].begin(), segtree[k].end(), x) - segtree[k].begin();
        }
        
        int lc = query(i, j, x, k * 2 + 1, l, (l + r) / 2);
        int rc = query(i, j, x, k * 2 + 2, (l + r) / 2, r);
        return lc + rc;
    }
    
public:
    RangeIka(VI v) {
        n = v.size();
        data = VI(v);
        segtree = vector<VI>(ST_SIZE);
        init(0, 0, n);
    }
    
    int get(int i, int j, long x) {
        return query(i, j, x, 0, 0, n);
    }
};

int main() {
    long n, k;
    cin >> n >> k;
    VI as;
    for (int i = 0; i < n; i++) {
        long a;
        cin >> a;
        a -= k;
        as.push_back(a);
    }
    VI sum = {0};
    for (auto a: as) {
        sum.push_back(sum.back() + a);
    }
    
    long ans = 0;
    RangeIka r(sum);
    for (int i = 0; i < n; i++) {
        ans += r.get(i + 1, n + 1, 1e18) - r.get(i + 1, n + 1, sum[i] - 1);
    }
    
    cout << ans << endl;
}


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

int main(){
	/*input*/
	int n;	cin >> n;
	vector<long int>h(n);
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}
	/*calculation*/
	bool flag = true;	//true:Yes false:No
	for(int i = n - 1; i > 0 && flag; i--){
		if(h[i] >= h[i-1]){
			flag = true;
		}else{
			if(h[i] == h[i-1] - 1){
				h[i-1] -= 1;
			}else{
				flag = false;
			}
		}
	}
	/*output*/
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll N, C;
ll D[50][50];
ll c;
ll cnt[3][50];

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

	cin >> N >> C;

	memset(cnt,0,sizeof(cnt));

	for (int i = 1;i <= C;i++){
		for (int j = 1;j <= C;j++){
			cin >> D[i][j];
		}
	}

	for (int i = 1;i <= N;i++){
		for (int j = 1;j <= N;j++){
			cin >> c;
			cnt[(i+j)%3][c]++;
		}
	}

	ll ans = LLONG_MAX;

	for (int i = 1;i <= C;i++){
		for (int j = 1;j <= C;j++){
			for (int k = 1;k <= C;k++){
				if(i == j || j == k || k == i) continue;
				ll sum = 0;
				for (int l = 1;l <= C;l++){
					sum += cnt[0][l]*D[l][i] + cnt[1][l]*D[l][j] + cnt[2][l]*D[l][k];
				}	
				ans = min(ans,sum);
			}
		}
	}

	cout << ans << endl;

	/*

	vector<P> lis[3];

	for (int i = 0;i < 3;i++){
		for (int j = 1;j <= C;j++){
			ll sum = 0;
			for (int k = 1;k <= C;k++){
				sum += D[k][j]*cnt[i][k];
			}		
			lis[i].push_back(P(sum,j));
		}
		sort(lis[i].begin(),lis[i].end(), greater<P>());
	}

	ll ans = LLONG_MAX;

	for (int i = 0;i < C;i++){
		for (int j = 0;j < C;j++){
			for (int k = 0;k < C;k++){
				P p1 = lis[0][i], p2 = lis[1][j], p3 = lis[2][k];
				if(p1.second == p2.second || p2.second == p3.second || p3.second == p1.second) continue;
				ll s = p1.first+p2.first+p3.first;
				ans = min(ans,s);
			}
		}
	}

	cout << ans << endl;
	*/

	return 0;

}


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

int main()
{
  int n,a,b;
  vector<vector<int> > V;
  vector<int> G;
  bool map[50][50];
  while(1){
    cin>>n;
    if(n==0)break;
    V.clear();
    V.resize(n);
    for(int i=0;i<n;i++){
      cin>>a;
      for(int j=0;j<a;j++){
	cin>>b;
	V[i].push_back(b);
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i==j)map[i][j]=true;
	else map[i][j]=false;
      }
    }

    for(int k=1;k<31;k++){
      G.clear();
      for(int i=0;i<V.size();i++){
	for(int j=0;j<V[i].size();j++){
	  if(k==V[i][j]){
	    G.push_back(i);
	    break;
	  }
	}
      }

      for(int i=1;i<G.size();i++){
	for(int j=0;j<n;j++){
	  if(map[G[i]][j])map[G[0]][j]=true;
	}
      }
      for(int i=1;i<G.size();i++){
	for(int j=0;j<n;j++){
	  map[G[i]][j]=map[G[0]][j];
	}
      }
      bool flag=false;
      for(int i=0;i<n;i++){
	int sum=0;
	for(int j=0;j<n;j++){
          if(map[i][j])sum++;
	}
        if(sum==n){
	  cout<<k<<endl;
	  flag=true;
	  break;
	}
      }
      if(flag)break;
      if(k==30)cout<<"-1"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
using LL = long long;

int main(){
    LL N;
    cin >> N;
    LL T = 0, A = 0;
    for(int i = 0;i < N;i++){
        LL ti, ai;
        cin >> ti >> ai;
        if(T == 0 && A == 0){
            T = ti;
            A = ai;
            continue;
        }
        LL p = T/ti;
        if(T%ti != 0)   p++;
        if(ai*p >= A){
            T = ti*p;
            A = ai*p;
            continue;
        }
        LL p2 = A/ai;
        if(A%ai != 0)   p2++;
        T = ti*p2;
        A = ai*p2;
    }
    LL ans = T+A;
    cout << ans << endl;
}

Measured memory_bytes: 256
//1009
#include <stdio.h>

int main()
{
   int a, b, i, n;

   while (scanf("%d %d", &a, &b) != EOF) {
       n = 1;
       for (i = 2; i <= a; i++) {
           if (a % i == 0 && b % i == 0) {
        n = i;
        }
    }
    printf("%d\n", n);
   }
   return 0;
}

Measured memory_bytes: 0