akhauriyash/Code-Regression huggingface dataset:
module mod_union_find
  implicit none
  integer :: n
  integer, allocatable :: par(:), rnk(:), siz(:)
  private
  public :: initialize, finalize, find, same, unite, size_of
contains
  subroutine initialize(m)
    implicit none
    integer, intent(in) :: m
    integer :: i
    n = m
    if (allocated(par)) deallocate(par)
    if (allocated(rnk)) deallocate(rnk)
    if (allocated(siz)) deallocate(siz)
    allocate(par(n),rnk(n),siz(n))
    rnk = 0
    siz = 1
    do i = 1, n
      par(i) = i
    end do
    return
  end subroutine initialize
  subroutine finalize()
    implicit none
    if (allocated(par)) deallocate(par)
    if (allocated(rnk)) deallocate(rnk)
    if (allocated(siz)) deallocate(siz)
    return
  end subroutine finalize
  recursive function find(i) result(j)
    implicit none
    integer, intent(in) :: i
    integer :: j
    if (par(i).ne.i) then
      par(i) = find(par(i))
    end if
    j = par(i)
    return
  end function find
  function same(i,j) result(y)
    implicit none
    integer, intent(in) :: i, j
    logical :: y
    y = find(i).eq.find(j)
  end function same
  subroutine unite(i,j)
    implicit none
    integer, intent(in) :: i, j
    integer :: x, y
    x = find(i)
    y = find(j)
    if (x.eq.y) return
    if (rnk(x).lt.rnk(y)) then
      par(x) = y
      siz(y) = siz(y)+siz(x)
    else
      par(y) = x
      siz(x) = siz(x)+siz(y)
      if (rnk(x).eq.rnk(y)) rnk(x) = rnk(x)+1
    end if
    return
  end subroutine unite
  function size_of(i) result(s)
    implicit none
    integer, intent(in) :: i
    integer :: s
    s = siz(find(i))
  end function size_of
end module mod_union_find
program alternating_path
  use mod_union_find
  implicit none
  integer :: h, w, a(400,400), i, j, num(160000,0:1)
  integer(8) :: m
  character(400) :: s
  a = 0
  num = 0
  read(*,*) h, w
  call initialize(h*w)
  do i = 1, h
    read(*,*) s
    s = trim(adjustl(s))
    do j = 1, w
      if (s(j:j).eq."#") a(i,j) = 1
      if (i.ne.1.and.a(i,j).ne.a(i-1,j)) call unite((i-1)*w+j,(i-2)*w+j)
      if (j.ne.1.and.a(i,j).ne.a(i,j-1)) call unite((i-1)*w+j,(i-1)*w+j-1)
    end do
  end do
  do i = 1, h
    do j = 1, w
      num(find((i-1)*w+j),a(i,j)) = num(find((i-1)*w+j),a(i,j))+1
    end do
  end do
  m = 0_8
  do i = 1, h*w
    m = m+int(num(i,0),8)*int(num(i,1),8)
  end do
  write(*,'(i0)') m
  call finalize()
  stop
end program alternating_path

Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define N 200005
using namespace std;
int a[N],i,j,k,l,s,n,m,Last,b[N];
long long ans;
int main() {
    scanf("%d",&n);
    for (i=1;i<=n;i++) scanf("%d",&a[i]);
    for (i=1;i<=n;i++) if (a[i]>=i) return puts("-1"),0;
    for (i=1;i<=n;i++) if (a[i]-a[i-1]>=2) return puts("-1"),0;
    for (i=n;i;i--) {
        if (a[i]==Last-1) Last--;
        else Last=a[i],ans+=a[i];
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 1152
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/
/*
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
*/
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void solve()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a), greater<ll>());
  int cnt = n - 1;
  int i = 0;
  ll sum = 0;
  while (cnt > 0)
  {
    sum += a[i];
    cnt--;
    if (cnt == 0)
      break;
    if (i == 0)
    {
      i++;
      continue;
    }
    sum += a[i];
    i++;
    cnt--;
  }
  cout << sum << "\n";
}

int main()
{
  init_main();
  solve();
}

Measured memory_bytes: 4780
// buy a lot of 0s
// or simply return 0 ?
// nope, it's buy one 0
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

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

  int n;
  cin >> n;
  cout << n + n * n + n * n * n << endl;
  return 0;
}


Measured memory_bytes: 3608
def resolve():
    n, m, k = map(int, input().split())
    for l in range(n + 1):
        for r in range(m + 1):
            black = l * m + r * n - 2 * r * l
            if black == k:
                print("Yes")
                return 0
    print("No")


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 2940
//#pragma comment(linker,"/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
const int INF=0x3f3f3f3f;
#define _for(i, a, b) for (int i = (a); i < (b); ++i)
#define _rep(i, a, b) for (int i = (a); i <= b; ++i)
const int max_number=1000000;



int main()
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    //if(x<=0||y<=0)cout<<"No"<< endl;
    
    if (x <= (w - r) && x >= r && y >= r && y <= (h - r)) {
        cout <<"Yes"<< endl;
    }

    else{cout<<"No"<< endl;}

    return 0;
}


Measured memory_bytes: 3116
# -*- coding: utf-8 -*-
"""
C - Coloring Colorfully
https://atcoder.jp/contests/abc124/tasks/abc124_c

"""
import sys


from itertools import cycle

def solve(S):
    c1 = cycle('10')
    ans1 = 0
    for s in S:
        if s != next(c1):
            ans1 += 1

    c2 = cycle('01')
    ans2 = 0
    for s in S:
        if s != next(c2):
            ans2 += 1
    return min(ans1, ans2)


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if ((s[2]==s[3])&&(s[4]==s[5]))
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>

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

using namespace std;

int main(int argc, char* argv[]){
  long long int N, M;
  cin >> N >> M;
  vector<long long int> H(N+1);
  rep(i, N){
    cin >> H[i+1];
  }

  vector<int> isGood(N+1, 1);
  rep(i, M){
    long long int a,b;
    cin >> a >> b;
    if(H[a] < H[b]){
      isGood[a] = 0;
    } else if(H[a] > H[b]){
      isGood[b] = 0;
    } else {
      isGood[a] = 0;
      isGood[b] = 0;
    }
  }

  long long int ans = 0;
  rep(i, N){
    if(isGood[i+1] == 1) ans++;
  }
  
  cout << ans << endl;

  return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    ll a,b, ans = 0; cin >> a >> b;

    if(abs(a-b)+1==2) {
        cout << (a^b) << '\n';
        return 0;
    }

    ll vanish_1st, vanish_last;
    if(a%2==0) {
        vanish_1st = a;
    }
    else {
        vanish_1st = a+1;
        ans ^= a;
    }

    if(b%2==1) {
        vanish_last = b;
    }
    else {
        vanish_last = b-1;
        ans ^= b;
    }

    ll vanish_range = vanish_last - vanish_1st + 1;
    if(vanish_range/2%2==1) ans ^= 1;

    cout << ans << '\n';
//    debug(vanish_1st);
//    debug(vanish_last);
//    debug(vanish_range);

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 256
def iread():
    return int(input())


def sread():
    return input()


def aread_int():
    tmp = input().split()
    ret = [int(i) for i in tmp]
    return ret


def aread_str():
    return input().split()


def check(arg):
    if arg == '#':
        return 1
    else:
        return 0

def format_print(matrix, colum, row):
    for i in range(colum):
        for j in range(row):
            print(matrix[i][j], end="")
        print("")

if __name__ == '__main__':
    h, w = map(int, input().split())
    matrix = []
    ans = []
    for _ in range(h):
        ans.append([0] * w)
        
    for _ in range(h):
        matrix.append(list(input()))

    for i in range(h):
        for j in range(w):
            if check(matrix[i][j]) > 0:
                ans[i][j] = '#'
            else:
                cnt = 0
                if i > 0 and i < h - 1:
                    cnt += check(matrix[i - 1][j])
                    cnt += check(matrix[i + 1][j])
                    if j > 0:
                        cnt += check(matrix[i - 1][j - 1])
                        cnt += check(matrix[i][j - 1])
                        cnt += check(matrix[i + 1][j - 1])
                    if j < w - 1:
                        cnt += check(matrix[i - 1][j + 1])
                        cnt += check(matrix[i][j + 1])
                        cnt += check(matrix[i + 1][j + 1])
                elif i > 0:
                    cnt += check(matrix[i - 1][j])
                    if j > 0:
                        cnt += check(matrix[i - 1][j - 1])
                        cnt += check(matrix[i][j - 1])
                    if j < w - 1:
                        cnt += check(matrix[i - 1][j + 1])
                        cnt += check(matrix[i][j + 1])
                elif i < h - 1:
                    cnt += check(matrix[i + 1][j])
                    if j > 0:
                        cnt += check(matrix[i][j - 1])
                        cnt += check(matrix[i + 1][j - 1])
                    if j < w - 1:
                        cnt += check(matrix[i][j + 1])
                        cnt += check(matrix[i + 1][j + 1])
                else:
                    if j > 0:
                        cnt += check(matrix[i][j - 1])
                    if j < w - 1:
                        cnt += check(matrix[i][j + 1])

                ans[i][j] = cnt
    format_print(ans, h, w)

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

int main(int argc, char *argv[]){
  int n, m;
  cin >> n;
  vector<int> s(n), l(n), p(n);
  vector<vector<int> > dp(n + 1, vector<int>(394, -1));
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> l[i] >> p[i];
  }
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 394; j++) {
      for (int k = s[i]; k <= l[i]; k++) {
        if(j < k){
          dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);        
        }else{
          if(dp[i + 1][j - k] == -1 &&
             dp[i][j] == -1)continue;
          dp[i + 1][j] = max(dp[i + 1][j],
                             max(dp[i][j],
                                 dp[i + 1][j - k] + p[i]));
        }
      }
    }
  }
  cin >> m;
  int query;
  vector<int> ans;
  for (int i = 0; i < m; i++) {
    cin >> query;
    ans.push_back(dp[n][query]);
    if(ans.back() == -1){
      std::cout << -1 << std::endl;
      return 0;
    }
  }
  for (int i: ans) {
    std::cout << i << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//高橋君の体力
		int A = sc.nextInt();
		//高橋君の攻撃力
		int B = sc.nextInt();
		//青木君の体力
		int C = sc.nextInt();
		//青木君の攻撃力
		int D = sc.nextInt();

		while(true) {
		if(B >= C ) {
			//
			System.out.println("Yes");
			break;
		}
		C = C - B;
		if(A <= D) {
		System.out.println("No");
		break;
	}
		A = A-D;
		}
		sc.close();
	}

}


Measured memory_bytes: 35664
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  string w;
  cin >> w;
  ll cnt[28]={};
  for(auto c:w){
    cnt[c-'a']++;
  }
  for(int i=0;i<28;i++){
    if(cnt[i]%2!=0){
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<complex>
#include<vector>
#include<iomanip>

using namespace std;

typedef complex<double> P;

#define EPS 1e-9
#define shosu(x) fixed<<setprecision(x)

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
  L(){;}
};
struct C{
  P c;double r;
  C(const P &c,double r):c(c),r(r){}
};

namespace std{//演算子の定義
  bool operator < (const P& a,const P& b){
    return real(a)!= real(b) ? real(a) < real(b) : imag(a) < imag(b);
    //return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b)
  }
  bool operator == (const P& a,const P& b){
    return a.real()==b.real() && a.imag()==b.imag();
  }
}

double dot(P a,P b){
  return real(conj(a)*b);
}

double cross(P a,P b){
  return imag(conj(a)*b);
}

int ccw(P a, P b, P c) {//3点の関係性
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;                               // a--c--b on line
}

P projection(L l, P p){//pの直線l上の射影の点
  double t=dot(p-l[0],l[0]-l[1])/norm(l[0]-l[1]);
  return l[0]+t*(l[0]-l[1]);
}

P reflection(L l, P p){//点pの直線lに関して対称な点
  return p+2.0*(projection(l,p)-p);
}

bool isOrthogonal(L l, L m){//2直線の直交判定
  return fabs(dot(l[1]-l[0], m[1]-m[0])) < EPS;
}

bool isParallel(L l, L m){//2直線の平行判定
  return fabs(cross(l[1]-l[0],m[1]-m[0])) < EPS;
}

bool intersectLL(L l, L m){//2直線の交差判定
  return !isParallel(l,m);
}

bool intersectSS(const L &s, const L &t) { //2線分の交差判定(完全に交差してないとだめ)
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
P crosspointSS(L a,L b){ //2線分の交点
double t1=abs(cross(a[1]-a[0],b[0]-a[0]));
double t2=abs(cross(a[1]-a[0],b[1]-a[0]));
return b[0]+(b[1]-b[0])*t1/(t1+t2);
}

P inP(){
  double x,y;
  cin >> x >> y;
  P p(x,y);
  return p;
}

L inL(){
  P p1=inP();
  P p2=inP();
  L l(p1,p2);
  return l;
}

int main(){

  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    L l1,l2;
    l1=inL();
    l2=inL();

    P ans=crosspointSS(l1,l2);
    cout << shosu(10) << ans.real() << " " << ans.imag() << endl;
  }

}



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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
int32_t LCM(int32_t a, int32_t b){return a * b / GCD(a, b);}
int64_t LCM(int64_t a, int64_t b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7; //10^9
constexpr int64_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/



//for dfs, I prepare container(tree) at global
vector<int> to[200005];
vector<int> ans;
void dfs(int v, int p = -1){
	for(int u: to[v]){
		if(u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}

//#define int int64_t
signed main()
{
	int n, q; cin >> n >> q;
	for(int i = 0, i_len = (int)n-1; i < i_len; ++i){
		int a, b;
		cin >> a >> b;
		--a;--b;
		to[a].emplace_back(b);
		to[b].emplace_back(a);		
	}
	ans.resize(n);
	for(int i = 0, i_len = (int)q; i < i_len; ++i){
		int p, x;
		cin >> p >> x;
		--p;
		ans[p] += x;
	}
	dfs(0);

	for(int i = 0, i_len = (int)n; i < i_len; ++i){
		cout << ans[i] << endl;
	}

}

Measured memory_bytes: 23552
#include <iostream>
#include <string>
#include <string.h>
using namespace std;
int main(int argc, char* argv[])
{
	string sT;
	cin>>sT;
	int n=sT.length();
	char *sA = new char[n+1];
	memset(sA,'g',n);
	sA[n]='\0';
	int pMax = n/2;
	int pN=0;
	int i=0;
	for (i=0;i<n;i++){
		if (sT[i]=='g'){
			if (pN<pMax){
				sA[i]='p';
				pN++;
			}else{
				break;
			}
		}
	}
	int sAN=0;
	for (i=0;i<n;i++){
		if (sA[i]=='p' && sT[i]=='p'){
		}
		if (sA[i]=='g' && sT[i]=='g'){
		}
		if (sA[i]=='p' && sT[i]=='g'){
			sAN++;
		}
		if (sA[i]=='g' && sT[i]=='p'){
			sAN--;
		}
	}
	cout<<sAN<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,m;
  while(1){
    cin>>n>>m;
    if(n==0 && m==0)break;
    vector<bool> v(n,false);
    pair< int,pii > p[200000];
    rep(i,m){
      cin>>p[i].first>>p[i].second.first>>p[i].second.second;
      p[i].second.first--;
      p[i].second.second--;
    }
    sort(p,p+m);
    v[0]=true;
    rep(i,m)
      if(v[p[i].second.first])v[p[i].second.second]=true;
    int ans=0;
    rep(i,n)if(v[i])ans++;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 5432
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
#include <algorithm>
using namespace std;
int main(void){
    string S; cin >> S;
    int i = 0;
    int a, b; a = 0; b = 0;
    while (i < S.size()) {
        if (i % 2 == 0) {
            if (S[i] == '0') {
                a++;
            }
        } else {
            if (S[i] == '1') {
                a++;
            }
        }
        i++;
    }
    i = 0;
    while (i < S.size()) {
        if (i % 2 == 0) {
            if (S[i] == '1') {
                b++;
            }
        } else {
            if (S[i] == '0') {
                b++;
            }
        }
        i++;
    }
    cout << min(a,b) << endl;
}


Measured memory_bytes: 3752
/*
 * dessert_witch.cpp
 *
 *  Created on: 2017/02/21
 *      Author: Nishio
 */
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
#define ck(n,a,b) (a<=(n)&&(n)<b)
#define F first
#define S second
using namespace std;


int main(){
	char field[8][8];
	int dx[8]={1,1,1,0,0,-1,-1,-1};
	int dy[8]={1,0,-1,1,-1,1,0,-1};
	bool d=1,flag1=1,flag2=1;
	pair<int,pair<int,int>> cnt,mx;//value,(x,y)
	mx.F=0;
	map<bool,char> m;
	int i,j,lx=7,ly=7,rx=0,ry=0;
	m[true]='o';
	m[false]='x';
	REP(l,0,8)	{
		REP(n,0,8){
			cin>>field[l][n];
			if(field[l][n]!='.'){
				lx=min(lx,n-1);
				rx=max(rx,n+1);
				ly=min(ly,l-1);
				ry=max(ry,l+1);
			}
		}
	}
	lx=max(lx,0);
	rx=min(rx,7);
	ly=max(ly,0);
	ry=min(ry,7);
	while(flag2){
		mx.F=0;
		vector<pair<int,int>> vt;
		REP(l,ly,ry+1){
			if(d) i=l;
			else i=ry-l+ly;
			REP(n,lx,rx+1){
				if(d) j=n;
				else j=rx-n+lx;
				if(field[i][j]!='.') continue;
				vector<pair<int,int>> change;
				cnt.F=0;
				cnt.S={j,i};
				REP(k,0,8){//8houi
					int nx=j+dx[k],ny=i+dy[k];
					if(!ck(nx,0,8)||!ck(ny,0,8)||field[ny][nx]!=m[!d]) continue;
					int tmp=0;
					vector<pair<int,int>> tmpch;
					while(field[ny][nx]!=m[d]){
						if(field[ny][nx]==m[!d]){
							tmp++;
							tmpch.push_back({nx,ny});
							nx+=dx[k]; ny+=dy[k];
						}
						if(!ck(nx,0,8)||!ck(ny,0,8)||field[ny][nx]=='.'){
							tmp=0;
							tmpch.clear();
							break;
						}

					}
					cnt.F+=tmp;
					REP(ii,0,(int)tmpch.size()) change.push_back(tmpch[ii]);
				}
				if(mx.F<cnt.F){
					mx=cnt;
					vt=change;
				}
			}
		}
		if(vt.size()!=0){
			field[mx.S.S][mx.S.F]=m[d];
			flag1=true;
			lx=min(lx,mx.S.F-1);
			rx=max(rx,mx.S.F+1);
			ly=min(ly,mx.S.S-1);
			ry=max(ry,mx.S.S+1);
			lx=max(lx,0);
			rx=min(rx,7);
			ly=max(ly,0);
			ry=min(ry,7);

		}else{
			if(!flag1) flag2=false;
			else flag1=false;
		}
		REP(l,0,(int)vt.size()){
			field[vt[l].S][vt[l].F]=m[d];
		}
		d=!d;
	}
	REP(l,0,8){
		REP(n,0,8){
			cout<<field[l][n];
		}
		p("");
	}
	return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main()
{
    FASTIO;
    int k=0; cin  >> k;
    ull ans = 0;
    for(int i=1; i<=k; i++){
        for(int j=i;j<=k; j++){
            for(int m=j; m<=k; m++){
                int a = __gcd(i,j);
                a = __gcd(a, m);
                if(i==j && i==m) ans += a;
                else if((i==j && j!=m)||(i==m&& j!=m)||(m==j&& i!=m)) ans += (a*3);
                else if(i!=j && i!=m && j!=m) ans += (a*6);
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
const ll MOD = 1e9 + 7;

const int MAX = 200001;

// fac[n]: n!
// finv[n]: (n!)^-1
// inv[n]: nの逆元
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void comb_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算 (combination)
// nCk = (n!) * (k!)^-1 * ((n-k)!)^-1 として計算
ll comb(int n, int k) {
  if (n < k) {
    return 0;
  }
  if (n < 0 || k < 0) {
    return 0;
  }
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 重複組み合わせを求める
ll nHr(ll n, ll r) { return comb(n + r - 1, r); }

ll N, K;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  comb_init();

  ll blue = K;
  ll red = N - K;

  for (ll i = 1; i <= blue; i++) {
    if (i > red + 1) {
      cout << 0 << endl;
      continue;
    }

    if (i == 1) {
      ll ans = comb(red + 1, i);
      cout << ans % MOD << endl;
    } else {
      ll ans = comb(red + 1, i) * comb(blue - 1, blue - i);
      cout << ans % MOD << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4992
import { readFileSync } from 'fs'

function main(input: string) {
  const [[N, M, C], BList, ...line] = input.split('\n').map(v => v.split(' ').map(Number))

  const sucsessList = line.filter(AList => {
    const total = AList
      .map((A, index) => {
        const B = BList[index]
        return A * B
      })
      .reduce((sum, v) => sum + v, 0)

    return total > -C
  })

  console.log(sucsessList.length)
}

main(readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 11596
n=int(input())
def is_prime(a):
    if a == 1:
        return False
    for i in range(2,int(a**(0.5)+1)):
        if a % i == 0:
            return False
    return True

for i in range(n,10**7):
    if is_prime(i) == True:
        print(i)
        exit()


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

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 1e9+7;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)


ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

int main() {
    int n,x = 0;
    cin >> n;
    vector<int> a(n+1,0);
    vector<ll> dp0(1<<20,0),dp1(1<<20,0),cnt(1<<20,0);
    for (int i = 1;i < n+1;++i) {
        scanf("%d",&a[i]);
        a[i] ^= a[i-1];
        dp0[a[i]] = 1;
    }
    for (int i = 1;i < n+1;++i) {
        if (a[i]) {
            (dp0[a[i]] += dp1[a[i]]*(x-cnt[a[i]])%mod) %= mod;
            (dp1[a[i]] += dp0[a[i]]) %= mod;
            cnt[a[i]] = x;
        } else x++;
    }
    if (a[n]) cout << dp0[a[n]] << endl;
    else {
        int ans = 0;
        for (int i = 1;i < (1<<20);++i) (ans += dp1[i]) %= mod;
        (ans += pow_mod(2,x-1)) %= mod;
        cout << ans << endl;
    }
    return 0;
}

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

int r , c , n ;

int side(int x , int y)
{
    if(x==0) return 1 ;
    else if(y==c) return 2 ;
    else if(x==r) return 3 ;
    else if(y==0) return 4 ;
    else return 0 ;
}

int main()
{
    scanf("%d%d%d",&r,&c,&n) ;
    vector<pair<pair<int,int>,int> > v[5] ;
    for(int i = 1 ; i <= n ; ++i)
    {
        int x1 , y1 , x2 , y2 ;
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2) ;
        if(side(x1,y1)!=0 && side(x2,y2)!=0)
        {
            v[side(x1,y1)].push_back({{x1,y1},i}) , v[side(x2,y2)].push_back({{x2,y2},i}) ;
        }
    }
    stack<int> s ;
    for(int i = 1 ; i <= 4 ; ++i)
    {
        sort(v[i].begin(),v[i].end()) ;
        if(i>2) reverse(v[i].begin(),v[i].end()) ;
        for(auto t : v[i])
        {
            if(s.empty()) s.push(t.second) ;
            else if(s.top()==t.second) s.pop() ;
            else s.push(t.second) ;
        }
    }
    if(s.empty()) puts("YES") ;
    else puts("NO") ;
    return 0 ;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
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;
}
int main() {
  cout << fixed << setprecision(10);
  int n,m,k;
  cin >> n >> m >> k;
  vector<int> a(n),b(m);
  rep(i,n){
    cin >> a[i];
  }
  rep(i,m){
    cin >> b[i];
  }
  vector<ll> c(n+1,0);
  vector<ll> d(m+1,0);
  rep(i,n){
    c[i+1]=c[i]+a[i];

  }
  rep(i,m){
  	d[i+1]=d[i]+b[i];
  }
  int ans = 0;
  for(int i=0; i<=n; i++){
    if(c[i]>k){
      continue;
    }else{
      int p=k-c[i];
      //cout << p << endl;
      int ok,ng;
      ok=0;
      ng = m+1;
      while(ng-ok>1){
        int mid=(ng+ok)/2;
        if(d[mid]<=p){
          ok=mid;
        }else{
            ng=mid;
        }

      }
      //cout << ok << endl;
      chmax(ans,i+ok);
    }
  }
    cout << ans << endl;

}



Measured memory_bytes: 7828
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mx = 3000;
double dp[mx][mx],coin[mx];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>coin[i];
    dp[0][0] =1.0;
    for(int i=1;i<=n;i++)
        for(int j=0;j<=i;j++)
    {
        if(j==0)
            dp[i][j] = dp[i-1][j]*(1.0-coin[i]);
        else
            dp[i][j] = (dp[i-1][j-1]*coin[i] + dp[i-1][j]*(1.0-coin[i]));
    }
    double ans =0;
    for(int i=(n+1)/2;i<=n;i++)
        ans+= dp[n][i];
    cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}



Measured memory_bytes: 68992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] B = new int[n-1];
		int ans = 0;
		for(int i = 0; i< n-1; i++) {
			B[i] = sc.nextInt();
		}
		switch(n){
		case 2:
			System.out.println(B[0]*2);
			break;
		default:
			ans = B[0] + B[n-2];
			for(int i = 1; i<=n-2;i++) {
				ans+= Math.min(B[i-1], B[i]);
			}
			System.out.println(ans);
		}
}
}


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

#ifdef HELTHAZAR
#define dout if (true) cout
#else
#define dout if (false) cout
#endif

#define rep(i, from, to) for (ll i = from; i < ll(to); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define pb push_back
#define fi first
#define se second

typedef int ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<vector<ll> > vvi;

void solve() {
	string s;
	cin >> s;

	int maxsum = 0;
	trav(c, s)
		maxsum += c - '0';

	int len = sz(s), cursum = 0;
	rep(i, 0, len) {
		if (s[i] != '0')
			maxsum = max(maxsum, ((int) cursum + s[i] - '0' - 1 + (len - 1 - i) * 9));
		cursum += s[i] - '0';
	}

	cout << maxsum;
}

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

	solve();
}


Measured memory_bytes: 256
# agc014_a.py]
A, B, C = map(int,input().split())
cnt = 0
inf = 10**6
for i in range(inf):
    if A%2==0 and B%2==0 and C%2==0: 
        a = (B+C)//2
        b = (A+C)//2
        c = (B+A)//2
        A = a
        B = b
        C = c
        cnt += 1
    else:
        break
if cnt == inf:
    cnt = -1
print(cnt)

Measured memory_bytes: 3064
import collections

N = int(input())

S_list = []

for i in range(N):
    tmp = str(input())
    S_list.append(tmp)

c = collections.Counter(S_list)

appear = max(list(c.values()))

keys = [k for k, v in c.items() if v == appear]

keys_sorted = sorted(keys)

for i in range(len(keys)):
    print(keys_sorted[i])


Measured memory_bytes: 35564
N, K = map(int, input().split())
 
count1 = 0
count2 = 0
for a in range(1,N+1):
    if a%K == 0:
        count1 += 1
if K%2 == 0:
    for a in range(1,N+1):
        if a%K == K//2:
            count2 += 1
print(count1**3 + count2**3)

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

using namespace std;

#define INF 1000000000
#define pb(a) push_back(a)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x;
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;++i)
#define FORVEC(i, v) for(int i = 0;i < sz(v);++i)


int main(){
    int a,b,c;
    int k;
    cin>>a>>b>>c>>k;
    int m=max(a,max(b,c));
    cout<<(a+b+c-m+(m<<k))<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{

    class Program
    {

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            long K = long.Parse(input[1]);

            Dictionary<int, long> dic = new Dictionary<int, long>();          

            for (int i = 0; i < N; i++)
            {
                input = Console.ReadLine().Split(' ');
                int a = int.Parse(input[0]);
                long b = long.Parse(input[1]);

                if (!dic.ContainsKey(a))
                {
                    dic[a] = b;
                }
                else
                {
                    dic[a] += b;
                }

            }

            var dic_sort = dic.OrderBy(x => x.Key);

            long cnt = 0;
            int ans = -1;

            foreach (var s in dic_sort)
            {

                int val = s.Key;
                long num = s.Value;

                if (cnt + num < K)
                {
                    cnt += num;
                }
                else
                {
                    ans = val;
                    break;
                }

            }

            Console.WriteLine(ans);

        }
    }
}

Measured memory_bytes: 20552
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int INF = 1e9;
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> A(M), S(M);
    rep(i, 0, M) {
        int b;
        cin >> A[i] >> b;
        rep(j, 0, b) {
            int c; cin >> c;
            S[i] |= (1 << (c - 1));
        }
    }
    vector<int> dp(1 << N, INF);
    dp[0] = 0;
    rep(mask, 0, 1 << N) rep(i, 0, M) {
        if(dp[mask] == INF) continue;
        chmin(dp[mask | S[i]], dp[mask] + A[i]);
    }
    int ans = dp[(1 << N) - 1];
    if(ans == INF) ans = -1;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<set>
using namespace std;
string reverse(string source)
{
	string dict = "";
	for (signed int i = 0; i < source.size(); i++)
	{
		dict += source[source.size() - 1 - i];
	}

	return dict;
}
int main()
{
	char ch[73];
	int n;
	cin >> n;

	for (signed int i = 0; i < n; i++)
	{
		cin >> ch;
		string str = ch;
		set<string> Set;
		for (int j = 0; j < str.size() - 1; j++)
		{
			string s1 = str.substr(0,j+1);
			string s2 = str.substr(j + 1, str.size());
			Set.insert(s1+s2);
			Set.insert(s2+s1);
			if (s1.size() >= 2)
			{
				Set.insert(reverse(s1)+s2);
				Set.insert(s2 + reverse(s1));
			}

			if (s2.size() >= 2)
			{
				Set.insert(s1 + reverse(s2));
				Set.insert(reverse(s2) + s1);
			}
			if (s1.size() >= 2 && s2.size() >= 2)
			{
				Set.insert(reverse(s2) + reverse(s1));
				Set.insert(reverse(s1) + reverse(s2));
			}
		}

		std::cout << Set.size() << endl;

	}
	return 0;
}

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

int data[10][10];

int small_x[5] = {0,-1,0,1,0};
int small_y[5] = {0,1,1,1,2};

void printSmall(int sx,int sy){
  cout << sx << ' ' << sy+1 << ' ' << 1 << endl;
}

int normal_x[9] = {0,1,2,0,1,2,0,1,2};
int normal_y[9] = {0,0,0,1,1,1,2,2,2};

void printNormal(int sx,int sy){
  cout << sx + 1 << ' ' << sy + 1 << ' ' << 2 << endl;
}

int big_x[13] = {0,-1,0,1,-2,-1,0,1,2,-1,0,1,0};
int big_y[13] = {0,1,1,1,2,2,2,2,2,3,3,3,4};

void printBig(int sx,int sy){
  cout << sx << ' ' << sy+2 << ' ' << 3 << endl;
}

bool check(int x,int y){
  if(!(0 <= x && x < 10))return false;
  if(!(0 <= y && y < 10))return false;
  return true;
}

bool isRemove(int x,int y,int ax[],int ay[],int len){
  for(int i = 0 ; i < len ; i++){
    int nx,ny;
    nx = x + ax[i];
    ny = y + ay[i];
    if(!check(nx,ny))return false;
    if(data[ny][nx] == 0)return false;
  }
  return true;
}

void remove(int x,int y,int ax[],int ay[],int len){
  for(int i = 0 ; i < len ; i++){
    int nx,ny;
    nx = x + ax[i];
    ny = y + ay[i];
    data[ny][nx]--;
  }
}

void draw(int x,int y,int ax[],int ay[],int len){
  for(int i = 0 ; i < len ; i++){
    int nx,ny;
    nx = x + ax[i];
    ny = y + ay[i];
    data[ny][nx]++;
  }
}

void display(){
  cout << "display" << endl;
  for(int i = 0 ; i < 10 ; i++){
    for(int j = 0 ; j < 10 ; j++){
      cout << data[i][j] << ' ';
    }
    cout << endl;
  }
}

bool dfs(int d,int x,int y,int rem){

  //cout << "d = " << d << " x = " << x << " y = " << y << " rem = " << rem << endl;//
  //display();

  if(d == 0 && rem == 0)return true;
  if(d == 0 && rem > 0)return false;

  if(data[y][x]){
    int rx,ry;
    if(isRemove(x,y,small_x,small_y,5)){
      remove(x,y,small_x,small_y,5);
      if(dfs(d-1,x,y,rem-5)){
	printSmall(x,y);
	return true;
      }
      draw(x,y,small_x,small_y,5);
    }

    if(isRemove(x,y,normal_x,normal_y,9)){
      remove(x,y,normal_x,normal_y,9);
      if(dfs(d-1,x,y,rem-9)){
	printNormal(x,y);
	return true;
      }
      draw(x,y,normal_x,normal_y,9);
    }
    
    if(isRemove(x,y,big_x,big_y,13)){
      remove(x,y,big_x,big_y,13);
      if(dfs(d-1,x,y,rem-13)){
	printBig(x,y);
	return true;
      }
      draw(x,y,big_x,big_y,13);
    }

    //cout << "?" << endl;
    return false;
  }

  bool f = false;
  for(int i = 0 ; i < 10 ; i++){
    for(int j = 0 ; j < 10 ; j++){
      if(!f){
	i = y;
	j = x+1;
	f = true;
	if(j >= 10)continue;
      }
      if(data[i][j])return dfs(d,j,i,rem);
    }
  }
  return false;
}

int main(){

  /*
  for(int i = 0 ; i < 10 ; i++){
    for(int j = 0 ; j < 10 ; j++){
      data[i][j] = 0;
    }
  }

  draw(5,5,big_x,big_y,13);
  display();

  return 0;
  */

  int d;
  cin >> d;
  int rem = 0;
  for(int i = 0 ; i < 10 ; i++){
    for(int j = 0 ; j < 10 ; j++){
      cin >> data[i][j];
      rem += data[i][j];
    }
  }
  dfs(d,0,0,rem);
  return 0;
}

Measured memory_bytes: 1164
//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define ve vector<int>
#define FOR(n)          for(int i=0; i<(int)(n); ++i)
#define TEST_CASE(t)    for(int z=1;z<=t;z++)
#define PRINT_CASE      printf("Case %d: ",z)
#define pb push_back
#define mod 1000000007
int arr[1000000];
int main()
{
  char str[1000];
  scanf("%s",str);
  int len=strlen(str);
  if(str[len-1]!= 's')
  {
      printf("%s",str);
      printf("s\n");
  }
  else
  {
            printf("%s",str);
      printf("es\n");

  }
}

Measured memory_bytes: 3700
#include<iostream>
using namespace std;
int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int e,y;
    cin>>e>>y;

    if(e==0){
        if(1868<=y&&y<=1911){
            cout<<'M'<<y-1868+1<<"\n";
        }

        if(1912<=y&&y<=1925){
            cout<<'T'<<y-1912+1<<"\n";
        }

        if(1926<=y&&y<=1988){
            cout<<'S'<<y-1926+1<<"\n";
        }

        if(1989<=y&&y<=2016){
            cout<<'H'<<y-1989+1<<"\n";
        }
    }

    if(e==1){
        cout<<1868+y-1<<"\n";
    }

    if(e==2){
        cout<<1912+y-1<<"\n";
    }

    if(e==3){
        cout<<1926+y-1<<"\n";
    }

    if(e==4){
        cout<<1989+y-1<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2;
    ll x3 = y1-y2+x2;
    ll y3 = x2-x1+y2;
    //cout << y3 << endl;
    ll x4 = x3+x1-x2;
    ll y4 = y3+y1-y2;
    printf("%lld %lld %lld %lld\n",x3,y3,x4,y4);
}

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

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    string ans =  "Yes";
    int count = 0;
    while (a >= b) {
        b *= 2;
        count++;
    }
    while (b >= c) {
        c *= 2;
        count++;
    }
    if (k < count) ans = "No";
    cout << ans << endl;

}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int sr, sc;
    cin >> sr >> sc;
    --sr; --sc;
    string s, t;
    cin >> s >> t;

    int l = 0, r = w, u = 0, d = h;
    if (s[n-1] == 'L') ++l;
    else if (s[n-1] == 'R') --r;
    else if (s[n-1] == 'U') ++u;
    else if (s[n-1] == 'D') --d;

    for (int i = n-2; i >= 0; --i) {
        if (t[i] == 'L') r = min(r+1, w);
        else if (t[i] == 'R') l = max(l-1, 0);
        else if (t[i] == 'U') d = min(d+1, h);
        else if (t[i] == 'D') u = max(u-1, 0);

        if (s[i] == 'L') ++l;
        else if (s[i] == 'R') --r;
        else if (s[i] == 'U') ++u;
        else if (s[i] == 'D') --d;
        if (l >= r || u >= d) {
            cout << "NO" << endl;
            return 0;
        }
    }

    if (sr >= u && sr < d && sc >= l && sc < r) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <bitset>

using namespace std;

#define rg register int

const int N = 2005;

inline bool getc()
{
    char c = getchar();
    while(!isdigit(c))c = getchar();
    return c == '1';
}

bitset<N> f[N], g[N], a[N];

int n;

int main()
{
    scanf("%d", &n);
    for (rg i = 2; i <= n; i++)
        for (rg j = 1; j < i; j++)
            a[i][j] = getc(), a[j][i] = !a[i][j];
  //  for (rg i = 1; i <= n; i++, putchar(10))
  //      for (rg j = 1; j <= n; j++)
 //           cerr << a[i][j] << " ";
    for (rg i = 1; i <= n; i++)
        f[i][i] = g[i][i] = 1;
    for (rg len = 2; len <= n; len++)
        for (rg l = 1;  l + len - 1 <= n; l++) 
        {
            int r = l + len - 1;
            if((g[l] & f[r - 1] & a[r]).any())
                g[l][r] = 1;
            if((g[l + 1] & f[r] & a[l]).any())
                f[r][l] = 1;
        }
    printf("%d\n", (g[1] & f[n]).count());
}

Measured memory_bytes: 1792
n,c,k=map(int,input().split())
t=[0]*n
for i in range(n):
  t[i]=int(input())
t=sorted(t)

ans=1
cnt=0
time=t[0]+k

for i in range(n):
  if cnt==c or time<t[i]:
    cnt=1
    ans+=1
    time=t[i]+k
  else:
    cnt+=1
    
print(ans)

Measured memory_bytes: 8240
#include <bits/stdc++.h>
using namespace std;
#define rip(a,b,c) for(int (a)=(c);(a)<(b);(a)++)
const long long INF= 1LL << 60;
int main(){
    //入力始まり
    long long  N,A,B;
    cin >> N >> A >> B;
    //入力終わり

    long long blue_ball=0LL;
    long long num=N/(A+B);
    long long remainder=N%(A+B);
    if(remainder<=A){
        blue_ball+=remainder;
    }else{
        blue_ball+=A;
    }
    blue_ball+=num*A;
    cout << blue_ball << endl;
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long x, a, b;
  cin >> x >> a >> b;
  long A = abs(x-a);
  long B = abs(x-b);
  if (A < B) puts("A");
  else puts("B");
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

size_t query(const std::string &str, size_t k) {
    size_t d = 0;
    size_t m = 0;
    size_t dm = 0;
    size_t dmc = 0;

    for (size_t i = 0; i < str.size(); i++) {
        if (i >= k) {
            if (str[i-k] == 'D') {
                d--;
                dm -= m;
            } else if (str[i-k] == 'M') {
                m--;
            }
        }
        if (str[i] == 'D') {
            d++;
        } else if (str[i] == 'M') {
            m++;
            dm += d;
        } else if (str[i] == 'C') {
            dmc += dm;
        }
    }

    return dmc;
}

int main()
{
    size_t n;
    std::cin >> n;
    std::string str;
    std::getline(std::cin, str); //empty
    std::getline(std::cin, str);
    size_t q;
    std::cin >> q;
    for (size_t i = 0; i < q; i++) {
        size_t k;
        std::cin >> k;
        std::cout << query(str, k) << std::endl;
    }
    return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

int n = 1e5;
const ll INF = 1e9*n;
vl dis(n, INF);
vector<vector<pii>> G(n);

void dfs(int i, ll d) {
  if (dis[i] != INF) return;
  dis[i] = d;

  for (auto&& j : G[i]) {
    dfs(j.first, d+j.second);
  }
}

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

  int n, q, k;
  cin >> n;
  rep(i, n-1) {
    int a, b, c;
    cin >> a >> b >> c;
    G[a-1].push_back({b-1, c});
    G[b-1].push_back({a-1, c});
  }
  cin >> q >> k;

  dfs(k-1, 0);

  rep(i, q) {
    int x, y;
    cin >> x >> y;
    cout << dis[x-1] + dis[y-1] << endl;
  }
}


Measured memory_bytes: 11264