akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

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

  int ans = max(h, w);

  vector<vector<int>> a(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      a[i][j] = s[j] == '#';
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j + 1 < w; j++) {
      a[i][j] ^= a[i][j + 1];
    }
  }
  for (int j = 0; j < w; j++) {
    for (int i = 0; i + 1 < h; i++) {
      a[i][j] ^= a[i + 1][j];
    }
  }

  vector<int> y(w, 1);
  vector<int> left(w);
  for (int i = 0; i < h - 1; i++) {
    vector<int> t;
    for (int j = 0; j < w; j++) {
      y[j] = a[i][j] == 1 ? 1 : y[j] + 1;
      if (j == w - 1) y[j] = 0;
      while (!t.empty() && y[t.back()] >= y[j]) {
        int width = j - left[t.back()];
        int height = y[t.back()];
        ans = max(ans, width * height);
        t.pop_back();
      }
      left[j] = t.empty() ? -1 : t.back();
      t.push_back(j);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 18048
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

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


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


int main(){
  ll N;cin>>N;
  ll a,b;cin>>a>>b;
  ll c;
  if(N==2){
    c = gcd(a,b);
  }
  else{
    c = gcd(a, gcd(b,c));
  }

  vector<ll> v = divisor(c);
  sort(v.begin(),v.end());
  rep(i,v.size()){
    cout<<v[i]<<endl;
  }

}



Measured memory_bytes: 3156
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define N 10000
#define Q 500

int main(){
	int n,q,s[N],t[Q];
	int sum=0;
	cin >> n;
	for(int i=0; i<n; ++i){
		cin >> s[i];
	}
	cin >> q;
	for(int i=0; i<q; ++i){
		cin >> t[i];
	}
	for(int i=0; i<q; ++i){
		for(int j=0; j<n; ++j){
			if(t[i] == s[j]){
				++sum;
				break;
			}
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define putchar putchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}


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


	int N = getint();
	int A = 0, B = 0;

	rep(i, N) {
		int a = getint();
		if (!(a & 3)) A++;
		else if (!(a & 1)) B++;
	}
	int ikeru = A * 2 + B;
	if (B == 0) ikeru++;
	
	if (ikeru >= N) co("Yes");
	else co("No");

	Would you please return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef pair<int, int> P;

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

int main()
{
    ll ans = 0;
    string S;
    cin >> S;

    int len = (int)S.size();

    vector<ll> cntb(13, 0);
    cntb[0] = 1;
    rep(i, len) {
        vector<ll> cnt(13, 0);
        if (S[len - i - 1] == '?') {
            rep(j, 10) {
                ll m = (j * mod_pow(10, i, 13));
                cnt[m % 13]++;
            }
        }
        else {
            ll d = S[len - i - 1] - '0';
            ll m = (d * mod_pow(10, i, 13));
            cnt[m % 13]++;
        }
        if (i == len - 1) {
            rep(j, 13) {
                ans += (cntb[j] * cnt[(13 + 5 - j) % 13]) % MOD;
                ans %= MOD;
            }
        }

        vector<ll> cntt(13, 0);
        rep(j, 13) {
            rep(k, 13) {
                cntt[(k + j) % 13] += (cntb[j] * cnt[k]) % MOD;
                cntt[(k + j) % 13] %= MOD;
            }
        }
        rep(j, 13) {
            cntb[j] = cntt[j];
        }
    }

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

Measured memory_bytes: 3744
# -*- coding: utf-8 -*-
# E

N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
mod = 10**9 + 7


class Cmb(object):
    def cmb_precalc(self, n, r, mod: int = 10 ** 9 + 7):
        if (r < 0) or (r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % mod

    def cmb_prep(self, N: int, mod: int = 10 ** 9 + 7):
        self.g1 = [1, 1]  # 元テーブル
        self.g2 = [1, 1]  # 逆元テーブル
        inverse = [0, 1]  # 逆元テーブル計算用テーブル

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


ans = 0
cmb = Cmb()
cmb.cmb_prep(N + 5)

for i in range(N):
    if i >= K-1:
        ans += A[i] * cmb.cmb_precalc(i, i-K+1)
    if N - i - 1 >= K-1:
        ans -= A[i] * cmb.cmb_precalc(N-i-1, K-1)

print(ans % mod)


Measured memory_bytes: 77224
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e5 + 7;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(MOD);
    while (m--) {
        int x, y;
        cin >> x >> y;
        x--;y--;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    queue<int> Q;
    vector<int> visited(MOD, -1);
    Q.push(0);
    visited[0] = 0;
    while (!Q.empty()) {
        int u = Q.front();
        Q.pop();
        for (auto& x : a[u]) {
            if (visited[x] >= 0) continue;
            visited[x] = u;
            Q.push(x);
        }
    }
    bool found = false;
    for (int i = 0; i < n; i++) {
        if (visited[i] < 0) found = true;
    }
    if (found) {
        cout << "No";
    }
    else {
        cout << "Yes" << "\n";
        for (int i = 1; i < n; i++) {
            cout << visited[i]+1 << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 10064
N = int(input())
A = list(map(int,input().split()))
M = []
m = []
if A[0] <= A[1]:
        m.append(A[0])
for i in range(N-2):
    if A[i+1] >= A[i] and A[i+1] > A[i+2]:
        M.append(A[i+1])
    elif A[i+1] < A[i] and A[i+1] <= A[i+2]:
        m.append(A[i+1])
if A[N-1] >= A[N-2]:
    M.append(A[N-1])
now = 1000
kabu = 0
for i in range(len(m)):
    kabu += now//m[i]
    now -= kabu*m[i]
    now += kabu*M[i]
    kabu = 0
print(now)

Measured memory_bytes: 61804
#include<stdio.h>
int main()
{
	int n,s,temp,sum=0;
	scanf("%d",&n);
	temp=n;
	while(temp!=0)
	{
		sum=sum+temp%10;
		temp=temp/10;
	}
	if(n%sum==0)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <iostream>
#include <utility>

int main(int argc, char *argv[]) {
  int n, m;
  std::cin >> n >> m;
  int max = 0, min = INT_MAX;
  for (int i = 0; i < m; ++i) {
    int r, l;
    std::cin >> l >> r;
    max = std::max(max, l);
    min = std::min(min, r);
  }

  if (min >= max)
    std::cout << min - max + 1 << std::endl;
  else
    std::cout << 0 << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int d;
    while(scanf("%d",&d)!=EOF){
        int sum=0;
        for(int i=1;i*d<600;i++){
            sum+=d*(i*d)*(i*d);
        }
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 2044
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
#include<map>

using namespace std;

#define ll long long
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) reps(i, 0, n)
#define P pair<int, int>

const ll mod = 1000000007;

#include<iostream>

using namespace std;

int const MAX_N = 100000;
int par[MAX_N]; // 親
int depth[MAX_N]; // 木の深さ

// n要素で初期化
void init(int n){
    for(int i = 0; i < n; i++){
        par[i] = i;
        depth[i] = 0;
    }
}

// 木の根を求める
int find(int x){
    if (par[x] == x) {
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を合併
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (depth[x] < depth[y]) {
        par[x] = y;
    }else{
        par[y] = x;
        if (depth[x] == depth[y]) depth[x]++;
    }
}

// xとyが同じ集合に属するか否か
bool same(int x, int y){
    return find(x) == find(y);
}


int main(){
    int n, m;
    cin >> n >> m;
    init(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        unite(a, b);
    }
    set<int> s;
    
    rep(i, n){
        s.insert(find(i));
    }
    cout << s.size()-1 << endl;
}

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

int main(){
    int A, B, C, X, Y, ans; cin >> A >> B >> C;

    X=A+B+C;
    Y=max(A, B);
    Y=max(Y, C);
    if (X%2 == 1 ) {
        if (Y%2 == 1) cout << (3*Y-X)/2 << endl;
        else cout << (3*Y+3-X)/2 << endl;
    }
    else {
        if (Y%2 == 0) cout << (3*Y-X)/2 << endl;
        else cout << (3*Y+3-X)/2 << endl;
    }
}

Measured memory_bytes: 256
N,A,B = [int(i) for i in input().split(" ")]


def check(N,A,B):
    if A == 0:
        return 0
    r  = N//(A+B)
    x = N-r*(A+B)
    if x > A:
        return r*A+A
    else:
        return r*A+x
print(check(N,A,B))

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

int main(){
    string s;
    int n,m;
    ios::sync_with_stdio(0);
    while(cin>>n){
        map<int,int> ma;
        int e,f;
        for(int i=0;i<n;i++){
            cin>>e;
            ma[e]++;
        }
        bool t=1;
        cin>>m;
        for(int i=0;i<m;i++){
            cin>>e;
            if(ma.find(e)==ma.end()){
                t=0;
            }
            else{
                ma[e]--;
                if(ma[e]==0)ma.erase(e);
            }
        }
        if(t){cout<<"YES"<<endl;}
        else cout<<"NO"<<endl;
    }
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M;
    cin >> N >> M;

    map<ll, ll> C;

    vector<ll> A(N);
    REP(i, N){
        cin >> A[i];
    }

    vector<ll> B(N);
    REP(i, N){
        if(i == 0){
            B[i] = A[i];
        }
        else{
            B[i] = B[i-1] + A[i];
        }
        C[B[i]%M]++;
    }

    ll ans = 0;

    for(auto c: C){
        ans += (c.second*(c.second-1)/2);
        if(c.first == 0){
            // ちょうどMの倍数なら単体でもカウントする
            ans += c.second;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    ios;
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    ll sum=0;
    for(int i=0;i<k;i++)
        sum+=a[i];
    cout<<sum<<endl;

}































Measured memory_bytes: 3624
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
//#include <chrono> //when you use, devide by 1e+9!!!!! auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)

ll N,C;
ll X[100000],V[100000];
ll dx[100000],dv[100000];
ll rx[100000],rv[100000];
ll dp[100000];//時計まわりどこまでで最大値
ll ans;
ll hoge,fuga;

void calc(){
	dv[0]=V[0];
	rv[N-1]=V[N-1];
	rep(i,N-1){
		dv[i+1]=dv[i]+V[i+1];
	}
	rrep(i,N-1){
		rv[i]=rv[i+1]+V[i];
	}
	dp[0]=max(0LL,V[0]-X[0]);
	rep(i,N-1){
		dp[i+1]=max(dv[i+1]-X[i+1],dp[i]);
	}
	ans=max(ans,max(dp[N-1],dv[N-1]-  (C-X[0])  ));
	rep(i,N-1){
		ans=max(ans, rv[i+1] - (C-X[i+1])*2 + dp[i]    );
	}

	
}

ll tv[100000],tx[100000];

int main()
{
	ans=0;
	cin>>N>>C;
	rep(i,N){
		cin>>X[i]>>V[i];
		rx[i]=C-X[i];
		tv[i]=V[i];
		tx[i]=X[i];
	}
	calc();
	rep(i,N){
		X[i]= C-tx[N-1-i];
		V[i]= tv[N-1-i];
		rx[i]=C-X[i];
	}
	calc();
	cout<<ans<<endl;
}

Measured memory_bytes: 7296
#include <stdio.h>
#include <stdlib.h>

typedef struct energy_ {
   int value,num;
} energy;

int cmp( const void *p, const void *q ) {
    return ((energy*)p)->value - ((energy*)q)->value;
}

int main(){
  int n,m;
  scanf("%d %d",&n,&m);
  energy drink[n];
  for(int i = 0; i < n; ++i) scanf("%d %d",&drink[i].value,&drink[i].num);
  qsort(drink,n,sizeof(energy),cmp);
  
  long answer = 0;
  int left = m;
  for(int i = 0; i < n; ++i){
    if(left < drink[i].num){
      answer += (long) left * (long) drink[i].value;
      left = 0;
    }else if(left >= drink[i].num){
      answer += (long) drink[i].value * (long) drink[i].num;
      left -= drink[i].num;
    }
    if(left == 0) break;
  }
  printf("%ld\n",answer);
  return 0;
}

Measured memory_bytes: 1788
N=gets.to_i
as=gets.split.map(&:to_i)
cnt=0
for i in 0..N-1
    if i==0
        cnt+=as[0]
    elsif i==N-1
        cnt+=as[N-2]
    else
        cnt+=[as[i-1],as[i]].min
    end
end
p cnt


Measured memory_bytes: 1788
#include<stdio.h>
int min(int a, int b){return a < b ? a : b;}
int main(){
    int i = 0, h, n;
    scanf("%d%d",&h,&n);
    int a[n], b[n], dp[h];
    for(; i < n; i++)
        scanf("%d%d",&a[i],&b[i]);
    for(i= 0; i < h; i++)
        dp[i] = (1 + i / a[0]) * b[0];
    for(i = 1; i < n; i++)
        for(int j = 0; j < h; j++){
            if(j < a[i])
                dp[j] = min(dp[j], b[i]);
            else
                dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
        }
    printf("%d\n",dp[h - 1]);
    return 0;
}

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

const int MOD=1e9+7;
int n,a=0,d=0,mmh=1;
int main(){
	register int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		d=max(d,i-1-(a+1)/2);
		mmh=1LL*mmh*(i-d)%MOD;
		scanf("%d",&a);
	}
	printf("%d\n",mmh);
}

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

using namespace std;

map<string, int> mp;

int n, m, mx;
char s[20];
int main()
{
	scanf("%d", &n);
	for(int i = 0 ; i < n ; ++i)
	{
		scanf("%s", s);
		mp[s]++;
	}
	scanf("%d", &m);
	for(int i = 0; i < m ; ++i)
	{
		scanf("%s", s);
		mp[s]--;
	}
	for(const auto &v : mp)
		if(v.second > mx)
			mx = v.second;
	printf("%d\n", mx);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	string a,b;
	cin >> a >> b;
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	reverse(b.begin(), b.end());
	
	
	cout << (a<b? "Yes": "No")<<endl;
	
	
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  cin >> N;
  vector<int> A(N+1);
  rep(i, N) cin >> A[i+1];
  vector<int> B(N+1);
  vector<int> ans;
  for(int m=N; m>=1; m--) {
    if(A[m] != B[m]) {
      B[m] = 1 - B[m];
      ans.push_back(m);
      vector<ll> divisor;
      for(int i=1; i<=sqrt(m); i++) {
        if(m % i == 0)
          divisor.push_back(i);
      }
      int n = divisor.size();
      for(int i=n-1; i>=0; i--) {
        if(m != (ll)pow(divisor[i], 2))
          divisor.push_back(m / divisor[i]);
      }
      for(auto d: divisor)
        if(d != m)
          B[d] = 1 - B[d];
    }
  }
  int cnt = ans.size();
  cout << cnt << endl;
  if(cnt != 0) {
    rep(i, cnt)
      cout << ans[cnt-1-i] << ' ';
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<vector<int> > edge(N);
  int a, b;
  for(int i=0;i<N-1;++i) {
    cin>>a>>b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  vector<int> C(N);
  for(int i=0;i<N;++i) cin>>C[i];
  sort(C.begin(), C.end(), greater<int>());
  queue<int> que;
  que.push(0);
  int ans[N];
  for(int i=0;i<N;++i) ans[i] = -1;
  int state;
  int index = 0;
  while(!que.empty()) {
    state = que.front();que.pop();
    if(ans[state]>-1) continue;
    ans[state] = index;
    index++;
    for(int i=0;i<edge[state].size();++i) {
      if(ans[edge[state][i]]>-1) continue;
      que.push(edge[state][i]);
    }
  }
  int ans1 = 0;
  for(int i=1;i<N;++i) {
    ans1 += C[i];
  }
  cout<<ans1<<endl;
  for(int i=0;i<N;++i) cout<<C[ans[i]]<<" ";
  cout<<endl;
}



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

int main() {
  int a,b,c,x,y,sum;
  cin>>a>>b>>c>>x>>y;

  if (a+b>c*2) {
    if (x<y) {
      sum=x*2*c;
      y-=x;
      if (b>c*2) {
	sum+=y*2*c;
      }
      else {
	sum+=y*b;
      }
    }
    else {
      sum=y*2*c;
      x-=y;
      if (a>c*2) {
	sum+=x*2*c;
      }
      else {
	sum+=x*a;
      }
    }
  }  
  else {
    sum=x*a+y*b;
  }

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define ll long long
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long
#define pb push_back
#define pll pair<ll,ll>
#define ff first
#define ss second
#define mp make_pair
#define N 2000001
//#define M 1000000007
int main()
{
  ll s,w;
  cin>>s>>w;
  if(w>=s)
  {
    cout<<"unsafe";
  }
  else 
    cout<<"safe";
}


Measured memory_bytes: 3624
V,E = map(int,input().strip().split())
K = [["INF" for _ in range(V)] for _ in range(V)]
for i in range(V):
    K[i][i] = 0
for t in range(E):
    S,T,D = map(int,input().strip().split())
    K[S][T] = D
for k in range(V):
    for i in range(V):
        for j in range(V):
            if (K[i][k] != "INF") and (K[k][j] != "INF"):
                if K[i][j] == "INF" or K[i][j] > K[i][k] + K[k][j]:
                    K[i][j] = K[i][k] + K[k][j]
b = 0
for t in range(V):
    if K[t][t] != "INF" and K[t][t] < 0:
        print("NEGATIVE CYCLE")
        b += 1
        break
if b == 0:
    for i in range(V):
        print(" ".join(map(str,K[i])))



Measured memory_bytes: 6008
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
  int N = 0, ans = 0 ;
  cin >> N ;
  char Col[N] ;
  cin >> Col ;
  int left = 0, right = N - 1 ;
  while(left < right){
    if(Col[left] != 'W') left++ ;
    else if(Col[right] != 'R') right-- ;
    else{
      Col[left] = 'R' ;
      Col[right] = 'W' ;
      ans++ ;
    }
  }
  cout << ans  << endl ;
  return 0 ;
}  

Measured memory_bytes: 3788
n = int(input())
p = list(map(int, input().split()))
nu = [i for i in range(1, n + 1)]
an = 0
for i in range(n):
    if p[i] != nu[i]:
        an += 1
    else:
        pass
if an == 2 or an == 0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 1<<18;

class BIT{
public:
  int n;
  ll bit0[MAX_N+1],bit1[MAX_N+1];//1オリジン
  
  BIT(){n = MAX_N;memset(bit0,0,sizeof(bit0));memset(bit1,0,sizeof(bit1));}
  BIT(int n){this->n=n;memset(bit0,0,sizeof(bit0));memset(bit1,0,sizeof(bit1));}
  
  ll sum(ll *b,int i){
    ll s=0;
    while(i>0){
      s=(s+b[i]);
      i-=i&-i;
    }
    return s;
  }

  void add(ll *b,int i,ll v){
    while(i<=n){
      b[i]=(b[i]+v);
      i+=i&-i;
    }
  }

  //[a,b]にxを加算(1<=a)
  void add (int a,int b,ll x){
    add(bit0,a,-x*(a-1));
    add(bit1,a,x);
    add(bit0,b+1,x*b);
    add(bit1,b+1,-x);
  }

  //[a,b]のsumを得る(1<=a)
  ll sum(int a,int b){
    ll res=0;
    res+=sum(bit0,b)+sum(bit1,b)*b;
    res-=sum(bit0,a-1)+sum(bit1,a-1)*(a-1);
    return res;
  }
};

string s;

bool check(int len){
  
  BIT bit=BIT(s.size());
  
  for(int i=0;i<s.size();i++)
    if(s[i]=='1') bit.add(i+1,i+1,1);
  
  for(int i=0;i<=s.size()-len;i++){
    int val=bit.sum(i+1,i+1);
    if(val%2==0) continue;
    bit.add(i+1,i+1+len-1,1);
  }
  
  int cnt=0;
  
  for(int i=0;i<s.size();i++){
    int val=bit.sum(i+1,i+1);
    if(val%2==0) cnt++;
    else break;
  }
  
  return len<=cnt;
}

void solve(){

  int l=0, r=s.size()+1;

  while(l<r){
    int m=(l+r)/2;
    if(check(m)) l=m+1;
    else r=m;
  }

  cout<<l-1<<endl;
}

int main(){

  cin>>s;
  
  solve();  
  
  return 0;
}


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

class NumTh{
	static long mod=1000000007; // 10e9 + 7
	static long GCD(long x, long y) {
		if(Math.max(x, y) % Math.min(x, y) == 0) return Math.min(x, y);
		return GCD(Math.min(x, y), Math.max(x, y) % Math.min(x, y));
	}
	static int GCD(int x, int y) {
		return (int)GCD((long)x, (long)y);
	}
}

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), X = sc.nextInt();
		int[] x = new int[N + 1];
		for(int i = 0; i < N; i++) x[i] = sc.nextInt();
		x[N] = X;
		Arrays.sort(x);
		int ans = x[1] - x[0];
		for(int i = 2; i < N + 1; i++) {
			ans = NumTh.GCD(ans, x[i] - x[i - 1]);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 50760
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;

int ans ;
int que;
    if(n%1000==0)
    {
        ans = 0;
    }
    else
    {
        que = n/1000;
        ans = 1000*(que+1) - n;
    }

    cout<<ans<<endl;

    
}

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

//nC2
ll choose2(ll n)
{
    return n *(n-1)/2;
}

int main(void) 
{
    string s;
    cin >> s;
    int n = s.size();

    int sep = (n -1)/2;
    string first = s.substr(0, sep);
    string end = s.substr(sep + 1, n - first.size());
   
    if(first == end)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
//Subhash Suman
//Date: 14/02/19 ; Day: Thursday ; Time: 09::04::46 
//Description : 

#include<bits/stdc++.h>
#define ll long long int
#define MAX INT_MAX
#define MIN INT_MIN
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>

using namespace std;
const int N = 405;
ll arr[N];
ll sum[N];
ll dp[N][N];

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    int n;
    cin>>n;
    for(int i = 1; i < n+1; i++){
        cin>>arr[i];
        sum[i] = sum[i-1] + arr[i];
    }
    for(int i = 1; i <= n; i++){
        for(int x = 1; x <= n-i; x++){
            dp[x][x+i] = INT64_MAX;
            for(int j = x; j < x+i; j++){
                dp[x][x+i] = min(dp[x][x+i],(dp[x][j]+dp[j+1][x+i]));
            }
            dp[x][x+i] += (sum[x+i] - sum[x-1]);
        }
    }
    cout<<dp[1][n]<<'\n';
    return 0;
}

Measured memory_bytes: 1536
xn = list(map(int, input().split()))
if xn[1] == 0:
  print(xn[0])
  exit()
  
p = list(map(int, input().split()))

flag = 0
abs = 0

while flag == 0:
  test1 = xn[0] + abs
  test2 = xn[0] - abs
  if not test2 in p:
    flag = 2
  elif not test1 in p:
    flag = 1
  abs += 1

if flag == 1:
  print(test1)
else:
  print(test2)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
int abc(char T){
  int A=T-'a';
  return A;
}
  
int main(){
  string S;
  cin>>S;
  vector<int>list(26,0);
  for(int i=0;i<S.size();i++){
    int C=abc(S.at(i));
    if(list.at(C)==0){
      list.at(C)=1;
    }
  }
  bool flag=true;
  for(int i=0;i<26;i++){
    if(list.at(i)==0){
      cout<<char(i+'a')<<endl;
      flag=false;
      break;
    }
  }
  if(flag){
    cout<<"None"<<endl;
  }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%N;x=x*x%N;n>>=1;}return res;}
ll modinverse(ll a){return power(a,  998244353-2);}
void solve()
{
    ll n;
    cin>>n;
    n%=1000;
    if(n==0)
    cout<<0<<endl;
    else
    cout<<1000-n;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
}

Measured memory_bytes: 3628
#include <stdio.h>

typedef struct {
	int is_left;
	int pos;
	int alive;
} ant_t;

int solve(void) {
	int n, l;
	ant_t ants[30];
	int i;
	int e_time = 0;
	int last_ant = 0;
	if (scanf("%d%d", &n, &l) != 2 || (n == 0 && l == 0)) return 0;
	for (i = 0; i < n; i++) {
		char d[4];
		if (scanf("%s%d", d, &ants[i].pos) != 2) return 0;
		ants[i].is_left = (d[0] == 'L');
		ants[i].alive = 1;
	}
	for (;;) {
		int ant_lives = 0;
		int ant_count[110] = {};
		for (i = 0; i < n; i++) {
			if (ants[i].alive) {
				ant_lives = 1;
				if (ants[i].is_left) {
					ants[i].pos--;
				} else {
					ants[i].pos++;
				}
				ant_count[ants[i].pos]++;
			}
		}
		if (!ant_lives) break;
		e_time++;
		for (i = 0; i < n; i++) {
			if (ants[i].alive && ants[i].pos == l) {
				ants[i].alive = 0;
				last_ant = i;
			}
		}
		for (i = 0; i < n; i++) {
			if (ants[i].alive) {
				if (ants[i].pos == 0) {
					ants[i].alive = 0;
					last_ant = i;
				} else if(ant_count[ants[i].pos] > 1) {
					ants[i].is_left = !ants[i].is_left;
				}
			}
		}
	}
	printf("%d %d\n", e_time, last_ant + 1);
	return 1;
}

int main(void) {
	while(solve());
	return 0;
}

Measured memory_bytes: 600
using System;
using System.Linq;

namespace ITP1_4_D
{
    class Program
    {
        static void Main()
        {
            Console.ReadLine();
            long[] x = Console.ReadLine().Split(' ', '\r', '\n').Select(long.Parse).ToArray();
            Console.WriteLine("{0} {1} {2}", x.Min(), x.Max(), x.Sum());
        }
    }
}


Measured memory_bytes: 18948
import sys
input = sys.stdin.readline

N, Q = map(int, input().split())

bond_lst = list([list(map(int,input().split())) for _ in range(N-1)])
      
point_lst = [0]*(N+1)

for _ in range(Q):
    a, b = map(int, input().split())
    point_lst[a] += b

graph = {}

for a, b in bond_lst:
    if a in graph:graph[a].append(b)
    else:graph[a] = [b]
    if b in graph:graph[b].append(a)
    else:graph[b] = [a]
      
passed = [0]*(N+1)
nxt_lst = [1]
while nxt_lst:
    nxt = nxt_lst.pop()
    for i in graph[nxt]:
        if passed[i] == 1:continue
        point_lst[i] += point_lst[nxt]
        nxt_lst.append(i)
    passed[nxt] = 1
print(*point_lst[1:])

Measured memory_bytes: 96852
s = input()

ans = 0
for i in range(len(s)):
    if i == 0:
        s = s[:-1]
        continue
    else:
        a = len(s)
        t = s[a//2:]
        if s == t + t and len(s)%2 == 0:
            ans = 1
            break
        else:
            s = s[:-1]

print(len(s))

Measured memory_bytes: 38256
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a+b<c) {
            System.out.println("No");
        }else {
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 23764
import collections, math

local = False
if local:
    file = open("input.txt", "r")

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]


n = int(inp())

if "7" in str(n):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 65040
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] array = new int[N];
		for(int i = 0; i < N; i++) {
			array[i] = sc.nextInt();
		}
		int ans = selectionSort(array);
		showArray(array);
		System.out.println(ans);
		sc.close();
	}

	// 選択ソート（昇順）
	public static int selectionSort(int[] a) {
		int cnt = 0;  // 要素の交換が行われた回数
		for(int i = 0; i < a.length - 1; i++) {
			int minj = i;
			for(int j = i + 1; j < a.length; j++) {
				if(a[j] < a[minj]) {
					minj = j;
				}
			}
			if(i != minj) {
				int tmp = a[minj];
				a[minj] = a[i];
				a[i] = tmp;
				cnt++;
			}
		}
		return cnt;
	}

	public static void showArray(int[] a) {
		System.out.print(a[0]);
		for(int i = 1; i < a.length; i++) {
			System.out.print(" " + a[i]);
		}
		System.out.println();
	}
}


Measured memory_bytes: 26308
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[405][405];
ll ans = 1e18;

ll go(ll arr[],int n)
{
    //base case
    for(int i=1;i<=n;i++)
        dp[i][i] = 0;
    
    //prefix_arr
    ll prefix[n+1];
    memset(prefix,0,sizeof(prefix));
    for(int i=1;i<=n;i++)
        prefix[i] = prefix[i-1]+arr[i];
    
    //main fun
    for(int len=2;len<=n;len++)
    {
        for(int i=1;i<=n;i++)
        {
            int j = i+len-1;
            if(j<=n)
            {
                ll curr = 1e18;
                for(int k=i;k<j;k++)
                {
                    curr = min(curr,dp[i][k]+dp[k+1][j]+prefix[j]-prefix[i-1]);
                }
                dp[i][j] = curr;
            }
        }
    }
    
    return dp[1][n];
}
      
int main()
{
    int n;
    cin >> n;
    
    ll arr[n+1];
    for(int i=1;i<=n;i++)
        cin >> arr[i];
    
    cout << go(arr,n) << endl;
    
    return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>

long kouyaku(long a,long b){
long n;
while(b!=0){
  n=a%b;
  a=b;
  b=n;
	}
	return a;
	}


int main(){

long a,b;
long x,y;
long n;

while(scanf("%ld %ld",&a,&b)!=EOF){
x=kouyaku(a,b);
n=a/x;
y=n*b;
printf("%ld %ld\n",x,y);
	}

return 0;
	}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    long long int a[n];
    map<long long int,long long int>mp;
    long long int sum = 0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum += a[i];
        mp[a[i]]++;
    }   
    long long int q;
    cin>>q;
    for(int i=0;i<q;i++)
    {
        long long int x,y;
        cin>>x>>y;
        if(mp.find(x) == mp.end() || mp[x] == 0)
        {
            cout<<sum<<endl;
            continue;
        }
        long long int z = mp[x];
        mp[x] = 0;
        mp[y] = mp[y] + z;
        sum = sum - (z*x) + (z*y);
        cout<<sum<<endl;
    }
}

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

int main(){
	int n;
	cin >> n;
	vector<int> b(n);
	for(int i=0;i<n-1;i++)
		cin >> b[i];
	b[n-1] = 0;
	vector<int> a(n);
	a[0] = b[0];
	for(int i=1;i<n-1;i++) {
		a[i] = min(b[i-1], b[i]);
	}
	a[n-1] = b[n-2];
	int sum = 0;
	for(int i=0;i<n;i++) {
		sum += a[i];
	}
	cout << sum << endl;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int max1=INF;
    for(int i=0;i<2*max(x,y)+1;i+=2){
            int ap = max(x-(i/2),0);
            int bp = max(y-(i/2),0);
            max1 = min(i*c+ap*a+bp*b,max1);
    }
    COUT(max1);
    return 0;
}

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

using namespace std;

int main(void) {
	long long N;
	vector<tuple<long long, long long, long long> > v;
	cin >> N;
	for(int i = 0; i < N; ++i) {
		long long a, b;
		cin >> a >> b;
		v.push_back(make_tuple(a + b, a, b));
	}
	sort(v.begin(), v.end());
	long long result = 0;
	for(int i = 0; i < N; ++i) {
		if(i % 2 == 0) {
			result += get<1>(v[N - i - 1]);
		} else {
			result -= get<2>(v[N - i - 1]);
		}
	}
	cout << result << '\n';
	return 0;
}



Measured memory_bytes: 4980
#include<stdio.h>

int main(void) {
    int H[300] = {};
    int W[300] = {};
    int i, j, k, l;
    
    for(i = 0; i < 300; i++) {
        scanf("%d %d", &H[i], &W[i]);
        if(H[i] == 0 && W[i] == 0) {
            break;
        }
    }
    
    for(j = 0; j < i; j++) {
        for(k = 1; k <= H[j]; k++) {
            for(l = 1; l <= W[j]; l++) {
                if((k + l) % 2 == 0) {
                    printf("#");
                }
                else {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>

using namespace std;

bool is_prime(uint64_t n) {
    if (n == 1) return false;
    for (uint32_t i = 2; i*i <= n; i += 1) {
        if (n % i == 0) return false;
    }
    return true;
}

int
main(int argc, char** argv) {
    uint64_t result = 0;
    uint64_t n; cin >> n;
    for (uint64_t i = 0; i < n; i++) {
        uint64_t a; cin >> a;
        if (is_prime(a)) {
            result += 1;
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 3116
#include  <stdio.h>

int main(void)
{
    int a,b;
    scanf("%d %d",&a,&b);
    
    if(a < 10)
    {
        printf("%d",100 * (10 - a) + b);
    }
    
    else printf("%d",b);
        
        
    return 0;
}

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


int main() {
  ll N, M;
  cin >> N >> M;

  cout << abs(N - 2) * abs(M - 2) << endl;
}


Measured memory_bytes: 256
#[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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
type I = usize;

fn main() {
    input!{
      s: chars,
    }
    let mut cnt = vec![0; 2];
    let mut ans = 0;
    for i in 0..s.len() {
        if s[i] == '1' {
            cnt[1] += 1;
            if cnt[0] > 0 {
                cnt[0] -= 1;
                cnt[1] -= 1;
                ans += 2;
            }
        } else {
            cnt[0] += 1;
            if cnt[1] > 0 {
                cnt[0] -= 1;
                cnt[1] -= 1;
                ans += 2;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;

    vector<int> f(n), b(n);

    int cnt = 0;
    int num = 1;
    rep(i, n) {
        if (cnt == 0) {
            if (s[i] == 'o') f[i] = num++, cnt += c;
        } else cnt--;
        if (num == k+1) break;
    }
    cnt = 0;
    num = k;
    rrep(i, n) {
        if (cnt == 0) {
            if (s[i] == 'o') b[i] = num--, cnt += c;
        } else cnt--;
        if (num == 0) break;
    }

    rep(i, n) if (f[i] == b[i] && f[i] != 0) cout << i+1 << endl;
}


Measured memory_bytes: 5128
fun main(array: Array<String>) {
    val n = readLine()!!.toInt()
    val (d, x) = readLine()!!.split(" ").map { it.toInt() }
    var a = mutableListOf<Int>()
    var sum = n
    repeat(n) {
        a.add(readLine()!!.toInt())
    }
    for(i in 0 until n) {
        for(j in 1 until d) {
            if(j * a[i] + 1 <= d) {
                sum++
            }
        }
    }
    print(sum + x)
}

Measured memory_bytes: 37872
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {    
    string o,e;
    cin >> o >> e;
    for(int i = 0; i < o.size(); i++) {
        cout << o[i];
        if(i < e.size()) cout << e[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
import math
input1 = list(map(int,input().split()))

X = input1[0]
Y = input1[1]

if (X+Y) % 3 != 0:
  print(0)
  exit()

if Y<X/2:
  print(0)
  exit()

if Y>X*2:
  print(0)
  exit()

s = int((2*X-Y)/3)
t = int((-X+2*Y)/3)

n = s+t
r = min(s,t)

def comb(n,k,p):
  if n==0 or k==0: return 1

  a=1
  for i in range(1,n+1):
    a*=i
    if a >= p:
      a = a%p

  b=1
  for i in range(1,k+1):
    b*=i
    if b >= p:
      b = b%p

  c=1
  for i in range(1,n-k+1):
    c*=i
    if c >= p:
      c = c%p

  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p


ans = comb(n,r,10**9+7)
print(ans)

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

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

int main(){
	int n, m, t[20001];
	while(cin >> n >> m, n||m){
		rep(i,n)	cin >> t[i];
		rep(i,m)	cin >> t[i+n];
		sort( t, t+n+m );
		int mDif = t[0];
		rep(i,n+m-1){
			if( t[i+1]-t[i] > mDif )
				mDif = t[i+1]-t[i];
		}
		cout << mDif << endl;
	}
	return 0;
}

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

template <class T>
void out(const T param) {
    cout << param << "\n";
}

int main() {
    
    int N;
    
    cin >> N;
    
    vector<long> A;
    
    for(int i=0; i<N; i++) {
        long num;
        cin >> num;
        A.push_back(num);
    }
    
    vector<long> B;
    
    for(int i=0; i<N; i++) {
        B.push_back(A[i] - (i+1));
    }
    
    sort(B.begin(), B.end());
    
    long b = 0;
    
    if(N%2 == 0) {
        b = B[(((N/2) + (N/2 + 1))/2) - 1];
    }
    else {
        b = B[((N+1)/2) - 1];
    }
    
    long ans = 0;
    
    for(int i=0; i<N; i++) {
        ans += abs(B[i] - b);
    }
    
    out(ans);
    
    return 0;
}


Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
#define BIGINF (int) 4e18 + 7
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define INF  (int)2e9 + 7
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;

int a[105], n;
//long long sol = 0;
long long dp[100005];


void sub(int &a, int b) {
    a -= b;
    if (a < 0) {
        a += MOD7;
    }
}


int main () {
    //freopen("inputf.txt", "r", stdin);
    //freopen("outputf.txt", "w", stdout);
    memset(dp, -1, sizeof(dp));
    int k;
    SCD(n);
    SCD(k);
    for (int i = 0; i < n; i++) {
    	SCD(a[i]);
    }
    MEM(dp, 0);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        vector<int> add(100005);
        for (int j = k; j >= 0; j--) {
            int L = j + 1;
            int R = j + min(a[i], k - j);
            if (L <= R) {
                add[L] = (add[L] + dp[j]) % MOD7;
                if (R + 1 <= k)
                    sub(add[R + 1], dp[j]);
            }   //L..R -> dp[L] = dp[L] + dp[j] 
        }
        int prefix = 0;
        for (int j = 0; j <= k; j++) {
            prefix = (prefix + add[j]) % MOD7;
            dp[j] = (dp[j] + prefix) % MOD7;
        }
    }

    printf("%d", dp[k]);

    return 0;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	std::cout << fixed << setprecision(10);
	ll w, h, x, y; cin >> w >> h >> x >> y;
	double res = (w * h) / (double)2;
	std::cout << res << " ";
	if (w == x*2 && h == y*2)
		std::cout << 1 << std::endl;
	else
		std::cout << 0 << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double a[200010];
int main(){
	int n,k;
	cin >> n >> k;
	for(int i=1;i<=n;i++){
		double t;
		cin >> t;
		a[i]=(1.0+t)/2.0;
	}
	double sum=0,maxn=0;
	for(int i=1;i<=n;i++){
		if(i<=k){
			sum+=a[i];
		}
		else{
			sum=sum-a[i-k]+a[i];
		}
		maxn=max(maxn,sum);
	}
	printf("%lf",maxn);
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9+7
#define LINF (long long)4e18


int main(){
   string O,E;
   cin >> O >> E;
   int NO = O.size();
   int NE = E.size();
   string ans = "";
   if(NO - NE == 0){
        rep(i,2*NE){
            if((i+1) % 2 == 1)ans += O[(i+1)/2];
            else ans += E[(i+1)/2-1];
        }
   }
   else{
       rep(i,2*NE + 1){
           if((i+1) % 2 == 1)ans += O[(i+1)/2];
            else ans += E[(i+1)/2-1];
       }
   }
   cout << ans << endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()


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

  if(s <= "2019/04/30"){
    cout << "Heisei";
  }else{
    cout << "TBD";
  }
}


Measured memory_bytes: 256
both = []
left = []
right = []
ans = 0

n = gets.to_i
n.times do
  s = gets.chomp
  ans += s.scan(/AB/).length
  if s[0] == "B" and s[-1] == "A"
    both << s
  elsif s[0] == "B"
    left << s
  elsif s[-1] == "A"
    right << s
  end
end

if both.length > 0
  ans += both.length - 1
  if left.length > 0
    left.pop
    ans += 1
  end
  if right.length > 0
    right.pop
    ans += 1
  end
end

while left.length > 0 and right.length > 0
  left.pop
  right.pop
  ans+= 1
end

puts ans

Measured memory_bytes: 2940
#include "bits/stdc++.h"
 
using namespace std;
 
// template<typename... T>
// void read(T&... args) {
//     ((cin >> args), ...);
// }
 
// template<typename... T>
// void write(T&&... args) {  
//     ((cout << args << " "), ...);
// }
 
// #define deb(x) cerr << #x << " " << x <<endl;
 
// #define debs(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << '\n'
// void err(istringstream *iss) {}
// template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) {
//     string _name;
//     *iss >> _name;
//     if (_name.back()==',') _name.pop_back();
//     cerr << _name << " = " << _val << "; ", err(iss, args ...);
// }


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

	long long n,a,b,k;
	while(cin>>n>>k){
		vector<pair<long long,long long>>lst;	
		for(long long i=0; i<n; ++i )cin>>a>>b, lst.push_back(make_pair(a,b));

		long long dp[n+2][k+2];
		// memset(dp,0,sizeof(dp));
		
		for(int i=0; i<=n; ++i)
			for(int j=0; j<=k; ++j)
				dp[i][j]=(!i or !j)?0ll:max(dp[i-1][j],(lst[i-1].first>j)?0ll:lst[i-1].second + dp[i-1][j-lst[i-1].first]);
			     	
		cout<<dp[n][k]<<endl; 

	}
	
    return 0;
}

Measured memory_bytes: 79232