akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;
typedef pair<P,P> PP;
 
int main() {
  int n,t;
  while(cin >> n >> t && n) {
    PP a[n];
    for(int i=0; i<n; i++) {
      cin >> a[i].F.F >> a[i].S.F >> a[i].S.S;
      a[i].F.S=i;
    }
    for(int m=1; m<=n; m++) {
      bool f=0;
      int b[n],c[t+1],cnt=0;
      memset(b,0,sizeof(b));
      memset(c,0,sizeof(c));
      c[0]=m;
      for(int k=0; k<t; k++) {
        for(int i=0; i<n; i++) {
          if(b[i]==-1) continue;
          if(c[k]&&b[i]<=k&&k<=b[i]+a[i].S.F) {
            if(k+a[i].F.F>t) break;
            c[k]--;
            c[k+a[i].F.F]++;
            b[i]=-1;
            cnt++;
          } else if(b[i]+a[i].S.F==k) b[i]=k+a[i].S.S;
        }
        if(cnt==n) {f=1;break;}
        c[k+1]+=c[k];
      }
      if(f) {cout << m << endl;break;}
    }
  }
  return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define INF 1e9
#define MOD 1e9+7
typedef long long llong;
using namespace std;

int main(){
	string s;
	cin>>s;
	
	string t=s.substr(0,2),u=s.substr(2,2);
	int fi=stoi(t),se=stoi(u);

	if(0<fi&&fi<=12&&0<se&&se<=12){
		cout<<"AMBIGUOUS"<<endl;
	}else if((fi<=0&&se>12)||(fi>12&&se<=0)||(fi>12&&se>12)||(fi<=0&&se<=0)){
		cout<<"NA"<<endl;
	}else if(fi>12||fi<=0){
		cout<<"YYMM"<<endl;
	}else{
		cout<<"MMYY"<<endl;
	}
}

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

int n, m;
double one = 0;

int solve();

int main() {
  cin >> n >> m;
  one = (n - m) * 100.0 + 1900.0 * m;
  cout << solve() << endl;
  return 0;
}

int solve() {
  double mot = 1;
  for(int i = 0; i < m; ++i) mot *= 2.0;
  return (int)(one * mot);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char c[52][52];
int h,w;
bool check(int a,int b){
  if(c[a+1][b]!='#'&&c[a-1][b]!='#'&&c[a][b+1]!='#'&&c[a][b-1]!='#')
    return true;
  return false;
}
int main(){
  cin>>h>>w;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin>>c[i][j];
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(c[i][j]=='#'){
        if(check(i,j)){
          cout<<"No";
          return 0;
        }
      }
    }
  }
  cout<<"Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 10001000
#define MOD 1000000007
#define rep(i, x, y) for(int i = (x); i <= (y); ++ i)
#define F(x) (x >= 10000000 ? 8 : f[x])
int f[M];
inline int Power(int x) {
	int ret = 1, t = 10;
	while(x) {
		if(x & 1) ret = 1ll * ret * t % MOD;
		x >>= 1; t = 1ll * t * t % MOD;
	}
	return ret;
}
#define num(x) (9ll * Power(x - 1) % MOD)
int main() {
	//freopen("in.txt", "r", stdin);
	int S; cin >> S;
	f[1] = 1; f[10] = 2; f[100] = 3; f[1000000] = 7;
	f[1000] = 4; f[10000] = 5; f[100000] = 6; f[10000000] = 8;
	rep(i, 1, 1e7) {
		if(!f[i]) f[i] = f[i - 1];
	}
	int r = 0, t = 0;
	int res = 0;
	rep(i, 1, (1e7) - 1) {
		r = max(r, i - 1);
		while(t + F(r + 1) <= S) ++ r, t += F(r);
		if(t == S) ++ res;
		t -= F(i);
		if(t < 0) t = 0;
	}
	rep(i, 8, S) {
		int w = S / i;
		int yu = S - w * i;
		if(w <= yu) continue;
		int a = w - yu;
		res += a / (i + 1) + (a % (i + 1) == 0 ? 0 : 1);
		if(res >= MOD) res -= MOD;
		if(yu == 0) res += MOD - 1;
		if(res >= MOD) res -= MOD;
	}
	for(int i = 1; i * i <= S; ++ i) {
		if(S % i != 0) continue;
		int x;
		if(i >= 8) {
			x = S / i;
			res += (num(i) - x + 1 + MOD) % MOD;
			if(res >= MOD) res -= MOD;	
		}
		if(S / i < 8 || i == S / i) continue;
		x = i;
		res += (num(S / i) - x + 1 + MOD) % MOD;
		if(res >= MOD) res -= MOD;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 39296
#!/usr/bin python3
# -*- coding: utf-8 -*-

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

    path =[]
    for h in range(H):
        if h%2==0:
            for w in WL:
                path.append((h, w))
        else:
            for w in WLR:
                path.append((h, w))
    ret = []
    for i in range(H*W-1):
        h, w = path[i]
        if A[h][w]%2==1:
            ret.append(i)
            hn, wn = path[i+1]
            A[hn][wn]+=1

    print(len(ret))
    for i in ret:
        h,w = path[i]
        nh,nw = path[i+1]
        print(h+1,w+1,nh+1,nw+1)

if __name__ == '__main__':
    main()

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

#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 repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long int lli;
typedef long long ll;

int main(){
    int n,T; cin >> n >> T;
    vector<int> c(n),t(n); rep(i,n) cin >> c[i] >> t[i];

    int ans = inf;
    rep(i,n){
        if(t[i] <= T) ans = min(ans, c[i]);
    }

    if(ans == inf) cout << "TLE" << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 256
H,W,K=map(int,input().split())
c=[]
for i in range(H):c.append(list(input()))
cnt,ans=0,0
for h in range(2**H):
  cnt=0
  for w in range(2**W):
    cnt=0
    for i in range(H):
      for j in range(W):
        if ((h>>i)&1) and ((w>>j)&1):
          if c[i][j]=="#":
            cnt+=1
    if cnt==K:
      ans+=1
print(ans)
          

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

#define int long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
const ld PI = acos(-1.0);
const int N = 405;
int dp[N][N];
int n,a[N] , p[N];
int solve(int l , int r)
{
	if(l > r)   return inf64;
	if(l == r)  return 0;
	if(dp[l][r] != -1) return dp[l][r];
	int res = inf64;
	for(int i=l ; i<r ; i++)
	{
		res = min(res , solve(l,i) + solve(i+1,r) + p[r] - p[l-1]);
	}
	return dp[l][r] = res;
}

int32_t main(){
	fast;
	cin >> n;
	
	f(i,1,n+1)
	{
		cin >> a[i];
		p[i] = p[i-1] + a[i];
	}
	
	memset(dp,-1,sizeof(dp));
	
	cout << solve(1,n);
}



Measured memory_bytes: 1536
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (100000 + 2)
int n, a[MAX_N];

ll calc(int large_index, int small_index, int left, int right, bool isNextLarge) {
  ll result = 0;
  if (isNextLarge) {
    large_index--;
    if (large_index <= small_index || large_index < 0) {
      // printf("1: large_index = %d, small_index = %d, left = %d, right = %d, isNextLarge = %d\n", large_index, small_index, left, right, (int)isNextLarge);
      return result;
    }

    result += abs(left - a[large_index]);
    // printf("5: result[%lld] = abs(%d - %d)\n", result, left, a[large_index]);
    left = a[large_index];

    large_index--;
    if (large_index <= small_index || large_index < 0) {
      // printf("2: large_index = %d, small_index = %d, left = %d, right = %d, isNextLarge = %d\n", large_index, small_index, left, right, (int)isNextLarge);
      return result;
    }

    result += abs(right - a[large_index]);
    // printf("6: result[%lld] = abs(%d - %d)\n", result, right, a[large_index]);
    right = a[large_index];
  }
  else {
    small_index++;
    if (small_index >= large_index || small_index >= n) {
      // printf("3: large_index = %d, small_index = %d, left = %d, right = %d, isNextLarge = %d\n", large_index, small_index, left, right, (int)isNextLarge);
      return result;
    }

    result += abs(left - a[small_index]);
    // printf("7: result[%lld] = abs(%d - %d)\n", result, left, a[small_index]);
    left = a[small_index];

    small_index++;
    if (small_index >= large_index || small_index >= n) {
      // printf("4: large_index = %d, small_index = %d, left = %d, right = %d, isNextLarge = %d\n", large_index, small_index, left, right, (int)isNextLarge);
      return result;
    }

    result += abs(right - a[small_index]);
    // printf("8: result[%lld] = abs(%d - %d)\n", result, right, a[small_index]);
    right = a[small_index];
  }

  return result + calc(large_index, small_index, left, right, !isNextLarge);

}

void exec(){
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  sort(a, a + n);

  int start = a[0];
  int end = a[n-1];

  ll a = calc(n, 0, start, start, true);
  ll b = calc(n - 1, -1, end, end, false);

  cout << max(a, b) << endl;
}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

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


Measured memory_bytes: 1408
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
#define F first
#define S second
#define MK make_pair
const ll E=1e17+7;
const ll MOD=1000000007;




int main(){
    ll n;
    cin>>n;
    vector<ll> a={1,1};
    for(int i=2;i<=44;i++){
        a.push_back(a[i-1]+a[i-2]);
    }
    cout<<a[n]<<endl;
    
    return 0;
}


Measured memory_bytes: 3156
#include <stdio.h>
int main(void){
  int i, N, x, sum=0;
  scanf("%d", &N);
  for(i=1;i<=N;i++){
    scanf("%d", &x);
    if(i!=x) sum++;
  }
  if(sum>=3){printf("NO");}
  else{printf("YES");}
}
    

Measured memory_bytes: 128
## constant

ALL_ONE = [1] * 5

### main

while true
  n = gets.strip.to_i
  break if n == 0

  bds = []

  n.times.each do
    d, p, q = gets.strip.split(' ').map{|s| s.to_i}

    if d == 1
      w = p
      h = 1
    else
      w = 1
      h = p
    end

    x = q - 1
    y = bds.length

    while y > 0
      hl = bds[y - 1]
      tf = true

      for i in (0...w)
        if hl[x + i] == 1
          tf = false
          break
        end
      end

      break if ! tf

      y -= 1
    end

    for y0 in (y...(y + h))
      if y0 >= bds.length
        bds << ([0] * 5)
      end

      for x0 in (x...(x + w))
        bds[y0][x0] = 1
      end
    end
    #p bds
    #p '---'

    bds.delete(ALL_ONE)
  end
  #p bds

  puts bds.flatten.select{|i| i == 1}.length
end

Measured memory_bytes: 6384
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

            var cin = GetIntArray().Sum();
            var ans = cin > 23 ? cin - 24 : cin;

            Console.WriteLine(ans);


            Console.Out.Flush();
            Console.ReadKey();
        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public char GetChar() { return Console.ReadLine().Trim()[0]; }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public Double[] GetDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V,W>(out T a, out U b, out V c, out W d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
        }
        static void Multi<T, U, V, W,X>(out T a, out U b, out V c, out W d,out X e)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);e = cv<X>(ar[4]);
        }
    }
}

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

using ll = long long;

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

    int n;
    cin>>n;

    ll ans=0;

    vector<int> a(3*n);

    for(int i=0;i<3*n;i++)cin>>a[i];

    sort(a.begin(),a.end(),greater<int>());

    for(int i=0;i<n;i++)ans+=a[2*i+1];

    cout<<ans<<"\n";

    return 0;
}


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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int xof[10];

int dp[100005][10][10][2]; // index, left pos, right pos, last foot

bool ok(int l, int r) {
	bool v = !l || !r || xof[l] <= xof[r];
	return v;
}

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	xof[1] = 1, xof[4] = 1, xof[7] = 1, xof[2] = 2, xof[8] = 2, xof[3] = 3, xof[6] = 3, xof[9] = 3;

	const int L = 0, R = 1;
	const int INF = 9999999;

	for (;;) {
		string s; cin >> s; if (s == "#") break;
		int n = s.length();
		s = " " + s;
		rep(i, 0, n + 1) rep(j, 0, 10) rep(k, 0, 10) dp[i][j][k][L] = dp[i][j][k][R] = INF;
		dp[0][0][0][L] = dp[0][0][0][R] = 0;
		rep(i, 1, n + 1) {
			int f = s[i] - '0';
			rep(j, 0, 10) rep(k, 0, 10) if (dp[i - 1][j][k][L] < INF || dp[i - 1][j][k][R] < INF) {
				//printf("Foot: %d, Prev: %d %d %d, L = %d, R = %d\n", f, i - 1, j, k, dp[i - 1][j][k][L], dp[i - 1][j][k][R]);
				dp[i][f][k][L] = !ok(f, k) ? INF : min(dp[i][f][k][L], min(
							// LL
							dp[i - 1][j][k][L] + 1,
							// LR
							dp[i - 1][j][k][R]));
				//if (dp[i][f][k][L] < INF)
				//	printf("%d %d %d %c: %d\n", i, f, k, 'L', dp[i][f][k][L]);
				dp[i][j][f][R] = !ok(j, f) ? INF : min(dp[i][j][f][R], min(
							// RL
							dp[i - 1][j][k][L],
							// RR
							dp[i - 1][j][k][R] + 1));
				//if (dp[i][j][f][R] < INF)
				//	printf("%d %d %d %c: %d\n", i, j, f, 'R', dp[i][j][f][R]);
			}
		}
		int ans = INF;
		rep(j, 0, 10) rep(k, 0, 10)
			ans = min(ans, min(dp[n][j][k][L], dp[n][j][k][R]));
		cout << ans << endl;
	}
}



Measured memory_bytes: 81292
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
#define pb push_back
#define ppb pop_back

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int N = 1e5 + 667;

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

    double n;
    cin >> n;
    int nn = (int) n;
    double ans = 1;
    double cnt = n / 3;
    if(nn % 3 == 0){
        ans = cnt * cnt * cnt;
    }
    else{
        ans *= cnt;
        ans *= cnt;
        n -= cnt*2;
        ans *= n;
    }
    cout << fixed;
    cout << setprecision(12) << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#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;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    t.pop_back();
    if(s == t) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3560
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main() {
  int N, A, B;
  std::cin >> N >> A >> B;
  int F{0};
  int G{0};
  std::string s;
  std::cin >> s;

  for (auto&& p : s) {
    if (p == 'a') {
      if (F < A + B) {
        F++;
        std::cout << "Yes" << std::endl;
        continue;
      }
    } else if(p=='b'){
      if(F < A+B){
        if (G < B){
          F++;
          G++;
          std::cout << "Yes" << std::endl;
          continue;
        }
      }
    }
    std::cout << "No" << std::endl;
  }
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if ((A == B && B != C) || (A != B && B == C) || (A == C && B != C)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <complex>
#include <cmath>
using namespace std;

#define EPS 1e-9

typedef complex<int> P;
typedef const P &rP;

double dot(rP a, rP b){
	return real(a) * real(b) + imag(a) * imag(b);
}

struct event{
	double tm;
	int a, b;
	
	bool operator< (const event &e) const{
		return tm < e.tm;
	}
};

struct robot{
	string name;
	vector<double> tm;
	vector<P> v;
};

vector<event> evs;

void approach(int R, int p, int q, P dp, P dv, double t0, double t1){
	vector<double> ret;

	double dt = t1 - t0;
	double a = norm(dv);
	double b = dot(dv, dp);
	double c = norm(dp) - R * R;
	double D = b * b - a * c;
	if(D > 0.0){
		D = sqrt(D);

		double t = (-b - D) / a;
		if(EPS < t && t <= dt){
			evs.push_back((event){t + t0, p, q});
		}

		t = (-b + D) / a;
		if(EPS < t && t <= dt){
			evs.push_back((event){t + t0, p, q});
		}
	}
}

void enumevent(int R, int p, int q, const robot &r1, const robot &r2){
	int k1 = 1, k2 = 1;
	int tp = 0;
	P p1 = r1.v[0], p2 = r2.v[0];
	
	if(norm(p2 - p1) <= R * R){
		evs.push_back((event){0.0, p, q});
	}
	
	while(k1 < r1.v.size() && k2 < r2.v.size()){
		int tn = min(r1.tm[k1], r2.tm[k2]);
		approach(R, p, q, p2 - p1, r2.v[k2] - r1.v[k1], tp, tn);

		p1 += r1.v[k1] * (tn - tp);
		p2 += r2.v[k2] * (tn - tp);

		if(r1.tm[k1] == tn){ ++k1; }
		if(r2.tm[k2] == tn){ ++k2; }

		tp = tn;
	}
}

int main(){
	int n, k, x, y, T, R, t;
	while(cin >> n >> T >> R, n){
		evs.clear();

		vector<robot> rbs(n);
		for(int i = 0; i < n; ++i){
			cin >> rbs[i].name;
			do{
				cin >> t >> x >> y;
				rbs[i].tm.push_back(t);
				rbs[i].v.push_back(P(x, y));
			} while(t != T);
		}

		for(int i = 0; i < n; ++i)
		for(int j = i + 1; j < n; ++j){
			enumevent(R, i, j, rbs[i], rbs[j]);
		}

		sort(evs.begin(), evs.end());
		vector<vector<char> > con(n, vector<char>(n));
		vector<char> has(n);
		has[0] = 1;

		for(int i = 0; i < evs.size(); ++i){
			int a = evs[i].a, b = evs[i].b;
			if(con[a][b]){
				con[a][b] = con[b][a] = 0;
			}
			else{
				con[a][b] = con[b][a] = 1;

				queue<int> q;
				if(has[a]){ q.push(a); }
				if(has[b]){ q.push(b); }
				while(!q.empty()){
					for(int j = 0; j < n; ++j){
						if(!has[j] && con[q.front()][j]){
							has[j] = 1;
							q.push(j);
						}
					}
					q.pop();
				}
			}
		}
		
		vector<string> ans;
		ans.reserve(n);
		for(int i = 0; i < n; ++i){
			if(has[i]){
				ans.push_back(rbs[i].name);
			}
		}
		sort(ans.begin(), ans.end());
		for(int i = 0; i < ans.size(); ++i){
			cout << ans[i] << '\n';
		}
	}
}

Measured memory_bytes: 1368
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int p, q, r;
int MAX;

int main(){
	cin >> p >> q >> r;
	MAX = max(p, q);
	MAX = max(MAX,r);
	p = p + q + r;
	p -= MAX;

	cout << p << endl;

	return 0;
}

Measured memory_bytes: 256
// abc135d: Digits Parade
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define in(x) cin>>(x)
#define oute(x) cout<<(x)<<endl

int main(){
  string s;in(s);
  int n = s.size();
  ull dp[n+1][13];
  rep(i,13) dp[0][i] = 0;
  dp[0][0] = 1;
  rep(i,n){
    rep(j,13) dp[i+1][j] = 0;
    int digit = s[i]=='?'? -1: s[i]-'0';
    rep(low,10){
      if(digit<0 || low==digit)
        rep(r,13) dp[i+1][(r*10 + low)%13] += dp[i][r];
    }
    rep(r,13) dp[i+1][r] %= MOD;
  }
  oute(dp[n][5]);
}

Measured memory_bytes: 10624
#include<stdio.h>

int main() {
  int n, m;
  int sum = 0;
  int a[255];
  int cnt = 0;

  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  for (int i = 0; i < n; i++) {
    int max = -1;
    int pos, tmp;
    for (int j = i; j < n; j++) {
      if (max < a[j]) {
        max = a[j];
        pos = j;
      }
    }
    tmp = a[i];
    a[i] = max;
    a[pos] = tmp;
    sum += a[i];
  }

  for (int i = 0; i < m; i++) {
    if (a[i] < (double)sum / (4*m)) {
      break;
    }
    cnt++;
  }

  if (cnt < m) {
    printf("No");
  } else {
    printf("Yes");
  }

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;

uint32 getd(uint64 a) {
	uint32 ret = 0;
	while (a) {
		++ret;
		a /= 10;
	}
	return ret;
}

int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint64 n;
	std::cin >> n;
	uint32 ans = 10;
	for(uint64 i=1;i<=1e5;++i) {
		if (!(n%i)) {
			ans = std::min(ans, std::max(getd(i), getd(n / i)));
		}
	}
	std::cout << ans << "\n";
	return 0;
}

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

#define mp make_pair
#define pb push_back

#define int int64_t
#define ld long double

const int MOD = 1e9+7;
const int N = 3e3+5;

int dp[N][N][2];
bool ismemo[N][N][2];
int arr[N];
int n;

int solve(int l, int r, int player) {
	if(l==r) {
		if(player==0) {
			return arr[l];
		}
		else {
			return -arr[l];
		}
	}
	if(ismemo[l][r][player]) {
		return dp[l][r][player];
	}
	ismemo[l][r][player]=1;
	if(player == 0) {
		return dp[l][r][player] = max(arr[l]+solve(l+1, r, 1), arr[r]+solve(l, r-1, 1));
	}
	return dp[l][r][player] = min(solve(l+1, r, 0)-arr[l], solve(l, r-1, 0)-arr[r]);
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0;i<n;i++) {
		cin>>arr[i];
	}

	cout<<solve(0, n-1, 0);

	return 0;
}

Measured memory_bytes: 102172
#include <stdio.h>
 
typedef struct {
  char mark;
  int num;
  int order;
} Card;
 
void BubbleSort(Card *A, int N);
void SelectionSort(Card *A, int N);
 
int main() {
  int n;
  Card C1[36], C2[36];
  int i,j;
 
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf(" %c%d", &C1[i].mark, &C1[i].num);
    C1[i].order = i;
    C2[i] = C1[i];
  }
 
  BubbleSort(C1, n);
  SelectionSort(C2, n);
 
  return 0;
}
//
void BubbleSort(Card *A, int n) {
  Card tmp;
  int stable;
  int i,j;
  int flag=1;

  while(flag){
    flag=0;
    for(j=n-1;j>=1;j--){
      if(A[j].num<A[j-1].num){
	tmp=A[j];
	A[j]=A[j-1];
	A[j-1]=tmp;
	flag=1;
      }
    }
  }
  ////
  stable = 1;
  for(i=0; i<n-1;i++) {
    printf("%c%d ", A[i].mark, A[i].num);
    if(i>0 && A[i].num==A[i-1].num && A[i].order<A[i-1].order) stable = 0;
  }
  printf("%c%d\n", A[i].mark,A[i].num);
  if(i>0 && A[i].num==A[i-1].num && A[i].order<A[i-1].order) stable = 0;
   
  if(stable==1)
    printf("Stable\n");
  else
    printf("Not stable\n");
}
 
void SelectionSort(Card A[], int n) {
  Card tmp;
  int minj;
  int stable;
  int i, j;

  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(A[j].num<A[minj].num){
	minj=j;
      }
    }
    tmp=A[i];
    A[i]=A[minj];
    A[minj]=tmp;
  }
  ////
  stable = 1;
  for(i=0;i<n-1;i++) {
    printf("%c%d ", A[i].mark,A[i].num);
    if(i>0 && A[i].num==A[i-1].num && A[i].order<A[i-1].order) stable = 0;
  }
  printf("%c%d\n", A[i].mark,A[i].num);
  if(i>0 && A[i].num==A[i-1].num && A[i].order<A[i-1].order) stable = 0;
  
  if(stable==1)
    printf("Stable\n");
  else
    printf("Not stable\n");
}
 



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

using namespace std;
const double inf = 1e100;

int n, m;
vector<int> G[600];
double P[600];
double E[600];
int main() {
  cin >> n >> m;
  for (int j = 0; j < m; ++j) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    G[a].push_back(b);
  }
  
  P[0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j : G[i]) {
      P[j] += P[i] / G[i].size();
    }
  }
  
  for (int i = n - 2; i >= 0; --i) {
    double sum = 0;
    for (int j : G[i]) {
      sum += E[j];
    }
    E[i] = sum / G[i].size() + 1;
  }
  
  double mn = 0;
  for (int i = 0; i < n; ++i) {
    int d = G[i].size();
    if (d <= 1) continue;
    for (int j : G[i]) {
      double ans = P[i] / d * (
        (d * E[i] - E[j] - 1) / (d - 1) - E[j] - 1
      );
      mn = min(mn, ans);
    }
  }
  cout << fixed << setprecision(16) << E[0] + mn << endl;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
	unsigned short *A, *B;
	
	int C[VMAX+ 1];
	int n,i,j;
	scanf("%d", &n);
	
	A = malloc(sizeof(short)*n+1);
	B = malloc(sizeof(short)*n+1);
	
	for(i = 0;i <= VMAX;i++) C[i] = 0;
	
	for(i = 0;i < n;i++){
		scanf("%hu",&A[i+1]);
		C[A[i+1]]++;
	}
	
	for(i = 1;i <= VMAX;i++) C[i] = C[i] + C[i-1];
	
	for(j = 1;j <= n;j++){
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
	
	for(i = 1;i <= n;i++){
		if(i > 1) printf(" ");
		printf("%d",B[i]);
	}
	printf("\n");
	
	return 0;
}

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

int main(){
    int group[] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
    int a,b;
    cin >> a >> b;
    if(group[a] == group[b]) cout << "Yes" << endl;
    else cout << "No" << endl;    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    int A[n], B[n], C[n], D[m], E[m], F[m];
    set<int> xs, ys;
    for (int i = 0; i < n; i++) {
        cin >> A[i] >> B[i] >> C[i];
        xs.insert(A[i]);
        xs.insert(B[i]);
        ys.insert(C[i]);
    }
    for (int i = 0; i < m; i++) {
        cin >> D[i] >> E[i] >> F[i];
        xs.insert(D[i]);
        ys.insert(E[i]);
        ys.insert(F[i]);
    }
    unordered_map<int, int> xi, yi;
    const int N = xs.size(), M = ys.size();
    vector<int> ix(N), iy(M);
    {
        int i = 0;
        for (int x : xs) { ix[i] = x; xi[x] = i++; }
        i = 0;
        for (int y : ys) { iy[i] = y; yi[y] = i++; }
    }
    queue<pair<int, int> > q;
    long long ans = 0;
    const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
    bool dir[N+1][M+1][4];
    for (int i = 0; i <= N; i++)
        for (int j = 0; j <= M; j++)
            for (int k = 0; k < 4; k++)
                dir[i][j][k] = true;
    for (int i = 0; i < n; i++) {
        // A[i], C[i] --- B[i], C[i];
        const int i1 = xi[A[i]], i2 = xi[B[i]], j = yi[C[i]];
        for (int ii = i1+1; ii <= i2; ii++) {
            dir[ii][j][1] = false;
            dir[ii][j+1][3] = false;
        }
    }
    for (int i = 0; i < m; i++) {
        const int i1 = xi[D[i]], j1 = yi[E[i]], j2 = yi[F[i]];
        for (int jj = j1+1; jj <= j2; jj++) {
            dir[i1][jj][0] = false;
            dir[i1+1][jj][2] = false;
        }
    }

    if (0 <= *xs.begin() || *xs.rbegin() <= 0 || 0 <= *ys.begin() || *ys.rbegin() <= 0) {
        cout << "INF\n";
        return 0;
    }
    
    bool used[N+1][M+1];
    memset(used, 0, sizeof used);
    for (int i = 1; i < N; i++) {
        if (ix[i-1] <= 0 && 0 <= ix[i]) {
            for (int j = 1; j < M; j++) {
                if (iy[j-1] <= 0 && 0 <= iy[j]) {
                    ans += (long long)(ix[i] - ix[i-1]) * (iy[j] - iy[j-1]);
                    q.push({i, j});
                    used[i][j] = true;
                }
            }
        }
    }
            
    while (!q.empty()) {
        int i = q.front().first, j = q.front().second;
        q.pop();
        // cerr << i << " " << j << " " << ix[i] << " " << iy[j] << endl;
        for (int k = 0; k < 4; k++) {
            if (dir[i][j][k]) {
                int i1 = i + dx[k], j1 = j + dy[k];
                if (0 <= i1 && i1 <= N && 0 <= j1 && j1 <= M && !used[i1][j1]) {
                    if (i1 == 0 || j1 == 0 || i1 == N || j1 == M) {
                        // cerr << i1 << ' ' << j1 << ' ' << ix[i1] << ' ' << iy[j1] << endl;
                        cout << "INF\n";
                        return 0;
                    }
                    ans += (long long)(ix[i1] - ix[i1-1]) * (iy[j1] - iy[j1-1]);
                    q.push({i1, j1});
                    used[i1][j1] = true;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 48160
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>

using namespace std;

void solve1() {
	string s;
	cin >> s;
	map<char, int> p;
	bool flag = false;
	for (int i = 0; i < s.size(); i++)
	{
		p[s[i]]++;
	}
	
	if (((p['W'] != 0 && p['E'] != 0) || (p['W'] == 0 && p['E'] == 0))&&
		((p['N'] != 0 && p['S'] != 0) || (p['N'] == 0 && p['S'] == 0)))flag = true;
	if (flag) {
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
}

int main() {
	solve1();
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    ll N;
    cin>>N;
    vector<ll> ls(N);
    rep(i, N) cin>>ls[i];

    sort(ls.begin(), ls.end());
    ll cnt = 0;
    rep(i, N - 2) {
        for (int j = i + 1; j < N - 1; j++) {
            cnt += distance(ls.begin() + j + 1, lower_bound(ls.begin() + j + 1, ls.end(), ls[i] + ls[j]));
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
import bisect,sys

input=sys.stdin.readline
sys.setrecursionlimit(1000000)

N=int(input())
a=list(map(int,input().split()))
edge=[[] for i in range(N)]
for i in range(N-1):
    u,v=map(int,input().split())
    edge[u-1].append(v-1)
    edge[v-1].append(u-1)

dp=[10**20 for i in range(N)]
ans=[-1 for i in range(0,N)]
def dfs(v,pv):
    pos=bisect.bisect_left(dp,a[v])
    prev=dp[pos]
    dp[pos]=a[v]
    ans[v]=bisect.bisect_left(dp,10**18)
    for i in edge[v]:
        if i==pv:
            continue

        dfs(i,v)

    dp[pos]=prev

dfs(0,-1)
for i in range(N):
    print(ans[i])


Measured memory_bytes: 356920
#include<iostream>
using namespace std;
main(){
  int n;
  int y,m,d;
  int mln=333*590+1;
  long long t;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> y >> m >> d;
    t=(y-1)/3*590+(y-1)%3*195;
    if(y%3==0) t+=(m-1)*20;
    else{
      if((m-1)%2==1){
	t+=20;
      }
      if(y%3==0)t+=(m-1)*20;
      else t+=(m-1)/2*39;
    }
    t+=d;
    cout << mln-t << endl;
  }
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    int a[n], b[m];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < m; i++)
        cin >> b[i];

    int ans = 0;
    if (a[0] <= k || b[0] <= k)
        ans = 1;
    for (int i = 1; i < n; i++)
    {
        a[i] += a[i - 1];
        if (a[i] <= k)
            ans = max(ans, i + 1);
    }
    for (int i = 1; i < m; i++)
    {
        b[i] += b[i - 1];
        if (b[i] <= k)
            ans = max(ans, i + 1);
    }
    int p1 = n - 1;
    int p2 = 0;
    while (p1 >= 0 && p2 < m)
    {
        if (a[p1] + b[p2] > k)
            p1--;
        else
        {
            ans = max(ans, p1 + p2 + 2);
            p2++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 6780
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 10000000;
static const ll MOD = 1000000007;

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : b;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int n;
	string s;
	cin >> n >> s;
	
	if(n % 2 == 1){
		cout << "No" << endl;
		return 0;
	}
	string s1, s2;
	for(int i = 0; i < n/2; ++i){
		s1 += s[i];
	}
	for(int i = 0; i < n/2; ++i){
		s2 += s[i + n/2];
	}
	if(s1 == s2) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int n;
vector<int> a;
vector<vector<bool> > used(3001, vector<bool>(3001, false));
vector<vector<long long> > memo(3001, vector<long long>(3001));
long long dfs(int left, int right, long long taro, long long jiro) {
  if (used[left][right]) return memo[left][right] + taro - jiro;
  if (left + right == n) return taro - jiro;
  used[left][right] = true;
  long long res;
  if ((left + right) % 2 == 0) { // taro
    res = max(dfs(left+1, right, taro+a[left], jiro), dfs(left, right+1, taro+a[n-right-1], jiro));
  } else {
    res = min(dfs(left+1, right, taro, jiro+a[left]), dfs(left, right+1, taro, jiro+a[n-right-1]));
  }
  memo[left][right] = res - taro + jiro;
  return res;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  cin >> n;
  REP(i, n) {
    int aa; cin >> aa;
    a.push_back(aa);
  }
  cout << dfs(0, 0, 0, 0) << '\n';
  return 0;
}


Measured memory_bytes: 74240
/***********************
*  Date: 2018.11.28    *
*  Problem:            *
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,q,appe[100010][20],coap[100010];//appe:appearance
vector <int> g[100010];

int main()
{
	cin>>n>>m;
	rep(i,m)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	cin>>q;
	repn(i,q)
	{
		int x,y;
		scanf("%d%d%d",&x,&y,&coap[i]);
		appe[x][y]=i;
	}
	for(int i=9;i>=0;i--)//算能不能覆盖appe[j][i]之前要先算出appe[p][i+1]会不会被覆盖，所以i要倒着循环 
	{
		repn(p,n)
		{
			rep(k,g[p].size())//i在这里代表可以控制的范围
			{
				int j=g[p][k];
				appe[j][i]=max(appe[j][i],appe[p][i+1]);/*远一条边距离就要加1，这里是看后者可不可以覆盖前者，
				可以说是一种dp，一个类似递归的过程，如果再之前的点把后者覆盖了，也会在前者上体现出来*/
			}	
		}	
	} 
	repn(i,n)
	{
		int lst=0;
		rep(j,11) lst=max(lst,appe[i][j]);
		cout<<coap[lst]<<endl;
	}
	rt0;
}

Measured memory_bytes: 14712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=203,INF=1<<30;
int H,W;
int dis[MAX][MAX];

vector<int> dh={0,1,0,-1},dw={1,0,-1,0};

void BFS(pair<int,int> s){
    queue<pair<int,int>> Q;
    dis[s.first][s.second]=0;
    Q.push(s);
    
    while(!Q.empty()){
        pair<int,int> a=Q.front();Q.pop();
        
        for(int i=0;i<4;i++){
            int toh=a.first+dh[i],tow=a.second+dw[i];
            
            if(0<=toh&&toh<H&&0<=tow&&tow<W&&dis[toh][tow]==INF){
                dis[toh][tow]=dis[a.first][a.second]+1;
                
                Q.push({toh,tow});
            }
        }
    }
    
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>H>>W;
    vector<string> S(H);
    pair<int,int> s,g;
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            dis[i][j]=INF;
        }
    }
    for(int i=0;i<H;i++){
        cin>>S[i];
        for(int j=0;j<W;j++){
            if(S[i][j]=='@') g={i,j};
            else if(S[i][j]=='%') s={i,j};
            else if(S[i][j]=='#') dis[i][j]=-1;
        }
    }
    
    BFS(s);
    
    
    int mini=INF;
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i][j]=='$') mini=min(mini,dis[i][j]);
        }
    }
    
    if(mini>dis[g.first][g.second]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}





Measured memory_bytes: 3440
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;
const int MOD = 1e9 + 7;

void hurui(vector<int> &hu) {
	vector<bool> table(1001, true);
	IFOR(i, 2, 1000) {
		if (!table[i])
			continue;
		hu.push_back(i);
		for (int j = 2; i*j <= 1000; j++) {
			table[i*j] = false;
		}
	}
}
int contains(int n, int p) {
	int cnt = 0;
	int pp = p;
	while (n / pp > 0) {
		cnt += n / pp;
		pp *= p;
	}
	return cnt;
}
int main() {
	int n;
	cin >> n;
	vector<int> primes;
	hurui(primes);
	long long res = 1;

	FOR(i, 0, primes.size()) {
		int p = primes[i];
		res = (res * (contains(n, p) + 1)) % MOD;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,ans=0; cin>>n;
    string s; cin>>s;
    rep(i,n-1){
        set<char> q; int cnt=0;
        for(int j=0;j<=i;j++) q.insert(s[j]);
        for(int j=i+1;j<n;j++){
            if(q.count(s[j])){
                cnt++; q.erase(s[j]);
            }
        }
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
  
  
namespace io{
    const int L = (1 << 20) + 1;
     
    char buf[L], *S , *T, c;
      
    char getchar() {
        if(S == T) {
            T = (S = buf) + fread(buf, 1, L, stdin);
            return (S == T ? EOF : *S++);
        }
        return *S++;
    }
     
    int inp() {
        int x = 0, f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    ll inp_ll() {
        ll x = 0; int f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    char B[25], *outs=B+20, *outr=B+20;
    template<class T>
    inline void print(register T a,register char x=0){
        if(x) *--outs = x, x = 0;
         
        if(!a)*--outs = '0';
        else
            while(a)
                *--outs = (a % 10) + 48, a /= 10;
         
        if(x)
            *--outs = x;
         
        fwrite(outs, outr - outs , 1, stdout);
        outs = outr;
    }
};
  
using io :: print;
using io :: inp;
using io :: inp_ll;
const int maxN = 4010;
const int MOD = 998244353;
int n,k;
ll F[maxN][maxN],C[maxN][maxN];
ll get(int a,int b)
{
	if(a == 0)
		return b == 0;
	else
		return C[a+b-1][a-1];
}
int main()
{
    F[0][0] = 1;
    for(int i=1;i<=2000;i++)   //f[i][j]在算什么？ 
    {
    	ll sum = 0;
    	for(int j = 0;j<=4000;j++)
    	{
    		F[i][j] = (sum *2 + F[i-1][j]) % MOD;
    		sum = (sum + F[i-1][j])%MOD;
		}
	}
	C[0][0] = 1;   //算二项式系数
	for(int i=1;i<=4000;i++)
	{
		C[i][0] = 1;
		for(int j = 1;j<=4000;++j)   //为什么是4000？
			C[i][j] = (C[i-1][j-1] + C[i-1][j]) % MOD; 
	} 
	k = inp();
	n = inp();
	for(int i=2;i<=2*k;++i)
	{
		int cnt = 0;
		for(int x = 1;x<=k;x++)
		{
			if(i-x >=1 && i-x <=k) cnt++;	
		}	
		//cout<<cnt<<endl;
		if(i%2 == 0)
		{
			ll ans = 0;
			for(int j = 0;j<=n;j++)
				(ans += F[(cnt-1)/2][j] * get(k-cnt,n-j) )%= MOD;       //i/2 出现次数为0 
			for(int j = 0;j<=n-1;j++)
				(ans += F[(cnt-1)/2][j] * get(k-cnt,n-j-1)) %= MOD;     //i/2出现次数为1 
			printf("%lld\n",ans);
		}
		else
		{
			ll ans = 0;
			for(int j = 0;j<=n;j++)
			{
				(ans += F[cnt/2][j] * get(k-cnt,n-j)) %= MOD;
			}
			printf("%lld\n",ans);
		}
	} 
    //printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 190720
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define clr(a,x) memset(a,x,sizeof(a))
#define SZ(x) ((int)(x).size())
#define lson rt<<1
#define rson rt<<1|1
#define pb push_back
#define fi first
#define se second
#define what_is(x) cerr<<#x<<" "<<x<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
template <typename T>
inline void _read(T& x){
    cin>>x;
}
void R(){}
template <typename T,typename... U>
void R(T&head,U&... tail){
    _read(head);
    R(tail...);
}

template <typename T>
inline void _write(const T& x){
    cout<<x<<' ';
}
void W(){cout<<endl;}
template <typename T,typename... U>
void W(const T&head,const U&... tail){
    _write(head);
    W(tail...);
}

void go();
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    go();
    return 0;
}
/****************ackun*********************/

void go(){
    string s;
    R(s);
    int len=s.length();
    int ans1=0;
    int ans2=0;
    rep(i,0,len-1){
        int w=i&1;
        if(s[i]-'0'==w){
            ans1++;
        }else{
            ans2++;
        }
    }
    W(min(ans1,ans2));
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define int long long

#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
signed main(){
    int n,X;
    cin >> n >> X;
    
    vector<ll> a(n);
    vector<ll> s(n+1);
    rep(i,n)cin >> a[i];
    ll sm = 0;
    for(int i=n-1;i>=0;i--){
        s[i]=a[i];
        sm += a[i];
        s[i] += s[i+1];
    }
    ll ans = (1LL<<60);
    
    for(int k=1;k<=n;k++){
        ll tmp = 5*sm+(n+k)*X;
        int c = n-k-1;
        int p = 0;
        while(c>=0){
            if(c-k+1 > 0){
                tmp += p*(s[c-k+1]-s[c+1]);
            }else{
                tmp += p*(s[0] - s[c+1]);
            }
            p += 2;
            c -= k;
            if(tmp > ans)break;
        }
        // cerr << k << " " << tmp << endl;
        chmin(ans,tmp); 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3456