akhauriyash/Code-Regression huggingface dataset:
// by newbiechd
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl

const int N_MAX = 200003;
long long init = 0xcfcfcfcfcfcfcfcf;
long long dp[N_MAX][3];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n >> dp[1][0];
  dp[1][1] = dp[1][2] = init;
  for (int i = 2; i <= n; ++i) {
    string op;
    int x;
    cin >> op >> x;
    if (op[0] == '-') {
      dp[i][0] = init;
      dp[i][1] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2])) - x;
      dp[i][2] = max(dp[i - 1][1], dp[i - 1][2]) + x;
    }
    else {
      dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2])) + x;
      dp[i][1] = max(dp[i - 1][1], dp[i - 1][2]) - x;
      dp[i][2] = dp[i - 1][2] + x;
    }
  }
  cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
  return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100010,maxm=1e6+10,mod=1e9+7;
int n,bas,ans;
int a[maxn],np[maxm],tg[maxm];

ll fpm(ll a,ll b){
    ll ret=1ll;
    for(;b;b>>=1,a=a*a%mod)
        if(b&1)ret=ret*a%mod;
    return ret;
}
void solve(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;++i)cin>>a[i];
    for(int i=2;i<maxm;++i){
        if(!np[i])
            for(int j=i;j<maxm;j+=i)
                np[j]=i;
    }
    for(int i=1,x;i<=n;++i){
        for(int x=a[i],y,cnt;x!=1;){
            cnt=0;
            for(y=np[x];x%y==0;){
                ++cnt;
                x/=y;
            }
            tg[y]=max(tg[y],cnt);
        }
    }
    bas=1,ans=0;
    for(int i=2;i<maxm;++i)
        bas=fpm(i,tg[i])*bas%mod;
    for(int i=1;i<=n;++i){
        ans+=1ll*bas*fpm(a[i],mod-2)%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
}
int main(){
    solve();

    return 0;
}

Measured memory_bytes: 8192
#include <stdio.h>

int maxn(int a[], int n)
{
  int max = a[0];
  int i;
  for (i = 0; i < n; i++)
    if (a[i] > max)
      max = a[i];
  return max;
}

int minn(int a[], int n)
{
  int min = a[0];
  int i;
  for (i = 0; i < n; i++)
    if (a[i] < min)
      min = a[i];
  return min;
}

int main(void)
{
  int x[100];
  int y[100];
  int n, m, X, Y;
  scanf("%d %d %d %d", &n, &m, &X, &Y);
  for (int i = 0; i < n; i++)
    scanf("%d", &x[i]);
  for (int j = 0; j < m; j++)
    scanf("%d", &y[j]);
  if (maxn(x, n) < minn(y, m) && X < Y && maxn(x, n) < Y && X < minn(y,m))
    puts("No War");
  else
    puts("War");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
double Pi = 3.1415926535897932384626;
 
//vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
ll mod = 1000000007;
/*
2000000011 is prime
2000000033 is prime
*/

ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

/*
ll fact[800005],rfact[800005];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[800000] = rui(fact[800000],mod - 2);
    for(ll i=800000; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r,l;
ll k,ans;
ll x[500005],y[500005],z[500005];

ll x1,x2,x3,x4;
ll y11,y2,y3,y4;
int main(){
    cin >> n;
    for(i=0;i<n;i++){
        cin >> x[i];
    }
    float ans = 0.0f;
    for(i=0;i<n;i++){
        ans += 1.0f / x[i];
    }
    ps(1/ans);
    return 0;
}






Measured memory_bytes: 2304
import scala.io.StdIn.readLine

object Main {
  val gesIndex = Map("Rock"->0,"Fire"-> 1, "Scissors" -> 2, "Snake" -> 3,
                    "Human"->4, "Tree"->5, "Wolf"->6, "Sponge"->7,
                    "Paper"->8, "Air"->9, "Water"->10, "Dragon"->11,
                    "Devil"->12, "Lightning"->13, "Gun" -> 14)

  def scan(list:Array[Int],i:Int,n:Int):String = {
    if(i==n) "Draw"
    else {
      val win = (list((i+1)%n)-list(i)+15)%15
      val j = if(i>0) i-1 else n-1
      val lose = (list(i)-list(j)+15)%15
      if(win<=7 && lose>7) gesIndex.find(_._2==list(i)).map(_._1).get
      else scan(list,i+1,n)
    }
  }

  def main(args:Array[String]) = {
    var n = 0
    while({n=readLine.trim.toInt;n}!=0) {
      val list = {for(i<-1 to n) yield gesIndex(readLine.trim)}.toArray.sorted
      println(scan(list,0,list.length))
    }
  }
}

Measured memory_bytes: 53992
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, x;
    cin >> a >> b >> x;
    if(a == 0LL){
    	cout << b / x + 1 << endl;
    	return 0;
    }
    a = (a - 1) / x;
    b /= x;
    cout << b - a << endl;

    return 0;
}


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

#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  int N, Q;
  cin >> N >> Q;
  fenwick_tree<ll> fen(N);
  REP(i, N) {
    int a;
    cin >> a;
    fen.add(i, a);
  }
  REP(i, Q) {
    int p, l, r;
    cin >> p >> l >> r;
    if (p) {
      cout << fen.sum(l, r) << "\n";
    } else {
      fen.add(l, r);
    }
  }
}

Measured memory_bytes: 8208
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int mod=1e9+7;
int n;
string s;
ll dp[3005][3005];
void mplus(int& a,ll b){
	a+=b;
	if(a>=mod){
		a-=mod;
	}
}
int main(){
	cin>>n>>s;
	s=' '+s;
	dp[1][1]=1;
	for(int i=2;i<=n;++i){
		if(s[i-1]=='<'){
			dp[i][1]=0;
			for(int j=2;j<=i;++j){
				dp[i][j]=(dp[i][j-1]+dp[i-1][j-1])%mod;
			}
		}
		else{
			dp[i][i]=0;
			for(int j=i-1;j>=1;--j){
				dp[i][j]=(dp[i][j+1]+dp[i-1][j])%mod;
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;++i){
		mplus(ans,dp[n][i]);
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 69120
def main():
    N = input()
    if int(N) < 0 or int(N) >= 10**200000:
        raise ValueError
    i = 0
    sum = 0
    for i in N:
        sum += int(i)
        if sum % 9 == 0:
            sum = 0
    if sum % 9 == 0:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

const int mINF = (-5) * (int)1e8;

struct Edge { int to, cost; };

void maxUpdate(int& a, int b) { a = max(a, b); }

struct Pocket {
	int n, mode;
	vector< int > dp[2][2][2][2];
	
	Pocket(vector< int >& cost_vec, int _mode_) {
		n = cost_vec.size() + (1 - _mode_);
		mode = _mode_;
		
		for_(i,0,2) for_(j,0,2) for_(ii,0,2) for_(jj,0,2) dp[i][j][ii][jj].assign(n + 10, mINF);
		dp[mode][0][0][0][0] = 0;
		
		for_(i,0,n) {
			int ci = i & 1, ni = 1 - ci;
			
			for_(cnt,0,n+1) for_(j,0,2) for_(k,0,2) dp[mode][ni][j][k][cnt] = mINF;
			
			for_(cnt,0,n+1) for_(j,0,2) for_(k,0,2) {
				if (dp[mode][ci][j][k][cnt] == mINF) continue;
				
				maxUpdate(dp[mode][ni][0][k][cnt], dp[mode][ci][j][k][cnt]);
				
				if (i > 0 && j && cost_vec[i - 1] == 0) continue;
				if (mode && i == n - 1 && k && cost_vec[n - 1] == 0) continue;
				
				maxUpdate(dp[mode][ni][1][k | (i == 0)][cnt + 1],
						  dp[mode][ci][j][k][cnt] +
						  (cnt != 0 && j ? cost_vec[i - 1] : 0) +
						  (mode && i == n - 1 && k ? cost_vec[n - 1] : 0));
			}
		}
	}
	
	int getCost(int k) {
		int res = mINF;
		for_(i,0,2) for_(j,0,2) maxUpdate(res, dp[mode][n & 1][i][j][k]);
		return res;
	}
	
	void dump() {
		for_(k,0,n+1) cout << getCost(k) << " ";
		cout << endl;
	}
};

int N, M, K, dp[2020][2020];
vector< vector< Edge > > edges;
vector< bool > vis;

void dfs(int v, int p, vector< int >& cost_vec) {
	if (vis[v]) return;
	vis[v] = true;
	
	for (Edge e : edges[v]) {
		if (e.to != p) {
			cost_vec.push_back(e.cost);
			dfs(e.to, v, cost_vec);
		}
	}
}

void solve() {
	vis.assign(N, false);
	
	vector< Pocket > pockets;
	
	for_(sz,1,3) {
		for_(v,0,N) {
			if (vis[v] || (int)edges[v].size() != sz) continue;
			vector< int > cost_vec;
			if (sz == 2) edges[v].pop_back();
			dfs(v, -1, cost_vec);
			pockets.push_back(Pocket(cost_vec, sz == 2));
			/*
			int n = cost_vec.size();
			cout << v << ", " << n << " : ";
			for_(i,0,n) cout << cost_vec[i] << " ";
			cout << endl;
			pockets.back().dump();
			*/
		}
	}
	
	int P = pockets.size(), cnt0 = 0;
	
	for_(v,0,N) cnt0 += (edges[v].size() == 0);
	
	for_(i,0,P+1) for_(j,0,K+1) dp[i][j] = mINF;
	
	for_(i,0,cnt0+1) dp[0][i] = 0;
	
	for_(i,0,P) {
		int n = pockets[i].n;
		
		for_(j,0,K+1) {
			if (dp[i][j] == mINF) continue;
			for_(k,0,n+1) maxUpdate(dp[i + 1][j + k], dp[i][j] + pockets[i].getCost(k));
		}
	}
	
	if (dp[P][K] == mINF) cout << "Impossible" << endl;
	else cout << dp[P][K] << endl;
}

int main() {
	cin >> N >> M >> K;
	
	edges.assign(N, vector< Edge >());
	
	for_(i,0,M) {
		int u, v, c;
		cin >> u >> v >> c;
		--u; --v;
		edges[u].push_back(Edge{v, c});
		edges[v].push_back(Edge{u, c});
	}
		
	solve();
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N, A, B;
  cin >> N >> A >> B;

  int cnta = 0;
  int cntb = 0;

  string s;
  cin >> s;
  vector<bool> ans(N);
  rep(i, N) ans[i] = false;
  rep(i, N){
    if(s[i]=='a'){
      if(cnta+cntb < A+B){
        cnta++;
        ans[i] = true;
      }
    }else if(s[i] == 'b'){
      if(cnta + cntb < A+B && cntb+1 <= B){
        cntb++;
        ans[i] = true;
      }
    }
  }

  rep(i, N){
    if(ans[i]){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }






  return 0;
}


Measured memory_bytes: 848
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  vector<vi> g(2, vi(n));
  rep(i, 2) rep(j, n) cin >> g[i][j];
  int ans = 0;
  rep(k, n) {
    int now = 0;
    int i = 0;
    rep(j, n) {
      now += g[i][j];
      if(k == j) {
        i++;
        now += g[i][j];
      }
    }
    ans = max(ans, now);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
S = input()

c = int(S, 2)
a = int(''.join('0' if x % 2 == 0 else '1' for x in range(len(S))), 2) ^ c
b = int(''.join('1' if x % 2 == 0 else '0' for x in range(len(S))), 2) ^ c

ax = len([x for x in str(bin(a)) if x == '1'])
bx = len([x for x in str(bin(b)) if x == '1'])

print(min(ax, bx))



Measured memory_bytes: 4092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  string S; cin >> S;
  int N = S.size();
  
  int w = 0;
  int ans = 0;
  rep(i, N) {
    if(S[i] == 'W') {
      ans += i-w;
      w++;
    }
  }
  if(w == N) {
    cout << 0 << endl;
    return 0;
  }
  cout << ans << endl;


}

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

int main(void) {
  ios::sync_with_stdio(false);
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  int all_min = H * 60 + M;

  double hour = (double)all_min * (360.0 / (12.0 * 60.0));
  double minu = (double)M * (360.0 / 60.0);
  double diff = max(hour, minu) - min(hour, minu);
  diff = min(diff, 360.0 - diff);
  double answer =
      sqrt(double(A * A + B * B) - 2.0 * A * B * cos(diff * M_PI / 180.0));
  cout << setprecision(20) << answer << endl;
  return 0;
}


Measured memory_bytes: 4268
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

ll gcd(ll a, ll b) {
    if(a < b) swap(a, b);
    ll r;
    while((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll lcm = C * D / gcd(C, D);
    cout << B - A + 1 - (B/C + B/D - B/lcm) + ((A-1)/C + (A-1)/D - (A-1)/lcm) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, num;
    char mark;
    cin >> n;
    vector<vector<int>> cards(4, vector<int>(14));
    for (int i=0; i<n; i++){
        cin >> mark >> num;
        if (mark == 'S'){
            cards.at(0).at(num) = 1; //0行をSの行に
        } else if (mark == 'H'){
            cards.at(1).at(num) = 1; //1行をHの行に
        } else if (mark == 'C'){
            cards.at(2).at(num) = 1; //2行をCの行に
        } else if (mark == 'D'){
            cards.at(3).at(num) = 1;
        }
    }
    for (int i=0; i<4; i++){
        for (int j=1; j<14; j++){
            if (cards.at(i).at(j) != 1){
                if (i == 0) mark = 'S';
                else if (i == 1) mark = 'H';
                else if (i == 2) mark = 'C';
                else mark = 'D';
                cout << mark << " " << j << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
#define N 1009
using namespace std;
typedef long long LL;

char mp[N][N];

void solve(int n)
{
    for(int i = 1; i <= n; i++) printf("#");
    printf("\n");
}



int main()
{
    int m, n;
    scanf("%d%d", &m, &n);
    for(int i = 1; i <= m; i++) scanf(" %s", &mp[i][1]);
    solve(n+2);
    for(int i = 1; i <= m; i++)
    {
        printf("#");
        for(int j = 1; j <= n; j++)
        {
            printf("%c", mp[i][j]);
        }
        printf("#\n");
    }
    solve(n+2);
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int func(string name,  map<string,int> &list,  map<string,vector<string> > &renkin){
  if(renkin.find(name)==renkin.end()) return list[name];
  int ret = 0;
  vector<string> mat = renkin[name];
  REP(i,mat.size()){
    ret += func(mat[i],list,renkin);
  }
  return min(list[name],ret);
}

int main(void){
  int n,m;
  while(cin>>n){
    if(n==0) break;
    map<string,int> list;
    map<string,vector<string> > renkin;
    REP(j,n){
      string i;
      int p;
      cin>>i>>p;
      list[i] = p;
    }
    cin>>m;
    REP(i,m){
      string o;
      int k;
      cin>>o>>k;
      vector<string> q(k);
      REP(j,k) cin>>q[j];
      renkin[o] = q;
    }
    string item;
    cin>>item;
    cout<<func(item,list,renkin)<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1001001001001;
const double EPS = 1e-10;

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

    ll n;
    cin>>n;
    ll ans=0;
    for(ll j=1;j<=n;j++){
        ans+=(j+(n/j)*j)*(n/j)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3656
#include<stdio.h>
    int main(void){
    int x,i;
    scanf("%d",&x);
    for(i=1;i<=x;i++){
        if(i%3==0||i%10000%1000%100%10==3||i%10000%1000%100/10==3||i%10000%1000/100==3||i%10000/1000==3){
            printf(" %d",i);
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int a[52][52]={};
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
int h,w;

//color B,W->+1,-1 ?????§??£??\B,W,B&W->+2,-2,10 ?£?->100
void paint(int y,int x,int color){
    if((fabs(a[y][x])!=2 && a[y][x]!=0) || a[y][x]==color)return;
    if(a[y][x]+color==0)color = 10;
    a[y][x] = color;
    rep(i,4)paint(y+dy[i],x+dx[i],color);
}

int main(void){
    char tmp;
    while(cin>>w>>h, w|h){
        int cntB=0,cntW=0;

        /*??\???*/
        rep1(y,h){
            rep1(x,w){
                cin>>tmp;
                if(tmp=='.')a[y][x] = 0;
                else if(tmp=='B')a[y][x] = 1;
                else a[y][x] = -1;
            }
        }

        /*?£??¨????*/
        rep(y,h+2)a[y][0]=a[y][w+1] = 100;
        rep(x,w+2)a[0][x]=a[h+1][x] = 100;

        /*????????????*/
        rep1(y,h)rep1(x,w)if(fabs(a[y][x])==1)rep(i,4)paint(y+dy[i],x+dx[i],2*a[y][x]);

        /*????????????*/
        rep1(y,h){
            rep1(x,w){
                if(a[y][x]==2)cntB++;
                else if(a[y][x]==-2)cntW++;
            }
        }
        cout<<cntB<<" "<<cntW<<endl;
    }

    return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[5],k;
  for(int i=0;i<5;i++){
    cin >> a[i];      /* code */
    }
    cin >> k;
    sort(a,a+5);
    if(a[4]-a[0]<=k) cout << "Yay!" << endl;
    else cout << ":(" << endl;

}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int popn( int B ){
    int cnt = 0;
    while(B){
        B -= (-B)&B;
        cnt++;
    }
    return cnt;
}

int N;

int swapn( vii& a ){
    int ret = 0;
    vi cnt(51,0);
    Rep(i,N){
        Repe(j,N,a[i].second){
            ret += cnt[j];
        }
        cnt[a[i].second]++;
    }
    return ret;
}

int main() {

    Scd(N);
    vi a(N),b(N);
    Rep(i,N){
        Scd(a[i]);
    }
    Rep(i,N){
        Scd(b[i]);
        if( i%2 ) swap(a[i],b[i]);
    }

    int B = 1<<N;
    int ans = INF;
    vii aa(N/2+1);
    vii bb(N/2);
    vii cc(N);
    bool ok;

    Rep(bi,B){
        if( popn(bi) != (N+1)/2 ) continue;
        aa.clear();
        bb.clear();
        cc.clear();
        Rep(i,N) if( (bi)&(1<<i)  ) aa.push_back({a[i],i});
        Rep(i,N) if( !(bi&(1<<i)) ) bb.push_back({b[i],i});
        sort(aa.begin(),aa.end());
        sort(bb.begin(),bb.end());
        Rep(i,N){
            cc[i] = (i%2?bb:aa)[i/2];
        }
        ok = true;
        Rep(i,N-1){
            if( cc[i].first > cc[i+1].first ) ok = false;
        }
        if( !ok ) continue;
        else{
            ans = min( ans, swapn(cc) );
        }
    }

    if( ans == INF ) ans = -1;
    printf ("%d\n", ans );


    return 0;
}



Measured memory_bytes: 256
S = input().replace('><','> <').split()
ans = 0
for s in S:
    up = s.count('<')
    down = len(s)-up
    if up < down:
        up -= 1
        ans += up*(up+1)//2 + down*(down+1)//2
    else:
        down -= 1
        ans += up*(up+1)//2 + down*(down+1)//2        
print(ans)

Measured memory_bytes: 12336
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
// using Graph = vector<vector<int>>;
const ll mod = 998244353;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
} c(200005);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ///////////////////////////////////////
  int n, m, k;
  cin >> n >> m >> k;
  mint ans = 0;
  mint col = m;
  for (int x = n - 1; x >= 0; --x) {
    mint now = col;
    now *= c(n - 1, x);
    if (x <= k) ans += now;
    col *= m - 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6240
#include <stdio.h>
#include <string.h>

int x, y, n;
int name[15], size[15];
int ans, record[10][10];

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

void copy(int saki[][10], int moto[][10])
{
    int i, j;
    
    for (i = 0; i < y; i++){
        for (j = 0; j < x; j++){
            saki[i][j] = moto[i][j];
        }
    }
}

int canPlace(int w, int h, int sy, int sx, int now, int map[][10])
{
    int i, j;
    int flag = 0;
    
    for (i = sy; i < sy + h; i++){
        for (j = sx; j < sx + w; j++){
            if (map[i][j] == name[now]){
                flag = 1;
            }
            else if (map[i][j]){
                return (0);
            }
        }
    }
    return (flag);
}

void place(int w, int h, int sy, int sx, int now, int map[][10])
{
    int i, j;
    
    for (i = sy; i < sy + h; i++){
        for (j = sx; j < sx + w; j++){
            map[i][j] = name[now];
        }
    }
}

int generateMap(int now, int map[][10])
{
    int i, j, k, t;
    int my, mx;
    int temp[10][10];
    int check;
    int w, h;
    
    
    if (now == n){
        copy(record, map);
        ans++;
        return (1);
    }

    check = 0;
    for (t = 1; t <= size[now]; t++){
        if (size[now] % t != 0){
            continue;
        }
        w = size[now] / t;
        h = t;
        
        for (i = 0; i <= y - h; i++){
            for (j = 0; j <= x - w; j++){
                if (canPlace(w, h, i, j, now, map)){
                    copy(temp, map);
                    place(w, h, i, j, now, temp);
                    check |= generateMap(now + 1, temp);
                }
            }
        }
    }
    
    return (check);
}

int main(void)
{
    
    int i, j;
    int map[10][10];
    
    while (1){
        scanf("%d%d%d", &x, &y, &n);
        
        if (x + y + n == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            scanf("%d%d", &name[i], &size[i]);
        }
        for (i = 0; i < y; i++){
            for (j = 0; j < x; j++){
                scanf("%d", &map[i][j]);
            }
        }
        
        memset(record, 0, sizeof(record));
        ans = 0;
        
        if (!generateMap(0, map) || ans != 1){
            printf("NA\n");
        }
        else {
            for (i = 0; i < y; i++){
                for (j = 0; j < x; j++){
                    printf("%d%c", record[i][j], j == x - 1 ? '\n' : ' ');
                }
            }
        }
    }
    
    return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;

long long factrial(long long n){
    long long sum = 1;
    for(int i=1; i<=n; i++){
        sum *= i;
    }
    return sum;
}

int main(){
    ll N; std::cin >> N;
    std::vector<ll> P, Q;
    for(int i=0; i<N; i++){
        ll b; std::cin >> b;
        P.push_back(b);
    }
    for(int i=0; i<N; i++){
        ll b; std::cin >> b;
        Q.push_back(b);
    }

    std::vector<ll> nums;
    for(int i=0; i<N; i++){
        nums.push_back(i+1);
    }

    ll a=0, b=0;
    for(int i=0; i<factrial(N); i++){
        if(nums==P) a = i;
        if(nums==Q) b = i;
        std::next_permutation(nums.begin(), nums.end());
    }

    std::cout << abs(a-b);
    return 0;
}


Measured memory_bytes: 256
function Main(input){
    input = input.split("\n");
    input.shift();
    var arr = {};
    for(var i=0;i<input.length;i++){
        if(!arr[input[i]]){
            arr[input[i]] = true;
        }
    }
    console.log(Object.keys(arr).length)
  }Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 83152
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long int
#define pb push_back
using namespace std;
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll a,b,k;
	scanf("%lld%lld%lld", &a,&b,&k);
	a -= k;
	if(a < 0) b += a, a = 0;
	printf("%lld %lld\n", a, max(b,0ll));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, m; cin>>n>>m;
    int sum = 0;
    int ans = 1;
    for(int i=0;i<n;i++){
        int a ; cin>>a;
        sum+= a;
        if(sum<=m) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
// by tmt514
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define SZ(x) ((int)(x).size())
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
using namespace std;
typedef long long LL;

const LL MOD = 998244353;
LL bigmod(LL a, LL n) {
  if(n==0) return 1;
  if(n==1) return a%MOD;
  return bigmod(a*a%MOD, n/2) * (n%2? a:1)%MOD;
}
int a[1005][1005] = {};
int main(void) {
  int n, m;
  cin >> n >> m;
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      cin >> a[i][j];
  int rank=0, w=0;
  if(n>m) {
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++)
        swap(a[i][j], a[j][i]);
    swap(n, m);
  }
  for(int i=0;i<m;i++) {
    int g=-1;
    for(int j=w;j<n;j++)
      if(a[j][i]==1) {
        g=j;
        break;
      }
    if(g>=0) {
      for(int k=0;k<m;k++)
        swap(a[w][k], a[g][k]);
      for(int j=w+1;j<n;j++) {
          if(a[j][i]==1)
        for(int k=0;k<m;k++)
          a[j][k] ^= a[w][k];
      }
      ++rank;
      ++w;
    }
  }
  
  LL t = bigmod(2, m-1) * (bigmod(2, n) - bigmod(2, n-rank)) % MOD;
  t=(t%MOD+MOD)%MOD;
  cout << t << endl;
  
      
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std ;
int main() {
	int k, x;
	cin >> k >> x ;
	
	if ( ( k * 500 ) >= x )
	{
		
		cout << "Yes" ;
		
	}
	
	else
	{
		
		cout << "No" ;
		
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

#define ll long long
#define db double
#define clr(a, b) memset(a, b, sizeof(a))

const int maxn = 2e5 + 10;
const int inf = 0x7ffffff;

int a[maxn], pos[maxn];

void solve()
{
    int N, x;
    cin >> N;
    clr(pos, 0);
    for (int i = 1; i <= N;i++)
    {
        cin >> a[i];
        pos[a[i]]++;
    }
    ll ans = 0;
    for (int i = 1; i <= N;i++)
    {
        if(pos[i])
            ans = ans + 1ll*(pos[i] - 1) * pos[i] / 2;
    }
    ll res = 0;
    for (int i = 1; i <= N;i++)
    {
        res = ans - 1ll*(pos[a[i]] - 1) * pos[a[i]] / 2 + 1ll*(pos[a[i]] - 1) * (pos[a[i]] - 2) / 2;
        cout << res << "\n";
    }
}

int main()
{
    //freopen("out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T-- > 0)
        solve();

}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define ll long long

using namespace std;
ll a[1010],b[1010],c[1010],d[1000100];
vector < ll > v;

int main()
{
    ll x,y,z,K;
    cin >> x >> y >> z >> K;
    for(int i = 0; i<x; i++)  cin >> a[i];
    for(int i = 0; i<y; i++)  cin >> b[i];
    for(int i = 0; i<z; i++)  cin >> c[i];
    int q = 0;
    for(int i = 0; i<x; i++)
    {
        for(int j = 0; j<y; j++)
        {
            d[q++] = a[i] + b[j];
        }
    }
    sort(d, d + q, greater < ll >());
    sort(c, c + z, greater < ll >());
    ll Start = 0, End = 9e18, Res;
    while(Start <= End)
    {
        ll mid = (Start + End)/2;
        ll j = z - 1, pos = 0;
        for(int i = 0; i<q; i++)
        {
            while(j - 1  >= 0 && d[i] + c[j] < mid)  j--;
            pos+=j + (d[i] + c[j] >= mid);
        }
        if(pos < K)  End = mid - 1;
        else  Res = mid , Start = mid + 1;
    }
    for(int i = 0;i<q;i++){
        int Start = 0 , End = z - 1 , idx = -1;
        while(Start <= End){
            int mid = (Start + End)/2;
            if(d[i] + c[mid] >= Res)  idx = mid , Start = mid + 1;
            else  End = mid - 1;
        }
        for(int k = idx;k>=0;k--)  v.push_back(d[i] + c[k]);
    }
    sort(v.rbegin() , v.rend());
    for(auto x : v)  if(K) cout << x << '\n' , K--;
    return 0;
}


Measured memory_bytes: 140764
n, k = map(int, input().split())
L = list(map(lambda x: (int(x) + 1) / 2, input().split()))

previous = sum(L[:k])
current_max = previous
for i in range(n-k):
    # print(previous)
    after = previous - L[i] + L[i+k]
    current_max = max(current_max, after)
    previous = after

print(current_max)

Measured memory_bytes: 23524
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
long long K;
int N = 50;
long long A[50];
int main(){
  int i;
  rd(K);
  for(i=(0);i<(N);i++){
    A[i] = N-1 + K / N;
  }
  K %= N;
  for(i=(0);i<(K);i++){
    A[i] += N+1;
  }
  for(i=(0);i<(N);i++){
    A[i] -= K;
  }
  wt_L(N);
  wt_L('\n');
  {
    int Lj4PdHRW;
    if(N==0){
      putchar_unlocked('\n');
    }
    else{
      for(Lj4PdHRW=(0);Lj4PdHRW<(N-1);Lj4PdHRW++){
        wt_L(A[Lj4PdHRW]);
        wt_L(' ');
      }
      wt_L(A[Lj4PdHRW]);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20190921-1

// --- original code ---
// ll K;
// int N = 50; ll A[50];
// {
//   rd(K);
//   rep(i,N) A[i] = N-1 + K / N;
//   K %= N;
//   rep(i,K) A[i] += N+1;
//   rep(i,N) A[i] -= K;
//   wt(N);
//   wt(A(N));
// }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N,H; cin >> N >> H;
    VI a(N), b(N);
    int MAX_A = 0;
    LL SUM_B = 0;

    REP(i,N)
    {
        int tmpa, tmpb;
        cin >> tmpa >> tmpb;
        a[i] = tmpa; b[i] = tmpb;
        if(MAX_A < tmpa) MAX_A = tmpa;
        SUM_B += tmpb * 1LL;

    }
    sort(b.begin(), b.end(), greater<int>());
    int ans = 0;
    int count = 0;

    while(H > 0)
    {
        if(b[count] > MAX_A)
        {
            H -= b[count];
            count++;
            ans++;
        }
        else
        {
            H -= MAX_A;
            ans++;
        }

    }

    //if(SUM_B >= H)
    //{
        //int count = 0;
    //
        //while(H > 0)
        //{
            //H -= b[count];
            //ans++;
        //}
//
    //}
    //else
    //{
        //H -= SUM_B;
        //ans += N;
        //ans += ((H+MAX_A-1) / MAX_A);
    //}

    cout << ans << endl;


}


Measured memory_bytes: 1024
require 'prime'
while line = gets
n = line.chomp.to_i
break if n == 0
ary = Prime.each(n).to_a
result = []
  for i in 0...(ary.size - 1)
    if ary[i + 1] - ary[i] == 2
      result[0] = ary[i]
      result[1] = ary[i + 1]
  end
end
puts result.join(" ")
end


Measured memory_bytes: 17392
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;
const ll MOD = 1e9+7;
const ll INF = 1e18;


#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}

int main(){
    ll n,m,x;
    cin >> n >> m >> x;
    ll c[n];
    ll a[n][m];
    for(ll i=0;i<n;i++){
        cin >> c[i];
        for(ll j=0;j<m;j++){
            cin >> a[i][j];
        }
    }

    bool ans=false;
    ll cost;

    for (int bit = 0; bit < (1 << n); ++bit) { //全部でN個
        vector<ll> rikaido(m,0);
        ll tmp=0;
        bool flag=true;
	    for (int i = 0; i < n; ++i) {
        	if (bit & (1 << i)){
			    //bitが立った要素iに対してやること
                for(ll j=0;j<m;j++){
                    rikaido[j]+=a[i][j];
                }
                tmp += c[i];
         	}
        }
        for(ll j=0;j<m;j++){
            if(rikaido[j]<x){
                flag = false;
            }
        }
        if(flag){
            ans=true;
            chmin(cost,tmp);
        }
    }
    if(ans){
        cout << cost << endl;
    }else{
        cout << -1 << endl;
    }
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,isp[10000010],num[10000010],tmp,cnt,ans=1;

int main()
{
	cin>>n;
	rep(i,10000005) isp[i]=num[i]=1;
	for(LL i=2;i<=n;i++)
	{
		if(isp[i]==0) continue;
		num[i]=2;
		for(LL j=i+i;j<=n;j+=i)
		{
			//cout<<'k';
			isp[j]=0;
			tmp=j;
			cnt=0;
			while(tmp%i==0)
			{
				tmp/=i;
				cnt++;
			}
			num[j]*=(cnt+1);
			//cout<<j<<' '<<cnt+1<<' '<<num[j]<<'p'<<endl;
		}
	}
	for(LL i=2;i<=n;i++) ans+=i*num[i];//,cout<<i<<' '<<num[i]<<endl;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 159880
#include <stdio.h>

int main(){
  int a,b,k;
  scanf("%d", &k);
  scanf("%d%d", &a,&b);
  if(1<=k&&k<=1000){
  if(a>=1&&a<=b&&b<=1000){
    for(int i=a; i<=b; i++){
      if(i%k == 0){
        printf("OK\n");
        return 0;
      }
    }
  }
}
printf("NG\n");
return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> d(1e5+1);
  rep(i,n) {
    int x;
    cin >> x;
    d[x]++;
  }
  int ans = 0;
  int sum = 0;
  for (int i = 1; i <= 1e5; i++) {
    sum += d[i];
    if (sum == n-sum) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3752
import sys

input = sys.stdin.readline


def main():
    A, B, C, K = map(int, input().split())

    if K <= A:
        ans = K
    elif K <= A + B:
        ans = A
    else:
        ans = A - (K - (A + B))

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9168
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 +7;



fn main() {
    input!{n:i64};
    let mut ans:i64 = 1;
    for i in 0..n {
        ans *= i+1;
        ans %= MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
N,K=map(int, input().split())
*A,=map(int, input().split())
def gcd(a,b):
    while b: a,b=b,a%b
    return a
g=0
for a in A: g=gcd(g,a)
print('POSSIBLE' if K%g==0 and K<=max(A) else 'IMPOSSIBLE')

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

// ABC128A - Apple Pie
// https://atcoder.jp/contests/abc128/tasks/abc128_a
void ABC128A() {

	int A, P;
	cin >> A >> P;

	//欠片の数
	P = P + A * 3;

	//答え
	cout << (int)(P / 2);

}


int main() {
	ABC128A();

	return 0;
}

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

############### TESTCASE ###############
test = ""
#test = \
"""
2 5
1 WA
1 AC
2 WA
2 AC
2 WA
ans 2 2
"""

"""
100000 3
7777 WA
7777 WA
7777 WA
ans 0 0
"""

"""
6 0
ans 0 0
"""

"""
2 10
1 WA
1 AC
2 WA
2 AC
2 WA
1 WA
1 AC
2 WA
2 AC
2 WA
ans 2 2
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
################# MAIN ################# 

n, m = map(int, input2().split())
ps = [None] * m
for i in range(m):
    tmp = input2().split()
    ps[i] = int(tmp[0]), tmp[1]

aced = [0] * (n + 1)
wabfac = [0] * (n + 1)

for item in ps:
    if item[1] == "AC":
        aced[item[0]] = 1
    if item[1] == "WA":
        if aced[item[0]] == 0:
            wabfac[item[0]] += 1

penaans = 0
for j in range(1, n+1):
    if aced[j] == 1:
        penaans += wabfac[j]

print(aced.count(1), penaans)




Measured memory_bytes: 20444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i, sz(v)) { if (i) os << " "; os << v[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a - mod; }

void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
      solve();
    }
}


void solve() {
  int n;
  cin >> n;

  rep3(i, n, inf) {
    int flg = 0;
    for (int j = 2; j * j <= i; ++j) {
      if (i % j == 0) {
        flg = 1;
        break;
      }
    }
    if (flg == 0) {
      cout << i << endl;
      return;
    }
  }
}


Measured memory_bytes: 256
import sys

line = sys.stdin.readline().strip()
n,m,k = map(int, line.split())
roots = [-1]*n
linked = [0]*n
def find_root(x):
    if roots[x] < 0:
        return x
    else:
        roots[x] = find_root(roots[x])
        return roots[x]
def unite(x, y):
    x = find_root(x)
    y = find_root(y)
    if (x==y):
        return
    if roots[x] > roots[y]:
        c, d = y,x
        x,y = c,d
    roots[x] += roots[y]
    roots[y] = x

for i in range(m):
    line = sys.stdin.readline().strip()
    a,b = map(int, line.split())
    c, d = a-1,b-1
    linked[c] += 1 
    linked[d] += 1
    unite(c,d)
#print(roots)
blacks = [[]for i in range(n)]
for i in range(k):
    line = sys.stdin.readline().strip()
    a,b = map(int, line.split())
    c,d = a-1, b-1
    blacks[c].append(d)
    blacks[d].append(c)
res = []
for i in range(n):
    r = -roots[find_root(i)] - 1 - linked[i]
    for one in blacks[i]:
        if find_root(one) == find_root(i):
            r -= 1
    res.append(r)
    
print (" ".join(map(str, res)))

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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int k, n;
    cin >> k >> n;
    vector<int> arr(n);
    for(int &x : arr) cin >> x;
    int ans = 0;
    for(int i = 0; i < n - 1; i++) {
        ans = max(ans, arr[i + 1] - arr[i]);
    }
    ans = max(ans, k + arr[0] - arr[n - 1]);
    cout << k - ans << '\n';
    return 0;
}

Measured memory_bytes: 1024