akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

class Parser{
public:
  string s;
  size_t i;
  string parse(){
    i = 0;
    return Cipher();
  }
  string Cipher(){
    //cout << "Cipher : " << i << endl;
    string t;
    while(i < s.size() && s[i] != ']'){
      t += String();
    }
    return t;
  }
  string String(){
    //cout << "String : " << i << endl;
    if(s[i] == '['){
      ++i;
      string u = Cipher(), v;
      ++i;
      for(int j = u.length()-1; j >= 0; --j){
        v += u[j];
      }
      return v;
    }else{
      char c = Letter();
      ++i;
      return string(1,c);
    }
  }
  char Letter(){
    //cout << "Letter : " << i << endl;
    if(s[i] == '+'){
      ++i;
      char c = Letter();
      if(c == '?') return c;
      else return (c-'A'+1)%26+'A';
    }else if(s[i] == '-'){
      ++i;
      char c = Letter();
      if(c == '?') return c;
      else return (c-'A'+25)%26+'A';
    }else{
      return s[i];
    }
  }
};

int main(){
  string S;
  while(cin >> S, S != "."){
    //cout << solve(S) << endl;
    Parser p;
    p.s = S;
    string s = p.parse();
    for(int i = 0; i < s.length(); ++i){
      if(s[i] == '?') cout << "A";
      else cout << s[i];
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3184
import collections
N, K = map(int, input().split())
M = [list(map(int, input().split())) for i in range(K * 2)]
snuke_snack = []
for i in range(K):
    snuke_snack.extend(M[2 * i + 1])
count = collections.Counter(snuke_snack)
print(N - len(count))

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

using namespace std;
#define int long long

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  void unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x != y) {
      if(data[x] > data[y]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }

  int find(int k)
  {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k)
  {
    return (-data[find(k)]);
  }
};

int N, R, s, t;
int a[100000], b[100000];
UnionFind tree(100000);
int ret[100000];
const int INF = 1LL << 59;

void ask(int v)
{
  map< int, vector< pair< int, int > > > backet;
  for(int i = 0; i < N; i++) {
    backet[a[i]].push_back(make_pair(b[i], i));
  }
  for(auto &obj : backet) {
    vector< pair< int, int > > &cc = obj.second;
    sort(begin(cc), end(cc));
    for(int j = 1; j < cc.size(); j++) {
      //tree.unite(cc[j - 1].second, cc[j].second);
    }
  }
  for(int i = 0; i < N; i++) {
    if(!backet.count(a[i] - R)) continue;
    auto &cc = backet[a[i] - R];

    auto p = lower_bound(begin(cc), end(cc), make_pair(b[i] - R - v, +INF));
    auto q = lower_bound(begin(cc), end(cc), make_pair(b[i] + R + v, -INF));
    ret[i] += q - p;
    if(p != q) tree.unite(i, p->second);
  }
  for(int i = 0; i < N; i++) {
    if(!backet.count(a[i] + R)) continue;
    auto &cc = backet[a[i] + R];
    auto p = lower_bound(begin(cc), end(cc), make_pair(b[i] - R - v, +INF));
    auto q = lower_bound(begin(cc), end(cc), make_pair(b[i] + R + v, -INF));
    ret[i] += q - p;
    if(p != q) tree.unite(i, p->second);
  }
}

signed main()
{
  cin >> N >> s >> t;
  for(int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    a[i] = x + y;
    b[i] = x - y;
  }
  --s, --t;
  R = max(abs(a[s] - a[t]), abs(b[s] - b[t]));
  ask(false);
  for(int i = 0; i < N; i++) swap(a[i], b[i]);
  ask(true);

  tree.unite(s, t);
  long long res = 0;
  for(int i = 0; i < N; i++) {
    if(tree.find(i) == tree.find(s)) res += ret[i];
  }
  cout << res / 2 << endl;
}

Measured memory_bytes: 14428
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int w, h; cin >> w >> h&&w;) {
		static int a[21][21];
		int si, sj, gi, gj;
		memset(a, 0, sizeof(a));
		rep(i, 0, h)rep(j, 0, w) {
			cin >> a[i][j];
			if (a[i][j] == 2)
				si = i, sj = j;
			else if (a[i][j] == 3)
				gi = i, gj = j;
		}
		auto inrange = [&](int i, int j) { return i >= 0 && i < h && j >= 0 && j < w; };
		function<int(int, int, int)> dfs = [&](int i, int j, int depth) {
			dump(i, j, depth);
			static const int di[] = { 1,0,-1,0 };
			static const int dj[] = { 0,1,0,-1 };
			int ret = INF;
			if (depth < 10) {
				rep(k, 0, 4) {
					int ci = i, cj = j;
					while (true) {
						int ni = ci + di[k], nj = cj + dj[k];
						if (!inrange(ni, nj))
							break;
						if (a[ni][nj] == 1) {
							if (!(i == ci && j == cj)) {
								a[ni][nj] = 0;
								chmin(ret, dfs(ci, cj, depth + 1));
								a[ni][nj] = 1;
							}
							break;
						}
						else if (a[ni][nj] == 3) {
							chmin(ret, depth);
							break;
						}
						else {
							ci += di[k], cj += dj[k];
							continue;
						}
					}
				}
			}
			return ret;
		};
		int res = dfs(si, sj, 0);
		if (res == INF) {
			cout << -1 << endl;
		}
		else {
			cout << res + 1 << endl;
		}
	}
	return 0;
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

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

    vector<i64> rcnt(n + 1);
    for (i64 i = 0; i < n; i++) {
        char c;
        cin >> c;
        rcnt[i + 1] = c == 'R';
    }
    partial_sum(all(rcnt), begin(rcnt));

    i64 ans = INF;
    for (i64 i = 0; i <= n; i++) {
        ans = min(ans, max(i - (rcnt[i] - rcnt[0]), rcnt[n] - rcnt[i]));
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)


int main() {
	ll r, d, x;
	cin >> r >> d >> x;
	FOR(i, 1, 10) {
		x = r*x - d;
		pv(x)
	}
	return(0);
}

Measured memory_bytes: 256
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  int N, X, c = 1, d = 0, l;
  cin >> N >> X;
  for (int i = 0; i < N; i++)
  {
    cin >> l;
    d += l;
    if (d > X)
    {
      break;
    }
    c++;
  }
  cout << c << endl;
}


Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
int N;
long long h[100010];

long long dp[100010];
int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) cin >> h[i];
    for (int i = 0; i < 100010; ++i) dp[i] = INF;
    dp[0] = 0;
    for (int i = 0; i < N-1; ++i) {
        chmin(dp[i+1], dp[i] + abs(h[i] - h[i + 1]));
        if (i < N-1) chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
//confilm 0LL and 1LL
//confilm cornercase such as 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll h, w, a, b;
	cin >> h >> w >> a >> b;
	co((h-a)*(w-b));

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;

typedef long long ll;

int main() {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int res = a * x + b * y;
	int Max = max(x, y);
	for (int i = 1; i <= Max; i++) {
		int tmp = 0;
		tmp+=2 * c * i ;
		if (x - i>0) {
			tmp += (x - i) * a;
		}
		if (y - i>0){
			tmp += (y - i) * b;
		}
		if (res > tmp)res = tmp;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

typedef struct{
  double x;
  double y;
} xy;

void kock(int, xy , xy );

int main() {
  int i,n;
  xy p1 = {0.0,0.0};
  xy p2 = {100.0,0.0};

  scanf("%d",&n);

  printf("%f %f\n",p1.x,p1.y);
  kock(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);

  return 0;
}

void kock(int n, xy p1, xy p2){
  xy s,t,u;

  if(n == 0) return;

  // p1, p2 から s, t, u を計算
 
  s.x = (2*p1.x+1*p2.x)/3.0;
  s.y = (2*p1.y+1*p2.y)/3.0;

  t.x = (1*p1.x+2*p2.x)/3.0;
  t.y = (1*p1.y+2*p2.y)/3.0;

  u.x = (t.x-s.x)*0.5-(t.y-s.y)*(sqrt(3)/2)+s.x;
  u.y = (t.x-s.x)*(sqrt(3)/2)+(t.y-s.y)*0.5+s.y;


  kock(n-1, p1, s);
  printf("%f %f\n",s.x,s.y);
  kock(n-1, s, u);
  printf("%f %f\n",u.x,u.y);
  kock(n-1, u, t);
  printf("%f %f\n",t.x,t.y);
  kock(n-1, t, p2);

  return ;

}

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

#define swap(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}

vector<double> simequ(vector<vector<double>> a){
    int N=a.size();
    // 前進消去
    for (int k = 0; k < N -1; k++) {
        for (int i = k + 1; i < N; i++) {
            double d = a[i][k] / a[k][k];
            for (int j = k + 1; j <= N; j++)
                a[i][j] -= a[k][j] * d;
        }
    }

    // 後退代入
    for (int i = N - 1; i >= 0; i--) {
        double d = a[i][N];
        for (int j = i + 1; j < N; j++)
            d -= a[i][j] * a[j][N];
        a[i][N] = d / a[i][i];
    }

    // 結果出力
    vector<double> result;
    for (int k = 0; k < N; k++)
        result.push_back(a[k][N]);

    return result;
}




int main()
{
    int n;
    double y;
    cin >> n >> y;
    int a;
    double b,c;

    for(a=0;a<=n;a++){
        vector<vector<double>> aa;
        aa.push_back({ 1.0, 1.0, (double)(n-a)});
        aa.push_back({ 5000.0,  1000.0, y-10000.0*a});
        vector<double> bb=simequ(aa);
        b=bb[0];
        c=bb[1];
        if(b>=0 && c>=0 && ceil(b)==floor(b) && ceil(c)==floor(c)){
            printf("%d %d %d\n",a,(int)b,(int)c);
            return 0;
        }
    }




    cout << "-1 -1 -1" << endl;


    return 0;
    
}






Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n,m,S,T,cnt,inf=1e9,sx,sy,tx,ty,hed[1005],d[1005],nex[50005],to[50005],val[50005],ans;queue<int>q;char ch;
void add(int x,int y,int z)
{
    to[cnt]=y;val[cnt]=z;nex[cnt]=hed[x];hed[x]=cnt++;
    to[cnt]=x;val[cnt]=0;nex[cnt]=hed[y];hed[y]=cnt++;
}
bool bfs()
{
    while(!q.empty()) q.pop();memset(d,0,sizeof(d));d[S]=1;q.push(S);
    while(!q.empty())
    {
        int x=q.front();q.pop();
        for(int i=hed[x];i!=-1;i=nex[i]) if(!d[to[i]]&&val[i]){d[to[i]]=d[x]+1;if(to[i]==T) return 1;q.push(to[i]);}
    }
    return 0;
}
int dfs(int x,int mf)
{
    if(x==T) return mf;int tmp=mf;
    for(int i=hed[x];i!=-1;i=nex[i]) if(d[to[i]]==d[x]+1&&val[i])
    {
        int k=dfs(to[i],min(val[i],tmp));
        if(!k) d[to[i]]=0;
        tmp-=k;val[i]-=k;val[i^1]+=k;
        if(!tmp) break;
    }
    return mf-tmp;
}
int main()
{
    scanf("%d%d",&n,&m);T=n+m+1;memset(hed,-1,sizeof(hed));
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
    {
        cin>>ch;
        if(ch=='S') add(S,i,inf),add(S,j+n,inf),sx=i,sy=j;
        if(ch=='T') add(i,T,inf),add(j+n,T,inf),tx=i,ty=j;
        if(ch=='o') add(i,j+n,1),add(j+n,i,1);
    }
    if(sx==tx||sy==ty) return puts("-1"),0;
    while(bfs()) ans+=dfs(0,inf*2);
    printf("%d\n",ans);
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef pair<int,int> P;
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define lowbit(x) (x&-x)
const ll INF=0x3f3f3f3f;
const double EPS=1e-7;
const int N=2e5+10;
const ll mod=1e9+7;
inline ll read()
{  ll f=1,x=0;char ch=getchar();
   for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-') f=-1;
   for(;ch<='9'&&ch>='0';ch=getchar()) x=x*10+ch-'0';
   return x*f;
}
ll n,k;
long double a[N];
bool check(long double mid)
{  ll cnt=0;
   for(ll i=1;i<=n;i++)
   {  if(a[i]<=mid)continue;
      ll q=ceil((a[i]-mid)/mid);
      //printf("q=%d\n",q);
      if(q)cnt=cnt+q;
      if(cnt>1000000000)return 0;
   }
   if(cnt>k)return 0;
   else return 1;
}
int main()
{  //printf("%lf",ceil(0.5/0.2-1.0));
   cin>>n>>k;
   for(int i=1;i<=n;i++)cin>>a[i];
   double l=0.000001,r=1e9+5,ans;
   while(r-l>=EPS)
   {  long double mid=(l+r)/2;
      if(check(mid))
      {  ans=mid;
         r=mid-0.000001;
      }
      else
      {  l=mid+0.000001;
      }
   }
   printf("%.0lf\n",max(1.0,ceil(ans-0.0001)));
}

Measured memory_bytes: 6856
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<vector<ll>>g(n);
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  rep(i,0,n-1){
    ll u,v;cin>>u>>v;u--;v--;
    g[u].PB(v);
    g[v].PB(u);
  }
  vector<ll>ret;
  {
    vector<bool>t(n);
    auto dfs=[&](auto &&f,ll k,ll par)->void{
      a[k]--;
      for(auto to:g[k]){
        if(to==par)continue;
        f(f,to,k);
      }
      a[k]++;
      for(auto to:g[k]){
        //cout<<a[k] spa k spa a[to] spa to spa par<<endl;
        if(to==par||a[to]>=a[k])continue;
        //cout<<to spa t[to]<<endl;
        if(!t[to])t[k]=true;
      }
    };
    rep(i,0,n){
      fill(ALL(t),false);
      dfs(dfs,i,-1);
      //debug(t,n);
      if(t[i])ret.PB(i+1);
    }
  }
  debug(ret,ret.size());
  return 0;
}

Measured memory_bytes: 640
def main():
    def solve(mid,g):
        for t,d in zip(x,y):
            if s[mid]==t:
                mid-=(d<'R')or-1
        return mid==g
    n,q,s,*z=open(0).read().split()
    x,y=z[::2],z[1::2]
    n,q=int(n),int(q)
    s=' %s '%s
    ok=0
    ng=n+1
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if solve(mid,0):
            ok=mid
        else:
            ng=mid
    a=ok
    ok=n+1
    ng=0
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if solve(mid,n+1):
            ok=mid
        else:
            ng=mid
    print(max(0,ok-a-1))
if __name__=='__main__':
    main()

Measured memory_bytes: 11412
N,K=map(int, input().split())
m=int(N/K)

min_0 = N
min_1 = abs(N-m*K)
min_2 = abs(min_1-K)
m=int(min_2/K)
min_3 = abs(min_2-m*K)

print(min(min_0, min_1, min_2, min_3))


Measured memory_bytes: 2940
# coding:utf-8

def main():
    N = int(input().rstrip())

    for i in range(N):
        ls = list(map(int, input().split(' ')))
        ls.sort()

        if(ls[0]**2 + ls[1]**2 == ls[2]**2):
            print('YES')
        else:
            print('NO')
            
if __name__ == "__main__":
    main()

Measured memory_bytes: 7600
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    
    while(x != NIL) {
        y = x;
        if(z->key < x->key) {
            x = x->left;
        }else {
            x = x->right;
        }
    }
    z->parent = y;
    
    if(y == NIL) {
        root = z;
    }else {
        if(z->key < y->key) {
            y->left = z;
        }else {
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if(u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, i, x;
    string com;
    
    scanf("%d", &n);
    
    for(i = 0; i < n; i++) {
        cin >> com;
        if(com == "insert") {
            scanf("%d", &x);
            insert(x);
        }else if(com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 26592
n = int(input())
s = [list(input()) for _ in range(n)]
a = set(s[0])
for i in s:
  a = a & set(i)
al = list(a)
for j in a:
  countl = []
  for k in s:
    countl.append(k.count(j))
  for _ in range(min(countl) - 1):
    al.append(j)
print("".join(sorted(al)))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int a,b; cin>>a>>b;
    cout<<(a-1)*(b-1)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


signed main(){
    int  a,b;
    cin >> a >> b;
    cout << a- b + 1 << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=201000;
int n,m,cnt[N][2],u,v,t;
int q[N],vis[N];
char s[N];
VI e[N];
void del(int u) {
	if (vis[u]) return;
	if (cnt[u][0]!=0&&cnt[u][1]!=0) return;
	q[t++]=u; vis[u]=1;
}
int main() {
	scanf("%d%d",&n,&m);
	scanf("%s",s);
	rep(i,0,m) {
		scanf("%d%d",&u,&v);
		--u; --v;
		e[u].pb(v);
		e[v].pb(u);
		cnt[u][s[v]-'A']++;
		cnt[v][s[u]-'A']++;
	}
//	rep(i,0,n) printf("%d %d\n",cnt[i][0],cnt[i][1]);
	rep(i,0,n) del(i);
	rep(i,0,t) {
		int u=q[i];
		for (auto v:e[u]) if (!vis[v]) {
			--cnt[v][s[u]-'A'];
			del(v);
		}
	}
	puts(t!=n?"Yes":"No");
}


Measured memory_bytes: 13440
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = INT32_MAX;
const ll INFL = INT64_MAX;
const int mod = 1e9 + 7;

template <typename T>
void print_vec(vector<T> v) {
  for (T i : v) cout << i << " ";
  cout << endl;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  ll ans = 0;
  rep(l, k + 1) {
    rep(r, k - l + 1) {
      if (l + r > n) break;
      int d = k - l - r;
      ll now = 0;
      vector<int> s;
      rep(i, l) {
        now += v[i];
        s.push_back(v[i]);
      }
      for (int i = n - r; i < n; i++) {
        now += v[i];
        s.push_back(v[i]);
      }
      sort(s.begin(), s.end());
      rep(i, d) {
        if (i >= s.size()) break;
        if (s[i] > 0) break;
        now -= s[i];
      }
      ans = max(ans, now);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, K = map(int, input().split())
    L = list(sorted(list(map(int, input().split()))))
    print(sum(L[-K:]))


if __name__ == '__main__':
    main()


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

string s;
li k;

int main() {
    cin >> s >> k;
    li n = sz(s);
    rep(i, sz(s)) {
        if (s[i] == 'a') {
            continue;
        }
        li cnt = 'z' - s[i] + 1;
        if (cnt <= k) {
            s[i] = 'a';
            k -= cnt;
        }
    }
    k = k % 26;
    rep(i, k) {
        s[n - 1] = (s[n - 1] == 'z' ? 'a' : s[n - 1] + 1);
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 512
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

struct UFT {
  int links[MAX_N], ranks[MAX_N], sizes[MAX_N];
  UFT() {}

  void clear(int n) {
    for (int i = 0; i < n; i++) links[i] = i, ranks[i] = sizes[i] = 1;
  }

  int root(int i) {
    int i0 = i;
    while (links[i0] != i0) i0 = links[i0];
    return (links[i] = i0);
  }

  int rank(int i) { return ranks[root(i)]; }
  int size(int i) { return sizes[root(i)]; }
  bool same(int i, int j) { return root(i) == root(j); }

  int merge(int i0, int i1) {
    int r0 = root(i0), r1 = root(i1), mr;
    if (r0 == r1) return r0;
    if (ranks[r0] == ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      ranks[r0]++;
      mr = r0;
    }
    else if (ranks[r0] > ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      mr = r0;
    }
    else {
      links[r0] = r1;
      sizes[r1] += sizes[r0];
      mr = r1;
    }
    return mr;
  }
};

/* global variables */

UFT uft;

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  uft.clear(n);

  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;

    uft.merge(a, b);
  }

  int s = min(uft.size(0), uft.size(1)), t = n - s;
  ll sum = (ll)s * (s - 1) / 2 + (ll)t * (t - 1) / 2 - m;
  printf("%lld\n", sum);

  return 0;
}


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

int main() {
  //2の累乗でN以下の最も大きいものを選ぶ
 
  int N;
  cin>>N;

  int i=1;
  while(i<=N){
    i*=2;}
  i=i/2;
  
  
   cout<<i<<endl;

  return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a,b,c,d;
int ans=0;
int main()
{
	scanf("%c%c%c%c",&a,&b,&c,&d);
	if (a=='2') ans++;
	if (b=='2') ans++;
	if (c=='2') ans++;
	if (d=='2') ans++;
	printf("%d",ans);
	return 0;
} 

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

int H, W, down[186][186], d[2][186][186][186], pos[186][186][186];
char A[186][186];

int main() {
	scanf("%d%d", &H, &W);
	for (int i = 1; i <= H; ++i)
		scanf("%s", A[i] + 1);
	for (int i = H; i; --i)
		for (int j = 1; j <= W; ++j)
			if (i < H && A[i + 1][j] == A[i][j])
				down[i][j] = down[i + 1][j];
			else
				down[i][j] = i;
	for (int i = 1; i <= H; ++i)
		for (int l = W; l; --l) {
			d[0][i][l][l] = down[i][l];
			int p = l - 1;
			for (int r = l + 1; r <= W; ++r) {
				d[0][i][l][r] = A[i][r] != A[i][l] ? 0 : min(d[0][i][l][r - 1], down[i][r]);
				while (p + 1 < r && d[0][i][l][p + 1] > d[0][i][p + 2][r])
					++p;
				pos[i][l][r] = p;
			}
		}
	if (d[0][1][1][W] == H) return puts("0"), 0;
	for (int k = 1;; ++k) {
		memset(d[k & 1], 0, sizeof d[k & 1]);
		for (int i = 1; i <= H; ++i)
			for (int l = W; l; --l)
				for (int r = l, p = l - 1; r <= W; ++r) {
					d[k & 1][i][l][r] = max({
						d[k - 1 & 1][i][l][r],
						d[k - 1 & 1][d[k - 1 & 1][i][l][r] + 1][l][r],
						pos[i][l][r] >= l && pos[i][l][r] < r ? d[k - 1 & 1][i][pos[i][l][r] + 1][r] : 0,
						pos[i][l][r] + 1 >= l && pos[i][l][r] + 1 < r ? d[k - 1 & 1][i][l][pos[i][l][r] + 1] : 0});
					while (p + 1 < r && d[k & 1][i][l][p + 1] > d[k & 1][i][p + 2][r])
						++p;
					pos[i][l][r] = p;
				}
		if (d[k & 1][1][1][W] == H) return printf("%d\n", k), 0;
	}
}


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

int main(){
  vector<vector<int>>A(3, vector<int>(3));
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> A.at(i).at(j);
    }
  }
  int N;
  cin >> N;
  
  vector<int>B(N);
  for(int i = 0; i < N; i++){
    cin >> B.at(i);
  }
  
  bool ans = false;
  int k = 0; 
  while(ans == false && k < N){
    
    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
         if(A.at(i).at(j) == B.at(k)){
           A.at(i).at(j) = 0;
         }
      }
    }
    
     for(int i = 0; i < 3; i++){
       if(A.at(i).at(0) == 0 && 
          A.at(i).at(1) == 0 &&
          A.at(i).at(2) == 0 ){
         ans = true;
       }
     }
    for(int i = 0; i < 3; i++){
       if(A.at(0).at(i) == 0 && 
          A.at(1).at(i) == 0 &&
          A.at(2).at(i) == 0 ){
         ans = true;
       }
     }
    if(A.at(0).at(0) == 0 && 
       A.at(1).at(1) == 0 &&
       A.at(2).at(2) == 0 ){
      ans = true;
    }
    if(A.at(0).at(2) == 0 && 
       A.at(1).at(1) == 0 &&
       A.at(2).at(0) == 0 ){
      ans = true;
    }
    
    k++;
  }
  
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}
  
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mp(a,b) make_pair(a,b)
#define vi vector<int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define vp vector<pair<int,int> >
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define F first
#define S second
#define endl "\n"
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define dom 998244353
#define pi 3.14159265
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define pii pair<int,int> 
#define mini 2000000000000000000
#define time_taken 1.0 * clock() / CLOCKS_PER_SEC
//mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
void shikhar7s(int cas)
{
    int n,x,t;
    cin>>n>>x>>t;
    int y=(n/x);
    if(n%x)
        y++;
    cout<<y*t;
}
signed main()
{
    fast;
    int t=1;
    //cin>>t;
    int cas=1;
    while(cas<=t)
    {
    shikhar7s(cas);
    cas++;
    }
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <map>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
 
using namespace std;
#define set_precision cout << fixed << setprecision(10)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define replb(i, a, b) for (ll i = a; i >= b; i--)
#define repl(i, a, b) for (ll i = a; i < b; i++)
#define repit(arr) for (auto it = arr.begin(); it != arr.end(); it++)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<int>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
#define pb push_back
#define ll long long
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define castl static_cast<ll>
#define BRAHAMASTRA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ull unsigned long long int

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

	BRAHAMASTRA

	int a,b,c;
	cin>>a>>b>>c;
	int k;
	cin>>k;
	while(a>=b)
	{
		b=b*2;
		k--;
		
	}
	while(b>=c)
	{
		c=c*2;
		k--;
	}
	if(k>=0)
		cout<<"Yes"<<"\n";
	else
		cout<<"No"<<"\n";
}

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

					using namespace std;
					typedef long long ll;
					int n, m, a[1111], s, k;
					double p;
					int main()
					{
						cin >> n >> m;
						for(int i = 1; i <= n; i++)
							cin >> a[i], s += a[i];
						p = s/(4.0*m);
						for(int i = 1; i <= n; i++)
						{
							if(a[i] < p)
								k++;
						}	
						if(n-k >= m)
							cout << "Yes";
						else cout << "No";	
					}

Measured memory_bytes: 256
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)


S,W = nm()
A  = nl()

if S <= W:
    print('unsafe')
else:
    print('safe')



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

int main(){
  int n;
  int count=0;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  for(int i=1;i<n-1;i++){
    if(p.at(i-1)<p.at(i) && p.at(i)<p.at(i+1)){
      count++;
    }else if(p.at(i-1)>p.at(i) && p.at(i)>p.at(i+1)){
      count++;
    }else{
     continue;
    }}
  cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      long X = sc.nextLong();
      
      // 預金額計算
      long prise = 100L;
      int year = 0;
      while(prise < X){
        long risi = prise / 100;
        prise += risi;
        year++;
      }
      
      // 出力
      System.out.println(year);
    }

}

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

typedef long long LL;
namespace IO
{
    const int S=(1<<20)+5;
    char buf[S],*H,*T;
    inline char Get()
    {
        if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
        if(H==T) return -1;return *H++;
    }
    inline LL read()
    {
        LL x=0;char c=Get();
        while(!isdigit(c)) c=Get();
        while(isdigit(c)) x=x*10+c-'0',c=Get();
        return x;
    }
    char obuf[S],*oS=obuf,*oT=oS+S-1,c,qu[55];int qr;
    inline void flush(){fwrite(obuf,1,oS-obuf,stdout);oS=obuf;}
    inline void putc(char x){*oS++ =x;if(oS==oT) flush();}
    template <class I>inline void print(I x)
    {
        if(!x) putc('0');
        while(x) qu[++qr]=x%10+'0',x/=10;
        while(qr) putc(qu[qr--]);
        putc('\n');
    }
}

using namespace IO;
const int N=100010;
int n,m,top=0;
LL a[N],f[N];
LL delta[N];

void solve(LL x,LL y)
{
    if(!x) return;
    int t=upper_bound(a+1,a+1+top,x)-a-1;
    if(!t) delta[1]+=y,delta[x+1]-=y;
    else f[t]+=x/a[t]*y,solve(x%a[t],y);
}

int main()
{
    a[++top]=n=read();m=read();
    for(int i=1;i<=m;i++)
    {
        LL x=read();
        while(x<=a[top]) top--;
        a[++top]=x;
    }
    f[top]=1;
    for(int i=top;i>=2;i--) f[i-1]+=a[i]/a[i-1]*f[i],solve(a[i]%a[i-1],f[i]);
    delta[1]+=f[1];delta[a[1]+1]-=f[1];
    for(int i=1;i<=n;i++) print(delta[i]+=delta[i-1]);
    flush();
    return 0;
}

Measured memory_bytes: 6144
// ITP1_7_B How many ways?
import java.io.*;

public class Main {

   public static void main(String[] args) {
      try {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
         while (true) {
            String strAry[] = br.readLine().split(" ");
            int n = Integer.parseInt(strAry[0]);
            int x = Integer.parseInt(strAry[1]);

            if ((n == 0 && x == 0) || (n < 3 || n > 100))
               break;

            System.out.println(combination(n, x));
         }
      }

      catch (Exception e) {
         System.err.println(e);
      }
   }

   private static int combination(int n, int x) {
      int count = 0;
      int i, j, k;
      for (i = 1; i <= n; i++) {
         for (j = 1; j < i; j++) {
            for (k = 1; k < j; k++) {
               if (i + j + k == x)
                  count++;
            }
         }
      }

      return count;
   }
}

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

int main(){
  int n,i,score_taro = 0,score_hana = 0;
  string str_taro, str_hana;

  cin >> n;
  for(i = 0; i < n;i++){
    cin >> str_taro >> str_hana;
    if(str_taro > str_hana)      score_taro += 3;
    else if(str_taro < str_hana) score_hana += 3;
    else{
      score_taro += 1; score_hana += 1;
    }
  }
  cout << score_taro << " " << score_hana << endl;
  return 0;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n, x;
    cin >> n >> x;

    vi l(n);
    rep(i, 0, n) { cin >> l[i]; }

    int cnt = 0, ans = 1;
    rep(i, 0, n) {
        if (cnt + l[i] <= x) {
            cnt += l[i];
            ++ans;
        } else {
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

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

const int MAX_N=100;

int N;
int a[MAX_N];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	do{
		cin>>N;
		if (N){
			REP(i,N){
				cin>>a[i];
			}
			int ans=0;
			REP(i,N){
				REP(j,N-i-1){
					if (a[j]>a[j+1]){
						ans++;
						swap(a[j],a[j+1]);
					}
				}
			}
			cout<<ans<<endl;
		}
	}while (N);
	return 0;
}

Measured memory_bytes: 1192
n, k = map(int, input().split())
ls = list(map(int, input().split()))
ls2 = list(map(lambda x: bin(x)[2:], ls))
m = max(map(len, ls2))
m = max(m, len(bin(k)[2:]))
ls2 = [s[::-1] for s in ls2]
res = []
for i in range(m):
    c0 = 0
    c1 = 0
    for s in ls2:
        if i < len(s):
            if s[i] == '0':
                c0 += 1
            else:
                c1 += 1
        else:
            c0 += 1
    if c1 > c0:
        res.append('0')
    else:
        res.append('1')
    x = int(''.join(res[::-1]), 2)
    if x > k:
        break

x = 0
mm = len(res)
for i, c in enumerate(res[::-1]):
    if c == '1':
        c = 2**(mm - i - 1)
        if x + c <= k:
            x += c

y = 0
for a in ls:
    y += x ^ a
print(y)

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,T; cin >> N >> M >> T;
    vector<int> a(N+2);
    a[0]=-M,a[N+1]=T+M;
    for (int i=0;i<N;++i) cin >> a[i+1];
    int ans=0;
    for (int i=0;i<N+1;++i) ans+=max(0,a[i+1]-a[i]-2*M);
    cout << ans << '\n';
}


Measured memory_bytes: 3212
import java.util.*;
import java.math.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
        String str = sc.nextLine().trim();
        sc.close();
        String[] strArr = str.split(" ");
        int n = Integer.parseInt(strArr[0]);
        int a = Integer.parseInt(strArr[1]);
        int b = Integer.parseInt(strArr[2]);
        int train = n * a;
        if(train < b){
            System.out.println(train);
        }else{
            System.out.println(b);
        }
	}
}

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

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define BOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){

    map<char,int> cnt;
    string s;
    cin>>s;
    REP(i,s.size()){
        if(cnt.find(s[i])!=cnt.end())cnt[s[i]]++;
        else cnt[s[i]]=1;
    }
    
    int ans=cnt['K'];
    ans=min(ans,cnt['U']);
    ans=min(ans,cnt['P']);
    ans=min(ans,cnt['C']);
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3228
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()

from collections import defaultdict
d = defaultdict(int)
ans = 0

for i in range(n):
    ans += d[i-a[i]]
    d[a[i]+i] += 1

print(ans)

Measured memory_bytes: 61072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n, k;
    cin >> n >> k;

    ll ans;
    if(n % k == 0) ans = 0;
    else if(n < k) ans = min(n, abs(n - k));
    else ans = min(n % k, abs(k - n % k));

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<string.h>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<climits>
using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin>>a>>b;
    if(a<=5){
        cout<<0<<endl;
        return 0;
    }else if(a>=6&&a<=12){
        cout<<b/2<<endl;
        return 0;
    }
    cout<<b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N);

    for (int i = 0; i < M; ++i) {
        int l, r; cin >> l >> r;
        --l; --r;
        ++A[l]; if ((r + 1) < N) --A[r + 1];
    }

    int ans = (A[0] >= M);
    for (int i = 1; i < N; ++i) {
        A[i] += A[i - 1];
        ans += (A[i] >= M);
    }

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

Measured memory_bytes: 640
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    List<List<Integer>> to = new ArrayList<>();
    List<List<Integer>> cost = new ArrayList<>();
    for (int i = 0; i < N; i++) {
      to.add(new ArrayList<>());
      cost.add(new ArrayList<>());
    }
    for (int i = 0; i < N-1; i++) {
      int u = sc.nextInt();
      int v = sc.nextInt();
      int w = sc.nextInt();
      u--;
      v--;
      to.get(u).add(v);
      to.get(v).add(u);
      cost.get(u).add(w);
      cost.get(v).add(w);
    }
    
    // BFS
    int[] ans = new int[N];
    Arrays.fill(ans, -1);
    LinkedList<Integer> q = new LinkedList<>();
    q.offer(0);
    ans[0] = 0;
    while (!q.isEmpty()) {
      int v = q.poll();
      for (int i = 0; i < to.get(v).size(); i++) {
        int vv = to.get(v).get(i);
        if (ans[vv] == -1) {
          ans[vv] = cost.get(v).get(i)%2 == 0 ? ans[v] : ans[v]^1;
          q.offer(vv);
        }
      }
    }
    
    for (int i = 0; i < N; i++) {
      System.out.println(ans[i]);
    }
  }
}



Measured memory_bytes: 117892
#include <stdio.h>

int main()
{
    int a, b, x, y, keep;
    
    while(scanf("%d %d", &a, &b) != EOF){
        if(a > b) {x = a, y = b;}
        else      {y = a, x = b;}
        while(y){
            keep = y;
            y = x % y;
            x = keep;
        }
        printf("%d %d\n", x, a / x * b);
    }
    return  0;
}

Measured memory_bytes: 596