akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

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

using namespace std;
using lint=long long;

template<class T> struct edge{
	int to;
	T wt;
	edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

template<class T>
void add_undirected_edge(weighted_graph<T>& G,int u,int v,const T& wt){
	G[u].emplace_back(v,wt);
	G[v].emplace_back(u,wt);
}

template<class T>
vector<T> Dijkstra(const weighted_graph<T>& G,int s){
	constexpr T INF=numeric_limits<T>::max();
	int n=G.size();
	vector<T> d(n,INF); d[s]=0;
	priority_queue<pair<T,int>> Q; Q.emplace(0,s);
	while(!Q.empty()){
		T d0=-Q.top().first;
		int u=Q.top().second; Q.pop();
		if(d0>d[u]) continue;
		for(const auto& e:G[u]){
			int v=e.to;
			if(d[v]>d[u]+e.wt) d[v]=d[u]+e.wt, Q.emplace(-d[v],v);
		}
	}
	return d;
}

const long long INF=1LL<<61;

int main(){
	int n,m,s,t; scanf("%d%d%d%d",&n,&m,&s,&t); s--; t--;
	weighted_graph<lint> G1(n),G2(n);
	rep(i,m){
		int u,v;
		lint c1,c2; scanf("%d%d%lld%lld",&u,&v,&c1,&c2); u--; v--;
		add_undirected_edge(G1,u,v,c1);
		add_undirected_edge(G2,u,v,c2);
	}

	auto d1=Dijkstra(G1,s);
	auto d2=Dijkstra(G2,t);

	vector<lint> ans(n);
	lint mn=INF;
	for(int u=n-1;u>=0;u--){
		mn=min(mn,d1[u]+d2[u]);
		ans[u]=1000000000000000-mn;
	}
	rep(u,n) printf("%lld\n",ans[u]);

	return 0;
}


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

int N,L;

int main(){
	scanf("%d%d",&N,&L);
	int first=L,last=N+L-1,ans;
	ans=(first+last)*N/2;
	if(first>0){
		ans-=first;
	}
	if(last<0){
		ans-=last;
	}
	printf("%d\n",ans);
	return 0;
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    string S;
    cin >>S;
    S+='R';
    int N=S.size();
    vector<int> A(N,1);
    
    //-----------------------------------
    int Rz=0,Lz;
    bool isR=true;
    for(int i=1;i<N;i++){
        if(isR){
            if(S[i]=='L'){
                isR=false;
                Lz=i;
            }else{
                A[i+1]+=A[i-1];
                A[i-1]=0;
            }
        }else{
            if(S[i]=='R'){
                isR=true;
                Rz=i;
            }else{
                if(i%2==Lz%2){
                    A[Lz]+=A[i];
                }else{
                    A[Lz-1]+=A[i];
                }
                A[i]=0;
            }
        }
    }
    printf("%d",A[0]);
    repd(i,1,N-1){
        printf(" %d",A[i]);
    }

    return (0);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll S;cin>>S;
    if(S <= 1e9){
        cout << "0 0 1 0 0 " << S <<endl;
        return 0;
    }
    ll x1 = 1e9;
    ll y2 = (S + (x1 - 1)) / x1;
    ll y1 = 1;
    ll x2 = x1 * y2 - S;

    cout << "0 0 " << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
}


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

const int INF = 1000000000;

int main() {
    int H, W;
    while(cin >> H >> W, H | W) {
        int n = H * W;
        vector<vector<int>> A(n, vector<int>(n, INF));
        vector<int> heart;
        for(int i = 0; i < n; ++i) A[i][i] = 0;
        for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j) {
            int h;
            cin >> h;
            if(h) heart.push_back(i * W + j);
            for(bool d: {false, true}) {
                int y = i + (d ? 1 : 0);
                int x = j + (d ? 0 : 1);
                if(y < 0 || H <= y) continue;
                if(x < 0 || W <= x) continue;
                A[i * W + j][y * W + x] = A[y * W + x][i * W + j] = 1;
            }
        }

        for(int k = 0; k < n; ++k) for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j)
            A[i][j] = min(A[i][j], A[i][k] + A[k][j]);

        vector<vector<int>> OPT(1 << heart.size(), vector<int>(n, INF));

        for(int i = 0; i < heart.size(); ++i) for(int q = 0; q < n; ++q)
            OPT[1 << i][q] = A[heart[i]][q];

        for(int S = 1; S < (1 << heart.size()); ++S) {
            if(!(S & (S - 1))) continue;

            for(int p = 0; p < n; ++p) for(int E = 1; E < S; ++E)
                if(E | S == S) 
                    OPT[S][p] = min(OPT[S][p], OPT[E][p] + OPT[S ^ E][p]);

            for(int p = 0; p < n; ++p) for(int q = 0; q < n; ++q)
                    OPT[S][p] = min(OPT[S][p], OPT[S][q] + A[q][p]);
        }

        int answer = INF;
        for(int S = 1; S < (1 << heart.size()); ++S) for(int q = 0; q < n; ++q)
            answer = min(answer, OPT[S][q] + OPT[((1 << heart.size()) - 1) ^ S][q]);

        cout << max(0, n - (answer + 1)) << endl;
    }
}

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

int main(void) 
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll ans = max(b*d, a*c);
    ans = max(b*c, ans);
    ans = max(a*d, ans);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=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--)

int main(){
    string s;
    cin >> s;
    set<char> ss;

    for(int i = 0;i < s.size();i++){
        ss.insert(s.at(i));
    }

    if(ss.size() == s.size())
        cout << "yes" << endl;
    else
        cout << "no" << endl;
    
} 

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int l[100005],r[100005];

int main(){
  int n,m,ans=0,mx=0,mn=100001;
  cin >> n >> m;

  for(int i = 1;i<=m;i++){
    cin >> l[i] >> r[i];
    if(l[i]>mx)mx=l[i];
    if(r[i]<mn)mn=r[i];

  }
	if(mn-mx+1<0)cout << 0 <<endl;
  else cout << mn-mx+1<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

constexpr int inf = 1e9;
int n, m, x, c[20];
int a[20][20];

int u[20];
int rec(int d, int cum) {
	if (d < 0) {
		for (int i = 0; i < m; i++)
			if (u[i] < x)
				return inf;
		return cum;
	}
	int v = rec(d - 1, cum);
	for (int i = 0; i < m; i++)
		u[i] += a[d][i];
	int w = rec(d - 1, cum + c[d]);
	for (int i = 0; i < m; i++)
		u[i] -= a[d][i];
	return min(v, w);
}

int main() {
	scanf("%d %d %d", &n, &m, &x);
	for (int i = 0; i < n; i++) {
		scanf("%d", c + i);
		for (int j = 0; j < m; j++)
			scanf("%d", a[i] + j);
	}
	int r = rec(n - 1, 0);
	if (inf <= r)
		r = -1;
	printf("%d\n", r);
}


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

//还是越界，不知道问题出在了哪里 

//往回回溯的时候容易runtime error
//往前加的时候一定不会越界 
//就是一直往前减到了0 
using namespace std;
const int maxn=3005;
char s[maxn];
char t[maxn];
int len1,len2;
//动态规划要搞清楚这个二维数组的两个量表示的含义 
 //const int maxnn=1e5+5;
 int dp[maxn][maxn];
 
 //标记任意一个都是可以的 
 bool vis[maxn] ;
 
 void FindMax()
{
	for(int i=1;i<=len1;i++)
	{
		for(int j=1;j<=len2;j++)
		{
			if(s[i-1]==t[j-1])
			dp[i][j]=dp[i-1][j-1]+1; 
			else
			dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
		}	
	} 
}

void FindWhat(int i,int j)
{
	if(i&&j)
	{
		//cout<<"sadjkhkajshdf";
		/*if((i-1>=0)&&(j-1>=0)&&dp[i][j]==dp[i-1][j-1]+1)	
		//先判断再访问， 不然的话，先那个越界了 
		{
		//	cout<<"isdfs";
			vis[i-1]=1;
			FindWhat(i-1,j-1);
		}
		else if((i-1>=0)&&dp[i][j]==dp[i-1][j])
		{
			FindWhat(i-1,j);
		}
		else 
		if(dp[i][j]==dp[i][j-1]&&(j-1)>=0)
		{
			FindWhat(i,j-1);
		}*/
		
		
		if(s[i-1]==t[j-1])
		{
			vis[i-1]=1;
			i--,j--;
			FindWhat(i,j);
		}
		else
		{
			if(dp[i][j]==dp[i-1][j]) i--;
			else j--;
			FindWhat(i,j);
		}
		
	}
	return; 
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>s>>t;
	len1=strlen(s);
	len2=strlen(t);
	
	FindMax();
	
//	cout<<dp[len1][len2];
	
	FindWhat(len1,len2);
	
	int flag=0;
	
	for(int i=0;i<len1;i++)
	{
		if(vis[i]) 
		{
			flag=1;
			cout<<s[i];
		}
	}
	
	if(flag==0)
	cout<<" ";
	
	return 0;
 } 

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

int main()
{
    int w,n;
    cin >> w;
    cin >> n;
    int order[30]={0};
    int a,b,temp;
    for (int i=0; i<w; i++)
    {
	order[i]=i;
    }
    for (int i=0; i<n; i++)
    {
	scanf("%d,%d",&a,&b);
	temp=order[a-1];
	order[a-1]=order[b-1];
	order[b-1]=temp;
    }
    for (int i=0; i<w; i++)
    {
	cout << order[i]+1 << endl;
    }
    return 0;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  string ans;
  if (a < 1200) ans = "ABC";
  else if (a < 2800) ans = "ARC";
  else ans = "AGC";

  cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string N;
    cin >> N;
    bool f = false;
    REP(i, 3) {
        if (N[i] - '0' == 7) f = true;
    }

    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}


Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int, int>P;
typedef pair<int, pair<int, int>>PP;
typedef long long ll;
ll inf = 1e9;

int main() {
	vector<int>cnt(4, 0);
	vector<ll>v[4];
	int n, W;
	cin >> n >> W;
	ll w0,v0;
	cin >> w0 >> v0;
	v[0].push_back(v0);
	cnt[0]++;
	for (int i = 1; i < n; i++) {
		ll w,V;
		cin >> w>>V;
		cnt[w - w0]++;
		v[w - w0].push_back(V);
	}
	for (int i = 0; i < 4; i++) {
		sort(v[i].begin(), v[i].end(),greater<ll>());
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 1; j < v[i].size(); j++) {
			v[i][j] += v[i][j - 1];
		}
		v[i].insert(v[i].begin(), 0);
	}
	ll ans = 0;
	for (int i = 0; i <= cnt[0]; i++) {
		for (int j = 0; j <= cnt[1]; j++) {
			for (int k = 0; k <= cnt[2]; k++) {
				for (int l = 0; l <= cnt[3]; l++) {
					if (w0 * i + (w0 + 1) * j + (w0 + 2) * k + (w0 + 3) * l <= W) {
						ans = max(ans, v[0][i] + v[1][j] + v[2][k] + v[3][l]);
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
if n%2 == 1:
    l = 1
    r = n-1
    for i in range(m):
        print(l, r)
        l += 1
        r -= 1
else:
    l = 1
    r = n-1
    flag = False
    for i in range(m):
        if (not flag) and r-l <= n//2:
            r -= 1
            flag = True
        print(l, r)
        l += 1
        r -= 1


Measured memory_bytes: 9284
#include<bits/stdc++.h>
const unsigned int M = 1000000007; 
#define all(v) (v).begin(), (v).end()
#define rall(v) v.rbegin(),v.rend()
#define  pb push_back
#define mpp make_pair
#define int  long long
#define N 998244353
#define endl "\n"
#define fr(i,n) for(int i=0;i<n;i++)
int power(int x,int y){int res=1;while(y>0){if(y&1)res=x*res; y=y>>1;x=x*x;}return res;}
int power(int x,int y,int mod){int res=1;while(y>0){if(y&1)res=x*res%mod; y=y>>1;x=x*x%mod;}return res;}

using namespace std;


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

	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
}


#define F first
#define S second

 signed main()
{
//nik();

int t=1;
//cin>>t;

while(t--)
{	
	int n;
	cin>>n;
	int a[n][3];
	fr(i,n)fr(j,3)cin>>a[i][j];

	int dp[n][3]={0};
	

	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	
	for(int i=1;i<n;i++)
	{
		fr(j,3)
		{
			fr(k,3)
			{

				if(k==j)continue;
			
			
				dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
			
		}

		}
	}

	
	//for(int i:dp1)cout<<i<<" ";

	int x=max(dp[n-1][0],dp[n-1][1]);
	x=max(x,dp[n-1][2]);
	cout<<x<<endl;


}
 return 0;
}



Measured memory_bytes: 4992
#include<iostream>
#include<cassert>

using namespace std;

int calc(int a, int b, int ope){
  if(ope == 0) return b;
  if(ope == 1) return a+b;
  if(ope == 2) return a-b;
  if(ope == 3) return a*b;
}

int main(){

  string s;
  while(cin >> s){
    int R1,R2,R3;
    bool error = false;
    R1 = R2 = R3 = 0;
    assert(s[s.length()-1] == '=');
    for(int i = 0; i < (int)s.length(); i++){
      if('0' <= s[i] && s[i] <= '9'){
	R2 *= 10;
	R2 += s[i]-'0';
	if(R2 < 0 || R2 > 9999) error = true;
      }else{
        R1 = calc(R1, R2, R3);
	if(R1 < 0 || R1 > 9999) error = true;
	R2 = 0;
	if(s[i] == '+') R3 = 1;
	if(s[i] == '-') R3 = 2;
	if(s[i] == '*') R3 = 3;
      }
    }
    if(error) cout << "E" << endl;
    else cout << R1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1188
#include<stdio.h>
#include<math.h>
int main (void){
long long int n,t,a[200001],i,b;
scanf("%lld %lld",&n,&t);
for(i=1;i<=n;i++){
scanf("%lld",&a[i]);
}
b=0;
for(i=2;i<=n;i++){
if (a[i]-a[i-1]>=t) b=b+t;
if (a[i]-a[i-1]<t) b=b+a[i]-a[i-1];
}
b=b+t;
printf("%lld\n",b);
return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct UF
{
  vector<int> par;
  vector<int> sz;
  vector<int> rank;
  UF(int n):par(n),sz(n),rank(n){
    for(int i = 0; i < n; i++){
      par[i] = i;sz[i] = 1;rank[i] = 0;
    }
  }
  int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  void merge(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }
    else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y])rank[x]++;
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int n){return sz[find(n)];}
};
vi kaku(222222,-1);
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  UF uni(n);
  for(int i=0;i<m;i++){
    ll x,y,z;
    cin>>x>>y>>z;
    /*   z%=2;
    if(z == 0){
      
    }else{
    }
    */
    uni.merge(x-1,y-1);
  }
  ll ans = 0;
  for(int i=0;i<n;i++){
    if(uni.find(i) == i)
      ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>

using namespace std;

int main(void) {

    int N;
    cin >> N;

    int *array = new int[N];
    for (int i = 0; i < N; ++i) {
        cin >> array[i];
    }

    int total = 0;
    for (int i = 0, min; i < N; ++i) {
        min = i;
        for (int j = i; j < N; ++j) {
            if (array[j] < array[min]) {
                min = j;
            }
        }
        if (i == min) continue;
        int tmp = array[min];
        array[min] = array[i];
        array[i] = tmp;
        ++total;
    }

    for (int i = 0; i < N - 1; ++i) {
        printf("%d ", array[i]);
    }
    printf("%d\n", array[N - 1]);
    printf("%d\n", total);

    delete[] array;
    return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

#include <iostream>
using namespace std;
/*
1≤k≤n≤10^7
p は素数 (上の実装ではさらに p>n を仮定している)
*/

const int MAX = 510000;//階乗の配列数
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

ll d[100005];

int main(){
  int n, k;
  cin >> n >>k;
  ll ans=0;
  for(int i=k; i>=1; i--){
    ll num=modpow(k/i, n, mod);
    for(int j=2; j*i<=k; j++){
      num+=mod-d[i*j];
      num%=mod;
    }
    d[i]=num;
    ans+=i*d[i];
    ans%=mod;
  }
  cout << ans << endl;
  return 0;
}


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

const li mod = 1e9 + 7;

li pow(li x, li n) {
    if (n == 0) {
        return 1;
    }
    if (n == 1) {
        return x;
    }

    li sq = pow(x, n / 2);
    if (n & 1) {
        return sq * sq % mod * x % mod;
    }
    return sq * sq % mod;
}

li inv(li x) {
    return pow(x, mod - 2);
}

// https://oeis.org/A030528
// dp[i][j] = j - 1 choose (i - j + 1 ). sorry writers!

int main() {
    li n;
    cin >> n;

    vector<li> pow;
    pow.push_back(1);
    for (int i = 0; i < n + 10; ++i) {
        pow.push_back(pow.back() * (i + 1) % mod);
    }

    li ans = 0;
    li dpacc = 0;
    for (int j = 0; j < n; ++j) {
        li comb = (j >= n - j) ? (pow[j - 1] * inv(pow[n - j - 1]) % mod * inv(pow[2 * j - n] % mod)) : 0;
        li totptn = comb % mod * pow[j] % mod * pow[n - 1 - j] % mod;
        ans += (totptn - dpacc + mod) % mod * j % mod;
        ans %= mod;

        dpacc = totptn;
    }

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


Measured memory_bytes: 9836
for i in range(20001):
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=='?':
        break
    elif op=='+':
        print(a+b)
    elif op=='-':
        print(a-b)
    elif op=='*':
        print(a*b)
    elif op=='/':
        print(int(a/b))


Measured memory_bytes: 5592
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskD {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			List<Integer>[] adj = new List[n];
			for (int i = 0; i < n; i++) {
				adj[i] = new ArrayList<>();
			}
			for (int i = 0; i < n - 1; i++) {
				int a = in.nextInt() - 1;
				int b = in.nextInt() - 1;
				adj[a].add(b);
				adj[b].add(a);
			}
			int[] adjLeaves = new int[n];
			for (int i = 0; i < n; i++) {
				for (int j : adj[i]) {
					if (adj[j].size() == 1) {
						++adjLeaves[i];
					}
				}
				if (adjLeaves[i] >= 2) {
					out.println("First");
					return;
				}
			}
			int[] q = new int[n];
			int qt = 0;
			int qh = 0;
			boolean[] dead = new boolean[n];
			boolean[] leaf = new boolean[n];
			for (int i = 0; i < n; i++) {
				if (adj[i].size() == 1) {
					q[qh++] = i;
					leaf[i] = true;
				}
			}
			int[] deg = new int[n];
			for (int i = 0; i < n; i++) {
				deg[i] = adj[i].size();
			}
			int leaves = 0;
			while (qt < qh) {
				int v = q[qt++];
				int nv = -1;
				for (int u : adj[v]) {
					if (dead[u]) {
						continue;
					}
					if (nv >= 0) {
						throw new AssertionError();
					}
					nv = u;
				}
				if (nv < 0) {
					continue;
				}
				++leaves;
				for (int x : adj[nv]) {
					if (dead[x]) {
						continue;
					}
					--deg[x];
					if (deg[x] == 1) {
						leaf[x] = true;
						q[qh++] = x;
					}
				}
				dead[v] = true;
				dead[nv] = true;
			}
			if (2 * leaves != n) {
				out.println("First");
				return;
			}
			out.println("Second");
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

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

	}
}



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


using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 2e5 + 5;
bool isPrime[MAXN];



ll fastPow(ll x, ll b)
{
    if (b == 0)
        return 1;
    else if (!(b & 1))
    {
        return fastPow(x * x, b / 2);
    }
    else
        return x * fastPow(x * x, (b - 1) / 2);
}

//__builtin_popcount ();
bool isPrim(int n)
{
    if (n == 1 || n == 0)
        return false;
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
            return false;
    }
    return true;
}
int main()
{
    FAST
    string h;
    cin>>h;
    while(true){
        h.pop_back();
        h.pop_back();
        string h1=h.substr(0,h.size()/2);
        string h2=h.substr(h.size()/2);
        if(h1==h2)
            return cout<<h.size(),0;

    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const int MAX_N=2e5+3;


const unsigned long long B=1e12+7;


int main(){
    int N;cin>>N;
    vector<int>Ai,Aj;
    REP(i,N){
        int a;
        cin>>a;
        Ai.PB(a+i);
        Aj.PB(i-a);
    }
    SORT(Aj);
    LL res=0;
    REP(n,N){
        LL cnt=upper_bound(Aj.begin(), Aj.end(), Ai[n])-lower_bound(Aj.begin(), Aj.end(), Ai[n]);
        res+=cnt;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 5060
#include <bits/stdc++.h>
using namespace std;
int x;
int main()
{
	scanf("%d", &x);
	double now = x / 1.08;
	if ((int)((int)now * 1.08) == x)
		printf("%d", (int)now);
	else if ((int)(((int)now + 1) * 1.08) == x)
		printf("%d", (int)now + 1);
	else if ((int)(((int)now - 1) * 1.08) == x)
		printf("%d", (int)now - 1);
	else printf(":(");
	return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    n = int(input())
    tl, xl, yl = [], [], []
    for i in range(n):
        t, x, y = map(int, input().split())
        tl.append(t)
        xl.append(x)
        yl.append(y)

    prex, prey, pret = 0, 0, 0
    for t, x, y in zip(tl, xl, yl):
        sumxy = x + y - prex - prey
        sumt = t - pret
        prex, prey, pret = x, y, t
        if sumxy > sumt or sumt % 2 != sumxy % 2:
            print('No')
            exit()
    print('Yes')


Measured memory_bytes: 11808
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(v) (v).begin(),(v).end()
#define endl "\n"
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define SET(A,VAL) memset(A, VAL, sizeof(A))
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int MAX = 1e6+8;
const int sz = 1e5+5;
void f_io(){
    IOS;
    // #ifndef ONLINE_JUDGE
    // FRE
    // #endif
}

std::vector<pair<int,pii>> seg;
vi BIT;
void update(int at,int by){
    while (at < BIT.size()){
        BIT[at] += by;
        at += (at&(-at));
    }

}
void updateR(int l,int r, int val){
    update(l,val);
    update(r+1,-val);
}
int query(int at){
    int ret = 0;
    while (at > 0){
        ret += BIT[at];
        at -= (at&(-at));
    }
    return ret;
}
int n,m;
int32_t main(){
    f_io();
    int t = 1;
    //cin>>t;
    while(t--){
        cin >> n >> m;
        BIT.resize(m+1,0);
        rep(i,0,n){
            int a,b; cin >> a >> b;
            seg.pb({b-a+1,{a,b}});
        }
        sort(seg.begin(), seg.end());
        int idx = 0,base = n;
        rep(d,1,m+1){
            for(; idx < n; idx++){
                auto s = seg[idx];
                if(s.ff < d){
                    base--;
                    updateR(s.ss.ff,s.ss.ss, 1);
                }
                else break;
            }
            int fans = 0;
            for(int k = d;k < m+1; k += d){
                fans += query(k);
            }
            cout << fans + base << endl;
        }
    }
}

Measured memory_bytes: 15468
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> II;

const int N = (int) 1e5 + 10;
const int P = (int) 1e9 + 7;
int n, m, x[N], y[N];

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%d", &x[i]);
	for (int j = 1; j <= m; ++j) scanf("%d", &y[j]);

	int sx = 0, sy = 0;
	for (int i = 1; i <= n - 1; ++i) sx = (sx + LL(x[i + 1] - x[i]) * i % P * (n - i) % P) % P;
	for (int i = 1; i <= m - 1; ++i) sy = (sy + LL(y[i + 1] - y[i]) * i % P * (m - i) % P) % P;
	cout << (LL) sx * sy % P;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
#define A


int bubbleSort(list<int>&arr, int n) {
	int cunt = 0;
	bool cont = true;
	while (cont)
	{
		list<int>::iterator it1 = arr.begin(), it2 = arr.begin();
		advance(it2, 1);
		cont = false;
		for (int i = 1; i < n; ++i, advance(it1, 1), advance(it2, 1))
		{
			if (*it1 > *it2) {
				swap(*it1, *it2);
				cont = true;
				cunt++;
			}
		}
	}
	return cunt;
}
int selectionSort();

#ifdef D
int main(void)
{
	int n;
	return 0;
}
#endif // D

#ifdef B
int main(void)
{
	int n;
	cin >> n;
	list<int> arr(n);
	for (auto &a : arr)
		cin >> a;
	int cunt = 0;
	list<int>::iterator it1, it2,min, itend = arr.end();
	for (it1 = arr.begin(); it1 != itend; advance(it1,1))
	{
		min = it1;
		for (it2 = next(it1); it2 != itend; advance(it2, 1))
		{
			if (*it2 < *min)
				min = it2;
		}
		if (it1 != min) {
			cunt++;
			swap(*it1, *min);
		}
	}
	list<int>::iterator it = arr.begin();
	cout << *it;
	advance(it, 1);
	for (; it != arr.end(); advance(it, 1))
		cout << " " << *it;
	cout << endl << cunt << endl;
	return 0;
}
#endif // B

#ifdef A
int main(void)
{
	int cunt = 0;
	int n;
	cin >> n;
	list<int> arr(n);
	for (auto& a : arr)
		cin >> a;
	cunt = bubbleSort(arr, n);
	list<int>::iterator it = arr.begin();
	cout << *it;
	advance(it, 1);
	for (; it !=arr.end(); advance(it,1))
		cout <<" "<< *it;
	cout << endl << cunt << endl;
	return 0;
}
#endif // A

Measured memory_bytes: 3084
import itertools


class Dice():
    def __init__(self, dice_labels):
        self.label = {
            'top': dice_labels[0],
            'south': dice_labels[1],
            'east': dice_labels[2],
            'west': dice_labels[3],
            'north': dice_labels[4],
            'bottom': dice_labels[5]
        }

    def roll(self, str_direction):
        if str_direction == 'E':
            self.__roll_to_east()
        elif str_direction == 'W':
            self.__roll_to_west()
        elif str_direction == 'S':
            self.__roll_to_south()
        elif str_direction == 'N':
            self.__roll_to_north()

    def turn(self, str_direction):
        if str_direction == 'L':
            self.__turn_left()
        elif str_direction == 'R':
            self.__turn_right()

    def __roll_to_east(self):
        self.label['top'], self.label['east'], self.label['west'], self.label['bottom'] = (self.label['west'], self.label['top'], self.label['bottom'], self.label['east'])

    def __roll_to_west(self):
        self.label['top'], self.label['east'], self.label['west'], self.label['bottom'] = (self.label['east'], self.label['bottom'], self.label['top'], self.label['west'])

    def __roll_to_south(self):
        self.label['top'], self.label['south'], self.label['north'], self.label['bottom'] = (self.label['north'], self.label['top'], self.label['bottom'], self.label['south'])

    def __roll_to_north(self):
        self.label['top'], self.label['south'], self.label['north'], self.label['bottom'] = (self.label['south'], self.label['bottom'], self.label['top'], self.label['north'])

    def __turn_right(self):
        self.label['south'], self.label['east'], self.label['west'], self.label['north'] = (self.label['east'], self.label['north'], self.label['south'], self.label['west'])

    def __turn_left(self):
        self.label['south'], self.label['east'], self.label['west'], self.label['north'] = (self.label['west'], self.label['south'], self.label['north'], self.label['east'])


def check_same_surface(dice1, dice2):
    for direction in ['top', 'bottom', 'east', 'west', 'south', 'north']:
        if dice1.label[direction] != dice2.label[direction]:
            return False
    return True


def check_same_dice(dice1, dice2):
    same_pattern_list = []
    for turn_lr in ['R'] * 4:
        for roll_sn in ['N'] * 4:
            for roll_ew in ['E'] * 4:
                dice2.roll(roll_ew)
                same_pattern_list.append(check_same_surface(dice1, dice2))
            dice2.roll(roll_sn)
            same_pattern_list.append(check_same_surface(dice1, dice2))
        dice2.turn(turn_lr)
        same_pattern_list.append(check_same_surface(dice1, dice2))
    return True in same_pattern_list


num_dices = int(input())
dices = []
for dice_number in range(0, num_dices):
    dice_labels = input().split(' ')
    dices.append(Dice(dice_labels))

is_same_dice_result_list = []
for dice1, dice2 in itertools.combinations(dices, 2):
    is_same_dice_result_list.append(check_same_dice(dice1, dice2))

if True in is_same_dice_result_list:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 5864
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix += [int(b) for b in a]
    return intMatrix


def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix


def makeInt(line):
    return int(line.rstrip())


def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    S = input_string
    cnt = 0
    maxCnt = 0
    for N in S:
        if N == 'A':
            cnt += 1
        elif N == 'T':
            cnt += 1
        elif N == 'G':
            cnt += 1
        elif N == 'C':
            cnt += 1
        else:
            if cnt > maxCnt:
                maxCnt = cnt
            cnt = 0
        if cnt > maxCnt:
            maxCnt = cnt
    return maxCnt


def main():
    input_lines = stdin.readline()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
int a,b;
int sum;
scanf("%d %d",&a,&b);
if(b<=9){sum=a*10+b;}
else if(b<=99){sum=a*100+b;}
else{sum=a*1000+b;}
for(int count=0;count<=sum;count++){
    if(count*count==sum){printf("Yes");return 0;}
}

printf("No");
    }


Measured memory_bytes: 128
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10 , Lg = 25;
int timer;
int fix[N] , sum[N] , sums[N] , in[N] , out[N] , color[N] , edge[N] , u[N] , v[N] , l[N] , col_u[N] , col_v[N] , col_l[N] , sum_u[N] , sum_v[N] , sum_l[N] , res[N] , L[N][Lg];
vector < pair < pair < int , int > , int > > query[N];
vector < pair < int , pair < int , int > > > edges[N];
inline bool upper(int a , int b){
	return (!a || (in[a] <= in[b] && out[a] >= out[b])) ? 1 : 0;
}
inline void dfs(int x , int p , int c , int d){
	fix[c] ++;
	sums[c] += d;
	for(int i = 0; i < query[x].size(); i ++){
		int color = query[x][i].first.second;
		int id = query[x][i].first.first;
		int ty = query[x][i].second;
		if(ty == 1) col_u[id] = fix[color] , sum_u[id] = sums[color]; 
		if(ty == 2) col_v[id] = fix[color] , sum_v[id] = sums[color];
		if(ty == 3) col_l[id] = fix[color] , sum_l[id] = sums[color]; 
	}
	for(int i = 0; i < edges[x].size(); i ++){
		int u = edges[x][i].first;
		int cx = edges[x][i].second.first;
		int dx = edges[x][i].second.second;
		if(u != p)
			dfs(u , x , cx , dx);
	}
	fix[c] --;
	sums[c] -= d;
}
inline void rec(int x , int p , int c , int d){
	sum[x] = sum[p] + d;
	in[x] = ++timer;
	L[x][0] = p;
	for(int i = 1; i < Lg; i ++)
		L[x][i] = L[L[x][i - 1]][i - 1];
	for(int i = 0; i < edges[x].size(); i ++){
		int u = edges[x][i].first;
		int cx = edges[x][i].second.first;
		int dx = edges[x][i].second.second;
		if(u != p)
			rec(u , x , cx , dx);
	}
	out[x] = ++timer;  
}
inline int lca(int a , int b){
	if(upper(a , b)) return a;
	if(upper(b , a)) return b;
	for(int i = Lg - 1; i >= 0; i --)
		if(!upper(L[a][i] , b)) a = L[a][i];
	return L[a][0]; 
}
int main(){
	int n , q;
	cin >> n >> q;
	for(int i = 1; i < n; i ++){
		int a , b , c , d;
		scanf("%d%d%d%d" , &a , &b , &c , &d); 
		edges[a].push_back({b , {c , d}});
		edges[b].push_back({a , {c , d}});
	}
	rec(1 , 0 , 0 , 0);
	for(int i = 1; i <= q; i ++){
		scanf("%d%d%d%d" , &color[i] , &edge[i] , &u[i] , &v[i]);
		l[i] = lca(v[i] , u[i]);
		query[u[i]].push_back({{i , color[i]} , 1});
		query[v[i]].push_back({{i , color[i]} , 2});
		query[l[i]].push_back({{i , color[i]} , 3});
	}
	dfs(1 , 0 , 0 , 0);
	for(int i = 1; i <= q; i ++){
		int fr = u[i] , to = v[i] , lc = l[i] , c = color[i] , ed = edge[i];
		int dist = sum[fr] + sum[to] - 2 * sum[lc];
		int num_col = col_u[i] + col_v[i] - 2 * col_l[i];
		int dist_col = sum_u[i] + sum_v[i] - 2 * sum_l[i]; 
		res[i] = dist - dist_col + num_col * ed;
	}
	for(int i = 1; i <= q; i ++) printf("%d\n" , res[i]);
}

Measured memory_bytes: 46776
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <sstream>
#include <limits>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#define PI (acos(-1.0))
#define Abs(a) (((a)<0) ? (-(a)) :(a) )
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define Rep(i,n) for(int i=0;i<(n);i++)
#define Rrep(i,n) for(int i=((n)-1);i>=0;i--)
#define rrep(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define Pii pair<int,int>
#define PB push_back
#define Size(x) ((int)(x.size()))
using namespace std;
typedef long long mint;
typedef unsigned long long umint;
int a[45], b[45], c[45];
int mnCost[405][405];
int main()
{
    //freopen("in.txt","r",stdin);
    memset(mnCost, -1, sizeof(mnCost));
    int n, ma, mb;
    cin >> n >> ma >> mb;
    Rep(i,n)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    int mxa = 0, mxb = 0;
    mnCost[0][0] = 0;
    Rep(i,n)
    {
        for(int j = mxa; j >= 0; j--)
        {
            for(int k = mxb; k >= 0; k--)
            {
                if(mnCost[j][k] == -1)
                {
                    continue;
                }
                if(mnCost[j + a[i]][k + b[i]] != -1)
                {
                    mnCost[j + a[i]][k + b[i]] = min(mnCost[j + a[i]][k + b[i]],
                                                    mnCost[j][k] + c[i]);
                }
                else
                {
                    mnCost[j + a[i]][k + b[i]] = mnCost[j][k] + c[i];
                }
                //cout <<j <<" "<<k <<" "<< mnCost[j][k] << endl;
                //cout << a[i] << " "<<b[i] <<" "<<c[i];
            }
        }
        mxa += a[i];
        mxb += b[i];
    }
    int oma = ma, omb = mb;
    int mn = numeric_limits<int>::max();
    while(ma <= mxa && mb <= mxb)
    {
        //cout <<ma <<" "<< mb <<endl;
        if(mnCost[ma][mb] != -1)
        {
            mn = min(mn, mnCost[ma][mb]);
        }
        //cout << mn << endl;
        ma += oma;
        mb += omb;
    }
    if(mn == numeric_limits<int>::max())
    {
        mn = -1;
    }
    cout << mn << endl;
    return 0;
}



Measured memory_bytes: 896
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int ans = 0;
        for (int i = A; i <= B; i++) {
            String s = Integer.toString(i);
            if(s.equals(new StringBuilder(s).reverse().toString()))ans++;
        }
        System.out.println(ans);
    }

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


Measured memory_bytes: 40660
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 998244353 #出力の制限
N = 2*10**5+5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


n,m,k=map(int,input().split())
ans=0
for i in range(k+1):
  ans=(ans+m*pow(m-1,n-i-1,mod)*cmb(n-1,i))%mod
print(ans)
  

Measured memory_bytes: 112428
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 1000000007;
const int N = 100000 + 7;

bool isprime(ll n)
{
    if(n==2)return 1;
    if(n==0||n==1||n%2==0)
        return 0;
    for(ll i=3;i*i<=n;i+=2)
        if(n%i==0)
            return 1;
    return 0;
}
ll n;
int main()
{
    cin>>n;
    ll ans=1e12;
    vector<pair<ll,ll>>divisors;
    for(ll i=1;i*i<=n;i++)
        if(n%i==0)
            divisors.push_back({i,n/i});

    for(int i=0;i<divisors.size();i++)
        ans=min(((divisors[i].first-1)+(divisors[i].second-1)),ans);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
from sys import stdin,stdout
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()
import math
from collections import Counter,defaultdict


n=IN()
ans=" "
while n>0:
    b=n%26
    if b==0:
        ans='z'+ans
        n=n//26
        n-=1
    else:
        ans=chr(ord('a')+b-1)+ans
        n//=26
print(ans)
        


Measured memory_bytes: 9388
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll a, b, c, k; cin >> a >> b >> c >> k;
    ll res;
    if(k%2==0) res = a-b;
    else res = b-a;
    cout << res << ln;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
int N;
int main(){
    cin >> N;
    if(N % 10==7){
        printf("Yes\n");
        return 0;
    }else if ( (N/10) % 10==7 ){
        printf("Yes\n");
        return 0;
    }else if(N /100==7){
        printf("Yes\n");
        return 0;
    }else{
        printf("No\n");
    }
}

Measured memory_bytes: 3580
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int sx,sy,tx,ty;

void solve(){
	vector<char> ans;
	int x = sx,y = sy;
	int cnt = 1;
	int w = tx-sx;
	int h = ty-sy;
	for(int i = 1;i <= h;i++) ans.push_back('U');
	for(int i = 1;i <= w;i++) ans.push_back('R');
	for(int i = 1;i <= h;i++) ans.push_back('D');
	for(int i = 1;i <= w;i++) ans.push_back('L');
	ans.push_back('L');
	for(int i = 1;i <= h+1;i++) ans.push_back('U');
	ans.push_back('R');
	for(int i = 1;i <= w;i++) ans.push_back('R');
	ans.push_back('D');
	ans.push_back('R');
	for(int i = 1;i <= h+1;i++) ans.push_back('D');
	ans.push_back('L');
	for(int i = 1;i <= w;i++) ans.push_back('L');
	ans.push_back('U');
	
	for(int i = 0;i < ans.size();i++) printf("%c",ans[i]);
	printf("\n");
}

int main(){
	scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
	solve();

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    int n = Integer.parseInt(s.next());
    for (int j=0;j<n;j++){
        int a = Integer.parseInt(s.next());
        int b = Integer.parseInt(s.next());
        int c = Integer.parseInt(s.next());
        if((a*a)+(b*b)==(c*c) || (b*b)+(c*c)==(a*a) || (c*c)+(a*a) == (b*b)){
            System.out.println("YES");
        }
        else {
            System.out.println("NO");
        }
    }
  }
}


Measured memory_bytes: 33780
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

const ll INF=1e18;

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

  int N;
  cin>>N;
  vector<ll> X(N),Y(N),P(N);
  rep(i,N) cin>>X[i]>>Y[i]>>P[i];

  vector<vector<ll>> xmi((1<<N),vector<ll>(N,INF));
  rep(bit,(1<<N)){
      rep(i,N){
          rep(j,N){
              if(bit&(1<<j)) chmin(xmi[bit][i],abs(X[i]-X[j]));
          }
      }
  }
  vector<vector<ll>> ymi((1<<N),vector<ll>(N,INF));
  rep(bit,(1<<N)){
      rep(i,N){
          rep(j,N){
              if(bit&(1<<j)) chmin(ymi[bit][i],abs(Y[i]-Y[j]));
          }
      }
  }

  vector<ll> ans(31,INF);
  for(int xbit=0;xbit<(1<<N);xbit++){
    vector<ll> mires(N,INF);
    rep(i,N) mires[i]=min(abs(X[i]),abs(Y[i]));
    rep(i,N) chmin(mires[i],xmi[xbit][i]);

    int szx=__builtin_popcount(xbit);
    int T=0;
    rep(i,N){
        if(xbit&(1<<i));
        else T+=(1<<i);
    } 
    for(int S=T;;S=(S-1)&T){
      vector<ll> tres=mires;
      rep(i,N) chmin(tres[i],ymi[S][i]);
      int szy=__builtin_popcount(S);
      ll res=0;
      rep(i,N) res+=P[i]*tres[i];
      chmin(ans[szx+szy],res);
      if(S==0) break;
    }
  }

  rep(i,N+1) cout<<ans[i]<<endl;

  return 0;
}


Measured memory_bytes: 12936