akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long n,x;
long long solve(long long a,long long b)
{
    if(a<b)swap(a,b);if(!b)return -a;
    return 2*(a-a%b)+solve(b,a%b);
}
int main()
{
    scanf("%lld%lld",&n,&x);
    cout<<n+solve(n-x,x)<<endl;
}

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

template <typename T, typename U>
struct min_cost_flow_graph {
	
	struct edge {
		int from, to;
		T cap, f;
		U cost;
	};
	
	vector<edge> edges;
	vector<vector<int>> g;
	int n, st, fin;
	T required_flow, flow;
	U cost;
	
	min_cost_flow_graph(int n, int st, int fin, T required_flow)
		: n(n), st(st), fin(fin), required_flow(required_flow) {
			assert(0 <= st && st < n && 0 <= fin && fin < n && st != fin);
			g.resize(n);
			flow = 0;
			cost = 0;
	}
	
	void clear_flow() {
		for (const edge &e : edges) {
			e.f = 0;
		}
		flow = 0;
		cost = 0;
	}
	
	void add(int from, int to, T cap = 1, T rev_cap = 0, U cost = 1) {
		assert(0 <= from && from < n && 0 <= to && to < n);
		g[from].emplace_back(edges.size());
		edges.push_back({from, to, cap, 0, cost});
		g[to].emplace_back(edges.size());
		edges.push_back({to, from, rev_cap, 0, -cost});
	}
	
	U min_cost_flow() {
		vector<U> h(n, 0);
		while (flow < required_flow) {
			vector<int> preve(n);
			vector<U> dist(n, numeric_limits<U>::max() / 2);
			priority_queue<pair<U, int>, vector<pair<U, int>>, greater<pair<U, int>>> pq;
			dist[st] = 0;
			pq.emplace(dist[st], st);
			while (!pq.empty()) {
				U expected = pq.top().first;
				int i = pq.top().second;
				pq.pop();
				if (expected != dist[i]) {
					continue;
				}
				for (int id : g[i]) {
					const edge &e = edges[id];
					if (0 < e.cap - e.f && dist[e.from] + e.cost + h[e.from] - h[e.to] < dist[e.to]) {
						dist[e.to] = dist[e.from] + e.cost + h[e.from] - h[e.to];
						preve[e.to] = id;
						pq.emplace(dist[e.to], e.to);
					}
				}
			}
			if (dist[fin] == numeric_limits<U>::max() / 2) {
				return -1;
			}
			for (int i = 0; i < n; i++) {
				h[i] += dist[i];
			}
			T d = required_flow - flow;
			for (int i = fin; i != st; i = edges[preve[i]].from) {
				d = min(d, edges[preve[i]].cap - edges[preve[i]].f);
			}
			flow += d;
			cost += d * h[fin];
			for (int i = fin; i != st; i = edges[preve[i]].from) {
				edges[preve[i]].f += d;
				edges[preve[i] ^ 1].f -= d;
			}
		}
		return cost;
	}
};

int main() {
	int n, m, f;
	cin >> n >> m >> f;
	min_cost_flow_graph<int, int> g(n, 0, n - 1, f);
	for (int i = 0; i < m; i++) {
		int from, to, cap, cost;
		cin >> from >> to >> cap >> cost;
		g.add(from, to, cap, 0, cost);
	}
	cout << g.min_cost_flow() << endl;
	return 0;
}

Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
vector<string >v;
int main(){
 int n , m;
 cin >> n >> m;
 for(int i=1;i<=n;i++){
    string s;
    cin >> s;
    v.push_back(s);
 }
 sort(v.begin(),v.end());
 for(int i=0;i<v.size();i++){
    cout << v[i];
 }
 cout << endl;

 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>a>>b>>c>>d;
	int cnt1=(c+b-1)/b;
	int cnt2=(a+d-1)/d;
	if(cnt1<=cnt2) return cout<<"Yes",0;
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
using namespace std;

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

long long lcm(long long a, long long b) {
  long long g = gcd(a,b);
  return (a/g)*b;
}

int main(){
  long long x, y;
  cin >> x >> y;
  if(x%y==0){
    cout << -1 << endl;
    return 0;
  }
  cout << lcm(x,y) - x << endl;
  return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
 int x,y,z,area1,area2,area3;
 cin>>x>>y>>z;
 area1=(x/2.0)*y;
 area2=(z/2.0)*x;
 area3=(y/2.0)*z;
 if(z>y && z>x)
 cout<<area1;
if(y>z && y>x)
 cout<<area2;
 if(x>y && x>z)
 cout<<area3;

  return 0;

}

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

using namespace std;

#define x first
#define y second
typedef long long ll;
const int N = 200010;
const int mod = 998244353;
const int oo = 1e9;
const int base = 27;
typedef pair<int,int> pii;


int dp[4010][4010],f1[4001],f2[4001];

string s;

ll adl(ll a , ll b){
  return (1ll*a+b)%mod;
}
int calc(int r , int b){
  if(r+b == 2*s.size())return 1;
  int &ret = dp[r][b];
  if(ret != -1)return ret;
  ret = 0;
  int idx = r+b;
  if(idx >= s.size()){
    if(b != f1[s.size()-1])ret = adl(ret,calc(r,b+1));
    if(r != f2[s.size()-1])ret = adl(ret,calc(r+1,b));
  }else{
    if(b != f1[idx])ret = adl(ret,calc(r,b+1));
    if(r != f2[idx])ret = adl(ret,calc(r+1,b));
  }
  return ret;
}
int main() {
  memset(dp,-1,sizeof dp);
  cin >> s;
  for (int i = 0; i < s.size(); ++i){
    if(s[i] == '1')f1[i]++,f2[i]++;
    if(s[i] == '2')f2[i]+=2;
    if(s[i] == '0')f1[i]+=2;
    if(i)
      f1[i] += f1[i-1];
    if(i)
      f2[i] += f2[i-1];
  }
  printf("%d\n",calc(0,0));

  return 0;
}

Measured memory_bytes: 63360
#include<cstdio>
#include<map>
using namespace std;
typedef long long int ll;
static const int MAX_N = 1500;
static const int MAX_M = 1500;

int N, M;
int h[MAX_N + 1], w[MAX_M + 1];

int main(){
	for(;;){
		scanf("%d %d", &N, &M);
		if(N == 0 && M == 0) break;
		for(int i = 1; i < N + 1; i++){
			scanf("%d", &h[i]);
			h[i] += h[i - 1];
		}
		for(int i = 1; i < M + 1; i++){
			scanf("%d", &w[i]);
			w[i] += w[i - 1];
		}
		map<int, int> mpa, mpb;
		for(int i = 0; i < N + 1; i++)
			for(int j = i + 1; j < N + 1; j++) mpa[h[j] - h[i]]++;
		for(int i = 0; i < M + 1; i++)
			for(int j = i + 1; j < M + 1; j++) mpb[w[j] - w[i]]++;
		int res = 0;
		map<int, int>::iterator itr;
		for(itr = mpa.begin(); itr != mpa.end(); itr++) res += itr -> second * mpb[itr -> first];
		printf("%d\n", res);
	}
	return 0;
}


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

int main(){
	long int N,W;
	vector<vector<long long int>>Table;
	vector<long long int>Weights;
	vector<long long int>Values;
	long long int i,j;
	cin>>N>>W;
	Table.reserve(N+1);
	Weights.reserve(N+1);
	Values.reserve(N+1);
	Table[0].reserve(W+1);
	//int temp;
	for(j=0;j<=W;j++){
		Table[0][j]=0;
	}
	for(i=1;i<=N;i++){
		Table[i].reserve(W+1);
		cin>>Weights[i]>>Values[i];
		for(j=0;j<=W;j++){
			if(j-Weights[i]<0){
				Table[i][j]=Table[i-1][j];
			}
			else{
				Table[i][j]=max(Table[i-1][j],Table[i-1][j-Weights[i]]+Values[i]);
			}
		}
	}
	cout<<Table[N][W];
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  string s;  
  cin >> s;

  int ans = 0;
  {
    vector<int> cumr(n, 0), cuml(n, 0);
    int sumr = 0, suml = 0;
    for ( int i = 0; i < n; i++ ) {
      if ( i ) {
	cumr[i] = cumr[i-1];
	cuml[i] = cuml[i-1];
      }
      if ( s[i] == '>' ) {
	cumr[i]++;
	sumr++;
      } else {
	cuml[i]++;
	suml++;      
      }
    }

    if ( sumr == n || suml == 0 ) ans = n;    
    for ( int i = 0; i < n; i++ ) {
      if ( s[i] == '<' ) continue;      
      int a = cumr[i];
      int b = cuml[i]+a;
      if ( b-1 == suml ) {      
	ans = max(ans, n-(int)(lower_bound(cumr.begin(), cumr.end(), 1)-cumr.begin()));
      }
      if ( b > suml ) continue;
      int c = lower_bound(cuml.begin(), cuml.end(), b)-cuml.begin();      
      ans = max(ans, c+1);
    }
    // cout << ans << endl;
  }
  {
    reverse(s.begin(), s.end());
    for ( int i = 0; i < n; i++ ) {
      if ( s[i] == '>' ) s[i] = '<';
      else s[i] = '>';      
    }
    // cout << s << endl;
    vector<int> cumr(n, 0), cuml(n, 0);
    int sumr = 0, suml = 0;
    for ( int i = 0; i < n; i++ ) {
      if ( i ) {
	cumr[i] = cumr[i-1];
	cuml[i] = cuml[i-1];
      }
      if ( s[i] == '>' ) {
	cumr[i]++;
	sumr++;
      } else {
	cuml[i]++;
	suml++;      
      }
    }

    if ( sumr == n || suml == 0 ) ans = n;    
    for ( int i = 0; i < n; i++ ) {
      if ( s[i] == '<' ) continue;      
      int a = cumr[i];
      int b = cuml[i]+a;
      if ( b-1 == suml ) {	
	ans = max(ans, n-(int)(lower_bound(cumr.begin(), cumr.end(), 1)-cumr.begin()));
      }
      if ( b > suml ) continue;
      int c = lower_bound(cuml.begin(), cuml.end(), b)-cuml.begin();
      // cout << a << " " << b << " " << i << " " << c+1 << endl;
      ans = max(ans, c+1);      
    }
  }

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


Measured memory_bytes: 3968
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<iomanip>

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long

typedef pair<lint, lint> P;

struct point { lint x, y; int num; };
const int MAX = 100005;
struct edge { lint from, to, cost; };
vector<edge> G;

struct union_find{
    vector<int> par;
    vector<int> rank;
    union_find(int n) : par(n), rank(n){
        for(int i = 0; i < n; i++){
            par[i] = i; rank[i] = 0;
        }
    }
    int root (int x){
        if(par[x] == x) return x;
        par[x] = root(par[x]);
        return par[x];
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (rank[rx] < rank[ry]){
            par[rx] = ry;
        }
        else{
            par[ry] = rx;
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
    }
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int n; cin >> n;
    vector<point> vp;
    rep(i, n){
        lint x, y; cin >> x >> y;
        vp.push_back(point{x, y, i});
    }

    sort(all(vp), [](point const& l, point const& r)->bool{
        return l.x < r.x;
    });
    rep(i, n-1){
        G.push_back(edge{vp[i].num, vp[i+1].num, vp[i+1].x - vp[i].x});
        G.push_back(edge{vp[i+1].num, vp[i].num, vp[i+1].x - vp[i].x});
    }

    sort(all(vp), [](point const& l, point const& r)->bool{
        return l.y < r.y;
    });
    rep(i, n-1){
        G.push_back(edge{vp[i].num, vp[i+1].num, vp[i+1].y - vp[i].y});
        G.push_back(edge{vp[i+1].num, vp[i].num, vp[i+1].y - vp[i].y});
    }

    sort(all(G), [](edge const& l, edge const& r)->bool{
        return l.cost < r.cost;
    });

    union_find uf(n);
    lint res = 0; int c = 0;
    for(edge& e: G){
        if(uf.same(e.to, e.from)) continue;
        uf.unite(e.to, e.from);
        res += e.cost; c++;
        if(c == n - 1) break;
    }
    cout << res << endl;
}


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

int main()
{
  int N; cin >> N;
  vector<int> A(N+1, 0);
  for (int i = 0; i < N+1; i++)
  {
    cin >> A[i];
  }
  vector<int> B(N+1 , 0);
  for (int i = 0; i < N; i++)
  {
    cin >> B[i];
  }
 
  long long ans = 0;
  for (int i=N-1; i >=0 ; i--)
  {
    if (B[i] >= A[i + 1]) {
      ans += A[i + 1];
      B[i] -= A[i + 1];
      if (B[i] >= A[i]) {
        ans += A[i];
        A[i] = 0;
      }
      else {
        ans += B[i];
        A[i] -= B[i];
      }
      
    }
    else {
      ans += B[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <map>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

ll N,K;
ll a[200200];
ll sa;
ll m=-1;
ll gcd(ll x,ll y){
  if(x < y){
    ll t = x;
    x = y;
    y = t;
  }
  if(x%y == 0) return y;
  return gcd(y,x%y);
}
int main(){
  cin >> N >> K;
  rep(i,N){
    cin >> a[i];
    if(i==0) sa = a[i];
    else{
      sa = gcd(sa,a[i]);
    }
    if(m < a[i]) m = a[i];
  }
  if(m < K || K%sa != 0){
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  cout << "POSSIBLE" << endl;


}


Measured memory_bytes: 1024
N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
for X in range(10**N):
  X = str(X)
  if len(X)==N and all(X[s-1]==str(c) for s, c in SC):
    print(X)
    break
else:
  print(-1)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int w,h,t;
int p;
int mp[52][52];

int main(){
  scanf("%d%d%d%d",&w,&h,&t,&p);
  REP(i,p){
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);
    mp[x][y]+=1;
  }
  int ans = 0;
  REP(j,h)REP(i,w){
    int c;
    scanf("%d",&c);
    if(c==1)ans+=mp[i][j];
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1200
/*input
3 3
abc


*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;

ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);    
	
	int N; cin >> N;
	
	ll pos[N];
	
	REP(i, N) {
		int cur; cin >> cur; cur--;
		pos[cur] = i;
		
	}
	
	ll ans = 0;
	
	multiset<ll> used;
	used.insert(-1); used.insert(-1); used.insert(N); used.insert(N);
	for(int i=N-1;i>=0;i--){
		
		used.insert(pos[i]);
		auto it = used.find(pos[i]);
		it--;
		ll s1 = *it;
		it--;
		ll s2 = *it;
		it++; it++; it++;
		ll e1 = *it;
		it++;
		ll e2 = *it; 
		ll curVal = i+1;
		ll numPos = 0;
		numPos += (e2 - e1) * (pos[i] - s1);
		numPos += (s1 - s2) * (e1 - pos[i]);;
		ans += curVal * numPos;
	}
	
	cout << ans << endl;
	
	return 0;
}

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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;

/////////////////////////////////

int const MAX = 30 * 1000;

vi ans;
int n;

int gcd(int a, int b) {
	return (a ? gcd(b % a, a) : b);
}

bool check(vi a) {
	int s = 0;
	for (int x : a) {
		s += x;
	}
	set<int> t;
	for (int x : a) {
		t.insert(x);
	}
	if (sz(t) != n) {
		err("sz ! %d != %d\n", sz(t), n);
		return false;
	}
	for (int x : a) {
		if (gcd(x, s) == 1) { 
			err("x = %d s = %d gcd = %d\n", x, s, gcd(x, s));
			return false;			
		}
	}
	int g = a[0];
	fi(1, sz(a) - 1) {
		g = gcd(g, a[i]);
	}
	if (g != 1) {
		return false;
	}
	return true;
}

int u[MAX + 1];

void solve() {
	vi ans;
	ans.pb(2);
	ans.pb(3);
	u[2] = u[3] = 1;
	for (int i = 2; i <= MAX; i += 2) {
		if (sz(ans) == n) break;
		if (!u[i]) {
			ans.pb(i);
			u[i] = 1;
		}
	}		

	for (int i = 3; i <= MAX; i += 3) {
		if (sz(ans) == n) break;
		if (!u[i]) {
			ans.pb(i);
			u[i] = 1;
		}
	}		
	int s = 0;
	for (int x : ans) {
		s += x;
	}
	while (1) {
		if (s % 6 == 0) break;
		int p = rand() % sz(ans);
		while (ans[p] == 2 || ans[p] == 3) {
			p = rand() % sz(ans);
		}		
		u[ans[p]] = 0;
		s -= ans[p];
		ans.erase(ans.begin() + p);
		bool f = false;
		fi(1, MAX) {
			if (!u[i] && (i + s) % 6 == 0 && gcd(i, s) != 1) {
				ans.pb(i);
				f = true;
				break;
			}
		}
		if (f) break;
		int x = rand() % MAX + 1;
		while (1) {
			if (u[x] || !(x % 3 == 0 || x % 2 == 0)) {
				x = rand() % MAX + 1;
				continue;
			}
			u[x] = 1;
			ans.pb(x);
			s += x;
			break;
		}
	}
	assert(check(ans));
	for (int x : ans) {
		printf("%d ", x);
	}
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 1408
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        long mod = 1000000000 + 7;
        int[] a = new int[M];
        boolean[] floors = new boolean[N + 1];
        Arrays.fill(floors, true);
        for (int i = 0; i < M; i++) {
            a[i] = sc.nextInt();
            floors[a[i]] = false;
        }

        long[] dp = new long[N + 1];
        dp[0] = 1;

        for (int now = 0; now < N; now++) {
            if (floors[now + 1]) {
                dp[now + 1] += dp[now];
                dp[now + 1] %= mod;
            }

            if (now == N - 1) {
                break;
            }

            if (floors[now + 2]) {
                dp[now + 2] += dp[now];
                dp[now + 2] %= mod;
            }
        }

        System.out.println(dp[N]);
    }
}

Measured memory_bytes: 65300
#include<iostream>
using namespace std;
int N,K,C;
string S;
int L[2<<17],R[2<<17];
int cnt[2<<17];
main()
{
	cin>>N>>K>>C>>S;
	int Lm=0;
	for(int i=0;i<N;i++)
	{
		if(S[i]=='o')
		{
			L[i+1]=Lm+1;
		}
		if(i>=C&&Lm<L[i-C+1])Lm=L[i-C+1];
	}
	int Rm=0;
	for(int i=N;i--;)
	{
		if(S[i]=='o')
		{
			R[i+1]=Rm+1;
		}
		if(N-i-1>=C&&Rm<R[i+C+1])Rm=R[i+C+1];
	}
	for(int i=1;i<=N;i++)
	{
		if(L[i]<L[i-1])L[i]=L[i-1];
	}
	for(int i=N;i;i--)
	{
		if(R[i]<R[i+1])R[i]=R[i+1];
	}
	int r=1;
	for(int i=-C;i<=N;i++)
	{
		int l=i>=0?L[i]:0;
		while(r<=N+1&&l+R[r]>=K)r++;
		if(r==N+2?l>=K:(r-i>=C+1&&l+R[r-1]>=K))
		{
			cnt[i+1>=0?i+1:0]++;
			cnt[r-1]--;
		}
	}
	for(int i=1;i<=N;i++)cnt[i]+=cnt[i-1];
	for(int i=1;i<=N;i++)if(S[i-1]=='o'&&cnt[i]==0)cout<<i<<endl;
}


Measured memory_bytes: 4228
N=int(input())
A=list(map(int,input().split()))

ans=[0]*N
t=0
for i in range(N):
    if i%2==0:
        t+=A[i]
    else:
        t-=A[i]
t=t/2
ans[0]=t
for i in range(1,N):
    ans[i]=A[i-1]-ans[i-1]
for i in range(N):
    ans[i]=int(2*ans[i])
print(*ans[0:])

Measured memory_bytes: 14408
while True:
    N, Q = map(int, input().split())
    if N == 0 and Q == 0:
        break
    counts = [0 for i in range(100)]
    for i in range(N):
        tmp = list(map(int, input().split()))
        M = tmp[0]
        for i in range(M):
            counts[tmp[i + 1] - 1] += 1
            
    max_count = max(counts)
    if max_count < Q:
        print(0)
    else:
        for i in range(100):
            if counts[i] == max_count:
                print(i + 1)
                break


Measured memory_bytes: 5616
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    
    if(S[K-1]=='A'){
        S[K-1]='a';
    }else{
        if(S[K-1]=='B'){
            S[K-1]='b';
        }else{
            S[K-1]='c';
        }
    }
    cout << S << endl;
        return 0;
    }


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

int main() {
  
  int n;
  cin >> n;
  
  vector<int> p(n);
  REP(i,n) {
    cin >> p[i];
  }
  
  int c = 0;
  REP(i,n) {
    if (p[i] != i+1) c++;
  }
  
  cout << ((c == 0 || c == 2) ? "YES" : "NO") << endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b;
    scanf("%d %d",&a ,&b);
	
	if(a<b){
	   printf("a < b\n");
		return 0;
	}
	if(a>b){ 
		printf("a > b\n");
		return 0;
	}
	if(a==b){
		printf("a == b\n");
		return 0;
	}
}	

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

void fnInput(int& rnAmount)
{
  cin >> rnAmount;
}

int fnAmtCheck(int nAmount)
{
  const int cnnCake = 4;
  const int cnnDonut = 7;

  int nCake = 0;
  while (true)
  {
    int nAmtCake = cnnCake * nCake;
    if (nAmtCake > nAmount)       return 0;

    int nRestAmt = nAmount - nAmtCake;
    if (nRestAmt % cnnDonut == 0) return 1;
    nCake++;
  }
}

int main()
{
  int nAmount;

  fnInput(nAmount);
  if (fnAmtCheck(nAmount)) cout << "Yes" << endl;
  else                       cout << "No"  << endl;

  return 0;
}

Measured memory_bytes: 256
import collections
N = int(input())
A = list(map(int,input().split()))
ikutu = collections.Counter(A)

#要素数リスト
Ac = [ikutu[x] for x in ikutu]

#抜かない時の組み合わせ数
kumi = 0
for i in range(len(Ac)):
    if Ac[i] != 1:
        kumi += (Ac[i]*(Ac[i]-1))//2

for j in range(N):
    if ikutu[A[j]] != 1:
        Ans = kumi - ((ikutu[A[j]])*(ikutu[A[j]]-1))//2 + ((ikutu[A[j]]-1)* (ikutu[A[j]]-2))//2
    else:
        Ans = kumi
    print(Ans)

Measured memory_bytes: 26780
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


vector<ll>adj[Max+10];

map<pll,ll>mp;

ll k;


void dfs(ll s,ll p)
{

    ll c=1;

    for(auto  x  : adj[s])
    {
        if(x!=p)
        {
            if(mp[{p,s}]==c)c++;



                mp[{s,x}]=c;
                mp[{x,s}]=c;
                c++;

            dfs(x,s);
        }
    }
}



int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

      cin>>n;

      vector<pll>Ans;

      k=0;


      for(i=1; i<n; i++)
      {
          cin>>a>>b;

          adj[a].eb(b);

          adj[b].eb(a);

          Ans.eb(a,b);

          k=max3((ll)adj[a].size(),(ll)adj[b].size(),k);


      }

      dfs(1,1);

      cout<<k<<endl;

      for(auto x  : Ans)
      cout<<mp[{x.F,x.S}]<<endl;











}



Measured memory_bytes: 68936
import sys
def input(): return sys.stdin.readline().rstrip()
from operator import itemgetter
def main():
    n,m=map(int,input().split())
    A=[int(_) for _ in input().split()]
    A.sort()
    D=[[int(_) for _ in input().split()] for i in range(m)]
    D.sort(key=itemgetter(1),reverse=True)
    len_D=len(D)
    index_d=0
    for i in range(n):
        if D[index_d][0]==0:
            index_d+=1
            if index_d==len_D:
                break
        if A[i]>=D[index_d][1]:
            break
        A[i]=D[index_d][1]
        D[index_d][0]-=1
    print(sum(A))

if __name__=='__main__':
    main()

Measured memory_bytes: 27080
// https://atcoder.jp/contests/abc057/tasks/abc057_c
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
const int INF = 1e9;

// 10進数の桁数
int getKeta(int num) {
    int digit = 0;
    while (num != 0) {
        num /= 10;
        digit++;
    }
    return digit;
}

// 約数列挙
vector<int> divisor(int n) {
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(ALL(ret));
    return ret;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    auto t = divisor(n);
    int minv = INF;
    for (auto &x : t) {
        minv = min(minv, max(getKeta(x), getKeta(n / x)));
    }
    cout << minv << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static int n;
	public static int[] list;

	public static void Calc(int num, int max) {
		if(num == n) {
			String ans = "";
			for(int i = 0; i < n; i++) {
				ans += (char) (list[i] + 'a');
			}
			System.out.println(ans);
		} else {
			for(int i = 0; i < max + 1; i++) {
				list[num] = i;
				if(i < max) {
					Calc(num + 1, max);
				} else {
					Calc(num + 1, max + 1);
				}
			}
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		list = new int[n];
		Calc(0, 0);

	}

}


Measured memory_bytes: 92984
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int a, b;

int main() {
    cin >> a >> b;
    int ans = 0;
    int cnt = 1;
    while (cnt < b) {
        ans++;
        cnt += a-1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }
#define output(x) cout << x << endl;

bool compare(const pair<int, int>& F, const pair<int, int>& S) {
    return F.second < S.second;
}

int main() {
    int A, B, C, X;
    int ans = 0;
    cin >> A >> B >> C >> X;
    for (int i = 0; i <= A; ++i) {
        for (int j = 0; j <= B; ++j) {
            for (int k = 0; k <= C; ++k) {
                if(500 * i + 100 * j + 50 * k == X) ++ans;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
int pri[1010];
const ll mod=1e9+7;
ll a[1010];
ll ans=1;
ll n;
ll cnt;
bool is_pri(ll m){
	for(int i=2;i<m;i++){
		if(m%i==0)return 0;
	}
	return 1;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	if(n==1){
		cout<<1;
		return 0;
	}
	for(int i=2;i<=n;i++){
		if(is_pri(i))pri[cnt++]=i,a[i]++;
		else {
			ll x=i;
			for(int j=0;j<cnt;j++){
				while(x%pri[j]==0){
					a[pri[j]]++;
					x/=pri[j];
				}
				if(x==1)break;
			}
		}
	}
	for(int i=0;i<cnt;i++)ans*=(a[pri[i]]+1),ans%=mod;
	cout<<ans;
	return 0;
}



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

#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define IN freopen("input.txt", "r", stdin);
#define OUT freopen("output.txt", "w", stdout);
#define LL long long
#define MOD 1000000007
#define INF 1000000000000000000
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)

using namespace std;

const int N=3001;
int F[N][N], T[N][N];
string s,t,x;

int main()
{
	// IN;OUT;
	FASTIO;
	cin >> s >> t;
	s.insert(0,1,'.');
	t.insert(0,1,'.');
	int m=s.size()-1, n=t.size()-1;
	for (int i=0; i<=max(m,n); i++) F[i][0] = F[0][i] = 0;
	for (int i=1; i<=m; i++)
		for (int j=1; j<=n; j++) {
			int V = max(F[i-1][j], F[i][j-1]);
			if (s[i] == t[j]) V = max(V, F[i-1][j-1]+1);
			F[i][j] = V;
			if (V == F[i-1][j]) T[i][j] = 0;
			else if (V == F[i][j-1]) T[i][j] = 1;
			else T[i][j] = 2;
		}
	x = "";
	int i,j;
	for (i=m, j=n; i>0 and j>0; ) {
		if (T[i][j] == 2) {
			x.insert(0, 1, s[i]);
			i--; j--;
		}
		else if (T[i][j] == 1) j--; else i--;
	}
	cout << x;
	return 0;
}


Measured memory_bytes: 70656
# coding: utf-8
import math

def str_intersection(w1, w2):
	s1 = set(w1)
	s2 = set(w2)
	set_intersection = s1.intersection(s2)
	result = ''
	for letter in set_intersection:
		num = min(w1.count(letter), w2.count(letter))
		result += letter*num
	return result


if __name__ == "__main__":
	n = int(input())
	s = []
	result = input()
	for _ in range(n-1):
		result = str_intersection(result, input())

	print(''.join(sorted(result)))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define uint unsigned
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define y1 wzpakking
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
using namespace std;
int n;
ll S,a[200005],b[60];
void insert(ll x){
	Rep(i,59,0)
		if (x&(1ll<<i)){
			if (!b[i]){
				b[i]=x; break;
			}
			else
				x^=b[i];
		}
}
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%lld",&a[i]),S^=a[i];
	For(i,1,n) insert(a[i]-(a[i]&S));
	ll ans=0;
	Rep(i,59,0)
		if ((ans^b[i])>ans)
			ans^=b[i];
	printf("%lld\n",2*ans+S);
}

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

using namespace std;

typedef long long LL;

const int maxn = 45;
const int P = 1e9 + 7;

int n, x, y, z, f[maxn][1 << 18];

inline int read(){
	char ch = getchar(); int u = 0, f = 1;
	while(!isdigit(ch)){if(ch == '-')f = -1; ch = getchar();}
	while(isdigit(ch)){u = u * 10 + ch - 48; ch = getchar();} return u * f; 
}

inline int pls(int x, int y) {x += y; return x >= P ? x - P : x;}
inline int dec(int x, int y) {x -= y; return x < 0 ? x + P : x;}
inline int mul(int x, int y) {LL rnt = 1ll * x * y; return (int)(rnt >= P ? rnt % P : rnt);}

inline int ksm(int x, int k) {
	int cnt = 1;
	while(k) {
		if(k & 1) cnt = mul(cnt, x);
		x = mul(x, x); k >>= 1;
	} return cnt;
}

int main(){
	n = read(); x = read(); y = read(); z = read();
	int ans = ksm(10, n);
	int tot = (1 << x - 1) | (1 << x + y - 1) | (1 << x + y + z - 1);
	int S = (1 << x + y + z);
	f[0][0] = 1;
	for(register int i = 1; i <= n; i++)
		for(int S2 = 0; S2 < S; S2++)
			for(register int k = 1; k <= 10; k++) {
				int cur = ((S2 << k) | (1 << k - 1)) & (S - 1);
				if((cur & tot) != tot)
					f[i][cur] = pls(f[i][cur], f[i - 1][S2]);
			}
	for(register int S2 = 0; S2 < S; S2++) ans = dec(ans, f[n][S2]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 41728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct LR{
  ll n;
  vector<ll>a;
  LR(int sz):n(sz),a(sz+1){}
  void Input(){
    for(int i=0;i<n;i++) cin>>a[i];
    a[n]=0;
  }
  ll solve(){
    ll ans=0,ls=0;
    stack<pair<ll,ll> >st;
    for(int j=0;j<n+1;j++){
      if(st.empty())st.push(make_pair(a[j],j));
      else if(st.top().first==a[j])continue;
      else if(st.top().first<a[j])st.push(make_pair(a[j],j));
      else{
        while(!st.empty()&&st.top().first>a[j]){
          ans=max(ans,(j-st.top().second)*st.top().first);
          ls=st.top().second;
          st.pop();
        }
        st.push(make_pair(a[j],ls));
      }
    }
    return ans;
  }
};
int main(){
  int n;
  cin>>n;
  LR L(n);
  L.Input();
  cout<<L.solve()<<endl;
}


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

int main() {
  int d = 1;
  int N, K;
  int i;

  cin >> N >> K;

  for (i=0;i<N;i++){
    if (d < K) {
      d += d;
    } else {
      d += K;
    }
  }

  cout << d;
}

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

int digits(ll x){
  int digits = 0;
  while(x > 0){
    x /= 10;
    digits++;
  }
  return digits;
}
int main(void){
  ll n;
  cin >> n;
  int ans = digits(n);
  for(ll A = 1; A * A <= n; A++){
    if(n % A == 0) {
      ll B = n / A;
      int cur = max(digits(A), digits(B));
      if (cur < ans) {
        ans = cur;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

ll calcScore(const int contest, const int day, vector<ll> &last, vector<ll> &c, vector<vector<ll>> &s)
{
  ll score = 0;
  last[contest] = day + 1;
  score += s[day][contest];
  for (int j = 0; j < 26; j++)
  {
    score -= c[j] * ((day + 1) - last[j]);
  }
  return score;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int D;
  cin >> D;
  vector<ll> c(26);
  for (auto &it : c)
    cin >> it;
  vector<vector<ll>> s(D, vector<ll>(26));
  for (int i = 0; i < D; i++)
  {
    for (int j = 0; j < 26; j++)
    {
      cin >> s[i][j];
    }
  }

  vector<ll> last(26, 0);
  vector<ll> t(D);

  ll score = 0;
  for (int i = 0; i < D; i++)
  {
    ll now = 0;
    ll best_contest = 0;
    for (int co = 0; co < 26; co++)
    {
      ll tmp = calcScore(co, i, last, c, s);
      if (tmp > now)
      {
        now = max(now, tmp);
        best_contest = co;
      }
    }
    last[best_contest] = i + 1;
    score += now;
    cerr << score << endl;
    cout << best_contest + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3704
#coding: utf-8
N, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
a.sort()
for i in range(len(a)):
    x -= a[i]
    ans += 1
    if x < 0:
        ans -= 1
print(ans if x <= 0 else ans - 1)

Measured memory_bytes: 3060
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int mod=1e9+7;
const int inv2=(mod+1)>>1;
const int N=200005;

int a[N],b[N],n;
int sum[4003][4003];
ll fac[8003],inv[8003];

il int calc(int a,int b){
	return fac[a+b]*inv[a]%mod*inv[b]%mod;
}

il void inc(int &x,const int &y=0){
	x+=y;
	if(x>=mod) x-=mod;
}

il void dec(int &x,const int &y=0){
	x-=y;
	if(x<0) x+=mod;
} 

int main(){
	inv[1]=1;
	rep(i,2,8000) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	fac[0]=inv[0]=1;
	rep(i,1,8000){
		fac[i]=fac[i-1]*i%mod;
		inv[i]=inv[i-1]*inv[i]%mod;
	}
	scanf("%d",&n);
	rep(i,1,n){
		scanf("%d%d",a+i,b+i);
		++sum[2000-a[i]][2000-b[i]];
	}
	rep(i,0,4000) rep(j,0,4000){
		if(i) inc(sum[i][j],sum[i-1][j]);
		if(j) inc(sum[i][j],sum[i][j-1]);
	}
	int ans=0;
	rep(i,1,n){
		inc(ans,sum[2000+a[i]][2000+b[i]]);
		dec(ans,calc(a[i]<<1,b[i]<<1));
	}
	ans=(ll)ans*inv[2]%mod;
	printf("%d\n",ans); 
	return 0;
}


Measured memory_bytes: 64512
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    ll ans = 1e18;
    for(ll i = 1; i*i <= n; i++){
        if(n % i != 0)  continue;
        ll j = n / i;
        ans = min(ans, i+j-2);
    }
    cout << ans << endl;
}

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

using namespace std;

int comp(const int *a, const int *b);

int main(void) {
	int hill[10];
	
	for(int i = 0; i < 10; i++) {
		cin >> hill[i];
	}
	
	qsort(hill, 10, sizeof(int), (int(*)(const void *, const void *))comp);
	
	cout << hill[9] << endl << hill[8] << endl << hill[7] << endl;
	
	return 0;
}

int comp(const int *a, const int *b) {
	if(*a < *b)				return -1;
	else if(*a == *b)		return  0;
	else					return  1;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int a,b;
int ans;
signed main(){
    cin>>a>>b;
    int x=a+b,y=a-b,z=a*b;
    ans=max(x,y);
    ans=max(ans,z);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define input ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define dl endl
#define ft first
#define sc second
using namespace std;
int k, n, a[1005];
ll sum = 0;
int main()
{
	//freopen("", "r", stdin);
	//freopen("", "w", stdout);
	input;
	cin >> n >> k;
	for (int i = 0; i < n; ++i) cin >> a[i];
	sort(a, a + n);
	for (int i = 0; i < k; ++i) sum += a[i];
	cout << sum;
}

Measured memory_bytes: 3628
#include<string.h>
#include<stdio.h>
int main(){
  char s[110];
  int i,k=0,j;
  scanf("%s",s);
  j=strlen(s);
  for(i=0;i<j;i++){
    if(i%2==0){
      if(s[i]=='R' || s[i]=='U' || s[i]=='D'){
      }
      else{
        k++;
        break;
      }
    }
    else{
      if(s[i]=='L' || s[i]=='U' || s[i]=='D'){
      }
      else{
        k++;
        break;
      }
    }
    if(k!=0){
      break;
    }
  }
  if(k==0){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl


// ax+by=1の解
ll extgcd(ll a, ll b, ll& x, ll& y) {
	ll d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1; y = 0;
	}
	return d;
}
// mod mでのaの逆数
ll mod_inverse(ll a, ll m) {
	ll x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}
// nの階乗 mod p
ll factorial(int n, int p) {
	ll r = 1;
	for (int i = 1; i <= n; i++)
		r = (r * i) % p;
	return r;
}
// nPr mod p
ll permutation(int n, int r, int p) {
	ll a = 1;
	for (int i = n - r + 1; i <= n; i++)
		a = (a * i) % p;
	return a;
}
// nCr mod p
ll combination(int n, int r, int p) {
	if (r == 0 || r == n) return 1;
	if (r > n / 2) r = n - r;
	ll numerator = permutation(n, r, p);
	ll denominator = factorial(r, p) % p;
	ll inv = mod_inverse(denominator, p);
	return (numerator * inv) % p;
}


signed main() {

	int N, M, K;
	cin >> N >> M >> K;

	int ans1 = 0;
	for (int i = 1; i <= M - 1; i++) {
		ans1 += i * (M - i);
		ans1 %= mod;
	}
	int ans2 = 0;
	for (int i = 1; i <= N - 1; i++) {
		ans2 += i * (N - i);
		ans2 %= mod;
	}
	int ans = ((((ans1 * N)%mod) * N)%mod) + ((((ans2 * M)%mod) * M)%mod);

	ans *= combination(N * M - 2, K - 2, mod);
	ans %= mod;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
x, k, d = map(int, input().split())
if x < 0:
    target = abs(x) // d
    x = x + d * min(target, k)
    k -= min(target, k)
else:
    target = x // d
    x = x - d * min(target, k)
    k -= min(target, k)
if k % 2 != 0:
    if x < 0:
        x += d
    else:
        x -= d
print(abs(x))


Measured memory_bytes: 9120
package main

import "fmt"

func main() {
	// Code for B - Bitter Alchemy
	var N, X int
	fmt.Scanf("%d %d", &N, &X)

	var m, sum int
	var min int = 1000
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &m)
		sum += m
		if min > m {
			min = m
		}
	}

	fmt.Println(N + (X-sum)/min)
}


Measured memory_bytes: 1836
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    rep3(i,1,n){
        rep3(j,i+1,n+1){
            ll temp=abs(i-j);
            ll cnt=0;
            while(temp%2==0){
                cnt++;
                temp/=2;
            }
            cout<<cnt+1<<" ";
        }
        cout<<endl;
    }
}

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

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int N, A, B; cin >> N >> A >> B;
    cout << min(A*N, B) << endl;
  
    return 0;
}



Measured memory_bytes: 256