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

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

using namespace std;

const LL MOD=1e9+7;

int n,x,ans=0;

int main()
{
	cin>>n;
	repn(i,n)
	{
		cin>>x;
		if(i%2==1&&x%2==1) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
open Printf
open Scanf

let id x = x
let read_int _ = bscanf Scanning.stdin " %d " id
let read_str _ = bscanf Scanning.stdin " %s " id
let read_pair _ = bscanf Scanning.stdin " %c %c " (fun x y -> (x,y))

let check s m inst dir =
  let n = String.length s in
  let rec check' i = function
    | _ when i = -1 || i = n -> true
    | [] -> false
    | (t,d)::rest ->
      if t = s.[i]
      then check' (if d = dir then i-1 else i+1) rest
      else check' i rest
  in check' m inst

let rec binary_search s l r inst d = match r - l = 1 with
    | true -> l
    | false ->
      let m = (l + r) / 2 in
      let (l',r') = if check s m inst d then (m, r) else (l, m) in
      binary_search s l' r' inst d

let rev_str s =
  let n = String.length s in
  String.init n (fun i -> s.[n-i-1])

let () =
  let n = read_int () in
  let q = read_int () in
  let s = read_str () in
  let inst = Array.(init q read_pair |> to_list) in
  let l = binary_search s (-1) n inst 'L' + 1 in
  let r = binary_search (rev_str s) (-1) n inst 'R' + 1 in
  printf "%d\n" (max 0 (n - r - l))


Measured memory_bytes: 13184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n, m;
  cin >> n >> m;
  int ans = n * (n - 1) / 2 + m * (m - 1) / 2;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
  int n;
  cin>>n;
  for(int i=0; i<n; i++){
    string s;
    cin>>s;
    string c="";
    int cnt=0;
    char t[5];
    for(int i=0; i<s.size(); i++){
      cnt=0;
      if(s[i]=='1'){
        t[0]='.',t[1]=',',t[2]='!',t[3]='?',t[4]=' ';
        while(1){
          if(s[i]==s[i+1]){i++,cnt++;}
          else{break;}
        }
        if(s[i+1]=='0'){c+=t[cnt%5];}
      }
      else if(s[i]=='2'){
        t[0]='a',t[1]='b',t[2]='c';
        while(1){
          if(s[i]==s[i+1]){i++,cnt++;}
          else{break;}
        }
        if(s[i+1]=='0'){c+=t[cnt%3];}
      }
      else if(s[i]=='3'){
        t[0]='d',t[1]='e',t[2]='f';
        while(1){
          if(s[i]==s[i+1]){i++,cnt++;}
          else{break;}
        }
        if(s[i+1]=='0'){c+=t[cnt%3];}
      }
      else if(s[i]=='4'){
        t[0]='g',t[1]='h',t[2]='i';
        while(1){
          if(s[i]==s[i+1]){i++,cnt++;}
          else{break;}
        }
        if(s[i+1]=='0'){c+=t[cnt%3];}
      }
      else if(s[i]=='5'){
        t[0]='j',t[1]='k',t[2]='l';
        while(1){
          if(s[i]==s[i+1]){i++,cnt++;}
          else{break;}
        }
        if(s[i+1]=='0'){c+=t[cnt%3];}
      }
      else if(s[i]=='6'){
        t[0]='m',t[1]='n',t[2]='o';
        while(1){
          if(s[i]==s[i+1]){i++,cnt++;}
          else{break;}
        }
        if(s[i+1]=='0'){c+=t[cnt%3];}
      }
      else if(s[i]=='7'){
        t[0]='p',t[1]='q',t[2]='r',t[3]='s';
        while(1){
          if(s[i]==s[i+1]){i++,cnt++;}
          else{break;}
        }
        if(s[i+1]=='0'){c+=t[cnt%4];}
      }
      else if(s[i]=='8'){
        t[0]='t',t[1]='u',t[2]='v';
        while(1){
          if(s[i]==s[i+1]){i++,cnt++;}
          else{break;}
        }
        if(s[i+1]=='0'){c+=t[cnt%3];}
      }
      else if(s[i]=='9'){
        t[0]='w',t[1]='x',t[2]='y',t[3]='z';
        while(1){
          if(s[i]==s[i+1]){i++,cnt++;}
          else{break;}
        }
        if(s[i+1]=='0'){c+=t[cnt%4];}
      }
    }
    cout<<c<<endl;
  }
}


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

int main(){
  int N, A, S = 100, J = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++){
    cin >> A;
  	while (2 <= A){//このループで入力されたAがどれだけ２で割れるか
    	if (A%2 == 0){
          A /=2;
      	  J +=1;
        }
      else{
        break;
      }
    }
    if (S >= J){
      S = J;
    }
    J = 0;
  }
  cout << S << endl;
}
      
      
      
    
  
  

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(long long i = a; i <= (b); ++i)
int main() {
    long long L, R;
    cin >> L >> R;
    
    R = min(R, L+4038);
    int ans = 2018;
    rep(i, L, R){
        rep(j, i+1, R){
            int x = i*j%2019;
            if (ans > x){
                ans = x;
            }
        }
    }
    cout << ans << endl;
}


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

using namespace std;

bool ok(const string& S, int L){
    for(int i=0;i<L-i-1;i++) if(S[i] != S[L-i-1]) return false;
    return true;
}

int main(){
    string S;
    while(cin >> S){
        int N = S.size();
        cout << (ok(S, N) && ok(S, N/2) ? "Yes" : "No") << endl;
    }
}

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

const int  mod = 1000000007;

struct mint{
    ll x;
    mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
    mint& operator+=(const mint a){//operatorは構造体同士の比較に用いられる
        if((x +=a.x)>=mod) x-=mod;
        return *this;//thisとは現在のオブジェクトのこと
    }
    mint& operator-=(const mint a){
        if((x +=mod-a.x)>=mod) x-=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x*=a.x)%=mod;
        return *this;
    }
    mint operator+(const mint a){
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a){
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a){
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const{
        if(!t) return 1;
        mint a=pow(t>>1);
        a*=a;
        if(t&1) a*=*this;
        return a;
    }
    mint inv() const{
        return pow(mod-2);//逆元
    }

    mint&operator/=(const mint a) {
        return (*this)*=a.inv();
    }
    mint&operator/(const mint a) const{
        mint res(*this);
        return res/=a;
    }
};

int main(void){
    string l;
    cin>>l;
    vector<mint> dp1(l.size());
    vector<mint> dp2(l.size());
    dp1[0]=1;
    dp2[0]=2;
    for(int i=1;i<l.size();i++){
        if(l[i]=='0'){
            dp1[i]=dp1[i-1]*3;
            dp2[i]=dp2[i-1];
        }
        else{
            dp1[i]=dp1[i-1]*3+dp2[i-1];
            dp2[i]=dp2[i-1]*2;
        }
        //cout<<dp1[i].x<<" "<<dp2[i].x<<endl;
    }
    cout<<(dp1[l.size()-1]+dp2[l.size()-1]).x<<endl;
    
}

Measured memory_bytes: 2048
# import sys
# input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**7)

n = int(input())
s = input().rstrip() + "#"

ans = 0
prev = s[0]
for ch in s[1:]:
    if ch != prev:
        ans += 1
    prev = ch
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  
  ll n;
  cin >> n;
  vector<ll> a(n),b(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  ll sumcheck = 0;
  rep(i,n){
    sumcheck += a[i]-b[i]; 
  }
  if(sumcheck < 0){
    cout << -1 << endl;
    return 0;
  }
  vector<ll> c(0);
  ll d = 0;
  ll ans1 = 0;
  rep(i,n){
    if(a[i]-b[i] >= 0){
      c.push_back(a[i]-b[i]);
    }else{
      d += b[i]-a[i];
      ans1 ++;
    }
  }
  if(ans1 == 0){
    cout << 0 << endl;
    return 0;
  }
  sort(all(c));
  reverse(all(c));
  ll ans2 = 0;
  for(ll p : c){
    ans2 ++;
    d -= p;
    if(d < 0) break;
  }
  cout << ans1 + ans2 << endl;
}

Measured memory_bytes: 5704
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{   int N,a[4]={0},s=0;
    char F;
    scanf("%d",&N);

    while(N--)
    {   getchar();
        scanf("%c",&F);
        if(F=='G')
            a[0]++;
        else if(F=='W')
            a[1]++;
        else if(F=='Y')
            a[2]++;
        else if(F=='P')
            a[3]++;
    }
    for(int i=0;i<4;i++)
        if(a[i])
        s++;
    if(s==3)
        printf("Three");
    else printf("Four");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)n;++i)
int a[5000], b[5000], dp[5001];

int main() {
  int A, B;
  while(cin >> A >> B) {
    REP(i, A) cin >> a[i];
    REP(i, B) cin >> b[i];
    memset(dp, 0, sizeof(dp));
    REP(i, A) {
      for (int j=B-1; j>=0; --j) {
        if (a[i] == b[j]) {
          dp[j+1] = dp[j]+1;
        }
      }
    }
    cout << *max_element(dp,dp+B+1) << endl;
  }
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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...));
}

int main() {
    int n, t; cin >> n >> t;
    vector<int> a(n), b(n);
    vector<pair<int, int>> p(n), q(n);

    REP(i, n) {
        int x, y; cin >> x >> y;
        p[i] = {x, y};
    }

    sort(p.begin(), p.end());

    REP(i, n) {
        a[i] = p[i].first;
        b[i] = p[i].second;
    }

    auto dp = make_v(n + 1, t + 1, 0);

    int ans = 0;

    REP(i, n)REP(j, t) {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        if (j + a[i] < t) {
            dp[i + 1][j + a[i]] = max(dp[i + 1][j + a[i]], dp[i][j] + b[i]);
        } else {
            ans = max(ans, dp[i][j] + b[i]);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

int main() {
    int n; cin >> n;
    vector<P> x;
    rep(i,n) {
        int a; cin >> a;
        x.push_back(P(a,i));
    }
    sort(all(x));
    int med_1 = x[n/2-1].first;
    int med_2 = x[n/2].first;
    vint ans(n);
    rep(i,n) {
        if (i <= (n/2-1)) ans[x[i].second] = med_2;
        else ans[x[i].second] = med_1;
    }
    rep(i,n) printf("%d\n",ans[i]);
}

Measured memory_bytes: 4592
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

struct edge {
   int u, v, cost;
};
bool comp(const edge& e1, const edge& e2) {
   return e1.cost < e2.cost;
}
struct UnionFind {
   vector<int> d;
   UnionFind(int n = 0) : d(n, -1) {}
   int find(int x) {
      if (d[x] < 0) return x;
      return d[x] = find(d[x]);
   }
   bool unite(int x, int y) {
      x = find(x);
      y = find(y);
      if (x == y) return false;
      if (d[x] > d[y]) swap(x, y);
      d[x] += d[y];
      d[y] = x;
      return true;
   }
   bool same(int x, int y) { return find(x) == find(y); }
   int size(int x) { return -d[find(x)]; }
};
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int V, E;
   cin >> V >> E;

   edge es[E];
   rep(i, 0, E) {
      int s, t, w;
      cin >> s >> t >> w;
      es[i].u = s, es[i].v = t, es[i].cost = w;
   }
   sort(es, es + E, comp);
   UnionFind uf(V);
   int res = 0;
   rep(i, 0, E) {
      edge e = es[i];
      if (!uf.same(e.u, e.v)) {
         uf.unite(e.u, e.v);
         res += e.cost;
      }
   }
   cout << res << endl;
   return 0;
}


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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  if(a+b>c+d){
    cout << "Left" << endl;
  }
  else if(a+b==c+d){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}


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

vector<long> yakusu(long n){
  vector<long> p;
  long i=1;
  while(i*i<=n){
    if(n%i==0){
      p.push_back(i);
      p.push_back(n/i);
    }
    i++;
  }
  //if(p.back()*p.back()==n) p.pop_back();
  return p;
}

int main ()
{
  int N;
  cin >> N;
  long A;
  cin >> A;
  vector<long> p;
  p=yakusu(A);
  sort(p.begin(),p.end());
  //for(auto itr = p.begin(); itr != p.end(); ++itr) {
  //cout << *itr << endl; 
  //}
  for(int i=1;i<N;i++){
    cin >> A;
    int j=0;
    while(j<p.size()){
      if(A%p.at(j)!=0) p.erase(p.begin()+j);
      else j++;
    }
  }
  cout << p.back() << endl;
  return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    int a,b,c; cin>>a>>b>>c;
    int ans=min(a+b,min(a+c,b+c));
    cout<<ans<<endl;
}





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

const int N = 500000;

int pre[N+5];

template<int M, int SZ> struct Persistable_Segment_Tree{
    int tot, p, k, L, R;
    int rt[M+5], lc[SZ+5], rc[SZ+5], cntv[SZ+5];
    void init(){ tot = rt[0] = lc[0] = rc[0] = cntv[0] = 0; }
    int update(int pre, int l, int r, int k){
        int now = ++tot;
        if (l == r){ cntv[now] = cntv[pre] + k; }
        else {
            int m = (l+r) >> 1;
            if (p <= m){ lc[now] = update(lc[pre], l, m, k); rc[now] = rc[pre]; }
            else { rc[now] = update(rc[pre], m+1, r, k); lc[now] = lc[pre]; }
            cntv[now] = cntv[lc[now]] + cntv[rc[now]];
        }
        return now;
    }
    void query(int o, int l, int r){
        if (L <= l && r <= R){
            k += cntv[o];
        }
        else {
            int m = (l+r) >> 1;
            if (L <= m) query(lc[o], l, m);
            if (R > m) query(rc[o], m+1, r); 
        }
    }
};

Persistable_Segment_Tree<N, N*40> psegt;

int main(){
    int n, q;
    scanf("%d %d", &n, &q);
    for (int i = 1; i <= n; ++i){
        int x; scanf("%d", &x);
        int rt = psegt.rt[i-1];
        if (pre[x]){
            psegt.p = pre[x];
            rt = psegt.update(rt, 1, n, -1);
        }
        pre[x] = i;
        psegt.p = i;
        rt = psegt.update(rt, 1, n, 1);
        psegt.rt[i] = rt;
    }
    for (int i = 1; i <= q; ++i){
        int l, r;
        scanf("%d %d", &l, &r);
        psegt.L = l;
        psegt.R = r;
        psegt.k = 0;
        psegt.query(psegt.rt[r], 1, n);
        printf("%d\n", psegt.k);
    }
    return 0;
}

Measured memory_bytes: 239488
(n, m) = map(int, raw_input().split())

a = [input() for i in range(n)]
b = [input() for i in range(m)]

c = [0 for i in range(n)]

for i in range(m):
  for j in range(n):
    if a[j] <= b[i]:
      c[j] += 1
      break

mx = max(c)
for i in range(n):
  if c[i] == mx:
    print i + 1

Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
int n,m;
char s[105][105];
int fx[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
int main(){
	
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>s[i]+1;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j]=='#'){
				int flag=0;
				for(int z=0;z<4;z++){
					int x=i+fx[z][0],y=j+fx[z][1];
					if(s[x][y]=='#') flag++;
				}
				if(flag==0)
				{
					cout<<"No"<<endl;
					return 0;
				} 
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}
/*
*/

Measured memory_bytes: 256
n = int(input())
xys = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    xys[i] = [list(map(int, input().split())) for _ in range(a)]

max_honest = 0
for i in range(2 ** n):
    bin_i = format(i, '015b')[::-1]
    ok = True

    for j in range(n):
        for x, y in xys[j]:
            if bin_i[j] == "1" and y != int(bin_i[x - 1]):
                ok = False
                break
        else:
            continue
        break

    if ok:
        honest = sum(int(x) for x in bin_i)
        max_honest = max(max_honest, honest)

print(max_honest)



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

int main(){
	int a , b;
	cin >> a >> b;
	if(a >=10 || b>= 10){
		cout<< -1 << endl;
		return 0;
	}
	cout << a*b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	string s;
	cin >> s;
    string ans = "Good";
    rep(i,3) if(s[i] == s[i+1]) ans = "Bad";
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main() {
    int n;
    vector<pair<string, int>> array, copy;

    cin >> n;
    array.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> array[i].first >> array[i].second;
        array[i].second *= -1;
    }
    copy = array;
    sort(array.begin(), array.end());

    for (int k = 0; k < array.size(); k++) {
        int m = 0;
        while (copy[m] != array[k]) {
            m++;
        }
        cout << m + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <string>
#include <set>
#include <map>
#define SIZE 50005
#define EPS 1e-12
#define DINF 1e9

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

struct BIT
{
	int bit[SIZE];
	
	void init()
	{
		memset(bit,0,sizeof(bit));
	}
	void add(int k,int x)
	{
		k++;
		while(k<SIZE)
		{
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int get(int k)
	{
		k++;
		int ret=0;
		while(k>0)
		{
			ret+=bit[k];
			k-=k&-k;
		}
		return ret;
	}
	int get(int s,int t)
	{
		return get(t)-get(s-1);
	}
	int pos(int k)//k 番目
	{
		int l=0,r=SIZE;
		while(r-l>1)
		{
			int m=(l+r)/2;
			if(get(m)<k) l=m;
			else r=m;
		}
		return r;
	}
};
BIT bit;
int A[SIZE],B[SIZE],C[SIZE];
int n;

vector <double> comp(vector <double> vx)
{
	sort(vx.begin(),vx.end());
	vector <double> ret;
	for(int i=0;i<vx.size();)
	{
		ret.push_back(vx[i]);
		int f=i;
		for(;i<vx.size()&&vx[i]-vx[f]<EPS;i++);
	}
	return ret;
}
ll solve(double X)
{
	vector <double> vx,vy;
	for(int i=0;i<n;i++)
	{
		double Y=(double) ((double) C[i]-X*(double) A[i])/(double) B[i];
		double Z=-(double) A[i]/(double) B[i];
		vx.push_back(Y);
		vy.push_back(Z);
	}
	vx=comp(vx);
	vy=comp(vy);
	vector <P> vt;
	for(int i=0;i<n;i++)
	{
		double Y=(double) (C[i]-X*A[i])/(double) B[i];
		double Z=-(double) A[i]/(double) B[i];
		int y=lower_bound(vx.begin(),vx.end(),Y-EPS)-vx.begin();
		int z=lower_bound(vy.begin(),vy.end(),Z-EPS)-vy.begin();
		vt.push_back(P(y,z));
	}
	sort(vt.begin(),vt.end());
	bit.init();
	ll ret=0;
	for(int i=0;i<n;i++)
	{
		P p=vt[i];
		ret+=bit.get(0,p.second);
		bit.add(p.second,1);
	}
	return ret;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d %d %d",&A[i],&B[i],&C[i]);
	double l=-DINF,r=DINF;
	for(int i=0;i<70;i++)
	{
		double d=(l+r)/2;
		ll cnt=solve(d);
		if(cnt*2<(ll) n*(ll) (n-1)/2) l=d;
		else r=d;
	}
	double px=l;
	for(int i=0;i<n;i++) swap(A[i],B[i]);
	l=-DINF,r=DINF;
	for(int i=0;i<70;i++)
	{
		double d=(l+r)/2;
		ll cnt=solve(d);
		if(cnt*2<(ll) n*(ll) (n-1)/2) l=d;
		else r=d;
	}
	double py=l;
	printf("%.10f %.10f\n",px,py);
	return 0;
}


Measured memory_bytes: 3556
n,k = map(int,input().split())
q = [0]*(k+1)
mod = 10**9+7
for i in range(k,0,-1):
    q[i] += pow(k//i,n,mod)
    for j in range(2,k//i + 1):
        q[i] -= q[i*j]
    q[i] %= mod
ans = 0
for i,j in enumerate(q):
    ans += i*j
    ans %= mod
print(ans)


Measured memory_bytes: 11288
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int c[3][3];
	REP(i, 3) {
		REP(j, 3) {
			cin >> c[i][j];
		}
	}

	bool col = false, row = false;

	int a12 = c[1][0] - c[0][0];
	int a13 = c[2][0] - c[0][0];
	int b12 = c[0][1] - c[0][0];
	int b13 = c[0][2] - c[0][0];

	if(a12 == (c[1][1]-c[0][1]) && a12 == (c[1][2]-c[0][2]) 
		&& a13 == (c[2][1] - c[0][1]) && a13 == (c[2][2] - c[0][2])) {
		col = true;
	}

	if (b12 == (c[1][1] - c[1][0]) && b12 == (c[2][1] - c[2][0])
		&& b13 == (c[1][2] - c[1][0]) && b13 == (c[2][2] - c[2][0])) {
		row = true;
	}

	if (col && row) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	

	system("pause");
	return 0;
}

Measured memory_bytes: 504
from collections import deque
n=int(raw_input())
a=deque(map(int, raw_input().split()))
out=deque([])
if len(a) % 2 == 1:
    out.append(a.popleft())
while len(a) > 0:
    out.append(a.popleft())
    out.appendleft(a.popleft())
print " ".join(map(str, out))


Measured memory_bytes: 23880
#include <iostream>
#include <vector>
#include <set>
#include <stack>
#include <functional>

using namespace std;

const int MOD = 1000000007;

struct Edge {
	Edge(int src, int dst) : src(src), dst(dst) {}
	int src, dst;
	int getMin() const { return min(src, dst); }
	int getMax() const { return max(src, dst); }
	bool operator < (const Edge& e) const {
		if(getMin() == e.getMin()){
			return getMax() < e.getMax();
		}
		return getMin() < e.getMin();
	}
};

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

vector< set<Edge> > findArt(const vector< vector<int> >& g){
	const int n = g.size();
	vector<int> order(n, -1), low(n, -1);
	vector< set<Edge> > comp;
	stack<Edge> edges;
	int time = 0;

	function<void(int)> f = [&](int v){
		order[v] = low[v] = time;
		++time;
		for(int i=0;i<g[v].size();i++){
			const int dst = g[v][i];
			if(order[dst] < order[v]) edges.push(Edge(v, dst));
			if(order[dst] == -1){
				f(dst);
				low[v] = min(low[v], low[dst]);
				if(order[v] <= low[dst]){
					comp.push_back(set<Edge>());
					while(true){
						Edge e = edges.top(); edges.pop();
						comp.back().insert(e);
						if(e.src == v && e.dst == dst) break;
					}
				}
			} else {
				low[v] = min(low[v], order[dst]);
			}
		}
	};

	for(int i=0;i<n;i++){
		if(order[i] != -1) continue;
		time = 0;
		f(i);
	}

	return comp;
}

long long modPow(long long a, long long p){
	if(p == 0) return 1;
	long long r = modPow(a, p/2);
	r = r*r%MOD;
	if(p%2 == 1) r = r*a%MOD;
	return r;
}

int main(){
	int N, M, K;
	long long comb[201][202];
	for(int i=1;i<=200;i++){
		comb[i][0] = 1;
		for(int j=1;j<i;j++){
			comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
			comb[i][j] %= MOD;
		}
		comb[i][i] = 1;
	}
	while(cin >> N >> M >> K){
		vector< vector<int> > g(N);
		for(int i=0;i<M;i++){
			int a, b; cin >> a >> b;
			--a; --b;
			g[a].push_back(b);
			g[b].push_back(a);
		}
		vector< set<Edge> > c = findArt(g);
		long long res = 1;
		for(int i=0;i<c.size();i++){
			const set<Edge>& v = c[i];
			if(v.size() == 1){
				res *= K;
				res %= MOD;
				continue;
			}
			set<int> S;
			for(const Edge& e : v){
				S.insert(e.src);
				S.insert(e.dst);
			}
			if(S.size() == v.size()){
				long long add = 0;
				for(int j=1;j<=S.size();j++){
					add += modPow(K, gcd(j, S.size()));
					add %= MOD;
				}
				add *= modPow(S.size(), MOD-2);
				add %= MOD;
				res *= add;
				res %= MOD;
			} else {
				res *= comb[v.size()+K-1][v.size()];
				res %= MOD;
			}
		}
		cout << res << endl;
	}
}



Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main()
{
	int n,a[100];
	cin >> n;
	for(int i=0;i<n;++i){
		cin >> a[i];
	}
	for(int i=n-1;i>0;--i){
		cout << a[i] << " ";
	}
	cout << a[0] << endl;
	return 0;
}

Measured memory_bytes: 1160
#!/usr/bin/env python
"""AtCoder Beginner Contest 168: D - .. (Double Dots)
https://atcoder.jp/contests/abc168/tasks/abc168_d
"""


def main():
    N, M = map(int, input().split())

    to = [[] for i in range(N)]
    for i in range(M):
        a, b = map(int, input().split())
        to[a-1].append(b-1)
        to[b-1].append(a-1)

    p = [-1]*N
    q = [0]
    while q:
        v = q.pop(0)
        for u in to[v]:
            if p[u] == -1:
                p[u] = v
                q.append(u)
    print('Yes')
    for i in range(1, N):
        print(p[i]+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 33700
#include<bits/stdc++.h>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  int w,h,n; cin >> w >> h >> n;
  vi x(n),y(n),a(n); rep(i,n) cin >> x[i] >> y[i] >> a[i];
  vector<vector<bool>> white(h,vector<bool>(w,true));

  rep(i,n){
    if(a[i] == 1){
      rep(j,h){
          rep(k,x[i]){
          white[j][k] = false;
        }
      }
    }else if(a[i] == 2){
      rep(j,h){
        for(int k = x[i]; k < w; k++){
          white[j][k] = false;
        }
      }
    }else if(a[i] == 3){
      rep(j,y[i]){
        rep(k,w){
          white[j][k] = false;
        }
      }
    }else if(a[i] == 4){
      for(int j = y[i]; j < h; j++){
        rep(k,w){
          white[j][k] = false;
        }
      }
    }
  }
  int ans = 0;
  rep(i,h) rep(j,w) if(white[i][j]) ans++;
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<cmath>
#define int long long
using namespace std;
int n,q;
int mi[200010],sum[200010];
int summ[1000010];
int la[1000010];
int x,y,z;
void build(int k,int l,int r)
{
	if(l==r)
	{
		summ[k]=mi[l]%998244353;
		return ;
	}
	int mid=(l+r)>>1;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
	summ[k]=(summ[k<<1]+summ[k<<1|1])%998244353;
}
void add(int k,int l,int r,int v)
{
	la[k]=v;
	summ[k]=((sum[r]-sum[l-1]+998244353)%998244353*v)%998244353;
}
void pushdown(int k,int l,int r,int mid)
{
	if(la[k]==0)
		return ;
	add(k<<1,l,mid,la[k]);
	add(k<<1|1,mid+1,r,la[k]);
	la[k]=0;
	return;
}
void updata(int k,int l,int r,int v)//y左，x右 
{
	if(l>=y&&r<=x)
	{
		add(k,l,r,v);
		return; 
	}
	int mid=(l+r)>>1;
	pushdown(k,l,r,mid);
	if(y<=mid)
		updata(k<<1,l,mid,v);
	if(mid+1<=x)
		updata(k<<1|1,mid+1,r,v);
	summ[k]=(summ[k<<1]+summ[k<<1|1])%998244353;
}
signed main()
{
	scanf("%lld%lld",&n,&q);
	mi[1]=1;
	sum[1]=1;
	for(int i=2;i<=n;i++)
	{
		mi[i]=(mi[i-1]*10)%998244353;
		sum[i]=(mi[i]+sum[i-1])%998244353;
	}
	build(1,1,n);
	for(int i=1;i<=q;i++)
	{
		scanf("%lld%lld%lld",&x,&y,&z);
		y=n-y+1;
		x=n-x+1;
		updata(1,1,n,z);
		printf("%lld\n",summ[1]);
	}	
}


Measured memory_bytes: 15096
#include <iostream>
#include <stdio.h>
using namespace std;
int main(int argc, char **argv){
	char s[20];
	fgets(s, sizeof(s), stdin);
	string strS;
	strS.append(s);
	string result = strS.substr(0,4) + string(" ") + strS.substr(4,11);
	printf("%s", result.c_str());
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		// input
		int num = scan.nextInt();
		int uneven = 0;
		for (int i = 0; i < num; i++) {
			int temp = scan.nextInt();
			if (temp % 2 != 0) {
				uneven++;
			}
		}

		// answer
		if (uneven % 2 == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}
}


Measured memory_bytes: 49352
MAX_N=10**6
P=10**9+7
Fact=[0 for i in range(MAX_N+1)]
Fact[0]=1
for i in range(MAX_N):
    Fact[i+1]=(Fact[i]*(i+1))%P
N,M=map(int,input().split())
X=sorted([int(i) for i in input().split()])
Y=sorted([int(i) for i in input().split()])
A=[i for i in X]
B=[i for i in Y]
if len(set(A))!=N or len(set(B))!=M:
    print(0)
    exit()
L=[]
x=0
y=0
D=N*M
while(len(A)>0 and len(B)>0):
    if max(A[-1],B[-1])==D:
        if A[-1]>B[-1]:
            A.pop()
            L.append(y)
            x+=1
        elif A[-1]<B[-1]:
            B.pop()
            L.append(x)
            y+=1
        else:
            A.pop()
            B.pop()
            x+=1
            y+=1
        D-=1
    else:
        C=max(A[-1],B[-1])+1
        tmp=x*y-(N*M-D)
        for i in range(C,D+1)[::-1]:
            L.append(tmp)
            tmp-=1
        D=max(A[-1],B[-1])
if len(A)>0:
    D=min(Y)-1
    while(len(A)>0):
        C=A[-1]+1
        tmp=x*y-(N*M-D)
        for i in range(C,D+1)[::-1]:
            L.append(tmp)
            tmp-=1
        D=A.pop()-1
        x+=1
        L.append(M)
if len(B)>0:
    D=min(X)-1
    while(len(B)>0):
        C=B[-1]+1
        tmp=x*y-(N*M-D)
        for i in range(C,D+1)[::-1]:
            L.append(tmp)
            tmp-=1
        D=B.pop()-1
        y+=1
        L.append(N)
m=min(min(X),min(Y))-1
ans=Fact[m]
for i in L:
    ans*=i
    ans%=P
print(ans)


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a) / (b) + (((a) % (b))?1:0)
#define endl '\n'

using namespace std;
typedef long long LL;
/*
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
*/
static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

typedef long double ld;
using P = complex<ld>;
const ld eps = 1e-10;

ld cross(const P& a, const P& b) {
    return a.real() * b.imag() - a.imag() * b.real();

}
ld dot(const P& a, const P& b) {
    return a.real() * b.real() + a.imag() * b.imag();

}

template <class iter>
std::pair<P, ld> min_ball(iter left, iter right, int seed = 1333) {
    const int n = right - left;

    assert(n >= 1);
    if (n == 1) {
        return {*left, ld(0)};
    }

    std::mt19937 mt(seed);
    std::shuffle(left, right, mt);
    // std::random_shuffle(left, right); // simple but deprecated

    iter ps = left;
    using circle = std::pair<P, ld>;

    auto make_circle_3 = [](const P &a, const P &b, const P &c) -> circle {
        ld A = std::norm(b - c), B = std::norm(c - a), C = std::norm(a - b),
           S = cross(b - a, c - a);
        P p = (A * (B + C - A) * a + B * (C + A - B) * b + C * (A + B - C) * c) / (4 * S * S);
        ld r2 = std::norm(p - a);
        return {p, r2};
    };

    auto make_circle_2 = [](const P &a, const P &b) -> circle {
        P c = (a + b) / (ld)2;
        ld r2 = std::norm(a - c);
        return {c, r2};
    };

    auto in_circle = [](const P &a, const circle &c) -> bool {
        return std::norm(a - c.first) <= c.second + eps;
    };

    circle c = make_circle_2(ps[0], ps[1]);

    // MiniDisc
    for (int i = 2; i < n; ++i) {
        if (!in_circle(ps[i], c)) {
            // MiniDiscWithPoint
            c = make_circle_2(ps[0], ps[i]);
            for (int j = 1; j < i; ++j) {
                if (!in_circle(ps[j], c)) {
                    // MiniDiscWith2Points
                    c = make_circle_2(ps[i], ps[j]);
                    for (int k = 0; k < j; ++k) {
                        if (!in_circle(ps[k], c)) {
                            c = make_circle_3(ps[i], ps[j], ps[k]);
                        }
                    }
                }
            }
        }
    }
    return c;
}

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

    int n;
    cin >> n;
    vector<P> points(n);
    for(int i = 0; i < n; ++i) {
        ld x, y;
        cin >> x >> y;
        points[i] = P(x, y);

    }

    pair<P, ld> res = min_ball(all(points));
    printf("%.10Lf\n", sqrt(res.second));
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[4];
int main()
{
	cin>>a[1]>>a[2]>>a[3];
	sort(a+1,a+4);
	cout<<a[3]*10+a[2]+a[1];
	return 0;
}

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

int main()
{
  int n, sum = 0, m = 101;
  cin >> n;
  rep(i, n){
    int a;
    cin >> a;
    sum += a;
    if(a % 10 != 0){
      m = min(m, a);
    }
  }
  if(sum % 10 != 0){
    cout << sum << endl;
  }
  else if(m != 101){
    cout << sum - m << endl;
  }
  else cout << 0 << endl;
  system("pause");
}


Measured memory_bytes: 504
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <chrono>
#include <utility>

using namespace std;

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

constexpr int cm = 1<<17;
char buff[cm], *ci = buff + cm, ct;

inline char readchar() {
  if (ci - buff == cm) {
    fread(buff, 1, cm, stdin);
    ci = buff;
  }
  return *ci++;
}

inline int readint() {
  int num = 0;
  if (ci - buff + 16 > cm) {
    while ((ct = readchar()) >= '0') {
      num = (num << 3) + (num << 1) + ct - '0';
    }
  } else {
    while ((ct = *ci++) >= '0') {
      num = (num << 3) + (num << 1) + ct - '0';
    }
  }
  return num;
}

int main(){
  auto start = chrono::system_clock::now();

  int n = readint();

  vector<queue<int>> v(1002, queue<int> ());
  rep(i, n) {
    rep(j, n - 1) {
      int a = readint();
      v[i + 1].emplace(a);
    }
  }

  for (int day = 1; day <= n * (n - 1) / 2; ++day) {
    bool done[1002] = {};
    for (int i = 1; i <= n; ++i) {
      if (done[i]) continue;
      if (v[i].empty()) continue;
      int next = v[i].front();
      if (done[next]) continue;
      if (v[next].front() == i) {
        v[i].pop(); v[next].pop();
        done[i] = done[next] = true;
      }
    }
    if (all_of(done, done + n, [](const bool& x){return x == false;})){
      printf("-1");
      return 0;
    }
    if (all_of(v.begin(), v.end(), [](const queue<int>& x){return x.empty();})) {
      printf("%d", day);
      return 0;
    }
    auto now = chrono::system_clock::now();
    auto dur = now - start;
    auto msec = chrono::duration_cast<chrono::microseconds>(dur).count();
    if (msec >= 27800) {
      printf("%d", n * (n - 1) / 2);
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 4864
#!/usr/bin/env perl
use 5.10.0;
use utf8;
use strict;
use warnings;
use open qw( :utf8 :std );
use Data::Dumper;
use POSIX qw( ceil );

my $line = readline;
my( $a, $b, $c, $d ) = split m{\s}, $line;
my %takagi = (
    hp => $a,
    attack => $b,
);
my %aoki = (
    hp => $c,
    attack => $d,
);

my $takagi_attack_count = ceil( $aoki{hp} / $takagi{attack} );
my $aoki_attack_count = ceil( $takagi{hp} / $aoki{attack} );

say(
    ( $takagi_attack_count <= $aoki_attack_count )
    ? "Yes"
    : "No"
);



exit;



Measured memory_bytes: 7448
#include <stdio.h>

long gojo(long a, long b){
  if(a % b)
    gojo(b, a%b);
  else
    return b;
}

int main(){
  long a, b;  scanf("%ld %ld", &a, &b);
  if(b > a){
    long t = a; a = b; b = t;
  }

  long yaku = gojo(a, b);
  long ans = 1;
  
  for(long i=2; i*i<=yaku; i++){
    if(yaku%i == 0){
      ans++;
      while(yaku%i == 0)  yaku /= i;
    }
  }
  if(yaku != 1)
    ans++;

  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 1692
package main

import (
	"bufio"
	"fmt"
	"os"
)

const N = 4040
var n int
var s string
var cnt[N][3] int

func getDiff(a int, b int) int {
	for i := 0; i < 3; i++ {
		if i != a && i != b {
			return i
		}
	}
	return -1
}

func getPos(c uint8) int {
	if c == 'R' {
		return 1
	}
	if c == 'B' {
		return 2
	}
	return 0
}

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d\n", &n)
	fmt.Fscanf(reader, "%s\n", &s)

	for i := n; i >= 1; i-- {
		for j := 0; j < 3; j++ {
			cnt[i][j] = cnt[i + 1][j]
			if getPos(s[i - 1]) == j {
				cnt[i][j]++
			}
		}
	}

	var ret = int64(0)

	for i := 1; i < n; i++ {
		for j := i + 1; j < n; j++ {
			if s[i - 1] != s[j - 1] {
				var a = getPos(s[i - 1])
				var b = getPos(s[j - 1])
				var c = getDiff(a, b)
				ret += int64(cnt[j + 1][c])
				var k = j + (j - i)
				if k > n {
					continue
				}
				if getPos(s[k - 1]) == c {
					ret--
				}
			}
		}
	}

	fmt.Fprintf(writer, "%d", ret)
}


Measured memory_bytes: 2016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    ll h,n,sum=0;
    cin >> h >> n;
    vll a(n);
    REP(i,n){
        cin >> a[i];
        sum+=a[i];
    }
    if(sum >= h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
  
using namespace std;
  
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
  
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
  
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
#define FF first
#define SS second
  
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
 
LL n, m;
LL f(LL a){
  return (m-a) / (n-1) + a / (n-1) + 1;
}
LL powm(LL a, LL b){
  if(b == 0) return 1;
  return powm(a*a%MOD, b/2) * (b%2?a:1) % MOD;
}
LL inv(LL x){
  return powm(x, MOD-2);
}
 
int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
 
  cin >> n >> m;
 
  if(n == 1){
    cout << (m+1) % MOD << endl;
    return 0;
  }
 
  LL d = m / (n-1) % MOD, r = (m - d % MOD * (n-1) % MOD) % MOD;
  m %= MOD;
  n %= MOD;
  cout << (m + 1
           + 2 * (d * (d-1) % MOD * inv(2) % MOD * (n-1) % MOD + d * (r + 1) % MOD)) % MOD
       << endl;
   
  return 0;
}

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

template<class Abel> struct UnionFind {
    vector<int> data; vector<Abel> cost; int sz;
    UnionFind(int sz, Abel unit = 0) : data(sz,-1), cost(sz,unit), sz(sz) { }
    bool unionSet (int x, int y, Abel w) {
        w += (weight(x) - weight(y));
        if ((x = root(x)) == (y = root(y))) { return false; }
        if (data[x] > data[y]) { swap(x, y); w = -w; }
        data[x] += data[y]; data[y] = x; cost[y] = w; sz--; return true;
    }
    bool findSet (int x, int y) { return root(x) == root(y); }
    int root (int x) {
        if (data[x] < 0) return x;
        int r = root(data[x]); cost[x] += cost[data[x]]; return data[x] = r;
    }
    Abel weight (int x) { root(x); return cost[x]; }
    Abel diff (int x, int y) { return weight(y) - weight(x); }
    int size (int x) { return -data[root(x)]; }
    int size () { return sz; }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind<int> uf(N);
    bool judge = true;
    for (int i = 0; i < M; i++) {
        int x, y, d;
        cin >> x >> y >> d;
        
        if (!uf.unionSet(x, y, d)) {
            int diff = uf.diff(x, y);
            if (d != diff) {
                judge = false;
                break;
            }
        }
    }
    
    if (judge == true) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<(vi==INF?"_":to_string(vi))<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  ll h,n;
  cin>>h>>n;
  vector<pll> a(n);
  cin>>a;

  auto solve = [&](auto a){
  // dp[i][j] := i番目までの魔法を使ってjダメージ与えるときの最小ダメ
  auto dp = _vec<ll>(n+1,1e5,INF);
    dp[0][0] = 0;
    rep(i,n)dp[i+1][0] = 0;
    rep(i,n){
      for(ll j=0;j<=h;++j){
        chmin(dp[i+1][j],dp[i][j]);
        if(j+a[i].first<1e5)chmin(dp[i+1][j+a[i].first],dp[i+1][j]+a[i].second);
      }
    }
    ll ans = INF;
    for(int i=h;i<1e5;++i)chmin(ans,dp[n][i]);

    return ans;
  };

  ll ans = INF;
  chmin(ans,solve(a));
  /*
  sort(a.begin(),a.end());
  chmin(ans,solve(a));
  sort(a.begin(),a.end(),greater<>());
  chmin(ans,solve(a));
  sort(a.begin(),a.end(),[](auto a,auto b){return a.second < b.second;});
  chmin(ans,solve(a));
  sort(a.begin(),a.end(),[](auto a,auto b){return a.second > b.second;});
  chmin(ans,solve(a));
  */

  auto ceil = [](auto a,auto b){
    return (a-1)/b+1;
  };

  rep(i,n){
    chmin(ans,ceil(h,a[i].first)*a[i].second);
  }

  cout<<(ans)<<endl;


}


Measured memory_bytes: 785920
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int main() {
    int N, K, S;
    cin >> N >> K >> S;
    for (int i = 0; i < K; i++) cout << S << " ";
    for (int i = 0; i < N - K; i++) cout << (S == 1000000000 ? 1 : S + 1) << " ";
    cout << endl;
}


Measured memory_bytes: 1280
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()

before = ""
ans = 0
flag = False

for i, si in enumerate(s):

    if flag:
        ans += 1
        before = ""
        flag = False


    elif before == "":
        ans += 1
        before = si

    else:
        if si == before:
            flag = True
        else:
            ans += 1
            before = si

print(ans)

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

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

int main() {
    ll q,w;
    while(cin>>q>>w) {
        ll c = gcd(q,w);
        cout << c <<" "<<q*w/c <<endl;
    }
}



Measured memory_bytes: 3076
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,L=map(int,input().split())
    T=[int(input()) for _ in range(n)]
    s=0
    from math import pi
    from cmath import rect
    for j in range(n):
        for i in range(j): # 0<=i<j<=n-1
            s+=-rect(1,(T[i]+T[j])*pi/L)*(j-i-1) # Ti<T<Tj なるTの個数はj-i-1
            s+= rect(1,(T[i]+T[j])*pi/L)*(n-(j-i+1)) # T<Ti, Tj<T なるTの個数はn-(j-i+1)
    s/=n*(n-1)*(n-2)/6
    print(s.real,s.imag)
resolve()

Measured memory_bytes: 42556
#include<iostream>

using namespace std;

int main () {
    int A, B, C;

    cin >> A >> B >> C;
    int x = A, y = B, z = C;
    int ans = 0;

    while (x % 2 == 0 && y % 2 == 0 && z % 2 == 0) {
        int tx = x;
        int ty = y;
        x = y / 2 + z / 2;
        y = tx / 2 + z / 2;
        z = tx / 2 + ty / 2;
        ++ans;
        if (x == A && y == B && z == C) {
            ans = -1;
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
/* created   : 2019-09-23 23:44:05
 * accepted  : 2019-09-23 23:47:33
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int n, k, q; cin >> n >> k >> q;
  vector<ll> v(n, k - q);
  for (int i = 0; i < q; i++) {
    int x; cin >> x;
    x--;
    v[x]++;
  }
  for (int i = 0; i < n; i++) {
    if (i > 0) {
      cout << '\n';
    }
    cout << (v[i] > 0 ? "Yes" : "No");
  }
  cout << '\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
#include <queue>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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 FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    ll x, y;
    cin >> x >> y;
    ll ans = 0ll;
    for (ll i = x; i <= y; i*=2) {
        ans++;
    }
    cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input());S = input()
r,g,b = [],[],[]
for i in range(len(S)):
    if S[i]=='R':r.append(i)
    elif S[i]=='G':g.append(i)
    else:b.append(i)
ans = len(r)*len(g)*len(b)
for r_i in r:
    for g_i in g:
        sho = min(r_i,g_i);dai = max(r_i,g_i)
        
        index = 2*sho-dai
        if index>=0:
            if S[index]=='B':ans-=1
                
        index = (sho+dai)//2
        if (sho+dai)%2 ==0:
            if S[index]=='B':ans-=1
        
        index = 2*dai-sho
        if index<len(S):
            if S[index]=='B':ans-=1
print(ans)

Measured memory_bytes: 9244