akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 998244353;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

// Range Maximum Query
class SegmentTree{
public:
    int n;
    vector<ll> node;

    SegmentTree(vector<ll> v){
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = max(node[2*i+1], node[2*i+2]);
    }

    void update(int x, ll val){
        x += (n - 1);
        node[x] = val;
        while(0 < x){
            x = (x - 1) / 2;
            node[x] = max(node[2*x+1], node[2*x+2]);
        }
    }

    ll getmax(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return node[k];

        ll vl = getmax(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getmax(a, b, 2*k+2, (l+r)/2, r);
        
        return max(vl, vr);
    }
};

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

    int n; cin>>n;
    vector<P> xd(n);
    for(int i=0; i<n; i++) cin>>xd[i].first>>xd[i].second;
    sort(xd.begin(), xd.end());

    vector<ll> x(n), d(n);
    for(int i=0; i<n; i++){
        x[i] = xd[i].first;
        d[i] = xd[i].second;
    }

    // r[i] := ロボット i を起動した際に連動して起動するロボットの最大のインデックス
    vector<int> r(n);
    SegmentTree seg(vector<ll>(n+1, 0));
    for(int i=n-1; i>=0; i--){
        int toid = lower_bound(x.begin(), x.end(), x[i] + d[i]) - x.begin();
        // 届く範囲で最大の r を求める
        r[i] = max(i, r[seg.getmax(i, toid)]);
        seg.update(i, r[i]);
    }

    vector<ll> dp(n+1, 0);
    dp[n] = 1;
    for(int i=n-1; i>=0; i--){
        // dp[i+1] := i を起動させないとき
        // dp[r[i] + 1] := i を起動させるとき、r[i] + 1 番目のロボットは連動して起動しない
        dp[i] = dp[i+1] + dp[r[i] + 1];
        dp[i] %= MOD;
    }

    cout << dp[0] << endl;

    return 0;
}

Measured memory_bytes: 11448
from collections import deque
from sys import stdin
input = stdin.readline


def main():
  H, W = list(map(int, input().split()))
  M = [input()[:-1] for _ in range(H)]

  white = 0
  black = 0
  for i in range(H):
    for j in range(W):
      if M[i][j] == '.':
        white += 1
      elif M[i][j] == '#':
        black += 1

  start = (0, 0)
  q = deque()
  q.append(start)
  is_visited = [[0]*W for _ in range(H)]
  d = [[float('inf')]*W for _ in range(H)]
  d[0][0] = 0

  while len(q):

    ur, uc = q.popleft()

    for vr, vc in [(ur, uc+1), (ur, uc-1), (ur-1, uc), (ur+1, uc)]:
      if 0 <= vr < H and \
         0 <= vc < W and \
         not(is_visited[vr][vc]) and not(M[vr][vc] == '#'):

        q.append((vr, vc))
        is_visited[vr][vc] = True
        d[vr][vc] = d[ur][uc] + 1

  if d[H-1][W-1] == float('inf'):
    print(-1)
  else:
    print(white - (d[H-1][W-1] + 1))


if(__name__ == '__main__'):
  main()

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

int main() {

    int N;
    cin >> N;
    vector<int> A(N), dp(N, INF);
    rep(i, N) cin >> A[i];

    rep(i, N) * lower_bound(dp.begin(), dp.end(), A[i]) = A[i];

    cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin() << endl;

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
#define fin {cout<<"No"<<endl;return 0;}
//template
int pw(int n,int k){
  if(k<0)return pw(n,k+MOD-1);
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
std::vector<int> Factorial(1e6),Finverse(1e6);
void Cinit(){
  Factorial[0]=1;
  for(int i=1;i<1e6;i++)Factorial[i]=Factorial[i-1]*i%MOD;
  for(int i=0;i<1e6;i++)Finverse[i]=pw(Factorial[i],MOD-2);
}
int nCk(int n,int k){
  if(n<k)return 1;if(k<0)return 0;
  int res=Factorial[n];
  res*=Finverse[k];res%=MOD;
  res*=Finverse[n-k];res%=MOD;
  return res;
}
//main
signed main(){
  int N,K;cin>>N>>K;Cinit();
  for(int i=1;i<=K;i++){
    if(N-K-(i-1)<0)cout<<0<<endl;
    else cout<<nCk(K-1,i-1)*nCk(N-K+1,i)%MOD<<endl;
  }
}


Measured memory_bytes: 16000
n = int(input())
res = 0
for i in range(1, n + 1, 2):
    counter = 0
    for j in range(1, int(i ** (1/2)) + 1):
        if i % j == 0:
            counter += 1
            if i // j != j:
                counter += 1
    if counter == 8:
        res += 1

print(res)


Measured memory_bytes: 9388
/// [Amberjack] CUT BEGIN
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define __GET_REP_MACRO(_1,_2,_3,NAME,...) NAME
#define __REP0(i,n) for(_loop_int i=0;i<(n);++i)
#define __REP1(i,a,b) for(_loop_int i=(a);i<(b);++i)
#define __REPR0(i,n) for(_loop_int i=(n)-1;i>=0;--i)
#define __REPR1(i,a,b) for(_loop_int i=(b)-1;i>=(a);--i)
#define REP(...) __GET_REP_MACRO(__VA_ARGS__,__REP1,__REP0)(__VA_ARGS__)
#define REPR(...) __GET_REP_MACRO(__VA_ARGS__,__REPR1,__REPR0)(__VA_ARGS__)

#ifdef BURI
#define __DEBUG0() "Hello"
#define __DEBUG1(x) #x"("<<(x)<<")"
#define __DEBUG2(x,...) #x"("<<(x)<<"), " __DEBUG1(__VA_ARGS__)
#define __DEBUG3(x,...) #x"("<<(x)<<"), " __DEBUG2(__VA_ARGS__)
#define __DEBUG4(x,...) #x"("<<(x)<<"), " __DEBUG3(__VA_ARGS__)
#define __DEBUG5(x,...) #x"("<<(x)<<"), " __DEBUG4(__VA_ARGS__)
#define __GET_DEBUG_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define __DEBUG(...) __GET_DEBUG_MACRO(__VA_ARGS__,__DEBUG5,__DEBUG4,__DEBUG3,__DEBUG2,__DEBUG1,__DEBUG0)(__VA_ARGS__)
#define DEBUG(...) cerr<<__DEBUG(__VA_ARGS__)<<endl
#else
#define DEBUG(...)
#endif

inline void getll(ll &x){
  int sgn=1;x=0;
  char c=getchar();
  while(c!='-'&&(c<'0'||c>'9'))c=getchar();
  if(c=='-') sgn=-1; else x=c-'0';
  c=getchar();
  while('0'<=c&&c<='9'){
    x*=10;
    x+=c-'0';
    c=getchar();
  }
  x*=sgn;
}
inline void read(ll &x){getll(x);}
inline void read(int &x){ll y;getll(y);x=y;}
inline void read(float &x){scanf("%f",&x);}
inline void read(double &x){scanf("%lf",&x);}
inline void read(long double &x){scanf("%Lf",&x);}
inline void read(char *s){scanf("%s",s);}
inline void read(string &s){int len=s.size();char *buf=(char*)malloc(len*sizeof(char));scanf("%s",buf);s=string(buf);free(buf);}
inline void read(char &c){char *buf=(char*)malloc(5*sizeof(char));scanf("%s",buf);c=buf[0];free(buf);}
inline void read(){}
template<typename S,typename ...T>
inline void read(S& first, T&... rest){
  read(first);
  read(rest...);
}
/// [/Amberjack] CUT END

int main(){
  int n,a,b;
  string s(125252,' ');
  read(n,a,b,s);
  REP(i,n){
    if(s[i]=='a'){
      if(a+b>0){
        puts("Yes");
        --a;
      }else{
        puts("No");
      }
    }else if(s[i]=='b'){
      if(a+b>0 && b>0){
        puts("Yes");
        --b;
      }else{
        puts("No");
      }
    }else{
      puts("No");
    }
  }
  return 0;
}


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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    string s;
    cin >> s;
    int size = s.size();

    vector<bool> exist(26, false);

    rep(i, size){
        exist[(int)(s[i] - 'a')] = true;
    }

    int ans = 26;

    rep(i, 26){
        if(!exist[i]){
            ans = i;
            break;
        }
    }

    if(ans == 26){
        cout << "None" << endl;
    }else{
        cout << (char)('a' + ans) << endl;
    }

    return 0;
}


Measured memory_bytes: 512
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple

/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))

#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
	return os << "(" << p.fst << "," << p.snd << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
	return a * a;
}

template <typename T>
T gcd(T a, T b) {
	if (a > b) return gcd(b, a);
	return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
	if (n == 0) return 1;
	if (n == 1) return b /* % MOD */;
	if (n % 2 == 0) {
		return mypow(b * b /* % MOD */, n / 2);
	}
	else {
		return mypow(b, n - 1) * b /* % MOD */;
	}
}

ll pcnt(ll b) {
	return __builtin_popcountll(b);
}



// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N, M;
	cin >> N >> M;
	if (N == 1) {
		N = 3;
	}
	if (M == 1) {
		M = 3;
	}
	cout << (N - 2)*(M - 2) << endl;
	return 0;
}

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

template<typename integer>
integer __lcm(integer a, integer b) {
  return (a * b) / __gcd(a, b);
}

int main() {
  int n, d, x;
  cin >> n >> d >> x;

  int step;
  vector<int> eaten_choco(d);

  rep (i, n) {
    cin >> step;
    int ai = 1;

    while (ai <= d) {
      eaten_choco[ai-1]++;
      ai += step;
    }
  }

  int sum = x;
  rep (i, d) sum += eaten_choco[i];

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



Measured memory_bytes: 256
import java.util.*;

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

	int W = sc.nextInt();
	int H = sc.nextInt();
	int x = sc.nextInt();
	int y = sc.nextInt();
	int r = sc.nextInt();
	

	if(x<W && y<H){
	  if(r<=x && r<=y){
	    System.out.println("Yes");
	  }else{
	    System.out.println("No");
	  }
	}else{
	  System.out.println("No");
	}

  }
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  string s1(n, (char) (m + '0'));
  string s2(m, (char) (n + '0'));
  cout << min(s1, s2) << '\n';
  return 0;
}


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

int main(){
  int a,b,c,d;
  int flag;
  cin>>a>>b>>c>>d;
  while(true){
    c-=b;
    if(c>0){
      ;
    }else{
      flag=1;
      	break;
    }
    a-=d;
    if(a>0){
      	;
    }else{
      flag=0;
      	break;
    }
  }
  if(flag==1){
	cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}
  

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i < (n); ++i)
#define repD(i, a, n) for(ll i = a; i > (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
// #define mp make_pair
#define pb push_back
// #define endl "\n"
#define MAXN 5000000
const long double PI = 3.141592653589793238462643383;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
int Ceil(int a, int b){
    if(a%b==0) return a/b;
    else return (a/b)+1;
}
ll p=1000000007;
float E = 0.00000000000001;
ll power(ll x, ll y){
    if(y==0){
        return 1;
    }
    if(y%2==0){
        ll q=power(x,y/2);
        q=q%p;
        return (q*q)%p;
    }
    ll q=power(x,y/2);
    q=q%p;
    return ((x%p)*((q*q)%p))%p; 
}
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}

bool isPowerOfTwo (int x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}  

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a); 
}
long long int mod(long long int a, long long int b) {
    long long int ret = a%b; return ret>=0? ret: ret+b; 
}

int powerCount(int num, int x){
    int count = 0;
    while(!(num%x)){
        count++;
        num/=x;
    }
    return count;
}

vector <int> SieveOfEratosthenes(int n) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
    vector<int> vec;
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) {
        vec.push_back(p);
          // cout << p << " ";
        } 
    return vec;
}

int main(){
    std::ios_base::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);   
    freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t = 1;
    while(t--){
    	int n,m;
    	cin>>n>>m;
    	cout<<n*m;
    }
    return 0;
}

Measured memory_bytes: 3644
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int n,num,ba,c[105],p[15];
  char s[105];
  while(scanf("%d",&n),n!=0){
    scanf("%s",s);
    num = 0;
    ba = 0;
    for(int i=0;i<n;i++) p[i] = 0;
    
    for(int i=0;s[i]!='\0';i++){
      num = i%n;
      if(s[i] == 'M'){
	p[num]++;
      }
      if(s[i] == 'S'){
	ba += p[num]+1;
	p[num] = 0;
      }
      if(s[i] == 'L'){
	p[num] += ba+1;
	ba = 0;
      }
    }
    sort(p,p+n);
    for(int i=0;i<n;i++){
      printf("%d ",p[i]);
    }
    printf("%d\n",ba);
  }
  return(0);
}



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

int main()
{
   double s[3760];
   long long x,i,j;
   cin>>x;
   s[0]=100;
   for(i=1;i<=3760;i++)
   {
       s[i]=s[i-1]*(1.01);
       j=s[i];
       if(j>=x)
       {
           cout<<i<<endl;
           break;
       }

       s[i]=j;
   }

    return 0;
}


Measured memory_bytes: 3644
l = ["" for i in range(7)]
ll = list(input())

for i in range(4):
    l[i*2] = ll[i]

flag = False
for i in range(2):
    if i==0:
        l[1] = '+'
    else:
        l[1] = '-'
    for ii in range(2):
        if ii==0:
            l[3] = '+'
        else:
            l[3] = '-'
        for iii in range(2):
            if iii==0:
                l[5] = '+'
            else:
                l[5] = '-'
            t = "".join(l)
            ans = eval(t)
            if ans==7:
                print(t+'=7')
                flag = True
                break
        if flag:
            break
    if flag:
        break

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>

using namespace std;

bool isPrime(int x){
	if(x == 2) return true;
	if(x < 2 || x % 2 == 0) return false;
	for(int i = 3; i <= sqrt(x); i = i + 2){
		if(x % i == 0) return false;
	}
	return true;
}

int main(){
	int n, count = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		if(isPrime(x)) count++;
	}
	cout << count << endl;

	return 0;
}

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

int main() {
  
  int N;
  cin >> N;
  
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++){ 
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int a = 0;
  int b = 0;
  
  for (int i = 0; i < N; i++){
    if (i % 2 == 0){
      a = a + vec.at(i);
    }
  }
  
  for (int i = 1; i < N; i++){
   if (i % 2 != 0){
     b = b + vec.at(i);
   }
  }
  
  
  cout << a - b << endl;
  
}




Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  vector<string> vec(10);
  vec[1] = ".,!? ";
  vec[2] = "abc";
  vec[3] = "def";
  vec[4] = "ghi";
  vec[5] = "jkl";
  vec[6] = "mno";
  vec[7] = "pqrs";
  vec[8] = "tuv";
  vec[9] = "wxyz";

  i64 n;
  cin >> n;
  rep(q, 0, n) {
    string s;
    cin >> s;
    i64 cnt = -1;
    string ans = "";
    rep(i,0,s.size()) {
      if(s[i] == '0') {
        if(cnt >= 0) {
          auto& v = vec[s[i - 1] + 1 - '1'];
          ans.push_back(v[cnt % v.size()]);
        }
        cnt = -1;
      }
      else {
        cnt++;
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3112
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 1003

int main() {
  int n, m;
  while(cin >> n >> m && n && m) {
    int r;
    cin >> r;
    vector<PP> pa;
    rep(i, r) {
      int t, p, q, s;
      cin >> t >> p >> q >> s;
      pa.push_back(PP(P(t, p), P(q, s)));
    }
    sort(ALL(pa));
    int q;
    cin >> q;
    rep(i, q) {
      int ts, te, q;
      int ans = 0, st = 0;
      int start, end;
      cin >> ts >> te >> q;
      rep(j, r) {
        PP &e = pa[j];
        if(e.second.first != q) {
          continue;
        }
        int ti = e.first.first;
        if(e.second.second) {
          if(!st)
            start = maxd(ti, ts);
          st += 1;
        } else {
          st -= 1;
          if(!st) {
            end = mind(ti, te);
            ans += maxd((end - start), 0);
          }
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}

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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 1e5 + 20;
const int maxm = (int) 1e6 + 20;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL MOD)
{
    if(n < 0) a = fp(a, MOD - 2, MOD), n = -n;
    LL res = 1; for(; n; n >>= 1, a = a * a % MOD) if(n & 1) res = res * a % MOD; return res;
}

string s[3];
bool ck[3][3][2222];

void check_string(int x, int y, int pos)
{
    string &head = s[x];
    string &tail = s[y];

    for(int i = pos, j = 0; i < head.size() && j < tail.size(); i++, j++)
        if(head[i] != '?' && tail[j] != '?' && head[i] != tail[j])
        {
            ck[x][y][pos] = 0;
            return ;
        }
    ck[x][y][pos] = 1;
}


void work()
{
    for(int i = 0; i < 3; i++) cin >>s[i];
    int mxlen = 0;
    for(int i = 0; i < 3; i++) mxlen = max(mxlen, (int)s[i].size());

    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++)
            if(i != j)
                for(int k = 0; k < mxlen; k++)
                    check_string(i, j, k);

    int ans = mxlen * 3;
    int t[] = {0, 1, 2};
    do
    {
        int x = t[0], y = t[1], z = t[2];
        for(int i = 0; i < s[x].size() + 1; i++)
        {
            if(i < s[x].size() && ck[x][y][i] == 0) continue;
            for(int j = 0; j < s[y].size() + 1 || i + j < s[x].size() + 1; j++)
            {
                if(i + j < s[x].size() && ck[x][z][i + j] == 0) continue;
                if(j < s[y].size() && ck[y][z][j] == 0) continue;

                ans = min(ans, max((int)s[x].size(), max(i + (int)s[y].size(), i + j + (int)s[z].size())));
            }
        }

    }while(next_permutation(t, t + 3));
    cout <<ans <<endl;
}

int main(int argc, char **argv)
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 2100100100;


int main() {
    int n,m;
    cin >> n >> m;
    vector<int> ans(n);
    int a,b;
    for (int i=0;i<m;i++){
        cin >> a >> b;
        a--;
        b--;
        ans.at(a)++;
        ans.at(b)++;
    }
    for (int i=0;i<n;i++){
        cout << ans.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define X 1000001
int ans;
int n,x;
bool p[X];
char dp[2*X];

int main(){
	p[0]=1;
	reps(i,2,X)if(!p[i])for(int j=i+i;j<X;j+=i)p[j]=1;
	for(;;){
		scanf("%d%d",&n,&x);
		if(!n)break;
		x++;
		vector<int> v(n);
		rep(i,n){
			cin >> v[i];
		}
		fill_n(dp,X,0);
		dp[0]=1;
		ans=0;
		rep(i,n){
			rep(j,x){
				if(dp[j] && j+v[i]<x){
					dp[j+v[i]]=1;
					if(!p[j+v[i]])ans = max(ans,j+v[i]);
				}
			}
		}
		if(ans)printf("%d\n",ans);
		else puts("NA");

	}
	return 0;
}

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


int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	map<int, int> mp; //連想配列
	long long ans = 0;
	for (int i = 0; i < N; i++) {
		int R = i - A[i];
		int L = i + A[i];
		mp[L]++;
		ans += mp[R];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 20756
from collections import deque

def bfs(grid, queue, wall, vis, hw):
    ans = 0
    dxy = [(1,0), (-1,0), (0,1), (0,-1)]
    while queue and vis < hw:
        cnt,y,x = queue.popleft()
        for dy, dx in dxy:
            y_,x_ = y+dy,x+dx
            if grid[y_][x_] == wall:
                continue
            queue.append([cnt+1,y_,x_])
            grid[y_][x_] = wall
            ans = max(ans, cnt+1)
            vis += 1
    return ans

H,W = map(int, input().split())
wall = '#'
queue = deque([])
edges = [wall for i in range(W+2)]
grid = [edges]
cnt = 0

for i in range(1,H+1):
    S = [wall]+list(input().strip())+[wall]
    for j in range(1,W+1):
        if S[j] == wall:
            queue.append([0,i,j])
            cnt += 1
    grid.append(S)
grid.append(edges)
print(bfs(grid, queue, wall, cnt, H*W))


Measured memory_bytes: 155224
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<string> w(n);
    for(int i=0;i<n;i++){
        cin>>w[i];
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(w[i]==w[j]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    
    for(int i=0;i<n-1;i++){
        if(w[i][w[i].length()-1]!=w[i+1][0]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    restaurants = []
    for i in range(N):
        s, p = input().split(" ")
        restaurants.append((s, -1 * int(p), i + 1))
    restaurants.sort()
    for r in restaurants:
        print(r[2])


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
# coding: utf-8

def main():
    N = int(input())
    fir, fir_i, sec, sec_i = 0, 0, 0, 0

    for i in range(N):
        tmp = int(input())
        if tmp > fir:
            sec = fir
            sec_i = fir_i
            fir = tmp
            fir_i = i
        elif tmp > sec:
            sec = tmp
            sec_i = i

    for i in range(N):
        if i != fir_i:
            print(fir)
        else:
            print(sec)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9200
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

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



// Main Code

vector<pair<double, int>> vp;
int cnt[35][N];

int main()
{
  int n, c;
  cin>>n>>c;
  rep(i, 0, n)
  {
    int a, b, z;
    cin>>a>>b>>z;
    cnt[z][a]++;
    cnt[z][b]++;
  }
  repn(i, 1, c)
  {
    int co = 0;
    double a, b;
    repn(j, 1, N)
    {
      if(cnt[i][j] == 1)
      {
        if(co == 0) a = j;
        else b = j;
        co++;
        co = co%2;
        if(co == 0)
        {
          vp.pb({a-0.5, 1});
          vp.pb({b, -1});
        }
      }
    }
  }
  sort(vp.begin(), vp.end());
  int ans = 0;
  int curr = 0;
  for(auto p: vp)
  {
    curr += p.s;
    ans = max(ans, curr);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 18032
#include <iostream>

using namespace std;

int A[21];
int B[21];
int C[21];

int main() {

  int n;
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> A[i];
  }
  for(int i = 1;i <= n;i++){
    cin >> B[i];
  }
  for(int i = 1;i < n;i++){
    cin >> C[i];
  }
  int old = -1, now, ans = 0;
  for(int i = 1;i <= n;i++){
    now = A[i];
    ans += B[now];
    if(old == now - 1){
      ans += C[old];
    }
    old = now;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3632
N = int(input())
A = [int(x) for x in input().split()]

counter = {}

for i in range(N):
    counter[i + A[i]] = 0

ans = 0
for i in range(N):
    if i - A[i] in counter:
        ans += counter[i - A[i]]
    counter[i + A[i]] += 1

print(ans)

Measured memory_bytes: 40648
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
#include <iomanip>


using namespace std;


int main() {
  int N;
  cin >> N;
  
  int W[N];
  for (int i = 0; i < N; i++) {
    cin >> W[i];
  }
  
  int sumW[N];
  sumW[0] = W[0];
  for (int i = 1; i < N; i ++) {
    sumW[i] = W[i] + sumW[i-1];
  }

  int ans = INT_MAX;
  for (int i = 0; i < N; i ++) {
    ans = min(ans, abs( (sumW[N-1]-sumW[i]) - sumW[i] ) );
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<time.h>
#include<map>
#include<queue>
#include<set>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n;
long long T,a[210000],l,r,ans;
int main(){
	scanf("%d%lld",&n,&T);
	fo(i,1,n) scanf("%lld",&a[i]);
	l=0;
	fo(i,1,n){
		if (a[i]<=r){
			r=a[i]+T;
		}
		else{
			ans+=r-l;
			l=a[i];
			r=a[i]+T; 
		}
	}
	ans+=r-l;
	printf("%lld\n",ans); 
	return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

	Scanner sc = new Scanner(System.in);

	class P {
		int id;
		int l;
		int r;
	}

	void run() {

		int n = sc.nextInt();

		P[] p = new P[n];

		for (int i = 0; i < n; i++) {
			p[i] = new P();
			p[i].l = sc.nextInt();
			p[i].r = sc.nextInt();
			p[i].id = i;
		}

		P[] p2 = Arrays.copyOf(p, p.length);

		Arrays.sort(p, (pp, pp2) -> pp.l - pp2.l);
		Arrays.sort(p2, (pp, pp2) -> pp.r - pp2.r);
		long ans = 0;

		boolean used[] = new boolean[n];
		int left = 0;
		int right = n - 1;

		greedyFromLeft: {
			int current = 0;
			long sum = 0;
			int count = 0;
			while (count < n) {

				while (used[p2[left].id]) {
					left++;
				}

				used[p2[left].id] = true;

				if (current > p2[left].r) {
					sum += (current - p2[left].r);
					current = p2[left].r;
				}
				count++;
				if (count == n) {
					break;
				}

				while (used[p[right].id]) {
					right--;
				}

				used[p[right].id] = true;
				if (current < p[right].l) {
					sum += (p[right].l - current);
					current = p[right].l;
				}

				count++;

			}
			ans = Math.max(ans, sum+Math.abs(current));
		}

		Arrays.fill(used, false);
		left = 0;
		right = n - 1;

		greedyFromRight: {
			int current = 0;
			long sum = 0;
			int count = 0;
			while (count < n) {

				while (used[p[right].id]) {
					right--;
				}

				used[p[right].id] = true;
				if (current < p[right].l) {
					sum += (p[right].l - current);
					current = p[right].l;
				}

				count++;
				if (count == n) {
					break;
				}

				while (used[p2[left].id]) {
					left++;
				}

				used[p2[left].id] = true;

				if (current > p2[left].r) {
					sum += (current - p2[left].r);
					current = p2[left].r;
				}
				count++;
			}
			ans = Math.max(ans, sum+Math.abs(current));

		}
		System.out.println(ans);

	}
}


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

typedef long long ll;
const ll N = 300005;

ll n, a, b, ans[N];

int main()
{
	scanf("%lld%lld%lld",&n,&b,&a);
	if(a*b < n || a+b > n+1) {
		puts("-1");
		return 0;
	}
	b -= (n + a - 1) / a;
	for(ll i=(n+a-1)/a;i>=1;i--) {
		ll S = a * (i-1) + 1, E = min(n, S+a-1);
		ll T = min(b, E-S);
		for(ll i=S;i<S+T;i++) {
			ans[i] = i;
		}
		for(ll i=S+T;i<=E;i++) {
			ans[i] = E - (i - (S+T));
		}
		b -= T;
	}
	for(ll i=1;i<=n;i++) {
		printf("%lld ",ans[i]);
	}
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define MOD 1000000007
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
#define tp(a, b, c) make_tuple(a, b, c)
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
//------------------変数-----------------------//
ll n;
//-------------------関数----------------------//

int main() {
  ll x, y;
  cin >> x >> y;
  ll cnt = 0;
  while (x <= y) {
    x *= 2;
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef map<int,int> MPi; typedef pair<Int,Int> Pl; typedef int8_t shor;
const int mod = 1e9+7; const Int INF=1e18+1LL;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en,h) for(int i=st; i<=en; i+=h)
#define PU push_back
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int n,k,l,a,b;

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

    cin>>n>>k>>l; UnionFind s(n),t(n);
	rep(i,k){
		cin>>a>>b; s.unite(a-1,b-1);
	}
	rep(i,l){
		cin>>a>>b; t.unite(a-1,b-1);
	}
	P o[n]; map<P,int> aho={};
	for (int i = 0; i < n; i++){
		o[i]=P(s.find(i),t.find(i));
		aho[o[i]]++;
	}
	for (int i = 0; i < n; i++)cout<<aho[o[i]]<<(i==n-1?'\n':' ');
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n';


signed main(){
	ll dp[2001];
	memset(dp, 0, sizeof(dp));
	int s;cin>>s;
	if(s<=2){
		cout<<0<<endl;
		return 0;
	}
	ll md = 1e9 + 7;
	dp[0] = 0, dp[1] = 0, dp[2] = 0;
	for(int i = 3; i <= s; i++){
		for(int j = 3; j<=s; ++j){
			if(i-j==0) dp[i]++;
			else if(i-j>0) dp[i] += dp[i-j];
			dp[i] %= md;
		}
	}
	cout<<dp[s]<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    ll N = 0;
    cin >> N;
    vector<ll> A(N,0);
    ll d = 0, q = 0, o = 0;
    for(ll i = 0; i < N; i++) {
        cin >> A.at(i);
        o += A.at(i)%2;
        d += (A.at(i)%2 == 0);
        q += (A.at(i)%4 == 0);
        d -= (A.at(i)%4 == 0);
    }
    //o += (d != 0);
    //cout << o << ':' << d << ':' << q << endl;
    if(q + 1 >= o + (d != 0)) {
        if(q == 0 && o) {
            cout << "NO" << endl;
            return 0;
        }
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }




    return 0;
}

Measured memory_bytes: 4020
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int c[3][3];
  for (int i=0; i<3; i++)
    for (int j=0; j<3; j++)
      scanf("%d", &c[i][j]);
  int b[3];
  bool judge = true;
  for (int i=0; i<3; i++)
    b[i] = c[0][i] - c[0][0];
  for (int i=0; i<3; i++) {
    for (int j=0; j<3; j++) {
      if (c[i][j] != c[i][0] + b[j]) {
        judge = false;
        break;
      }
    }
  }
  if (judge) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 128
#pragma region include
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 4e18;
void input() {}
template<typename... R> void input(int& f, R&... r) { scanf("%d", &f); input(r...); }
template<typename... R> void input(double& f, R&... r) { scanf("%lf", &f); input(r...); }
template<typename... R> void input(ll& f, R&... r) { scanf("%lld", &f); input(r...); }
template<typename... R> void input(char& f, R&... r) { scanf("%c", &f); input(r...); }
template<typename T, typename... R> void input(vector<T>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion

struct mint {
private:
    ll x;
public:
    mint(ll x = 0) :x(x%MOD) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    friend ostream& operator<<(ostream& os, const mint& n) {
        return os << n.x;
    }
};

int next(int n) {
    switch (n) {
        case 0:
            return 0;
        case 1:
            return 10;
        case 2:
            return 7;
        case 3:
            return 4;
        case 4:
            return 1;
        case 5:
            return 11;
        case 6:
            return 8;
        case 7:
            return 5;
        case 8:
            return 2;
        case 9:
            return 12;
        case 10:
            return 9;
        case 11:
            return 6;
        case 12:
            return 3;
    }
}

int main() {
    // dp[i][j]:前からi番目までで13で割ってj余るものの個数
    string s; cin >> s;
    vector<vector<mint>>  dp(s.size()+1, vector<mint>(13,0));
    dp[0][0] = 1;
    REP(i, s.size()) {
        if (s[i] != '?') {
            REP(j, 13) {
                dp[i + 1][(next(j) + (s[i] - '0')) % 13] += dp[i][j];
            }
        }
        else {
            REP(j, 13) {
                REP(k, 10) {
                    dp[i + 1][(next(j) + k) % 13] += dp[i][j];
                }
            }
        }
    }
    cout << dp[s.size()][5] << endl;
    getchar(); getchar();
}

Measured memory_bytes: 13696
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int a,b,c;
    map<int,int>mp;
    cin>>a>>b>>c;
    mp[a]++;
    mp[b]++;
    mp[c]++;
    if(mp[5]==2 && mp[7]==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 3652
n = int(input())
w = [int(i) for i in input().split()]

ans = 100000
for t in range(0,n-1):
  s1 = sum(w[0:t+1])
  s2 = sum(w[t+1:n])
  ans = min(ans, abs(s1-s2))
  
print(ans)

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

using namespace std;

int main()
{
	vector<int> dy_arr;
	
	int n;
	cin >> n;
	
	for (int i =0; i < n; i++)
	{
		int cmd;
		cin >> cmd;
		switch (cmd)
		{
			int p;			
			case 0 :
				cin >> p;
				dy_arr.push_back(p);
				break;
			case 1 :
				cin >> p;
				cout << dy_arr[p] << endl;
				break;
			case 2 :
				dy_arr.pop_back();
				break;
		}
	}
} 


Measured memory_bytes: 3876
#include <stdio.h>

int n_card(const int* hand);
int straight(int* hand);

int main(void)
{
	int hand[5],j1,j2;

	while(scanf("%d,%d,%d,%d,%d",hand,hand+1,hand+2,hand+3,hand+4)!=EOF)
	{
		j1=n_card(hand);
		j2=straight(hand);
		if(j1==1&&j2==1) puts("null");
		else if(j2==5) puts("straight");
		else{
			switch(j1){
			case 7:
				puts("four card");
				break;
			case 6:
				puts("full house");
				break;
			case 4:
				puts("three card");
				break;
			case 3:
				puts("two pair");
				break;
			case 2:
				puts("one pair");
				break;
			}
		}
	}
	return 0;
}

int n_card(const int* hand)
{
	int i,j,cnt[14];

	for(i=1;i<=13;i++){
		cnt[i]=0;
		for(j=0;j<5;j++){
			if(hand[j]==i) cnt[i]++;
		}
	}

	for(i=1;i<=13;i++){
		if(cnt[i]==4){
			return 7;
		}
		else if(cnt[i]==3){
			for(j=i+1;j<=13;j++){
				if(cnt[j]==2){
					return 6;
				}
			}
			return 4;
		}
		else if(cnt[i]==2){
			for(j=i+1;j<=13;j++){
				if(cnt[j]==2){
					return 3;
				}
				else if(cnt[j]==3){
					return 6;
				}
			}
			return 2;
		}
	}
	return 1;
}

int straight(int* hand)
{
	int i,j,t;
	for(i=0;i<5;i++){
		for(j=i+1;j<5;j++){
			if(hand[i]>hand[j]){
				t=hand[i];
				hand[i]=hand[j];
				hand[j]=t;
			}
		}
	}
	if(hand[4]-hand[3]==1&&hand[3]-hand[2]==1&&hand[2]-hand[1]==1){
		if(hand[1]-hand[0]==1||(hand[4]==13&&hand[0]==1)) return 5;
	}

	return 1;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    
    vec<int> a(N+1);
    rep(i, N) cin >> a[i+1];
    int ans = 0;
    for(int i=1;i<=N;i+=2){
        if(a[i]%2 == 1)++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <cmath>

#define LMIN 0
#define RMAX 1000
#define REPNUM 80
using namespace std;

typedef struct P
{
  double x, y;
}P;

inline double dist(P a, P b)
{
  double dx = a.x - b.x;
  double dy = a.y - b.y;
  return (dx * dx + dy * dy);
}

double f(vector<P>& p, double x, double y)
{
  double res = 0;
  for(int i = 0; i < p.size(); ++i)
  {
    res = max(res, dist((P){x, y}, p[i]));
  }
  return sqrt(res);
}

double g(vector<P>& p, double x)
{
  double l = LMIN, r = RMAX;
  for(int i = 0; i < REPNUM; ++i)
  {
    double c1 = (l * 2 + r) / 3;
    double c2 = (l + r * 2) / 3;
    if(f(p, x, c1) > f(p, x, c2))
      l = c1;
    else
      r = c2;
  }
  return f(p, x, l);
}

int main()
{
  int n;
  cin >> n;
  vector<P> p(n);
  for(int i = 0; i < n; ++i)
    cin >> p[i].x >> p[i].y;

  double l = LMIN, r = RMAX;
  for(int i = 0; i < REPNUM; ++i)
  {
    double c1 = (l * 2 + r) / 3;
    double c2 = (l + r * 2) / 3;
    if(g(p, c1) > g(p, c2))
      l = c1;
    else
      r = c2;
  }
  printf("%.10f\n", g(p, l));
  return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

int main() {
  int n, x;
  cin >> n >> x;
  vector<ll> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if (x < v[i] + v[i + 1]) {
      ll d = v[i] + v[i + 1] - x;
      ans += d;
      if (v[i + 1] < d) {  // 右側の箱の調整だけでは足らなかったら
        v[i + 1] = 0;
        v[i] -= (d - v[i + 1]);  // 左側も減らす
      } else {
        v[i + 1] -= d;  // そうじゃなかったら、普通に右側を減らす
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int n;
	char s[101];
	scanf("%d%s", &n, s);

	int cntr = 0, cntb = 0;
	REP(i, n) {
		if (s[i] == 'R')cntr++;
		else cntb++;
	}
	if (cntr > cntb)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,d,x,y,ans=0;
    cin>>n>>d;
    while(n--)
    {
        cin>>x>>y;
        if((x*x)+(y*y)<=d*d)
            ans+=1;
    }
    cout<<ans;
}


Measured memory_bytes: 3608